/** * Initialize product from request parameters * * @return Mage_Catalog_Model_Product */ protected function _initProduct() { $productId = (int) $this->getRequest()->getParam('id'); $product = Mage::getModel('catalog/product')->setStoreId($this->getRequest()->getParam('store', 0)); if (!$productId) { if ($setId = (int) $this->getRequest()->getParam('set')) { $product->setAttributeSetId($setId); } if ($typeId = $this->getRequest()->getParam('type')) { $product->setTypeId($typeId); } } if ($productId) { $product->load($productId); } $attributes = $this->getRequest()->getParam('attributes'); if ($attributes && $product->isConfigurable() && (!$productId || !$product->getTypeInstance()->getUsedProductAttributeIds())) { $product->getTypeInstance()->setUsedProductAttributeIds(explode(",", base64_decode(urldecode($attributes)))); } // Init attribute label names for store selected in dropdown Mage_Catalog_Model_Resource_Eav_Attribute::initLabels($product->getStoreId()); // Required attributes of simple product for configurable creation if ($this->getRequest()->getParam('popup') && ($requiredAttributes = $this->getRequest()->getParam('required'))) { $requiredAttributes = explode(",", $requiredAttributes); foreach ($product->getAttributes() as $attribute) { if (in_array($attribute->getId(), $requiredAttributes)) { $attribute->setIsRequired(1); } } } if ($this->getRequest()->getParam('popup') && $this->getRequest()->getParam('product') && !is_array($this->getRequest()->getParam('product')) && $this->getRequest()->getParam('id', false) === false) { $configProduct = Mage::getModel('catalog/product')->setStoreId(0)->load($this->getRequest()->getParam('product'))->setTypeId($this->getRequest()->getParam('type')); /* @var $configProduct Mage_Catalog_Model_Product */ $data = array(); foreach ($configProduct->getTypeInstance()->getEditableAttributes() as $attribute) { /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */ if (!$attribute->getIsUnique() && $attribute->getFrontend()->getInputType() != 'gallery' && $attribute->getAttributeCode() != 'required_options' && $attribute->getAttributeCode() != 'has_options' && $attribute->getAttributeCode() != $configProduct->getIdFieldName()) { $data[$attribute->getAttributeCode()] = $configProduct->getData($attribute->getAttributeCode()); } } $product->addData($data)->setWebsiteIds($configProduct->getWebsiteIds()); } $product->setData('_edit_mode', true); Mage::register('product', $product); Mage::register('current_product', $product); return $product; }