opencartopencart2.xopencart-moduleopencart2.3

opencart 2.3.0.2 latest products without special prices


I want, in the latest module to be able to show only the products that don't have special price! in model/catalog/product.php I have modified getLatestProducts() function from

foreach ($query->rows as $result) {

                $product_data[$result['product_id']] = $this->getProduct($result['product_id']);

        }

with

foreach ($query->rows as $result) {
$queryCheckSpecial = $this->db->query("SELECT product_id FROM ". DB_PREFIX ."product_special WHERE product_id =".$result['product_id']);
    if (!$queryCheckSpecial->row){
        $product_data[$result['product_id']] = $this->getProduct($result['product_id']);
    }else{
        continue;
        }
    }

but it's not working! What I'm doing wrong? any help will be apreciated!


Solution

  • Edit:

    catalog\controller\extension\module\latest.php
    

    Find:

    'sort'  => 'p.date_added',
    

    Add after:

    'ignore_special'  => 1,
    

    Edit:

    catalog\model\catalog\product.php
    

    Find (first match):

    if (!empty($data['filter_name']) || !empty($data['filter_tag'])) {
    

    Add before:

    if (!empty($data['ignore_special'])) {
        $sql .= " AND (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) IS NULL";
    }
    

    Then clear your caches.