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: * Catalog composite product configuration controller
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Adminhtml_Customer_Cart_Product_Composite_CartController extends Mage_Adminhtml_Controller_Action
35: {
36: /**
37: * Customer we're working with
38: *
39: * @var Mage_Customer_Model_Customer
40: */
41: protected $_customer = null;
42:
43: /**
44: * Quote we're working with
45: *
46: * @var Mage_Sales_Model_Quote
47: */
48: protected $_quote = null;
49:
50: /**
51: * Quote item we're working with
52: *
53: * @var Mage_Sales_Model_Quote_Item
54: */
55: protected $_quoteItem = null;
56:
57: /**
58: * Loads customer, quote and quote item by request params
59: *
60: * @return Mage_Adminhtml_Customer_Cart_Product_Composite_CartController
61: */
62: protected function _initData()
63: {
64: $customerId = (int) $this->getRequest()->getParam('customer_id');
65: if (!$customerId) {
66: Mage::throwException($this->__('No customer id defined.'));
67: }
68:
69: $this->_customer = Mage::getModel('customer/customer')
70: ->load($customerId);
71:
72: $quoteItemId = (int) $this->getRequest()->getParam('id');
73: $websiteId = (int) $this->getRequest()->getParam('website_id');
74:
75: $this->_quote = Mage::getModel('sales/quote')
76: ->setWebsite(Mage::app()->getWebsite($websiteId))
77: ->loadByCustomer($this->_customer);
78:
79: $this->_quoteItem = $this->_quote->getItemById($quoteItemId);
80: if (!$this->_quoteItem) {
81: Mage::throwException($this->__('Wrong quote item.'));
82: }
83:
84: return $this;
85: }
86:
87: /**
88: * Ajax handler to response configuration fieldset of composite product in customer's cart
89: *
90: * @return Mage_Adminhtml_Customer_Cart_Product_Composite_CartController
91: */
92: public function configureAction()
93: {
94: $configureResult = new Varien_Object();
95: try {
96: $this->_initData();
97:
98: $quoteItem = $this->_quoteItem;
99:
100: $optionCollection = Mage::getModel('sales/quote_item_option')
101: ->getCollection()
102: ->addItemFilter($quoteItem);
103: $quoteItem->setOptions($optionCollection->getOptionsByItem($quoteItem));
104:
105: $configureResult->setOk(true);
106: $configureResult->setProductId($quoteItem->getProductId());
107: $configureResult->setBuyRequest($quoteItem->getBuyRequest());
108: $configureResult->setCurrentStoreId($quoteItem->getStoreId());
109: $configureResult->setCurrentCustomer($this->_customer);
110: } catch (Exception $e) {
111: $configureResult->setError(true);
112: $configureResult->setMessage($e->getMessage());
113: }
114:
115: /* @var $helper Mage_Adminhtml_Helper_Catalog_Product_Composite */
116: $helper = Mage::helper('adminhtml/catalog_product_composite');
117: $helper->renderConfigureResult($this, $configureResult);
118:
119: return $this;
120: }
121:
122: /**
123: * IFrame handler for submitted configuration for quote item
124: *
125: * @return Mage_Adminhtml_Customer_Cart_Product_Composite_CartController
126: */
127: public function updateAction()
128: {
129: $updateResult = new Varien_Object();
130: try {
131: $this->_initData();
132:
133: $buyRequest = new Varien_Object($this->getRequest()->getParams());
134: $this->_quote->updateItem($this->_quoteItem->getId(), $buyRequest);
135: $this->_quote->collectTotals()
136: ->save();
137:
138: $updateResult->setOk(true);
139: } catch (Exception $e) {
140: $updateResult->setError(true);
141: $updateResult->setMessage($e->getMessage());
142: }
143:
144: $updateResult->setJsVarName($this->getRequest()->getParam('as_js_varname'));
145: Mage::getSingleton('adminhtml/session')->setCompositeProductResult($updateResult);
146: $this->_redirect('*/catalog_product/showUpdateResult');
147:
148: return $this;
149: }
150:
151: /**
152: * Check the permission to Manage Customers
153: *
154: * @return bool
155: */
156: protected function _isAllowed()
157: {
158: return Mage::getSingleton('admin/session')->isAllowed('customer/manage');
159: }
160: }
161: