Good day. How does Opencart 2 define new products? How, for example, to increase their number? Searching on the Internet, it became clear that Opencart 2 forms new items by date of addition. But where is this setting? Is it 3 days, 5 days, 10? And how to manage it? Thank.
2 answers
If you are talking about the standard Latest module, then look for the following lines in the catalog\controller\module\latest.php :
$filter_data = array( 'sort' => 'p.date_added', 'order' => 'DESC', 'start' => 0, 'limit' => $setting['limit'] ); $results = $this->model_catalog_product->getProducts($filter_data); This is a call to the getProducts() model method. The $ results will return the array of products that have been edited by date_added DESC , in the amount of $setting['limit'] that you specify in the module settings in the admin panel. And you donβt manage the days. To do this, you need to slightly change the logic:
//catalog\controller\module\latest.php $filter_data = array( 'sort' => 'p.date_added', 'order' => 'DESC', 'start' => 0, 'limit' => $setting['limit'], // Π΄ΠΎΠ±Π°Π²ΠΈΠΌ Π² ΡΠΈΠ»ΡΡΡ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ Π΄Π½Π΅ΠΉ, Π·Π° ΠΊΠΎΡΠΎΡΡΠ΅ Ρ
ΠΎΡΠΈΠΌ ΠΏΠΎΠ»ΡΡΠΈΡΡ Π½ΠΎΠ²ΠΈΠ½ΠΊΠΈ 'days' => '10', ); //catalog\model\catalog\product.php //ΠΈΡΠΈΡΠ΅ ΡΠ°ΠΊΠΎΠΉ Π±Π»ΠΎΠΊ ΠΊΠΎΠ΄Π°: $sql .= " LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status <> 0 AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'"; //ΠΈ ΠΏΠΎΡΠ»Π΅ Π½Π΅Π³ΠΎ Π²ΡΡΠ°Π²Π»ΡΠ΅ΡΠ΅ ΠΏΡΠΎΠ²Π΅ΡΠΊΡ ΠΏΠΎΡΠ»Π΅Π΄Π½ΠΈΡ
Π΄Π½Π΅ΠΉ. if(isset($data['days'])){ $sql .= " AND p.date_added > (NOW() - INTERVAL ". (int)$data['days'] ." DAY)"; } The number changes in the admin, in the module settings, change the limit.
Edit the date in mysql, using phpmyadmin or upload via admin panel - export \ import (oc_product branch), you are interested in date_added and date_modified , editing with any familiar editor, you will achieve the necessary sorting, then save and import back.