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_Tax
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: class Mage_Tax_Model_Class_Source_Product extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
29: {
30: /**
31: * Get all options
32: *
33: * @return array
34: */
35: public function getAllOptions($withEmpty = false)
36: {
37: if (is_null($this->_options)) {
38: $this->_options = Mage::getResourceModel('tax/class_collection')
39: ->addFieldToFilter('class_type', Mage_Tax_Model_Class::TAX_CLASS_TYPE_PRODUCT)
40: ->load()
41: ->toOptionArray();
42: }
43:
44: $options = $this->_options;
45: array_unshift($options, array('value'=>'0', 'label'=>Mage::helper('tax')->__('None')));
46: if ($withEmpty) {
47: array_unshift($options, array('value'=>'', 'label'=>Mage::helper('tax')->__('-- Please Select --')));
48: }
49: return $options;
50: }
51:
52: /**
53: * Get a text for option value
54: *
55: * @param string|integer $value
56: * @return string
57: */
58: public function getOptionText($value)
59: {
60: $options = $this->getAllOptions(false);
61:
62: foreach ($options as $item) {
63: if ($item['value'] == $value) {
64: return $item['label'];
65: }
66: }
67: return false;
68: }
69:
70: /**
71: * Convert to options array
72: *
73: * @return array
74: */
75: public function toOptionArray()
76: {
77: return $this->getAllOptions();
78: }
79:
80: /**
81: * Retrieve flat column definition
82: *
83: * @return array
84: */
85: public function getFlatColums()
86: {
87: $attributeCode = $this->getAttribute()->getAttributeCode();
88: $column = array(
89: 'unsigned' => true,
90: 'default' => null,
91: 'extra' => null
92: );
93:
94: if (Mage::helper('core')->useDbCompatibleMode()) {
95: $column['type'] = 'int';
96: $column['is_null'] = true;
97: } else {
98: $column['type'] = Varien_Db_Ddl_Table::TYPE_INTEGER;
99: $column['nullable'] = true;
100: $column['comment'] = $attributeCode . ' tax column';
101: }
102:
103: return array($attributeCode => $column);
104: }
105:
106: /**
107: * Retrieve Select for update attribute value in flat table
108: *
109: * @param int $store
110: * @return Varien_Db_Select|null
111: */
112: public function getFlatUpdateSelect($store)
113: {
114: return Mage::getResourceModel('eav/entity_attribute_option')
115: ->getFlatUpdateSelect($this->getAttribute(), $store, false);
116: }
117: }
118: