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
00033
00034
00035 class Mage_Tax_Model_Mysql4_Calculation_Rate_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
00036 {
00037 protected function _construct()
00038 {
00039 $this->_init('tax/calculation_rate');
00040 }
00041
00042 public function joinCountryTable()
00043 {
00044 $this->_select->join(
00045 array('country_table' => $this->getTable('directory/country')),
00046 'main_table.tax_country_id=country_table.country_id',
00047 array('country_name' => 'iso2_code')
00048 );
00049 return $this;
00050 }
00051
00052
00053
00054
00055
00056
00057 public function joinRegionTable()
00058 {
00059 $this->_select->joinLeft(
00060 array('region_table' => $this->getTable('directory/country_region')),
00061 'main_table.tax_region_id=region_table.region_id',
00062 array('region_name' => 'code')
00063 );
00064 return $this;
00065 }
00066
00067
00068
00069
00070
00071
00072
00073 public function joinTitle($store = null)
00074 {
00075 $storeId = Mage::app()->getStore($store)->getId();
00076 $this->_select->joinLeft(
00077 array('title_table' => $this->getTable('tax/tax_calculation_rate_title')),
00078 "main_table.tax_calculation_rate_id=title_table.tax_calculation_rate_id AND title_table.store_id = '{$storeId}'",
00079 array('title' => 'value')
00080 );
00081 return $this;
00082 }
00083
00084
00085
00086
00087
00088
00089 public function joinStoreTitles()
00090 {
00091 $storeCollection = Mage::getModel('core/store')->getCollection()->setLoadDefault(true);
00092 foreach ($storeCollection as $store) {
00093 $this->_select->joinLeft(
00094 array('title_table_' . $store->getId() => $this->getTable('tax/tax_calculation_rate_title')),
00095 "main_table.tax_calculation_rate_id=title_table_{$store->getId()}.tax_calculation_rate_id AND title_table_{$store->getId()}.store_id = '{$store->getId()}'",
00096 array('title_' . $store->getId() => 'value')
00097 );
00098 }
00099 return $this;
00100 }
00101
00102 public function addRateFilter($rateId)
00103 {
00104 if (is_int($rateId) && $rateId > 0) {
00105 return $this->_select->where('main_table.tax_rate_id=?', $rateId);
00106 }
00107 else {
00108 return $this;
00109 }
00110 }
00111
00112 public function toOptionArray()
00113 {
00114 return $this->_toOptionArray('tax_calculation_rate_id', 'code');
00115 }
00116
00117 public function toOptionHash()
00118 {
00119 return $this->_toOptionHash('tax_calculation_rate_id', 'code');
00120 }
00121
00122 }