_existsCountriesPrices) { $collection = Mage::getModel('orange35_shipping/country')->getCollection(); $countriesDictionary = $this->_getCountriesDictionary(); foreach ($collection as $key => $item) { if ($item->getCountryCode() == 'default') { $this->_defaultCountryItem = $item; $collection->removeItemByKey($key); continue; } /** @var Orange35_Shipping_Model_Country */ $item->setCountryTitle($countriesDictionary[$item->getCountryCode()]); } $this->_existsCountriesPrices = $collection; } return $this->_existsCountriesPrices; } public function getExistsCountries() { $existsCountriesPrices = $this->getExistsCountiesPrices(); $existsCountries = $this->_getCountriesDictionary(); foreach ($existsCountriesPrices as $item) { unset($existsCountries[$item->getCountryCode()]); } return $existsCountries; } protected function _getCountriesDictionary() { $countriesCollection = Mage::getModel('directory/country')->getCollection(); $countriesDictionary = array(); foreach ($countriesCollection as $item) { $countriesDictionary[$item->getCountryId()] = $item->getName(); } return $countriesDictionary; } /** * @param string $countryCode * @return Varien_Object */ public function getCountryPrices($countryCode) { if (null == $this->_countryPrices) { $collection = $this->getExistsCountiesPrices(); foreach ($collection as $item) { $this->_countryPrices[$item->getCountryCode()] = new Varien_Object($item->getData()); } } return isset($this->_countryPrices[$countryCode]) ? $this->_countryPrices[$countryCode] : new Varien_Object(); } public function getCountryTitle($countryCode) { $dictionary = $this->_getCountriesDictionary(); return isset($dictionary[$countryCode]) ? $dictionary[$countryCode] : false; } public function getDefaultAdditionPrice() { return $this->_getDefaultCountryItem()->getData('addition_price', 0); } public function getDefaultAdditionPercent() { return $this->_getDefaultCountryItem()->getData('percent', 0); } protected function _getDefaultCountryItem() { if (null == $this->_defaultCountryItem) { $collection = Mage::getModel('orange35_shipping/country') ->getCollection() ->addFieldToSelect('*') ->addFieldToFilter('country_code', array('eq' => 'default')); if (count($collection)) { $item = $collection->getFirstItem(); $this->_defaultCountryItem = new Varien_Object($item->getData()); } else { $this->_defaultCountryItem = new Varien_Object(); } } return $this->_defaultCountryItem; } public function clearCountriesTable() { $table = Mage::getModel('orange35_shipping/country') ->getResource()->getTable('orange35_shipping_country'); $adapter = Mage::getModel('core/resource')->getConnection('core_write'); $adapter->query('TRUNCATE ' . $table); return $this; } }