Jump to content

How to display products randomly on promotion block.


hurray

Recommended Posts

Hi,

I am using prestashop 1.5.6.2. On my promotion block that appears on the right-hand side of the webiste, right now there are 3 products that get displayed. These products do not change at all, no matter how many times I refresh my browser. On top of that, 2 of the products on the block at the most expensive products that are on promotion. I do not want them to show there.

How can I randomize the products that show in this block?

Link to comment
Share on other sites

Hi Nemo, please look at the right-hand side on my homepage http://www.savdana.com/. The block that is all the way at the bottom is called "Promotions" and it displays 3 products and sorts them "High-to-Low" according to the price. I would like them to sort eithr "Low-to-High" pricewise or randomly. Whichever can be done easily will be fine with me.

May be this makes it clearer to you now.

Link to comment
Share on other sites

Hi Nemo,

Finally I figured out the name of this block. It is "Multiple Specials block". ON the back-end the number of product to display is set to 3.

Now here is what I have in blockmultiplespecials.php for hookRightColumn

 

public function hookRightColumn($params)
    {
        $nbr=Configuration::get('BLOCKSPECIALS_NBR');

            $products = Product::getPricesDrop($this->context->language->id, 0, $nbr, false);

            $this->smarty->assign(array(
                'products' => $products,
                'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
                'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
            ));
        
        return $this->display(__FILE__, 'blockmultiplespecials.tpl');
    }

Link to comment
Share on other sites

You can add a further parameter for the order by
 

public static function getPricesDrop($id_lang, $page_number = 0, $nb_products = 10, $count = false,
$order_by = null, $order_way = null, $beginning = false, $ending = false, Context $context = null)

I guess you want to set that to price? Then add 'asc' as next parameter as well
Link to comment
Share on other sites

  • 2 weeks later...
  • 9 months later...

Well, I tried a lot of times to get it working with random way but I gave up.

 

My solution is to show the products in date update DESC to show last edited promotions.

 

My  working code is 

getPricesDrop((int)$params['cookie']->id_lang, 0, Configuration::get('BLOCKSPECIALS_SPECIALS_NBR'), 0, 'date_upd', 'DESC');

but I tried with

getPricesDrop((int)$params['cookie']->id_lang, 0, Configuration::get('BLOCKSPECIALS_SPECIALS_NBR'), 0, 'name', 'RAND');

or

getPricesDrop((int)$params['cookie']->id_lang, 0, Configuration::get('BLOCKSPECIALS_SPECIALS_NBR'), 0, 'name', 'RAND()');

but none of these worked - any help to get this random?

Link to comment
Share on other sites

Well, none of theese working either:

getPricesDrop((int)$params['cookie']->id_lang, 0, Configuration::get('BLOCKSPECIALS_SPECIALS_NBR'), 0, 'RAND()');

is giving lot of print_r arrays/objects on page

getPricesDrop((int)$params['cookie']->id_lang, 0, Configuration::get('BLOCKSPECIALS_SPECIALS_NBR'), 0, 'RAND');

is giving SQL error Unknown column 'RAND' in 'order clause' and the end of query looks like this

ORDER BY RAND DESC
LIMIT 0, 12
 
I just trully don't know the reason :/
Link to comment
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
×
×
  • Create New...