1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_Adminhtml
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * Product after creation popup window
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Adminhtml_Block_Catalog_Product_Created extends Mage_Adminhtml_Block_Widget
35: {
36: protected $_configurableProduct;
37: protected $_product;
38:
39: public function __construct()
40: {
41: parent::__construct();
42: $this->setTemplate('catalog/product/created.phtml');
43: }
44:
45:
46: protected function _prepareLayout()
47: {
48: $this->setChild(
49: 'close_button',
50: $this->getLayout()->createBlock('adminhtml/widget_button')
51: ->setData(array(
52: 'label' => Mage::helper('catalog')->__('Close Window'),
53: 'onclick' => 'addProduct(true)'
54: ))
55: );
56: }
57:
58:
59: public function getCloseButtonHtml()
60: {
61: return $this->getChildHtml('close_button');
62: }
63:
64: public function getProductId()
65: {
66: return (int) $this->getRequest()->getParam('id');
67: }
68:
69: /**
70: * Indentifies edit mode of popup
71: *
72: * @return boolean
73: */
74: public function isEdit()
75: {
76: return (bool) $this->getRequest()->getParam('edit');
77: }
78:
79: /**
80: * Retrive serialized json with configurable attributes values of simple
81: *
82: * @return string
83: */
84: public function getAttributesJson()
85: {
86: $result = array();
87: foreach ($this->getAttributes() as $attribute) {
88: $value = $this->getProduct()->getAttributeText($attribute->getAttributeCode());
89:
90: $result[] = array(
91: 'label' => $value,
92: 'value_index' => $this->getProduct()->getData($attribute->getAttributeCode()),
93: 'attribute_id' => $attribute->getId()
94: );
95: }
96:
97: return Mage::helper('core')->jsonEncode($result);
98: }
99:
100: public function getAttributes()
101: {
102: if ($this->getConfigurableProduct()->getId()) {
103: return $this->getConfigurableProduct()->getTypeInstance(true)->getUsedProductAttributes($this->getConfigurableProduct());
104: }
105:
106: $attributes = array();
107:
108: $attributesIds = $this->getRequest()->getParam('required');
109: if ($attributesIds) {
110: $attributesIds = explode(',', $attributesIds);
111: foreach ($attributesIds as $attributeId) {
112: $attribute = $this->getProduct()->getTypeInstance(true)->getAttributeById($attributeId, $this->getProduct());
113: if (!$attribute) {
114: continue;
115: }
116: $attributes[] = $attribute;
117: }
118: }
119:
120: return $attributes;
121: }
122:
123: /**
124: * Retrive configurable product for created/edited simple
125: *
126: * @return Mage_Catalog_Model_Product
127: */
128: public function getConfigurableProduct()
129: {
130: if (is_null($this->_configurableProduct)) {
131: $this->_configurableProduct = Mage::getModel('catalog/product')
132: ->setStore(0)
133: ->load($this->getRequest()->getParam('product'));
134: }
135: return $this->_configurableProduct;
136: }
137:
138: /**
139: * Retrive product
140: *
141: * @return Mage_Catalog_Model_Product
142: */
143: public function getProduct()
144: {
145: if (is_null($this->_product)) {
146: $this->_product = Mage::getModel('catalog/product')
147: ->setStore(0)
148: ->load($this->getRequest()->getParam('id'));
149: }
150: return $this->_product;
151: }
152: } // Class Mage_Adminhtml_Block_Catalog_Product_Created End
153: