Jump to content

Voucher Code For Multiple Shop


Recommended Posts

I have multishop configured in my prestashop..The voucher code for selected shop is not workin..Please help me...My code is as below...

 

 

 

public static function getCustomerCartRules($id_lang, $id_customer, $active = false, $includeGeneric = true, $inStock = false, Cart $cart = null)
    {
        if (!CartRule::isFeatureActive())
            return array();
 
        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
        SELECT *
        FROM `'._DB_PREFIX_.'cart_rule` cr
        LEFT JOIN `'._DB_PREFIX_.'cart_rule_lang` crl ON (cr.`id_cart_rule` = crl.`id_cart_rule` AND crl.`id_lang` = '.(int)$id_lang.')
        WHERE (
            cr.`id_customer` = '.(int)$id_customer.' OR cr.group_restriction = 1
            '.($includeGeneric ? 'OR cr.`id_customer` = 0' : '').'
        )
        AND cr.date_from < "'.date('Y-m-d H:i:s').'"
        AND cr.date_to > "'.date('Y-m-d H:i:s').'"
        '.($active ? 'AND cr.`active` = 1' : '').'
        '.($inStock ? 'AND cr.`quantity` > 0' : ''));
        //echo "<pre>";
        
        //print_r($result);
        //echo "</pre>";
        //die;
        
        /** Added  for Shop restriction *********/
         
        foreach ($result as $key => $cart_rule){
            
                $result2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
        SELECT *
        FROM `'._DB_PREFIX_.'cart_rule_shop` crs
        WHERE crs.id_cart_rule = '.$cart_rule['id_cart_rule']);
        echo "<pre>";
        
        print_r($result2);
        echo "</pre>";
        //die;
        
            if(count($result2))
            {
                //echo "<br>----------------";
                //echo "<br>SHOP".Context::getContext()->shop->id;
                
                //echo "<br>".$value2['id_shop'];
                //echo "<br>--------------------";
                foreach($result2 as $key2 =>$value2){
                if(Context::getContext()->shop->id != $value2['id_shop'])
                
                    //echo ($result[$key]);
                    unset($result[$key]);
                
                
                }
            }
         
        }

Link to comment
Share on other sites

×
×
  • Create New...