/** * Prepares and render result of composite product configuration request * * $configureResult holds either: * - 'ok' = true, and 'product_id', 'buy_request', 'current_store_id', 'current_customer' or 'current_customer_id' * - 'error' = true, and 'message' to show * * @param Mage_Adminhtml_Controller_Action $controller * @param Varien_Object $configureResult * @return Mage_Adminhtml_Helper_Catalog_Product_Composite */ public function renderConfigureResult($controller, Varien_Object $configureResult) { try { if (!$configureResult->getOk()) { Mage::throwException($configureResult->getMessage()); } $currentStoreId = (int) $configureResult->getCurrentStoreId(); if (!$currentStoreId) { $currentStoreId = Mage::app()->getStore()->getId(); } $product = Mage::getModel('catalog/product')->setStoreId($currentStoreId)->load($configureResult->getProductId()); if (!$product->getId()) { Mage::throwException($this->__('Product is not loaded.')); } Mage::register('current_product', $product); Mage::register('product', $product); // Prepare buy request values $buyRequest = $configureResult->getBuyRequest(); if ($buyRequest) { Mage::helper('catalog/product')->prepareProductOptions($product, $buyRequest); } $isOk = true; $productType = $product->getTypeId(); } catch (Exception $e) { $isOk = false; $productType = null; Mage::register('composite_configure_result_error_message', $e->getMessage()); } $this->_initConfigureResultLayout($controller, $isOk, $productType); $controller->renderLayout(); }
/** * Action to reconfigure cart item */ public function configureAction() { // Extract item and product to configure $id = (int) $this->getRequest()->getParam('id'); $quoteItem = null; try { $cart = $this->_getCart(); $quoteItem = $cart->getQuote()->getItemById($id); if (!$quoteItem) { $this->_message($this->__('Quote item is not found.'), self::MESSAGE_STATUS_ERROR); return; } $params = new Varien_Object(); $params->setCategoryId(false); $params->setConfigureMode(true); $params->setBuyRequest($quoteItem->getBuyRequest()); $productHelper = Mage::helper('catalog/product'); $buyRequest = $params->getBuyRequest(); /** @var $product Mage_Catalog_Model_Product */ $product = $productHelper->initProduct($quoteItem->getProduct()->getId(), $this, $params); if ($buyRequest) { $productHelper->prepareProductOptions($product, $buyRequest); } if ($params->hasConfigureMode()) { $product->setConfigureMode($params->getConfigureMode()); } $this->loadLayout(false); $this->getLayout()->getBlock('xmlconnect.catalog.product')->setProduct($product); $this->renderLayout(); } catch (Exception $e) { $this->_message($this->__('Cannot configure product.'), self::MESSAGE_STATUS_ERROR); Mage::logException($e); return; } }