Answer the question
In order to leave comments, you need to log in
How to sort by discount size in opencart?
The /specials page displays all discounted products. It is necessary that the products with the highest discount are displayed first. Or to display products with a discount greater than a certain one.
Answer the question
In order to leave comments, you need to log in
Look for the controller of the module responsible for this, it should have settings, or at least it will be written in the code where it takes the settings from (). In the standard Opencart1564, there is no such path by default, there is only a module for displaying on other pages, it is located in catalog/controller/module/special.php, if your specials page was written not quite by a crooked specialist, then he should have used the same controller. Sorting there is set by the fields:
'sort' => 'pd.name',
'order' => 'ASC',
The easiest way for stocks, at least which seemed adequate to me when solving this problem and helped me:
1. Create a column in the oc_product table and name it, for example, product_special, type INT (10)
2. In the file admin/model/catalog/product we find two functions addProduct and editProduct
3. In each of them, in the body of the function, we find a check for the existence of a stock in the product and write the following query to the oc_product table:
$this->db->query("UPDATE " . DB_PREFIX . "product SET product_special = '" . (float)$product_special['price'] . "' WHERE product_id = '" . (int)$product_id . "'");
Here is how the condition itself looks like and already the query that needs to be inserted there:
if (isset($data['product_special'])) {
foreach ($data['product_special'] as $product_special) {
$this->db->query("INSERT INTO " . DB_PREFIX . "product_special SET product_id = '" . (int)$product_id . "', customer_group_id = '" . (int)$product_special['customer_group_id'] . "', priority = '" . (int)$product_special['priority'] . "', price = '" . (float)$product_special['price'] . "', date_start = '" . $this->db->escape($product_special['date_start']) . "', date_end = '" . $this->db->escape($product_special['date_end']) . "'");
}
$this->db->query("UPDATE " . DB_PREFIX . "product SET product_special = '" . (float)$product_special['price'] . "' WHERE product_id = '" . (int)$product_id . "'");
}
$data['sorts'][] = array(
'text' => $this->language->get('text_special_asc'),
'value' => 'p.product_special-asc',
'href' => $this->url->link($route, $path . '&sort=p.product_special&order=asc' . $url)
);
$sort_data = array(
'pd.name',
'p.model',
'p.quantity',
'p.price',
и тд...
);
$sort_data = array(
'pd.name',
'p.model',
'p.quantity',
'p.price',
'rating',
'p.sort_order',
'p.date_added',
'p.product_special-asc'
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question