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
00035 class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config extends Mage_Adminhtml_Block_Widget implements Mage_Adminhtml_Block_Widget_Tab_Interface
00036 {
00037
00038
00039
00040
00041 public function __construct()
00042 {
00043 parent::__construct();
00044 $this->setProductId($this->getRequest()->getParam('id'));
00045 $this->setTemplate('catalog/product/edit/super/config.phtml');
00046 $this->setId('config_super_product');
00047 }
00048
00049
00050
00051
00052
00053
00054 public function getTabClass()
00055 {
00056 return 'ajax';
00057 }
00058
00059
00060
00061
00062
00063
00064 public function isReadonly()
00065 {
00066 return $this->_getProduct()->getCompositeReadonly();
00067 }
00068
00069
00070
00071
00072
00073
00074 protected function _prepareLayout()
00075 {
00076 $this->setChild('grid',
00077 $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_super_config_grid')
00078 );
00079
00080 $this->setChild('create_empty',
00081 $this->getLayout()->createBlock('adminhtml/widget_button')
00082 ->setData(array(
00083 'label' => Mage::helper('catalog')->__('Create Empty'),
00084 'class' => 'add',
00085 'onclick' => 'superProduct.createEmptyProduct()'
00086 ))
00087 );
00088
00089 if ($this->_getProduct()->getId()) {
00090 $this->setChild('simple',
00091 $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_super_config_simple')
00092 );
00093
00094 $this->setChild('create_from_configurable',
00095 $this->getLayout()->createBlock('adminhtml/widget_button')
00096 ->setData(array(
00097 'label' => Mage::helper('catalog')->__('Copy From Configurable'),
00098 'class' => 'add',
00099 'onclick' => 'superProduct.createNewProduct()'
00100 ))
00101 );
00102 }
00103
00104 return parent::_prepareLayout();
00105 }
00106
00107
00108
00109
00110
00111
00112 protected function _getProduct()
00113 {
00114 return Mage::registry('current_product');
00115 }
00116
00117
00118
00119
00120
00121
00122 public function getAttributesJson()
00123 {
00124 $attributes = $this->_getProduct()->getTypeInstance(true)
00125 ->getConfigurableAttributesAsArray($this->_getProduct());
00126 if(!$attributes) {
00127 return '[]';
00128 }
00129 return Zend_Json::encode($attributes);
00130 }
00131
00132
00133
00134
00135
00136
00137 public function getLinksJson()
00138 {
00139 $products = $this->_getProduct()->getTypeInstance(true)
00140 ->getUsedProducts(null, $this->_getProduct());
00141 if(!$products) {
00142 return '{}';
00143 }
00144 $data = array();
00145 foreach ($products as $product) {
00146 $data[$product->getId()] = $this->getConfigurableSettings($product);
00147 }
00148 return Zend_Json::encode($data);
00149 }
00150
00151
00152
00153
00154
00155
00156
00157 public function getConfigurableSettings($product) {
00158 $data = array();
00159 $attributes = $this->_getProduct()->getTypeInstance(true)
00160 ->getUsedProductAttributes($this->_getProduct());
00161 foreach ($attributes as $attribute) {
00162 $data[] = array(
00163 'attribute_id' => $attribute->getId(),
00164 'label' => $product->getAttributeText($attribute->getAttributeCode()),
00165 'value_index' => $product->getData($attribute->getAttributeCode())
00166 );
00167 }
00168
00169 return $data;
00170 }
00171
00172
00173
00174
00175
00176
00177 public function getGridHtml()
00178 {
00179 return $this->getChildHtml('grid');
00180 }
00181
00182
00183
00184
00185
00186
00187 public function getGridJsObject()
00188 {
00189 return $this->getChild('grid')->getJsObjectName();
00190 }
00191
00192
00193
00194
00195
00196
00197 public function getNewEmptyProductUrl()
00198 {
00199 return $this->getUrl(
00200 '*/*/new',
00201 array(
00202 'set' => $this->_getProduct()->getAttributeSetId(),
00203 'type' => Mage_Catalog_Model_Product_Type::TYPE_SIMPLE,
00204 'required' => $this->_getRequiredAttributesIds(),
00205 'popup' => 1
00206 )
00207 );
00208 }
00209
00210
00211
00212
00213
00214
00215 public function getNewProductUrl()
00216 {
00217 return $this->getUrl(
00218 '*/*/new',
00219 array(
00220 'set' => $this->_getProduct()->getAttributeSetId(),
00221 'type' => Mage_Catalog_Model_Product_Type::TYPE_SIMPLE,
00222 'required' => $this->_getRequiredAttributesIds(),
00223 'popup' => 1,
00224 'product' => $this->_getProduct()->getId()
00225 )
00226 );
00227 }
00228
00229
00230
00231
00232
00233
00234 public function getQuickCreationUrl()
00235 {
00236 return $this->getUrl(
00237 '*/*/quickCreate',
00238 array(
00239 'product' => $this->_getProduct()->getId()
00240 )
00241 );
00242 }
00243
00244
00245
00246
00247
00248
00249 protected function _getRequiredAttributesIds()
00250 {
00251 $attributesIds = array();
00252 foreach ($this->_getProduct()->getTypeInstance(true)->getConfigurableAttributes($this->_getProduct()) as $attribute) {
00253 $attributesIds[] = $attribute->getProductAttribute()->getId();
00254 }
00255
00256 return implode(',', $attributesIds);
00257 }
00258
00259
00260
00261
00262
00263
00264
00265 public function escapeJs($string)
00266 {
00267 return addcslashes($string, "'\r\n\\");
00268 }
00269
00270
00271
00272
00273
00274
00275 public function getTabLabel()
00276 {
00277 return Mage::helper('catalog')->__('Associated Products');
00278 }
00279
00280
00281
00282
00283
00284
00285 public function getTabTitle()
00286 {
00287 return Mage::helper('catalog')->__('Associated Products');
00288 }
00289
00290
00291
00292
00293
00294
00295 public function canShowTab()
00296 {
00297 return true;
00298 }
00299
00300
00301
00302
00303
00304
00305 public function isHidden()
00306 {
00307 return false;
00308 }
00309
00310
00311
00312
00313
00314
00315 public function getShowUseDefaultPrice()
00316 {
00317 return !Mage::helper('catalog')->isPriceGlobal()
00318 && $this->_getProduct()->getStoreId();
00319 }
00320 }