1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Tax_Model_Resource_Calculation_Rate_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
36: {
37: 38: 39:
40: protected function _construct()
41: {
42: $this->_init('tax/calculation_rate');
43: }
44:
45: 46: 47: 48: 49:
50: public function joinCountryTable()
51: {
52: $this->_select->join(
53: array('country_table' => $this->getTable('directory/country')),
54: 'main_table.tax_country_id = country_table.country_id',
55: array('country_name' => 'iso2_code')
56: );
57:
58: return $this;
59: }
60:
61: 62: 63: 64: 65:
66: public function joinRegionTable()
67: {
68: $this->_select->joinLeft(
69: array('region_table' => $this->getTable('directory/country_region')),
70: 'main_table.tax_region_id = region_table.region_id',
71: array('region_name' => 'code')
72: );
73: return $this;
74: }
75:
76: 77: 78: 79: 80: 81:
82: public function joinTitle($store = null)
83: {
84: $storeId = (int)Mage::app()->getStore($store)->getId();
85: $this->_select->joinLeft(
86: array('title_table' => $this->getTable('tax/tax_calculation_rate_title')),
87: $this->getConnection()->quoteInto('main_table.tax_calculation_rate_id = title_table.tax_calculation_rate_id AND title_table.store_id = ?', $storeId),
88: array('title' => 'value')
89: );
90:
91: return $this;
92: }
93:
94: 95: 96: 97: 98:
99: public function joinStoreTitles()
100: {
101: $storeCollection = Mage::app()->getStores(true);
102: foreach ($storeCollection as $store) {
103: $tableAlias = sprintf('title_table_%s', $store->getId());
104: $joinCondition = implode(' AND ', array(
105: "main_table.tax_calculation_rate_id = {$tableAlias}.tax_calculation_rate_id",
106: $this->getConnection()->quoteInto($tableAlias . '.store_id = ?', $store->getId())
107: ));
108: $this->_select->joinLeft(
109: array($tableAlias => $this->getTable('tax/tax_calculation_rate_title')),
110: $joinCondition,
111: array($tableAlias => 'value')
112: );
113: }
114: return $this;
115: }
116:
117: 118: 119: 120: 121: 122:
123: public function addRateFilter($rateId)
124: {
125: if (is_int($rateId) && $rateId > 0) {
126: return $this->addFieldToFilter('main_table.tax_rate_id', $rateId);
127: }
128:
129: return $this;
130: }
131:
132: 133: 134: 135: 136:
137: public function toOptionArray()
138: {
139: return $this->_toOptionArray('tax_calculation_rate_id', 'code');
140: }
141:
142: 143: 144: 145: 146:
147: public function toOptionHash()
148: {
149: return $this->_toOptionHash('tax_calculation_rate_id', 'code');
150: }
151:
152: 153: 154: 155: 156: 157: 158: 159:
160: public function toOptionHashOptimized()
161: {
162: return $this->_toOptionHashOptimized('tax_calculation_rate_id', 'code');
163: }
164: }
165:
166: