00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Tax 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 /** 00028 * Tax Rule Model 00029 * 00030 * @author Magento Core Team <core@magentocommerce.com> 00031 */ 00032 class Mage_Tax_Model_Calculation_Rule extends Mage_Core_Model_Abstract 00033 { 00034 protected $_ctcs = null; 00035 protected $_ptcs = null; 00036 protected $_rates = null; 00037 00038 protected $_ctcModel = null; 00039 protected $_ptcModel = null; 00040 protected $_rateModel = null; 00041 00042 protected $_calculationModel = null; 00043 00044 /** 00045 * Varien model constructor 00046 */ 00047 protected function _construct() 00048 { 00049 $this->_init('tax/calculation_rule'); 00050 } 00051 00052 /** 00053 * After save rule 00054 * Redeclared for populate rate calculations 00055 * 00056 * @return Mage_Tax_Model_Calculation_Rule 00057 */ 00058 protected function _afterSave() 00059 { 00060 parent::_afterSave(); 00061 $this->saveCalculationData(); 00062 Mage::dispatchEvent('tax_settings_change_after'); 00063 return $this; 00064 } 00065 00066 /** 00067 * After rule delete 00068 * redeclared for dispatch tax_settings_change_after event 00069 * 00070 * @return Mage_Tax_Model_Calculation_Rule 00071 */ 00072 protected function _afterDelete() 00073 { 00074 Mage::dispatchEvent('tax_settings_change_after'); 00075 return parent::_afterDelete(); 00076 } 00077 00078 public function saveCalculationData() 00079 { 00080 $ctc = $this->getData('tax_customer_class'); 00081 $ptc = $this->getData('tax_product_class'); 00082 $rates = $this->getData('tax_rate'); 00083 00084 Mage::getSingleton('tax/calculation')->deleteByRuleId($this->getId()); 00085 foreach ($ctc as $c) { 00086 foreach ($ptc as $p) { 00087 foreach ($rates as $r) { 00088 $dataArray = array( 00089 'tax_calculation_rule_id' =>$this->getId(), 00090 'tax_calculation_rate_id' =>$r, 00091 'customer_tax_class_id' =>$c, 00092 'product_tax_class_id' =>$p, 00093 ); 00094 Mage::getSingleton('tax/calculation')->setData($dataArray)->save(); 00095 } 00096 } 00097 } 00098 } 00099 00100 public function getCalculationModel() 00101 { 00102 if (is_null($this->_calculationModel)) { 00103 $this->_calculationModel = Mage::getSingleton('tax/calculation'); 00104 } 00105 return $this->_calculationModel; 00106 } 00107 00108 public function getRates() 00109 { 00110 return $this->getCalculationModel()->getRates($this->getId()); 00111 } 00112 00113 public function getCustomerTaxClasses() 00114 { 00115 return $this->getCalculationModel()->getCustomerTaxClasses($this->getId()); 00116 } 00117 00118 public function getProductTaxClasses() 00119 { 00120 return $this->getCalculationModel()->getProductTaxClasses($this->getId()); 00121 } 00122 }