1

In Shopping Cart Price Rule I can set condition as "Shipping Country" "is" or "is not". I need to extend this condition to all European Union Countries. Since Magento has this configuration in

system > configuration > general > countries options

there is a way to use it in Shopping Cart Price price condition?

1 Answer 1

2

There is no standard feature. For such a rule you should use the ANY type in conditions:

enter image description here

In case you want to extend the standard condition model, then you should do the rewrite and add the appropriate condition like this:

In class where rewriting Mage_SalesRule_Model_Rule_Condition_Address:

public function loadAttributeOptions()
{
    $attributes = parent::loadAttributeOptions()->getAttributeOption();
    $additionalAttributes = array(
        'eu' => Mage::helper('salesrule')->__('Europe Union Country'),
    );
    $attributes = array_merge($attributes, $additionalAttributes);
    $this->setAttributeOption($attributes);

    return $this;
}

and

/**
 * Validate Address Rule Condition
 *
 * @param Varien_Object $object
 * @return bool
 */
public function validate(Varien_Object $object)
{
    $address = $object;
    if (!$address instanceof Mage_Sales_Model_Quote_Address) {
        if ($object->getQuote()->isVirtual()) {
            $address = $object->getQuote()->getBillingAddress();
        }
        else {
            $address = $object->getQuote()->getShippingAddress();
        }
    }
    // Eu check start
    if ('eu' == $this->getAttribute() && !$address->getEu()) {
        $this->setValue(boolval($this->getValue()));
        $euCountries = explode(',', Mage::getStoreConfig('general/country/eu_countries'));
        if (empty($euCountries)) {
            $euCountries = array();
        }
        $isEu = in_array($address->getCountry(), $euCountries);
        $address->setEu($isEu);
    }
    // Eu check end

    return parent::validate($address);
}

The field will appear in the conditions: enter image description here

Everything should work correctly in the rules: enter image description here enter image description here

2
  • I tried this by override the model file Mage_SalesRule_Model_Rule_Condition_Address in local folder but i have a blank page on cart. Didn't find any error in server log.
    – krybbio
    Commented May 19, 2016 at 7:36
  • 1
    This solution is for the rewrite model and not for the version in local. Here is an example you can use: blog.mageworx.com/2016/05/…
    – Mageworx
    Commented May 19, 2016 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.