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 sales order create sidebar block
29: *
30: * @category Mage
31: * @package Mage_Adminhtml
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Adminhtml_Block_Sales_Order_Create_Sidebar_Abstract extends Mage_Adminhtml_Block_Sales_Order_Create_Abstract
35: {
36: /**
37: * Default Storage action on selected item
38: *
39: * @var string
40: */
41: protected $_sidebarStorageAction = 'add';
42:
43: /**
44: * Return name of sidebar storage action
45: *
46: * @return string
47: */
48: public function getSidebarStorageAction()
49: {
50: return $this->_sidebarStorageAction;
51: }
52:
53: /**
54: * Retrieve display block availability
55: *
56: * @return bool
57: */
58: public function canDisplay()
59: {
60: return $this->getCustomerId();
61: }
62:
63: public function canDisplayItemQty()
64: {
65: return false;
66: }
67:
68: /**
69: * Retrieve availability removing items in block
70: *
71: * @return bool
72: */
73: public function canRemoveItems()
74: {
75: return true;
76: }
77:
78: /**
79: * Retrieve identifier of block item
80: *
81: * @param Varien_Object $item
82: * @return int
83: */
84: public function getIdentifierId($item)
85: {
86: return $item->getProductId();
87: }
88:
89: /**
90: * Retrieve item identifier of block item
91: *
92: * @param mixed $item
93: * @return int
94: */
95: public function getItemId($item)
96: {
97: return $item->getId();
98: }
99:
100: /**
101: * Retrieve product identifier linked with item
102: *
103: * @param mixed $item
104: * @return int
105: */
106: public function getProductId($item)
107: {
108: return $item->getId();
109: }
110:
111: /**
112: * Retreive item count
113: *
114: * @return int
115: */
116: public function getItemCount()
117: {
118: $count = $this->getData('item_count');
119: if (is_null($count)) {
120: $count = count($this->getItems());
121: $this->setData('item_count', $count);
122: }
123: return $count;
124: }
125:
126: /**
127: * Retrieve all items
128: *
129: * @return array
130: */
131: public function getItems()
132: {
133: $items = array();
134: $collection = $this->getItemCollection();
135: if ($collection) {
136: $productTypes = Mage::getConfig()->getNode('adminhtml/sales/order/create/available_product_types')->asArray();
137: if (is_array($collection)) {
138: $items = $collection;
139: } else {
140: $items = $collection->getItems();
141: }
142:
143: /*
144: * Filtering items by allowed product type
145: */
146: foreach($items as $key => $item) {
147: if ($item instanceof Mage_Catalog_Model_Product) {
148: $type = $item->getTypeId();
149: } else if ($item instanceof Mage_Sales_Model_Order_Item) {
150: $type = $item->getProductType();
151: } else if ($item instanceof Mage_Sales_Model_Quote_Item) {
152: $type = $item->getProductType();
153: } else {
154: $type = '';
155: // Maybe some item, that can give us product via getProduct()
156: if (($item instanceof Varien_Object) || method_exists($item, 'getProduct')) {
157: $product = $item->getProduct();
158: if ($product && ($product instanceof Mage_Catalog_Model_Product)) {
159: $type = $product->getTypeId();
160: }
161: }
162: }
163: if (!isset($productTypes[$type])) {
164: unset($items[$key]);
165: }
166: }
167: }
168:
169: return $items;
170: }
171:
172: /**
173: * Retrieve item collection
174: *
175: * @return mixed
176: */
177: public function getItemCollection()
178: {
179: return false;
180: }
181:
182: public function canDisplayPrice()
183: {
184: return true;
185: }
186:
187: }
188: