00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Adminhtml 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 /** 00028 * Product after creation popup window 00029 * 00030 * @category Mage 00031 * @package Mage_Adminhtml 00032 * @author Magento Core Team <core@magentocommerce.com> 00033 */ 00034 class Mage_Adminhtml_Block_Catalog_Product_Created extends Mage_Adminhtml_Block_Widget 00035 { 00036 protected $_configurableProduct; 00037 protected $_product; 00038 00039 public function __construct() 00040 { 00041 parent::__construct(); 00042 $this->setTemplate('catalog/product/created.phtml'); 00043 } 00044 00045 00046 protected function _prepareLayout() 00047 { 00048 $this->setChild( 00049 'close_button', 00050 $this->getLayout()->createBlock('adminhtml/widget_button') 00051 ->setData(array( 00052 'label' => Mage::helper('catalog')->__('Close Window'), 00053 'onclick' => 'addProduct(true)' 00054 )) 00055 ); 00056 } 00057 00058 00059 public function getCloseButtonHtml() 00060 { 00061 return $this->getChildHtml('close_button'); 00062 } 00063 00064 public function getProductId() 00065 { 00066 return (int) $this->getRequest()->getParam('id'); 00067 } 00068 00069 /** 00070 * Indentifies edit mode of popup 00071 * 00072 * @return boolean 00073 */ 00074 public function isEdit() 00075 { 00076 return (bool) $this->getRequest()->getParam('edit'); 00077 } 00078 00079 /** 00080 * Retrive serialized json with configurable attributes values of simple 00081 * 00082 * @return string 00083 */ 00084 public function getAttributesJson() 00085 { 00086 $result = array(); 00087 foreach ($this->getAttributes() as $attribute) { 00088 $value = $this->getProduct()->getAttributeText($attribute->getAttributeCode()); 00089 00090 $result[] = array( 00091 'label' => $value, 00092 'value_index' => $this->getProduct()->getData($attribute->getAttributeCode()), 00093 'attribute_id' => $attribute->getId() 00094 ); 00095 } 00096 00097 return Zend_Json::encode($result); 00098 } 00099 00100 public function getAttributes() 00101 { 00102 if ($this->getConfigurableProduct()->getId()) { 00103 return $this->getConfigurableProduct()->getTypeInstance(true)->getUsedProductAttributes($this->getConfigurableProduct()); 00104 } 00105 00106 $attributes = array(); 00107 00108 $attributesIds = $this->getRequest()->getParam('required'); 00109 if ($attributesIds) { 00110 $attributesIds = explode(',', $attributesIds); 00111 foreach ($attributesIds as $attributeId) { 00112 $attribute = $this->getProduct()->getTypeInstance(true)->getAttributeById($attributeId, $this->getProduct()); 00113 if (!$attribute) { 00114 continue; 00115 } 00116 $attributes[] = $attribute; 00117 } 00118 } 00119 00120 return $attributes; 00121 } 00122 00123 /** 00124 * Retrive configurable product for created/edited simple 00125 * 00126 * @return Mage_Catalog_Model_Product 00127 */ 00128 public function getConfigurableProduct() 00129 { 00130 if (is_null($this->_configurableProduct)) { 00131 $this->_configurableProduct = Mage::getModel('catalog/product') 00132 ->setStore(0) 00133 ->load($this->getRequest()->getParam('product')); 00134 } 00135 return $this->_configurableProduct; 00136 } 00137 00138 /** 00139 * Retrive product 00140 * 00141 * @return Mage_Catalog_Model_Product 00142 */ 00143 public function getProduct() 00144 { 00145 if (is_null($this->_product)) { 00146 $this->_product = Mage::getModel('catalog/product') 00147 ->setStore(0) 00148 ->load($this->getRequest()->getParam('id')); 00149 } 00150 return $this->_product; 00151 } 00152 } // Class Mage_Adminhtml_Block_Catalog_Product_Created End