DARKF3D3 Posted February 17, 2013 Share Posted February 17, 2013 Someone know how to the number of products shown in new products never Does anyone know how to make that the number of products in the "new products" never falls below a pre-set number, like 4. I would like to ensure that even if I dont add new products for a long time, prestashop always shown some of the last products addes, but i dont' want to increase the range that now I set it to 14 days. Link to comment Share on other sites More sharing options...
Paulito Posted February 17, 2013 Share Posted February 17, 2013 Good morning, I suppose he easiest way would be to have a category called "New Products" and add or subtract when you wish, at least this would be easier than changing codes etc Paul Link to comment Share on other sites More sharing options...
DARKF3D3 Posted February 17, 2013 Author Share Posted February 17, 2013 That could be the easiest solution, but not very pratical, because i add like 40-50 products a month. The best solution would be something that automatically do that. Link to comment Share on other sites More sharing options...
PascalVG Posted February 17, 2013 Share Posted February 17, 2013 Think you have to override product.php and change the function getNewProducts a little. Give it a try Pascal Link to comment Share on other sites More sharing options...
PascalVG Posted February 18, 2013 Share Posted February 18, 2013 (edited) Well, I found some solution. Not the most elegant one, but it works... Backoffice products tab should be adjusted (i.e. some field should be added to it), if you want to change the # of products and the '# of days as sort of new' in the BO, instead of directly in the code. But if you're happy to install it once, and forget (until you update your Prestshop version...Make a BIG note to do this!), then: edit your /modules//blocknewproducts/blocknewproducts.php find the line: if (!$newProducts && !Configuration::get('PS_BLOCK_NEWPRODUCTS_DISPLAY')) return; then add directly after this: (sorry, tabs are gone in my code snippet, please align with original code elseif (!$newProducts) // we always want some 'new' products to show { $originalDays = Configuration::get('PS_NB_DAYS_NEW_PRODUCT'); // remember the original nmbr of days regarded as new Configuration::updateValue('PS_NB_DAYS_NEW_PRODUCT', '1000'); // change to about 3 years of 'new-ness' $newProducts = Product::getNewProducts((int)($params['cookie']->id_lang), 0, 4, false, 'date_add'); // 4 = number of products to show Configuration::updateValue('PS_NB_DAYS_NEW_PRODUCT', $originalDays); // put it back neatly } Save the file and see if it works... Hope this helps, Pascal N.B. Short description what it does: Check first if there are no new products according to normal rules. (If there are, it will just display these as normal (i.e. amount of products shown as indicated in configuration of the module) if no new products found, temporarily save the days a product is considered new. Then change this date to 1000 days (about 3 years, should be enough) Re-run finding 'New' products, using these 1000 days requirements this time. Limit the amount of selected products to 4. It takes the for lates added products (by using the 'date_add' parameter...) restore the original number of days considered as new. Continue with the module code with either the original, real new products, or the newly found 'New' products. (if there are still no products found within the 1000 days interval, it will display the 'No new products found' message as before) Edited February 18, 2013 by PascalVG (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts