00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 class Mage_Tax_Model_Calculation_Rate extends Mage_Core_Model_Abstract
00033 {
00034 protected $_titles = null;
00035 protected $_titleModel = null;
00036
00037
00038
00039
00040 protected function _construct()
00041 {
00042 $this->_init('tax/calculation_rate');
00043 }
00044
00045
00046
00047
00048
00049
00050 protected function _beforeSave()
00051 {
00052 parent::_beforeSave();
00053 $country = $this->getTaxCountryId();
00054 $region = $this->getTaxRegionId();
00055 $regionModel = Mage::getModel('directory/region');
00056 $regionModel->load($region);
00057 if ($regionModel->getCountryId() != $country) {
00058 $this->setTaxRegionId('*');
00059 }
00060 return $this;
00061 }
00062
00063
00064
00065
00066
00067
00068 protected function _afterSave()
00069 {
00070 $this->saveTitles();
00071 Mage::dispatchEvent('tax_settings_change_after');
00072 return parent::_afterSave();
00073 }
00074
00075
00076
00077
00078
00079
00080
00081 protected function _afterDelete()
00082 {
00083 Mage::dispatchEvent('tax_settings_change_after');
00084 return parent::_afterDelete();
00085 }
00086
00087 public function saveTitles($titles = null)
00088 {
00089 if (is_null($titles)) {
00090 $titles = $this->getTitle();
00091 }
00092
00093 $this->getTitleModel()->deleteByRateId($this->getId());
00094 if (is_array($titles) && $titles) {
00095 foreach ($titles as $store=>$title) {
00096 if ($title !== '') {
00097 $this->getTitleModel()
00098 ->setId(null)
00099 ->setTaxCalculationRateId($this->getId())
00100 ->setStoreId((int) $store)
00101 ->setValue($title)
00102 ->save();
00103 }
00104 }
00105 }
00106 }
00107
00108 public function getTitleModel()
00109 {
00110 if (is_null($this->_titleModel)) {
00111 $this->_titleModel = Mage::getModel('tax/calculation_rate_title');
00112 }
00113 return $this->_titleModel;
00114 }
00115
00116 public function getTitles()
00117 {
00118 if (is_null($this->_titles)) {
00119 $this->_titles = $this->getTitleModel()->getCollection()->loadByRateId($this->getId());
00120 }
00121 return $this->_titles;
00122 }
00123
00124 public function deleteAllRates()
00125 {
00126 $this->_getResource()->deleteAllRates();
00127 Mage::dispatchEvent('tax_settings_change_after');
00128 return $this;
00129 }
00130 }