How to display this product has cart rule in prestashop 1.6

1.3k views Asked by At

For prestashop 1.6 We have set cart rules for specific product, by adding 3products, another 1 product would be added as gift,

This is all working well on cart page,

but how to display this on that specific product page

$context::$this->$cart->$getCartRules();

not showing on product page

We have to display cart rule on specific product which is having respected cart rules,

ex. "buy this product and you will get xyz product for free"
3

There are 3 answers

0
STOCKED On

My solution in Product.php

 public function getRule($category = "0"){
   $rules = Db::getInstance()->executeS('SELECT *,rg.quantity as minimum_quantity FROM `'._DB_PREFIX_.'cart_rule_product_rule_value` cv 
            LEFT JOIN `'._DB_PREFIX_.'cart_rule_product_rule` pr ON cv.id_product_rule = pr.id_product_rule 
            LEFT JOIN `'._DB_PREFIX_.'cart_rule_product_rule_group` rg ON pr.id_product_rule_group = rg.id_product_rule_group
            LEFT JOIN `'._DB_PREFIX_.'cart_rule` cr ON cr.id_cart_rule = rg.id_cart_rule
            WHERE code = "" and ((cv.id_item = '.$this->id.' and type = "products") or (cv.id_item = '.$category.' and type = "categories")) AND cr.date_to >= "'.date("Y-m-d H:i:s").'"'
    );
    return $rules;
}
0
issinatour muñoz On

i think u will have to build your own query selecting the cart_rules with your gift_product id that still actives.

Add an static method in CartRule (or where u need) and call in the product.tpl directly and show it

ex: {CartRule::getGifts($product.id)} then, handle the result

0
SagarPPanchal On

Build custom query for the same :

$result = Db::getInstance()->executeS('
            SELECT *,rg.quantity as minimum_quantity FROM `'._DB_PREFIX_.'cart_rule_product_rule_value` cv 
                LEFT JOIN `'._DB_PREFIX_.'cart_rule_product_rule` pr ON cv.id_product_rule = pr.id_product_rule 
                LEFT JOIN `'._DB_PREFIX_.'cart_rule_product_rule_group` rg ON pr.id_product_rule_group = rg.id_product_rule_group
                LEFT JOIN `'._DB_PREFIX_.'cart_rule` cr ON cr.id_cart_rule = rg.id_cart_rule
                WHERE cv.id_item = '.$this->id_product.' AND cr.gift_product > 0 AND cr.date_to >= "'.date("Y-m-d H:i:s").'"'
            );