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_Adminhtml_Block_Catalog_Product_Edit_Tab_Price_Tier extends Mage_Adminhtml_Block_Widget implements Varien_Data_Form_Element_Renderer_Interface
00035 {
00036
00037 protected $_element = null;
00038 protected $_customerGroups = null;
00039 protected $_websites = null;
00040
00041 public function __construct()
00042 {
00043 $this->setTemplate('catalog/product/edit/price/tier.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 return $this->toHtml();
00055 }
00056
00057 public function setElement(Varien_Data_Form_Element_Abstract $element)
00058 {
00059 $this->_element = $element;
00060 return $this;
00061 }
00062
00063 public function getElement()
00064 {
00065 return $this->_element;
00066 }
00067
00068 public function getValues()
00069 {
00070 $values =array();
00071 $data = $this->getElement()->getValue();
00072
00073 if (is_array($data)) {
00074 usort($data, array($this, '_sortTierPrices'));
00075 $values = $data;
00076 }
00077 return $values;
00078 }
00079
00080 protected function _sortTierPrices($a, $b)
00081 {
00082 if ($a['website_id']!=$b['website_id']) {
00083 return $a['website_id']<$b['website_id'] ? -1 : 1;
00084 }
00085 if ($a['cust_group']!=$b['cust_group']) {
00086 return $this->getCustomerGroups($a['cust_group'])<$this->getCustomerGroups($b['cust_group']) ? -1 : 1;
00087 }
00088 if ($a['price_qty']!=$b['price_qty']) {
00089 return $a['price_qty']<$b['price_qty'] ? -1 : 1;
00090 }
00091 return 0;
00092 }
00093
00094 public function getCustomerGroups($groupId=null)
00095 {
00096 if (!$this->_customerGroups) {
00097 $collection = Mage::getModel('customer/group')->getCollection()
00098 ->load();
00099 $this->_customerGroups = array(
00100 Mage_Customer_Model_Group::CUST_GROUP_ALL => Mage::helper('catalog')->__('ALL GROUPS'),
00101 );
00102 foreach ($collection->getIterator() as $item) {
00103 $this->_customerGroups[$item->getId()] = $item->getCustomerGroupCode();
00104 }
00105 }
00106 return is_null($groupId) ? $this->_customerGroups :
00107 (isset($this->_customerGroups[$groupId]) ? $this->_customerGroups[$groupId] : null);
00108 }
00109
00110 public function getWebsiteCount()
00111 {
00112 return count($this->getWebsites());
00113 }
00114
00115 public function isMultiWebsites()
00116 {
00117 return !Mage::app()->isSingleStoreMode();
00118 }
00119
00120 public function getWebsites()
00121 {
00122 if (!is_null($this->_websites)) {
00123 return $this->_websites;
00124 }
00125 $websites = array();
00126 $websites[0] = array(
00127 'name' => $this->__('All Websites'),
00128 'currency' => Mage::app()->getBaseCurrencyCode()
00129 );
00130 if (Mage::app()->isSingleStoreMode() || $this->getElement()->getEntityAttribute()->isScopeGlobal()) {
00131 return $websites;
00132 }
00133 elseif ($storeId = $this->getProduct()->getStoreId()) {
00134 $website = Mage::app()->getStore($storeId)->getWebsite();
00135 $websites[$website->getId()] = array(
00136 'name' => $website->getName(),
00137 'currency' => $website->getConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
00138 );
00139 }
00140 else {
00141 $websites[0] = array(
00142 'name' => $this->__('All Websites'),
00143 'currency' => Mage::app()->getBaseCurrencyCode()
00144 );
00145 foreach (Mage::app()->getWebsites() as $website) {
00146 if (!in_array($website->getId(), $this->getProduct()->getWebsiteIds())) {
00147 continue;
00148 }
00149 $websites[$website->getId()] = array(
00150 'name' => $website->getName(),
00151 'currency' => $website->getConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
00152 );
00153 }
00154 }
00155 $this->_websites = $websites;
00156 return $this->_websites;
00157 }
00158
00159 public function getDefaultCustomerGroup()
00160 {
00161 return Mage_Customer_Model_Group::CUST_GROUP_ALL;
00162 }
00163
00164 protected function _prepareLayout()
00165 {
00166 $this->setChild('add_button',
00167 $this->getLayout()->createBlock('adminhtml/widget_button')
00168 ->setData(array(
00169 'label' => Mage::helper('catalog')->__('Add Tier'),
00170 'onclick' => 'tierPriceControl.addItem()',
00171 'class' => 'add'
00172 )));
00173 return parent::_prepareLayout();
00174 }
00175
00176 public function getAddButtonHtml()
00177 {
00178 return $this->getChildHtml('add_button');
00179 }
00180
00181
00182
00183
00184
00185
00186
00187
00188 public function getPriceColumnHeader($default)
00189 {
00190 if ($this->hasData('price_column_header')) {
00191 return $this->getData('price_column_header');
00192 } else {
00193 return $default;
00194 }
00195 }
00196 }