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: class Mage_Weee_Block_Renderer_Weee_Tax extends Mage_Adminhtml_Block_Widget implements Varien_Data_Form_Element_Renderer_Interface
35: {
36:
37: protected $_element = null;
38: protected $_countries = null;
39: protected $_websites = null;
40:
41: public function __construct()
42: {
43: $this->setTemplate('weee/renderer/tax.phtml');
44: }
45:
46: public function getProduct()
47: {
48: return Mage::registry('product');
49: }
50:
51: public function render(Varien_Data_Form_Element_Abstract $element)
52: {
53: $this->setElement($element);
54: $this->_setAddButton();
55: return $this->toHtml();
56: }
57:
58: public function setElement(Varien_Data_Form_Element_Abstract $element)
59: {
60: $this->_element = $element;
61: return $this;
62: }
63:
64: public function getElement()
65: {
66: return $this->_element;
67: }
68:
69: public function getValues()
70: {
71: $values =array();
72: $data = $this->getElement()->getValue();
73:
74: if (is_array($data) && count($data)) {
75: usort($data, array($this, '_sortWeeeTaxes'));
76: $values = $data;
77: }
78: return $values;
79: }
80:
81: protected function _sortWeeeTaxes($a, $b)
82: {
83: if ($a['website_id']!=$b['website_id']) {
84: return $a['website_id']<$b['website_id'] ? -1 : 1;
85: }
86: if ($a['country']!=$b['country']) {
87: return $a['country']<$b['country'] ? -1 : 1;
88: }
89: return 0;
90: }
91:
92: public function getWebsiteCount()
93: {
94: return count($this->getWebsites());
95: }
96:
97: public function isMultiWebsites()
98: {
99: return !Mage::app()->isSingleStoreMode();
100: }
101:
102: public function getCountries()
103: {
104: if (is_null($this->_countries)) {
105: $this->_countries = Mage::getModel('adminhtml/system_config_source_country')
106: ->toOptionArray();
107: }
108:
109: return $this->_countries;
110: }
111:
112: public function getWebsites()
113: {
114: if (!is_null($this->_websites)) {
115: return $this->_websites;
116: }
117: $websites = array();
118: $websites[0] = array(
119: 'name' => $this->__('All Websites'),
120: 'currency' => Mage::app()->getBaseCurrencyCode()
121: );
122:
123: if (!Mage::app()->isSingleStoreMode() && !$this->getElement()->getEntityAttribute()->isScopeGlobal()) {
124: if ($storeId = $this->getProduct()->getStoreId()) {
125: $website = Mage::app()->getStore($storeId)->getWebsite();
126: $websites[$website->getId()] = array(
127: 'name' => $website->getName(),
128: 'currency' => $website->getConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
129: );
130: } else {
131: foreach (Mage::app()->getWebsites() as $website) {
132: if (!in_array($website->getId(), $this->getProduct()->getWebsiteIds())) {
133: continue;
134: }
135: $websites[$website->getId()] = array(
136: 'name' => $website->getName(),
137: 'currency' => $website->getConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
138: );
139: }
140: }
141: }
142: $this->_websites = $websites;
143: return $this->_websites;
144: }
145:
146: protected function _setAddButton()
147: {
148: $this->setChild('add_button',
149: $this->getLayout()->createBlock('adminhtml/widget_button')
150: ->setData(array(
151: 'label' => Mage::helper('catalog')->__('Add Tax'),
152: 'onclick' => "weeeTaxControl.addItem('".$this->getElement()->getHtmlId()."')",
153: 'class' => 'add'
154: )));
155: }
156:
157: public function getAddButtonHtml()
158: {
159: return $this->getChildHtml('add_button');
160: }
161:
162: }
163: