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 class Mage_Weee_Block_Renderer_Weee_Tax extends Mage_Adminhtml_Block_Widget implements Varien_Data_Form_Element_Renderer_Interface
00035 {
00036
00037 protected $_element = null;
00038 protected $_countries = null;
00039 protected $_websites = null;
00040
00041 public function __construct()
00042 {
00043 $this->setTemplate('weee/renderer/tax.phtml');
00044 }
00045
00046 public function getProduct()
00047 {
00048 return Mage::registry('product');
00049 }
00050
00051 public function render(Varien_Data_Form_Element_Abstract $element)
00052 {
00053 $this->setElement($element);
00054 $this->_setAddButton();
00055 return $this->toHtml();
00056 }
00057
00058 public function setElement(Varien_Data_Form_Element_Abstract $element)
00059 {
00060 $this->_element = $element;
00061 return $this;
00062 }
00063
00064 public function getElement()
00065 {
00066 return $this->_element;
00067 }
00068
00069 public function getValues()
00070 {
00071 $values =array();
00072 $data = $this->getElement()->getValue();
00073
00074 if (is_array($data) && count($data)) {
00075 usort($data, array($this, '_sortWeeeTaxes'));
00076 $values = $data;
00077 }
00078 return $values;
00079 }
00080
00081 protected function _sortWeeeTaxes($a, $b)
00082 {
00083 if ($a['website_id']!=$b['website_id']) {
00084 return $a['website_id']<$b['website_id'] ? -1 : 1;
00085 }
00086 if ($a['country']!=$b['country']) {
00087 return $a['country']<$b['country'] ? -1 : 1;
00088 }
00089 return 0;
00090 }
00091
00092 public function getWebsiteCount()
00093 {
00094 return count($this->getWebsites());
00095 }
00096
00097 public function isMultiWebsites()
00098 {
00099 return !Mage::app()->isSingleStoreMode();
00100 }
00101
00102 public function getCountries()
00103 {
00104 if (is_null($this->_countries)) {
00105 $this->_countries = Mage::getModel('adminhtml/system_config_source_country')
00106 ->toOptionArray();
00107 }
00108
00109 return $this->_countries;
00110 }
00111
00112 public function getWebsites()
00113 {
00114 if (!is_null($this->_websites)) {
00115 return $this->_websites;
00116 }
00117 $websites = array();
00118 $websites[0] = array(
00119 'name' => $this->__('All Websites'),
00120 'currency' => Mage::app()->getBaseCurrencyCode()
00121 );
00122
00123 if (!Mage::app()->isSingleStoreMode() && !$this->getElement()->getEntityAttribute()->isScopeGlobal()) {
00124 if ($storeId = $this->getProduct()->getStoreId()) {
00125 $website = Mage::app()->getStore($storeId)->getWebsite();
00126 $websites[$website->getId()] = array(
00127 'name' => $website->getName(),
00128 'currency' => $website->getConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
00129 );
00130 } else {
00131 foreach (Mage::app()->getWebsites() as $website) {
00132 if (!in_array($website->getId(), $this->getProduct()->getWebsiteIds())) {
00133 continue;
00134 }
00135 $websites[$website->getId()] = array(
00136 'name' => $website->getName(),
00137 'currency' => $website->getConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
00138 );
00139 }
00140 }
00141 }
00142 $this->_websites = $websites;
00143 return $this->_websites;
00144 }
00145
00146 protected function _setAddButton()
00147 {
00148 $this->setChild('add_button',
00149 $this->getLayout()->createBlock('adminhtml/widget_button')
00150 ->setData(array(
00151 'label' => Mage::helper('catalog')->__('Add Tax'),
00152 'onclick' => "weeeTaxControl.addItem('".$this->getElement()->getHtmlId()."')",
00153 'class' => 'add'
00154 )));
00155 }
00156
00157 public function getAddButtonHtml()
00158 {
00159 return $this->getChildHtml('add_button');
00160 }
00161
00162 }