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: * Adminhtml catalog product composite helper
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Adminhtml_Helper_Catalog_Product_Composite extends Mage_Core_Helper_Abstract
35: {
36: /**
37: * Init layout of product configuration update result
38: *
39: * @param Mage_Adminhtml_Controller_Action $controller
40: * @return Mage_Adminhtml_Helper_Catalog_Product_Composite
41: */
42: protected function _initUpdateResultLayout($controller)
43: {
44: $controller->getLayout()->getUpdate()
45: ->addHandle('ADMINHTML_CATALOG_PRODUCT_COMPOSITE_UPDATE_RESULT');
46: $controller->loadLayoutUpdates()->generateLayoutXml()->generateLayoutBlocks();
47: return $this;
48: }
49:
50: /**
51: * Prepares and render result of composite product configuration update for a case
52: * when single configuration submitted
53: *
54: * @param Mage_Adminhtml_Controller_Action $controller
55: * @param Varien_Object $updateResult
56: * @return Mage_Adminhtml_Helper_Catalog_Product_Composite
57: */
58: public function renderUpdateResult($controller, Varien_Object $updateResult)
59: {
60: Mage::register('composite_update_result', $updateResult);
61:
62: $this->_initUpdateResultLayout($controller);
63: $controller->renderLayout();
64: }
65:
66: /**
67: * Init composite product configuration layout
68: *
69: * $isOk - true or false, whether action was completed nicely or with some error
70: * If $isOk is FALSE (some error during configuration), so $productType must be null
71: *
72: * @param Mage_Adminhtml_Controller_Action $controller
73: * @param bool $isOk
74: * @param string $productType
75: * @return Mage_Adminhtml_Helper_Catalog_Product_Composite
76: */
77: protected function _initConfigureResultLayout($controller, $isOk, $productType)
78: {
79: $update = $controller->getLayout()->getUpdate();
80: if ($isOk) {
81: $update->addHandle('ADMINHTML_CATALOG_PRODUCT_COMPOSITE_CONFIGURE')
82: ->addHandle('PRODUCT_TYPE_' . $productType);
83: } else {
84: $update->addHandle('ADMINHTML_CATALOG_PRODUCT_COMPOSITE_CONFIGURE_ERROR');
85: }
86: $controller->loadLayoutUpdates()->generateLayoutXml()->generateLayoutBlocks();
87: return $this;
88: }
89:
90: /**
91: * Prepares and render result of composite product configuration request
92: *
93: * $configureResult holds either:
94: * - 'ok' = true, and 'product_id', 'buy_request', 'current_store_id', 'current_customer' or 'current_customer_id'
95: * - 'error' = true, and 'message' to show
96: *
97: * @param Mage_Adminhtml_Controller_Action $controller
98: * @param Varien_Object $configureResult
99: * @return Mage_Adminhtml_Helper_Catalog_Product_Composite
100: */
101: public function renderConfigureResult($controller, Varien_Object $configureResult)
102: {
103: try {
104: if (!$configureResult->getOk()) {
105: Mage::throwException($configureResult->getMessage());
106: };
107:
108: $currentStoreId = (int) $configureResult->getCurrentStoreId();
109: if (!$currentStoreId) {
110: $currentStoreId = Mage::app()->getStore()->getId();
111: }
112:
113: $product = Mage::getModel('catalog/product')
114: ->setStoreId($currentStoreId)
115: ->load($configureResult->getProductId());
116: if (!$product->getId()) {
117: Mage::throwException($this->__('Product is not loaded.'));
118: }
119: Mage::register('current_product', $product);
120: Mage::register('product', $product);
121:
122: // Register customer we're working with
123: $currentCustomer = $configureResult->getCurrentCustomer();
124: if (!$currentCustomer) {
125: $currentCustomerId = (int) $configureResult->getCurrentCustomerId();
126: if ($currentCustomerId) {
127: $currentCustomer = Mage::getModel('customer/customer')
128: ->load($currentCustomerId);
129: }
130: }
131: if ($currentCustomer) {
132: Mage::register('current_customer', $currentCustomer);
133: }
134:
135: // Prepare buy request values
136: $buyRequest = $configureResult->getBuyRequest();
137: if ($buyRequest) {
138: Mage::helper('catalog/product')->prepareProductOptions($product, $buyRequest);
139: }
140:
141: $isOk = true;
142: $productType = $product->getTypeId();
143: } catch (Exception $e) {
144: $isOk = false;
145: $productType = null;
146: Mage::register('composite_configure_result_error_message', $e->getMessage());
147: }
148:
149: $this->_initConfigureResultLayout($controller, $isOk, $productType);
150: $controller->renderLayout();
151: }
152: }
153: