/** * Validate Address Rule Condition * * @param Varien_Object $object * * @return bool */ public function validate(Varien_Object $object) { $objectForParent = $object; $adressAttributes = array('weight', 'shipping_method', 'postcode', 'region', 'region_id', 'country_id'); if ($this->getAttribute() == 'method') { $objectForParent = $object->getPayment(); } if (in_array($this->getAttribute(), $adressAttributes)) { if ($object->isVirtual()) { $objectForParent = $object->getBillingAddress(); } else { $objectForParent = $object->getShippingAddress(); } try { $countryId = $objectForParent->getCountryId(); if (!is_null($countryId)) { $numOfCountryRegions = count(Mage::getModel('directory/country')->loadByCode($countryId)->getRegions()->getData()); if ($numOfCountryRegions == 0) { $objectForParent->setRegionId('0'); } } } catch (Exception $e) { Mage::log('Exception: ' . $e->getMessage() . ' in ' . __CLASS__ . ' on line ' . __LINE__); } } return parent::validate($objectForParent); }