Пример #1
0
 /**
  * Set country filter
  *
  * @param string|Mage_Directory_Model_Country $country
  * @return Mage_Directory_Model_Resource_Country_Format_Collection
  */
 public function setCountryFilter($country)
 {
     if ($country instanceof Mage_Directory_Model_Country) {
         $countryId = $country->getId();
     } else {
         $countryId = $country;
     }
     return $this->addFieldToFilter('country_id', $countryId);
 }
 public function getCountry()
 {
     if (is_null($this->country)) {
         $this->country = Mage::getModel('directory/country');
         try {
             $this->country->loadByCode($this->getData('country_code'));
         } catch (Exception $e) {
         }
     }
     return $this->country;
 }
 /**
  * Check region
  *
  * @param array $data
  * @param Mage_Directory_Model_Country $country
  * @return bool
  */
 protected function _checkRegion($data, Mage_Directory_Model_Country $country)
 {
     /* @var $regions Mage_Directory_Model_Resource_Region_Collection */
     $regions = $country->getRegions();
     // Is it the country with predifined regions?
     if ($regions->count()) {
         if (!array_key_exists('region', $data) || empty($data['region'])) {
             $this->_addError('"State/Province" is required.');
             return false;
         }
         if (!is_string($data['region'])) {
             $this->_addError('Invalid "State/Province" type.');
             return false;
         }
         $count = $regions->addFieldToFilter(array('default_name', 'code'), array($data['region'], $data['region']))->clear()->count();
         if (!$count) {
             $this->_addError('State/Province does not exist.');
             return false;
         }
     } else {
         if (array_key_exists('region', $data) && !is_string($data['region'])) {
             $this->_addError('Invalid "State/Province" type.');
             return false;
         }
     }
     return true;
 }