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_Attribute_Edit_Tab_Options extends Mage_Adminhtml_Block_Widget
00035 {
00036
00037 public function __construct()
00038 {
00039 parent::__construct();
00040 $this->setTemplate('catalog/product/attribute/options.phtml');
00041 }
00042
00043 protected function _prepareLayout()
00044 {
00045 $this->setChild('delete_button',
00046 $this->getLayout()->createBlock('adminhtml/widget_button')
00047 ->setData(array(
00048 'label' => Mage::helper('catalog')->__('Delete'),
00049 'class' => 'delete delete-option'
00050 )));
00051
00052 $this->setChild('add_button',
00053 $this->getLayout()->createBlock('adminhtml/widget_button')
00054 ->setData(array(
00055 'label' => Mage::helper('catalog')->__('Add Option'),
00056 'class' => 'add',
00057 'id' => 'add_new_option_button'
00058 )));
00059 return parent::_prepareLayout();
00060 }
00061
00062 public function getDeleteButtonHtml()
00063 {
00064 return $this->getChildHtml('delete_button');
00065 }
00066
00067 public function getAddNewButtonHtml()
00068 {
00069 return $this->getChildHtml('add_button');
00070 }
00071
00072 public function getStores()
00073 {
00074 $stores = $this->getData('stores');
00075 if (is_null($stores)) {
00076 $stores = Mage::getModel('core/store')
00077 ->getResourceCollection()
00078 ->setLoadDefault(true)
00079 ->load();
00080 $this->setData('stores', $stores);
00081 }
00082 return $stores;
00083 }
00084
00085 public function getOptionValues()
00086 {
00087 $attributeType = $this->getAttributeObject()->getFrontendInput();
00088 $defaultValues = $this->getAttributeObject()->getDefaultValue();
00089 if ($attributeType == 'select' || $attributeType == 'multiselect') {
00090 $defaultValues = explode(',', $defaultValues);
00091 } else {
00092 $defaultValues = array();
00093 }
00094
00095 switch ($attributeType) {
00096 case 'select':
00097 $inputType = 'radio';
00098 break;
00099 case 'multiselect':
00100 $inputType = 'checkbox';
00101 break;
00102 default:
00103 $inputType = '';
00104 break;
00105 }
00106
00107 $values = $this->getData('option_values');
00108 if (is_null($values)) {
00109 $values = array();
00110 $optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
00111 ->setAttributeFilter($this->getAttributeObject()->getId())
00112 ->setPositionOrder('desc', true)
00113 ->load();
00114
00115 foreach ($optionCollection as $option) {
00116 $value = array();
00117 if (in_array($option->getId(), $defaultValues)) {
00118 $value['checked'] = 'checked="checked"';
00119 } else {
00120 $value['checked'] = '';
00121 }
00122
00123 $value['intype'] = $inputType;
00124 $value['id'] = $option->getId();
00125 $value['sort_order'] = $option->getSortOrder();
00126 foreach ($this->getStores() as $store) {
00127 $storeValues = $this->getStoreOptionValues($store->getId());
00128 if (isset($storeValues[$option->getId()])) {
00129 $value['store'.$store->getId()] = htmlspecialchars($storeValues[$option->getId()]);
00130 }
00131 else {
00132 $value['store'.$store->getId()] = '';
00133 }
00134 }
00135 $values[] = new Varien_Object($value);
00136 }
00137 $this->setData('option_values', $values);
00138 }
00139
00140 return $values;
00141 }
00142
00143 public function getLabelValues()
00144 {
00145 $values = array();
00146 $values[0] = $this->getAttributeObject()->getFrontend()->getLabel();
00147
00148 $frontendLabel = $this->getAttributeObject()->getFrontend()->getLabel();
00149 if (is_array($frontendLabel)) {
00150 $frontendLabel = array_shift($frontendLabel);
00151 }
00152 $translations = Mage::getModel('core/translate_string')
00153 ->load(Mage_Catalog_Model_Entity_Attribute::MODULE_NAME.Mage_Core_Model_Translate::SCOPE_SEPARATOR.$frontendLabel)
00154 ->getStoreTranslations();
00155 foreach ($this->getStores() as $store) {
00156 if ($store->getId() != 0) {
00157 $values[$store->getId()] = isset($translations[$store->getId()]) ? $translations[$store->getId()] : '';
00158 }
00159 }
00160 return $values;
00161 }
00162
00163 public function getStoreOptionValues($storeId)
00164 {
00165 $values = $this->getData('store_option_values_'.$storeId);
00166 if (is_null($values)) {
00167 $values = array();
00168 $valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
00169 ->setAttributeFilter($this->getAttributeObject()->getId())
00170 ->setStoreFilter($storeId, false)
00171 ->load();
00172 foreach ($valuesCollection as $item) {
00173 $values[$item->getId()] = $item->getValue();
00174 }
00175 $this->setData('store_option_values_'.$storeId, $values);
00176 }
00177 return $values;
00178 }
00179
00180 public function getAttributeObject()
00181 {
00182 return Mage::registry('entity_attribute');
00183 }
00184
00185 }