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:
35: class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config extends Mage_Adminhtml_Block_Widget
36: implements Mage_Adminhtml_Block_Widget_Tab_Interface
37: {
38: 39: 40: 41:
42: public function __construct()
43: {
44: parent::__construct();
45: $this->setProductId($this->getRequest()->getParam('id'));
46: $this->setTemplate('catalog/product/edit/super/config.phtml');
47: $this->setId('config_super_product');
48: $this->setCanEditPrice(true);
49: $this->setCanReadPrice(true);
50: }
51:
52: 53: 54: 55: 56:
57: public function getTabClass()
58: {
59: return 'ajax';
60: }
61:
62: 63: 64: 65: 66:
67: public function isReadonly()
68: {
69: return (bool) $this->_getProduct()->getCompositeReadonly();
70: }
71:
72: 73: 74: 75: 76:
77: public function isAttributesConfigurationReadonly()
78: {
79: return (bool) $this->_getProduct()->getAttributesConfigurationReadonly();
80: }
81:
82: 83: 84: 85: 86:
87: public function isAttributesPricesReadonly()
88: {
89: return $this->_getProduct()->getAttributesConfigurationReadonly() ||
90: (Mage::helper('catalog')->isPriceGlobal() && $this->isReadonly());
91: }
92:
93: 94: 95: 96: 97:
98: protected function _prepareLayout()
99: {
100: $this->setChild('grid',
101: $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_super_config_grid',
102: 'admin.product.edit.tab.super.config.grid')
103: );
104:
105: $this->setChild('create_empty',
106: $this->getLayout()->createBlock('adminhtml/widget_button')
107: ->setData(array(
108: 'label' => Mage::helper('catalog')->__('Create Empty'),
109: 'class' => 'add',
110: 'onclick' => 'superProduct.createEmptyProduct()'
111: ))
112: );
113:
114: if ($this->_getProduct()->getId()) {
115: $this->setChild('simple',
116: $this->getLayout()->createBlock('adminhtml/catalog_product_edit_tab_super_config_simple',
117: 'catalog.product.edit.tab.super.config.simple')
118: );
119:
120: $this->setChild('create_from_configurable',
121: $this->getLayout()->createBlock('adminhtml/widget_button')
122: ->setData(array(
123: 'label' => Mage::helper('catalog')->__('Copy From Configurable'),
124: 'class' => 'add',
125: 'onclick' => 'superProduct.createNewProduct()'
126: ))
127: );
128: }
129:
130: return parent::_prepareLayout();
131: }
132:
133: 134: 135: 136: 137:
138: protected function _getProduct()
139: {
140: return Mage::registry('current_product');
141: }
142:
143: 144: 145: 146: 147:
148: public function getAttributesJson()
149: {
150: $attributes = $this->_getProduct()->getTypeInstance(true)
151: ->getConfigurableAttributesAsArray($this->_getProduct());
152: if(!$attributes) {
153: return '[]';
154: } else {
155:
156: foreach ($attributes as &$attribute) {
157: if (isset($attribute['values']) && is_array($attribute['values'])) {
158: foreach ($attribute['values'] as &$attributeValue) {
159: if (!$this->getCanReadPrice()) {
160: $attributeValue['pricing_value'] = '';
161: $attributeValue['is_percent'] = 0;
162: }
163: $attributeValue['can_edit_price'] = $this->getCanEditPrice();
164: $attributeValue['can_read_price'] = $this->getCanReadPrice();
165: }
166: }
167: }
168: }
169: return Mage::helper('core')->jsonEncode($attributes);
170: }
171:
172: 173: 174: 175: 176:
177: public function getLinksJson()
178: {
179: $products = $this->_getProduct()->getTypeInstance(true)
180: ->getUsedProducts(null, $this->_getProduct());
181: if(!$products) {
182: return '{}';
183: }
184: $data = array();
185: foreach ($products as $product) {
186: $data[$product->getId()] = $this->getConfigurableSettings($product);
187: }
188: return Mage::helper('core')->jsonEncode($data);
189: }
190:
191: 192: 193: 194: 195: 196:
197: public function getConfigurableSettings($product) {
198: $data = array();
199: $attributes = $this->_getProduct()->getTypeInstance(true)
200: ->getUsedProductAttributes($this->_getProduct());
201: foreach ($attributes as $attribute) {
202: $data[] = array(
203: 'attribute_id' => $attribute->getId(),
204: 'label' => $product->getAttributeText($attribute->getAttributeCode()),
205: 'value_index' => $product->getData($attribute->getAttributeCode())
206: );
207: }
208:
209: return $data;
210: }
211:
212: 213: 214: 215: 216:
217: public function getGridHtml()
218: {
219: return $this->getChildHtml('grid');
220: }
221:
222: 223: 224: 225: 226:
227: public function getGridJsObject()
228: {
229: return $this->getChild('grid')->getJsObjectName();
230: }
231:
232: 233: 234: 235: 236:
237: public function getNewEmptyProductUrl()
238: {
239: return $this->getUrl(
240: '*/*/new',
241: array(
242: 'set' => $this->_getProduct()->getAttributeSetId(),
243: 'type' => Mage_Catalog_Model_Product_Type::TYPE_SIMPLE,
244: 'required' => $this->_getRequiredAttributesIds(),
245: 'popup' => 1
246: )
247: );
248: }
249:
250: 251: 252: 253: 254:
255: public function getNewProductUrl()
256: {
257: return $this->getUrl(
258: '*/*/new',
259: array(
260: 'set' => $this->_getProduct()->getAttributeSetId(),
261: 'type' => Mage_Catalog_Model_Product_Type::TYPE_SIMPLE,
262: 'required' => $this->_getRequiredAttributesIds(),
263: 'popup' => 1,
264: 'product' => $this->_getProduct()->getId()
265: )
266: );
267: }
268:
269: 270: 271: 272: 273:
274: public function getQuickCreationUrl()
275: {
276: return $this->getUrl(
277: '*/*/quickCreate',
278: array(
279: 'product' => $this->_getProduct()->getId()
280: )
281: );
282: }
283:
284: 285: 286: 287: 288:
289: protected function _getRequiredAttributesIds()
290: {
291: $attributesIds = array();
292: $configurableAttributes = $this->_getProduct()
293: ->getTypeInstance(true)->getConfigurableAttributes($this->_getProduct());
294: foreach ($configurableAttributes as $attribute) {
295: $attributesIds[] = $attribute->getProductAttribute()->getId();
296: }
297:
298: return implode(',', $attributesIds);
299: }
300:
301: 302: 303: 304: 305: 306:
307: public function escapeJs($string)
308: {
309: return addcslashes($string, "'\r\n\\");
310: }
311:
312: 313: 314: 315: 316:
317: public function getTabLabel()
318: {
319: return Mage::helper('catalog')->__('Associated Products');
320: }
321:
322: 323: 324: 325: 326:
327: public function getTabTitle()
328: {
329: return Mage::helper('catalog')->__('Associated Products');
330: }
331:
332: 333: 334: 335: 336:
337: public function canShowTab()
338: {
339: return true;
340: }
341:
342: 343: 344: 345: 346:
347: public function isHidden()
348: {
349: return false;
350: }
351:
352: 353: 354: 355: 356:
357: public function getShowUseDefaultPrice()
358: {
359: return !Mage::helper('catalog')->isPriceGlobal()
360: && $this->_getProduct()->getStoreId();
361: }
362: }
363: