Jump to content

Block new products sorted by add_date not by ID


hurraken
 Share

Recommended Posts

Change this code in blocknewproducts.php:

$newProducts = Product::getNewProducts(intval($params['cookie']->id_lang), 0, Configuration::get('NEW_PRODUCTS_NBR'));



to this:

$newProducts = Product::getNewProducts(intval($params['cookie']->id_lang), 0, Configuration::get('NEW_PRODUCTS_NBR'), false, 'date_add', 'DESC');



Now, while I was going to post the code above, I found this. In Product::getNewProducts(), I see this code:

if (empty($orderBy) || $orderBy == 'position') $orderBy = 'date_add';
       if (empty($orderWay)) $orderWay = 'DESC';


Which leads me to think that it defaults to date_add DESC.

How is yours coming up, anyway? What version of PS are you using?

Share this post


Link to post
Share on other sites

Hello MrBaseball34,

Thank you very much for your reply.

I made a mistake, i use HomeNewProducts from Prestacrea :

The code is this one :

   function hookHome($params)
   {
   global $smarty, $cookie;

     $category = new Category(1);
     $nb = intval(Configuration::get('HOME_NEW_PRODUCTS_NBR'));
   $rand = intval(Configuration::get('HOME_NEW_PRODUCTS_RANDOM'));
   if ($rand == 1) {
     $products = Product::getNewProducts(intval($cookie->id_lang), 0, $nb); 
   if ( $products )
   {
   shuffle($products);
   array_splice($products, ($nb ? $nb : 10));
   }
   }
   else 
   {
     $products = Product::getNewProducts(intval($cookie->id_lang), NULL - 0, (intval($nb ? $nb : 4)), false, NULL, NULL);
   }        



I'm using Pretsashop 1.3.7

Best regards

Share this post


Link to post
Share on other sites

Here's what this code tells me:

function hookHome($params) {
 global $smarty, $cookie;
 $category = new Category(1);


Get configuration parameters:

 $nb = intval(Configuration::get('HOME_NEW_PRODUCTS_NBR'));
 $rand = intval(Configuration::get('HOME_NEW_PRODUCTS_RANDOM'));


If you want random new products, get the list of new products and
shuffle them in a random order.

 if ($rand == 1) {
   $products = Product::getNewProducts(intval($cookie->id_lang), 0, $nb); 
   if ( $products ) {
     shuffle($products);
     array_splice($products, ($nb ? $nb : 10));
   }


otherwise, get the regular list of products in date_add DESC order.

 } else {
   $products = Product::getNewProducts(intval($cookie->id_lang), NULL - 0, (intval($nb ? $nb : 4)), false, NULL, NULL);
 } 
}



So, all you have to do is set the HOME_NEW_PRODUCTS_RANDOM to 0 in ps_configuration to make the items come out
in the order you want. It is probably a configuration parameter in the module that you are
using.

Share this post


Link to post
Share on other sites

  • 3 months later...

Do Prestacrea make a module to randomize the New Products Block?
Or is there another solution? I'd like the New Products block to randomly show a different product on page load rather than the same one all the time!

Or even better would be a JQuery sliding block to cycle through a few new products..
Any suggestions? :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More