1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Adminhtml_Block_Sales_Order_Create_Items_Grid extends Mage_Adminhtml_Block_Sales_Order_Create_Abstract
35: {
36: 37: 38: 39: 40:
41: protected $_moveToCustomerStorage = true;
42:
43: public function __construct()
44: {
45: parent::__construct();
46: $this->setId('sales_order_create_search_grid');
47: }
48:
49: public function getItems()
50: {
51: $items = $this->getParentBlock()->getItems();
52: $oldSuperMode = $this->getQuote()->getIsSuperMode();
53: $this->getQuote()->setIsSuperMode(false);
54: foreach ($items as $item) {
55:
56: $item->setQty($item->getQty());
57: $stockItem = $item->getProduct()->getStockItem();
58: if ($stockItem instanceof Mage_CatalogInventory_Model_Stock_Item) {
59:
60: 61: 62: 63: 64:
65: if ($item->getProduct()->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_DISABLED) {
66: $item->setMessage(Mage::helper('adminhtml')->__('This product is currently disabled.'));
67: $item->setHasError(true);
68: }
69: }
70: }
71: $this->getQuote()->setIsSuperMode($oldSuperMode);
72: return $items;
73: }
74:
75: public function getSession()
76: {
77: return $this->getParentBlock()->getSession();
78: }
79:
80: public function getItemEditablePrice($item)
81: {
82: return $item->getCalculationPrice()*1;
83: }
84:
85: public function getOriginalEditablePrice($item)
86: {
87: if ($item->hasOriginalCustomPrice()) {
88: $result = $item->getOriginalCustomPrice()*1;
89: } elseif ($item->hasCustomPrice()) {
90: $result = $item->getCustomPrice()*1;
91: } else {
92: if (Mage::helper('tax')->priceIncludesTax($this->getStore())) {
93: $result = $item->getPriceInclTax()*1;
94: } else {
95: $result = $item->getOriginalPrice()*1;
96: }
97: }
98: return $result;
99: }
100:
101: public function getItemOrigPrice($item)
102: {
103:
104: return $this->convertPrice($item->getPrice());
105: }
106:
107: public function isGiftMessagesAvailable($item=null)
108: {
109: if(is_null($item)) {
110: return $this->helper('giftmessage/message')->getIsMessagesAvailable(
111: 'items', $this->getQuote(), $this->getStore()
112: );
113: }
114:
115: return $this->helper('giftmessage/message')->getIsMessagesAvailable(
116: 'item', $item, $this->getStore()
117: );
118: }
119:
120: public function isAllowedForGiftMessage($item)
121: {
122: return Mage::getSingleton('adminhtml/giftmessage_save')->getIsAllowedQuoteItem($item);
123: }
124:
125: 126: 127: 128: 129:
130: public function displayTotalsIncludeTax()
131: {
132: $res = Mage::getSingleton('tax/config')->displayCartSubtotalInclTax($this->getStore())
133: || Mage::getSingleton('tax/config')->displayCartSubtotalBoth($this->getStore());
134: return $res;
135: }
136:
137: public function getSubtotal()
138: {
139: $address = $this->getQuoteAddress();
140: if ($this->displayTotalsIncludeTax()) {
141: if ($address->getSubtotalInclTax()) {
142: return $address->getSubtotalInclTax();
143: }
144: return $address->getSubtotal()+$address->getTaxAmount();
145: } else {
146: return $address->getSubtotal();
147: }
148: return false;
149: }
150:
151: public function getSubtotalWithDiscount()
152: {
153: $address = $this->getQuoteAddress();
154: if ($this->displayTotalsIncludeTax()) {
155: return $address->getSubtotal()+$address->getTaxAmount()+$this->getDiscountAmount();
156: } else {
157: return $address->getSubtotal()+$this->getDiscountAmount();
158: }
159: }
160:
161: public function getDiscountAmount()
162: {
163: return $this->getQuote()->getShippingAddress()->getDiscountAmount();
164: }
165:
166: 167: 168: 169: 170:
171: public function getQuoteAddress()
172: {
173: if ($this->getQuote()->isVirtual()) {
174: return $this->getQuote()->getBillingAddress();
175: }
176: else {
177: return $this->getQuote()->getShippingAddress();
178: }
179: }
180:
181: 182: 183: 184: 185: 186:
187: public function usedCustomPriceForItem($item)
188: {
189: return $item->hasCustomPrice();
190: }
191:
192: 193: 194: 195: 196: 197:
198: public function canApplyCustomPrice($item)
199: {
200: return !$item->isChildrenCalculated();
201: }
202:
203: public function getQtyTitle($item)
204: {
205: $prices = $item->getProduct()->getTierPrice();
206: if ($prices) {
207: $info = array();
208: foreach ($prices as $data) {
209: $qty = $data['price_qty']*1;
210: $price = $this->convertPrice($data['price']);
211: $info[] = $this->helper('sales')->__('Buy %s for price %s', $qty, $price);
212: }
213: return implode(', ', $info);
214: }
215: else {
216: return $this->helper('sales')->__('Item ordered qty');
217: }
218: }
219:
220: public function getTierHtml($item)
221: {
222: $html = '';
223: $prices = $item->getProduct()->getTierPrice();
224: if ($prices) {
225: foreach ($prices as $data) {
226: $qty = $data['price_qty']*1;
227: $price = $this->convertPrice($data['price']);
228: $info[] = $this->helper('sales')->__('%s for %s', $qty, $price);
229: }
230: $html = implode('<br/>', $info);
231: }
232: return $html;
233: }
234:
235: 236: 237: 238: 239: 240:
241: public function getCustomOptions(Mage_Sales_Model_Quote_Item $item)
242: {
243: $optionStr = '';
244: $this->_moveToCustomerStorage = true;
245: if ($optionIds = $item->getOptionByCode('option_ids')) {
246: foreach (explode(',', $optionIds->getValue()) as $optionId) {
247: if ($option = $item->getProduct()->getOptionById($optionId)) {
248: $optionValue = $item->getOptionByCode('option_' . $option->getId())->getValue();
249:
250: $optionStr .= $option->getTitle() . ':';
251:
252: $quoteItemOption = $item->getOptionByCode('option_' . $option->getId());
253: $group = $option->groupFactory($option->getType())
254: ->setOption($option)
255: ->setQuoteItemOption($quoteItemOption);
256:
257: $optionStr .= $group->getEditableOptionValue($quoteItemOption->getValue());
258: $optionStr .= "\n";
259: }
260: }
261: }
262: return $optionStr;
263: }
264:
265: 266: 267: 268: 269:
270: public function getMoveToCustomerStorage()
271: {
272: return $this->_moveToCustomerStorage;
273: }
274:
275: public function displaySubtotalInclTax($item)
276: {
277: if ($item->getTaxBeforeDiscount()) {
278: $tax = $item->getTaxBeforeDiscount();
279: } else {
280: $tax = $item->getTaxAmount() ? $item->getTaxAmount() : 0;
281: }
282: return $this->formatPrice($item->getRowTotal() + $tax);
283: }
284:
285: public function displayOriginalPriceInclTax($item)
286: {
287: $tax = 0;
288: if ($item->getTaxPercent()) {
289: $tax = $item->getPrice() * ($item->getTaxPercent() / 100);
290: }
291: return $this->convertPrice($item->getPrice()+($tax/$item->getQty()));
292: }
293:
294: public function displayRowTotalWithDiscountInclTax($item)
295: {
296: $tax = ($item->getTaxAmount() ? $item->getTaxAmount() : 0);
297: return $this->formatPrice($item->getRowTotal()-$item->getDiscountAmount()+$tax);
298: }
299:
300: public function getInclExclTaxMessage()
301: {
302: if (Mage::helper('tax')->priceIncludesTax($this->getStore())) {
303: return Mage::helper('sales')->__('* - Enter custom price including tax');
304: } else {
305: return Mage::helper('sales')->__('* - Enter custom price excluding tax');
306: }
307: }
308:
309: public function getStore()
310: {
311: return $this->getQuote()->getStore();
312: }
313:
314: 315: 316: 317: 318: 319:
320: public function getConfigureButtonHtml($item)
321: {
322: $product = $item->getProduct();
323:
324: $options = array('label' => Mage::helper('sales')->__('Configure'));
325: if ($product->canConfigure()) {
326: $options['onclick'] = sprintf('order.showQuoteItemConfiguration(%s)', $item->getId());
327: } else {
328: $options['class'] = ' disabled';
329: $options['title'] = Mage::helper('sales')->__('This product does not have any configurable options');
330: }
331:
332: return $this->getLayout()->createBlock('adminhtml/widget_button')
333: ->setData($options)
334: ->toHtml();
335: }
336:
337: 338: 339: 340: 341: 342:
343: public function ($item)
344: {
345: return $this->getLayout()
346: ->getBlock('order_item_extra_info')
347: ->setItem($item);
348: }
349:
350: 351: 352: 353: 354: 355:
356: public function isMoveToWishlistAllowed($item)
357: {
358: return $item->getProduct()->isVisibleInSiteVisibility();
359: }
360:
361:
362: 363: 364: 365: 366:
367: public function getCustomerWishlists()
368: {
369: return Mage::getModel("wishlist/wishlist")->getCollection()
370: ->filterByCustomerId($this->getCustomerId());
371: }
372: }
373: