Jump to content

Can't Get Voucher Highlight To Work Properly


Recommended Posts

Hi, 

 

I am running PS 1.6.1.4 on PHP7 and default theme and I face an issue with voucher highlights. I setup one to provide free shipping on order more than 45$. This one has no code and highlight is on. At checkout, it is displayed under the voucher code box as I want it. Then I setup another one, same config except that I send a gift on order over 15$. This one does not show up under the voucher box, but does get added to the cart when the rule applies. I would like to have it displayed like the free shipping is. Am I missing something?

 

I cleared PS cache (even turned it off entirely), cleared browser cache, no luck, cannot get this working :-(

 

Any help appreciated!

Thanks!

Link to comment
Share on other sites

Hi, 

 

I tracked down this issue and I think I found the cause. I think this is a bug in the CartRule.php file.

 

Here is the deal; I setup free shipping for order above a given amount for some countries. Then I setup gift product for order above a given amount, without any restriction. Given this setup, the problem seems to be in the CartRule.php file. In the function getCustomerCartRules, the last part scans for country restrictions. As soon as one voucher is country restricted, it seems like it is assumed that all voucher will be. If they are not, they will not be copied back to the result array. 

 

So I changed this part of code (line 350 to 380 in the current code base on GitHub) :

 $result_bak = $result;
        $result = array();
        $country_restriction = false;
        foreach ($result_bak as $key => $cart_rule) {
            if ($cart_rule['country_restriction']) {
                $country_restriction = true;
                $countries = Db::getInstance()->ExecuteS('
                    SELECT `id_country`
                    FROM `'._DB_PREFIX_.'address`
                    WHERE `id_customer` = '.(int)$id_customer.'
                    AND `deleted` = 0'
                );
                if (is_array($countries) && count($countries)) {
                    foreach ($countries as $country) {
                        $id_cart_rule = (bool)Db::getInstance()->getValue('
                            SELECT crc.id_cart_rule
                            FROM '._DB_PREFIX_.'cart_rule_country crc
                            WHERE crc.id_cart_rule = '.(int)$cart_rule['id_cart_rule'].'
                            AND crc.id_country = '.(int)$country['id_country']);
                        if ($id_cart_rule) {
                            $result[$id_cart_rule] = $result_bak[$key];
                        }
                    }
                }
            }
        }
        if (!$country_restriction) {
            $result = $result_bak;
        }

with this code:

$country_restriction = false;
foreach ($result as $key => $cart_rule) {
	if ($cart_rule['country_restriction']) {
		$country_restriction = true;
		$countries = Db::getInstance()->ExecuteS('
			SELECT `id_country`
			FROM `'._DB_PREFIX_.'address`
			WHERE `id_customer` = '.(int)$id_customer.'
			AND `deleted` = 0'
		);

		if (is_array($countries) && count($countries)) {
			foreach ($countries as $country) {
			   $id_cart_rule = (bool)Db::getInstance()->getValue('
					SELECT crc.id_cart_rule
					FROM '._DB_PREFIX_.'cart_rule_country crc
					WHERE crc.id_cart_rule = '.(int)$cart_rule['id_cart_rule'].'
					AND crc.id_country = '.(int)$country['id_country']);
				if (!$id_cart_rule) {
					unset($result[$key]);
				}
			}
		}
	}
}

This solved it for me, however I am not familiar with the code base so I cannot tell if this fix is the proper one in all cases. Also, I would suggest that the customer country query should be done only once, not for all vouchers.

 

Hope this helps!

 

Thanks!

Edited by bergie (see edit history)
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...