购物车欧盟国家的价格规则
-
29-09-2020 - |
题
在购物车价格规则我可以将条件设置为“运输国家”是“或”不是“。我需要向所有欧洲联盟国家延伸这种情况。由于Magento在
中具有此配置system > configuration > general > countries options
.
有一种方法可以在购物车价格价格条件下使用它?
解决方案
没有标准功能。对于这样的规则,您应该在条件下使用任何类型:
如果要扩展标准条件模型,那么您应该执行重写并添加这样的相应条件:在重写世代odicetagcode:
的类中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;
}
.
和
/**
* 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);
}
.