Jump to content

Edit History

ruisonika

ruisonika

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}

 

ruisonika

ruisonika

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?

×
×
  • Create New...