Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top