1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Shipping
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Shipping table rates collection
29: *
30: * @category Mage
31: * @package Mage_Shipping
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
35: {
36: /**
37: * main table name
38: *
39: * @deprecated since 1.4.1.0
40: * @var string
41: */
42: protected $_shipTable;
43:
44: /**
45: * directory/country table name
46: *
47: * @var string
48: */
49: protected $_countryTable;
50:
51: /**
52: * directory/country_region table name
53: *
54: * @var string
55: */
56: protected $_regionTable;
57:
58: /**
59: * Define resource model and item
60: *
61: */
62: protected function _construct()
63: {
64: $this->_init('shipping/carrier_tablerate');
65: $this->_shipTable = $this->getMainTable();
66: $this->_countryTable = $this->getTable('directory/country');
67: $this->_regionTable = $this->getTable('directory/country_region');
68: }
69:
70: /**
71: * Initialize select, add country iso3 code and region name
72: *
73: * @return void
74: */
75: public function _initSelect()
76: {
77: parent::_initSelect();
78:
79: $this->_select
80: ->joinLeft(
81: array('country_table' => $this->_countryTable),
82: 'country_table.country_id = main_table.dest_country_id',
83: array('dest_country' => 'iso3_code'))
84: ->joinLeft(
85: array('region_table' => $this->_regionTable),
86: 'region_table.region_id = main_table.dest_region_id',
87: array('dest_region' => 'code'));
88:
89: $this->addOrder('dest_country', self::SORT_ORDER_ASC);
90: $this->addOrder('dest_region', self::SORT_ORDER_ASC);
91: $this->addOrder('dest_zip', self::SORT_ORDER_ASC);
92: $this->addOrder('condition_value', self::SORT_ORDER_ASC);
93: }
94:
95: /**
96: * Add website filter to collection
97: *
98: * @param int $websiteId
99: * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection
100: */
101: public function setWebsiteFilter($websiteId)
102: {
103: return $this->addFieldToFilter('website_id', $websiteId);
104: }
105:
106: /**
107: * Add condition name (code) filter to collection
108: *
109: * @param string $conditionName
110: * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection
111: */
112: public function setConditionFilter($conditionName)
113: {
114: return $this->addFieldToFilter('condition_name', $conditionName);
115: }
116:
117: /**
118: * Add country filter to collection
119: *
120: * @param string $countryId
121: * @return Mage_Shipping_Model_Resource_Carrier_Tablerate_Collection
122: */
123: public function setCountryFilter($countryId)
124: {
125: return $this->addFieldToFilter('dest_country_id', $countryId);
126: }
127: }
128: