razvy Posted March 6, 2017 Share Posted March 6, 2017 Hi, Does anyone know a free module that allows me to offer a free product when the customer is buying a specific product? Thanks! Link to comment Share on other sites More sharing options...
BeComWeb Posted March 10, 2017 Share Posted March 10, 2017 Hi, Did you have a look on cart rules native feature ? Link to comment Share on other sites More sharing options...
razvy Posted March 12, 2017 Author Share Posted March 12, 2017 Native cart rules would work, but is there a way to add a "Free gift" badge on the product list and product page so the cutomer see that there is a gift? Link to comment Share on other sites More sharing options...
BeComWeb Posted March 14, 2017 Share Posted March 14, 2017 Basically you may add a sentence in product description (A gift_product_name offers if you buy this product). If you want to add a badge or anything else, you will have to develop the feature by yourself or find a module on PS marketplace) Link to comment Share on other sites More sharing options...
ruisonika Posted February 25, 2019 Share Posted February 25, 2019 (edited) Hi guys, I've made something to achieve that. Imagine that you have created a cart rule when your customer buy one product you offer another or the same...that info only comes to client in shopping detail forward...so with the following modifications i can show in detail of the product that was an offer or in product list...In file: classes/product.php I've added this code: /* this is for know if the id has a gift */public function getFreeProductWithThisOne($id_product){ $sql = 'SELECT `id_item` FROM ps_cart_rule_product_rule_value LEFT JOIN ps_cart_rule_product_rule ON ps_cart_rule_product_rule_value.id_product_rule = ps_cart_rule_product_rule.id_product_rule LEFT JOIN ps_product ON ps_cart_rule_product_rule_value.id_item = ps_product.id_product LEFT JOIN ps_cart_rule_product_rule_group ON ps_cart_rule_product_rule.id_product_rule_group = ps_cart_rule_product_rule_group.id_product_rule_group LEFT JOIN ps_cart_rule ON ps_cart_rule.id_cart_rule = ps_cart_rule_product_rule_group.id_cart_rule WHERE code = "" AND (ps_cart_rule_product_rule_value.id_item = '.(int)$id_product.' and ps_cart_rule_product_rule.type = "products")'; $result = Db::getInstance()->getRow($sql, $use_cache = 0); return $result['id_item']; } /* this is to know what is the gift, i want reference */ public function whatIsTheGift($id_product){ $sql = 'SELECT `reference` from ps_product where `id_product` IN (SELECT gift_product FROM ps_cart_rule_product_rule_value LEFT JOIN ps_cart_rule_product_rule ON ps_cart_rule_product_rule_value.id_product_rule = ps_cart_rule_product_rule.id_product_rule LEFT JOIN ps_product ON ps_cart_rule_product_rule_value.id_item = ps_product.id_product LEFT JOIN ps_cart_rule_product_rule_group ON ps_cart_rule_product_rule.id_product_rule_group = ps_cart_rule_product_rule_group.id_product_rule_group LEFT JOIN ps_cart_rule ON ps_cart_rule.id_cart_rule = ps_cart_rule_product_rule_group.id_cart_rule WHERE code = "" AND (ps_cart_rule_product_rule_value.id_item = '.(int)$id_product.' and ps_cart_rule_product_rule.type = "products"))'; $result = Db::getInstance()->getRow($sql, $use_cache = 0); return $result['reference']; } In tpl file of your theme (product.tpl) where you want to show add this, and this will call the functions on product.php (above) {if $product->id == (Product::getFreeProductWithThisOne(Tools::getvalue('id_product')))} <div class="box--gift"> <!--i class="fa fa-gift"></i><span>REF: {Product::whatIsTheGift(Tools::getvalue('id_product'))}</span--> <img src="/img/botao_ofertas.png" alt="etiqueta de oferta" title="Na compra de {Product::whatsTheQuantity(Tools::getvalue('id_product'))} unidades, oferta de 1 uni. da Ref. {Product::whatIsTheGift(Tools::getvalue('id_product'))}"> </div> {/if} In tpl file of your theme (product-list.tpl) {assign var='productGift' value=Product::getFreeProductWithThisOne($product.id_product)} {if isset($productGift) && $productGift > 0} <span class="product-label is_gift_boxzinha" title="Produto com Oferta"> <i class="fa fa-gift"></i> <span class="is_gift_label">OFERTA</span> </span> {/if} Edited April 8, 2019 by ruisonika (see edit history) Link to comment Share on other sites More sharing options...
Alex Sanchez Posted April 8, 2019 Share Posted April 8, 2019 On 2/25/2019 at 5:39 PM, ruisonika said: Hi guys, I've made something to achieve that. In file: classes/product.php I've added this code: /* this is for know if the id has a gift */ public static function getFreeProductWithThisOne($id_product){ $sql = 'SELECT `id_item` FROM ps_cart_rule_product_rule_value LEFT JOIN ps_cart_rule_product_rule ON ps_cart_rule_product_rule_value.id_product_rule = ps_cart_rule_product_rule.id_product_rule LEFT JOIN ps_product ON ps_cart_rule_product_rule_value.id_item = ps_product.id_product LEFT JOIN ps_cart_rule_product_rule_group ON ps_cart_rule_product_rule.id_product_rule_group = ps_cart_rule_product_rule_group.id_product_rule_group LEFT JOIN ps_cart_rule ON ps_cart_rule.id_cart_rule = ps_cart_rule_product_rule_group.id_cart_rule WHERE code = "" AND (ps_cart_rule_product_rule_value.id_item = '.(int)$id_product.' and ps_cart_rule_product_rule.type = "products")'; $result = Db::getInstance()->getRow($sql, $use_cache = 0); return $result['id_item']; } /* this is to know what is the gift, i want reference */ public static function whatIsTheGift($id_product){ $sql = 'SELECT `reference` from ps_product where `id_product` IN (SELECT gift_product FROM ps_cart_rule_product_rule_value LEFT JOIN ps_cart_rule_product_rule ON ps_cart_rule_product_rule_value.id_product_rule = ps_cart_rule_product_rule.id_product_rule LEFT JOIN ps_product ON ps_cart_rule_product_rule_value.id_item = ps_product.id_product LEFT JOIN ps_cart_rule_product_rule_group ON ps_cart_rule_product_rule.id_product_rule_group = ps_cart_rule_product_rule_group.id_product_rule_group LEFT JOIN ps_cart_rule ON ps_cart_rule.id_cart_rule = ps_cart_rule_product_rule_group.id_cart_rule WHERE code = "" AND (ps_cart_rule_product_rule_value.id_item = '.(int)$id_product.' and ps_cart_rule_product_rule.type = "products"))'; $result = Db::getInstance()->getRow($sql, $use_cache = 0); return $result['reference']; } In tpl file of your theme (product.tpl) where you want to show add this, and this will call the functions on product.php (above) {if $product->id == (Product::getFreeProductWithThisOne(Tools::getvalue('id_product')))} <div class="box--gift" title="Oferta da Ref: {Product::whatIsTheGift(Tools::getvalue('id_product'))} na compra deste produto"> <i class="fa fa-gift"></i><span>REF: {Product::whatIsTheGift(Tools::getvalue('id_product'))}</span> </div> {/if} And now i'm stucked how to show a small icon on product list whenever there is a gift with the product... Can someone help me? Hi ! What you got with that? I'm trying it but nothing show on the product edit. Link to comment Share on other sites More sharing options...
ruisonika Posted April 8, 2019 Share Posted April 8, 2019 57 minutes ago, Alex Sanchez said: Hi ! What you got with that? I'm trying it but nothing show on the product edit. Hi Alex... The code above is only to show something if the product himself has a offer (gift product)...the gifts are made in cart rules... but when you make a cart rule with gift...the gift it's only showed in shopping cart details, and i think that the customer must see the gift in product list or in product detail. And that's why i made this code (for me and it works)... Link to comment Share on other sites More sharing options...
Alex Sanchez Posted April 8, 2019 Share Posted April 8, 2019 1 hour ago, ruisonika said: Hi Alex... The code above is only to show something if the product himself has a offer (gift product)...the gifts are made in cart rules... but when you make a cart rule with gift...the gift it's only showed in shopping cart details, and i think that the customer must see the gift in product list or in product detail. And that's why i made this code (for me and it works)... Hi ruisonika Oh okay! Will test it!! So to understand better: 1- put the code In file: classes/product.php 2- Put in tpl also. 3- add a cart rule for BUY PRODUCT_ID_233 and get PRODUCT_ID_244 as gift (it's only an example) That's right ? So i will see in the product.tpl or product-list.tpl the GIFT for the product ? Let me know please! Regards Link to comment Share on other sites More sharing options...
ruisonika Posted April 8, 2019 Share Posted April 8, 2019 1 hour ago, Alex Sanchez said: Hi ruisonika Oh okay! Will test it!! So to understand better: 1- put the code In file: classes/product.php 2- Put in tpl also. 3- add a cart rule for BUY PRODUCT_ID_233 and get PRODUCT_ID_244 as gift (it's only an example) That's right ? So i will see in the product.tpl or product-list.tpl the GIFT for the product ? Let me know please! Regards yeah that's right...the only perhaps is that you don't see the product gift (you could change the code to see) but my result is in the images attached. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now