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_Sales
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: * Order Item Model
29: *
30: * @method Mage_Sales_Model_Resource_Order_Item _getResource()
31: * @method Mage_Sales_Model_Resource_Order_Item getResource()
32: * @method int getOrderId()
33: * @method Mage_Sales_Model_Order_Item setOrderId(int $value)
34: * @method int getParentItemId()
35: * @method Mage_Sales_Model_Order_Item setParentItemId(int $value)
36: * @method int getQuoteItemId()
37: * @method Mage_Sales_Model_Order_Item setQuoteItemId(int $value)
38: * @method int getStoreId()
39: * @method Mage_Sales_Model_Order_Item setStoreId(int $value)
40: * @method string getCreatedAt()
41: * @method Mage_Sales_Model_Order_Item setCreatedAt(string $value)
42: * @method string getUpdatedAt()
43: * @method Mage_Sales_Model_Order_Item setUpdatedAt(string $value)
44: * @method int getProductId()
45: * @method Mage_Sales_Model_Order_Item setProductId(int $value)
46: * @method string getProductType()
47: * @method Mage_Sales_Model_Order_Item setProductType(string $value)
48: * @method float getWeight()
49: * @method Mage_Sales_Model_Order_Item setWeight(float $value)
50: * @method int getIsVirtual()
51: * @method Mage_Sales_Model_Order_Item setIsVirtual(int $value)
52: * @method string getSku()
53: * @method Mage_Sales_Model_Order_Item setSku(string $value)
54: * @method string getName()
55: * @method Mage_Sales_Model_Order_Item setName(string $value)
56: * @method string getDescription()
57: * @method Mage_Sales_Model_Order_Item setDescription(string $value)
58: * @method string getAppliedRuleIds()
59: * @method Mage_Sales_Model_Order_Item setAppliedRuleIds(string $value)
60: * @method string getAdditionalData()
61: * @method Mage_Sales_Model_Order_Item setAdditionalData(string $value)
62: * @method int getFreeShipping()
63: * @method Mage_Sales_Model_Order_Item setFreeShipping(int $value)
64: * @method int getIsQtyDecimal()
65: * @method Mage_Sales_Model_Order_Item setIsQtyDecimal(int $value)
66: * @method int getNoDiscount()
67: * @method Mage_Sales_Model_Order_Item setNoDiscount(int $value)
68: * @method float getQtyBackordered()
69: * @method Mage_Sales_Model_Order_Item setQtyBackordered(float $value)
70: * @method float getQtyCanceled()
71: * @method Mage_Sales_Model_Order_Item setQtyCanceled(float $value)
72: * @method float getQtyInvoiced()
73: * @method Mage_Sales_Model_Order_Item setQtyInvoiced(float $value)
74: * @method float getQtyOrdered()
75: * @method Mage_Sales_Model_Order_Item setQtyOrdered(float $value)
76: * @method float getQtyRefunded()
77: * @method Mage_Sales_Model_Order_Item setQtyRefunded(float $value)
78: * @method float getQtyShipped()
79: * @method Mage_Sales_Model_Order_Item setQtyShipped(float $value)
80: * @method float getBaseCost()
81: * @method Mage_Sales_Model_Order_Item setBaseCost(float $value)
82: * @method float getPrice()
83: * @method Mage_Sales_Model_Order_Item setPrice(float $value)
84: * @method float getBasePrice()
85: * @method Mage_Sales_Model_Order_Item setBasePrice(float $value)
86: * @method Mage_Sales_Model_Order_Item setOriginalPrice(float $value)
87: * @method float getBaseOriginalPrice()
88: * @method Mage_Sales_Model_Order_Item setBaseOriginalPrice(float $value)
89: * @method float getTaxPercent()
90: * @method Mage_Sales_Model_Order_Item setTaxPercent(float $value)
91: * @method float getTaxAmount()
92: * @method Mage_Sales_Model_Order_Item setTaxAmount(float $value)
93: * @method float getBaseTaxAmount()
94: * @method Mage_Sales_Model_Order_Item setBaseTaxAmount(float $value)
95: * @method float getTaxInvoiced()
96: * @method Mage_Sales_Model_Order_Item setTaxInvoiced(float $value)
97: * @method float getBaseTaxInvoiced()
98: * @method Mage_Sales_Model_Order_Item setBaseTaxInvoiced(float $value)
99: * @method float getDiscountPercent()
100: * @method Mage_Sales_Model_Order_Item setDiscountPercent(float $value)
101: * @method float getDiscountAmount()
102: * @method Mage_Sales_Model_Order_Item setDiscountAmount(float $value)
103: * @method float getBaseDiscountAmount()
104: * @method Mage_Sales_Model_Order_Item setBaseDiscountAmount(float $value)
105: * @method float getDiscountInvoiced()
106: * @method Mage_Sales_Model_Order_Item setDiscountInvoiced(float $value)
107: * @method float getBaseDiscountInvoiced()
108: * @method Mage_Sales_Model_Order_Item setBaseDiscountInvoiced(float $value)
109: * @method float getAmountRefunded()
110: * @method Mage_Sales_Model_Order_Item setAmountRefunded(float $value)
111: * @method float getBaseAmountRefunded()
112: * @method Mage_Sales_Model_Order_Item setBaseAmountRefunded(float $value)
113: * @method float getRowTotal()
114: * @method Mage_Sales_Model_Order_Item setRowTotal(float $value)
115: * @method float getBaseRowTotal()
116: * @method Mage_Sales_Model_Order_Item setBaseRowTotal(float $value)
117: * @method float getRowInvoiced()
118: * @method Mage_Sales_Model_Order_Item setRowInvoiced(float $value)
119: * @method float getBaseRowInvoiced()
120: * @method Mage_Sales_Model_Order_Item setBaseRowInvoiced(float $value)
121: * @method float getRowWeight()
122: * @method Mage_Sales_Model_Order_Item setRowWeight(float $value)
123: * @method int getGiftMessageId()
124: * @method Mage_Sales_Model_Order_Item setGiftMessageId(int $value)
125: * @method int getGiftMessageAvailable()
126: * @method Mage_Sales_Model_Order_Item setGiftMessageAvailable(int $value)
127: * @method float getBaseTaxBeforeDiscount()
128: * @method Mage_Sales_Model_Order_Item setBaseTaxBeforeDiscount(float $value)
129: * @method float getTaxBeforeDiscount()
130: * @method Mage_Sales_Model_Order_Item setTaxBeforeDiscount(float $value)
131: * @method string getExtOrderItemId()
132: * @method Mage_Sales_Model_Order_Item setExtOrderItemId(string $value)
133: * @method string getWeeeTaxApplied()
134: * @method Mage_Sales_Model_Order_Item setWeeeTaxApplied(string $value)
135: * @method float getWeeeTaxAppliedAmount()
136: * @method Mage_Sales_Model_Order_Item setWeeeTaxAppliedAmount(float $value)
137: * @method float getWeeeTaxAppliedRowAmount()
138: * @method Mage_Sales_Model_Order_Item setWeeeTaxAppliedRowAmount(float $value)
139: * @method float getBaseWeeeTaxAppliedAmount()
140: * @method Mage_Sales_Model_Order_Item setBaseWeeeTaxAppliedAmount(float $value)
141: * @method float getBaseWeeeTaxAppliedRowAmount()
142: * @method Mage_Sales_Model_Order_Item setBaseWeeeTaxAppliedRowAmount(float $value)
143: * @method float getWeeeTaxDisposition()
144: * @method Mage_Sales_Model_Order_Item setWeeeTaxDisposition(float $value)
145: * @method float getWeeeTaxRowDisposition()
146: * @method Mage_Sales_Model_Order_Item setWeeeTaxRowDisposition(float $value)
147: * @method float getBaseWeeeTaxDisposition()
148: * @method Mage_Sales_Model_Order_Item setBaseWeeeTaxDisposition(float $value)
149: * @method float getBaseWeeeTaxRowDisposition()
150: * @method Mage_Sales_Model_Order_Item setBaseWeeeTaxRowDisposition(float $value)
151: * @method int getLockedDoInvoice()
152: * @method Mage_Sales_Model_Order_Item setLockedDoInvoice(int $value)
153: * @method int getLockedDoShip()
154: * @method Mage_Sales_Model_Order_Item setLockedDoShip(int $value)
155: * @method float getPriceInclTax()
156: * @method Mage_Sales_Model_Order_Item setPriceInclTax(float $value)
157: * @method float getBasePriceInclTax()
158: * @method Mage_Sales_Model_Order_Item setBasePriceInclTax(float $value)
159: * @method float getRowTotalInclTax()
160: * @method Mage_Sales_Model_Order_Item setRowTotalInclTax(float $value)
161: * @method float getBaseRowTotalInclTax()
162: * @method Mage_Sales_Model_Order_Item setBaseRowTotalInclTax(float $value)
163: * @method float getHiddenTaxAmount()
164: * @method Mage_Sales_Model_Order_Item setHiddenTaxAmount(float $value)
165: * @method float getBaseHiddenTaxAmount()
166: * @method Mage_Sales_Model_Order_Item setBaseHiddenTaxAmount(float $value)
167: * @method float getHiddenTaxInvoiced()
168: * @method Mage_Sales_Model_Order_Item setHiddenTaxInvoiced(float $value)
169: * @method float getBaseHiddenTaxInvoiced()
170: * @method Mage_Sales_Model_Order_Item setBaseHiddenTaxInvoiced(float $value)
171: * @method float getHiddenTaxRefunded()
172: * @method Mage_Sales_Model_Order_Item setHiddenTaxRefunded(float $value)
173: * @method float getBaseHiddenTaxRefunded()
174: * @method Mage_Sales_Model_Order_Item setBaseHiddenTaxRefunded(float $value)
175: * @method int getIsNominal()
176: * @method Mage_Sales_Model_Order_Item setIsNominal(int $value)
177: * @method float getTaxCanceled()
178: * @method Mage_Sales_Model_Order_Item setTaxCanceled(float $value)
179: * @method float getHiddenTaxCanceled()
180: * @method Mage_Sales_Model_Order_Item setHiddenTaxCanceled(float $value)
181: * @method float getTaxRefunded()
182: * @method Mage_Sales_Model_Order_Item setTaxRefunded(float $value)
183: * @method float getBaseTaxRefunded()
184: * @method Mage_Sales_Model_Order_Item setBaseTaxRefunded(float $value)
185: * @method float getDiscountRefunded()
186: * @method Mage_Sales_Model_Order_Item setDiscountRefunded(float $value)
187: * @method float getBaseDiscountRefunded()
188: * @method Mage_Sales_Model_Order_Item setBaseDiscountRefunded(float $value)
189: *
190: * @category Mage
191: * @package Mage_Sales
192: * @author Magento Core Team <core@magentocommerce.com>
193: */
194: class Mage_Sales_Model_Order_Item extends Mage_Core_Model_Abstract
195: {
196:
197: const STATUS_PENDING = 1; // No items shipped, invoiced, canceled, refunded nor backordered
198: const STATUS_SHIPPED = 2; // When qty ordered - [qty canceled + qty returned] = qty shipped
199: const STATUS_INVOICED = 9; // When qty ordered - [qty canceled + qty returned] = qty invoiced
200: const STATUS_BACKORDERED = 3; // When qty ordered - [qty canceled + qty returned] = qty backordered
201: const STATUS_CANCELED = 5; // When qty ordered = qty canceled
202: const STATUS_PARTIAL = 6; // If [qty shipped or(max of two) qty invoiced + qty canceled + qty returned]
203: // < qty ordered
204: const STATUS_MIXED = 7; // All other combinations
205: const STATUS_REFUNDED = 8; // When qty ordered = qty refunded
206:
207: const STATUS_RETURNED = 4; // When qty ordered = qty returned // not used at the moment
208:
209: protected $_eventPrefix = 'sales_order_item';
210: protected $_eventObject = 'item';
211:
212: protected static $_statuses = null;
213:
214: /**
215: * Order instance
216: *
217: * @var Mage_Sales_Model_Order
218: */
219: protected $_order = null;
220: protected $_parentItem = null;
221: protected $_children = array();
222:
223: /**
224: * Init resource model
225: */
226: protected function _construct()
227: {
228: $this->_init('sales/order_item');
229: }
230:
231: /**
232: * Init mapping array of short fields to
233: * its full names
234: *
235: * @return Varien_Object
236: */
237: protected function _initOldFieldsMap()
238: {
239: $this->_oldFieldsMap = Mage::helper('sales')->getOldFieldMap('order_item');
240: return $this;
241: }
242:
243: /**
244: * Prepare data before save
245: *
246: * @return Mage_Sales_Model_Order_Item
247: */
248: protected function _beforeSave()
249: {
250: parent::_beforeSave();
251: if (!$this->getOrderId() && $this->getOrder()) {
252: $this->setOrderId($this->getOrder()->getId());
253: }
254: if ($this->getParentItem()) {
255: $this->setParentItemId($this->getParentItem()->getId());
256: }
257: return $this;
258: }
259:
260: /**
261: * Set parent item
262: *
263: * @param Mage_Sales_Model_Order_Item $item
264: * @return Mage_Sales_Model_Order_Item
265: */
266: public function setParentItem($item)
267: {
268: if ($item) {
269: $this->_parentItem = $item;
270: $item->setHasChildren(true);
271: $item->addChildItem($this);
272: }
273: return $this;
274: }
275:
276: /**
277: * Get parent item
278: *
279: * @return Mage_Sales_Model_Order_Item || null
280: */
281: public function getParentItem()
282: {
283: return $this->_parentItem;
284: }
285:
286: /**
287: * Check item invoice availability
288: *
289: * @return bool
290: */
291: public function canInvoice()
292: {
293: return $this->getQtyToInvoice()>0;
294: }
295:
296: /**
297: * Check item ship availability
298: *
299: * @return bool
300: */
301: public function canShip()
302: {
303: return $this->getQtyToShip()>0;
304: }
305:
306: /**
307: * Check item refund availability
308: *
309: * @return bool
310: */
311: public function canRefund()
312: {
313: return $this->getQtyToRefund()>0;
314: }
315:
316: /**
317: * Retrieve item qty available for ship
318: *
319: * @return float|integer
320: */
321: public function getQtyToShip()
322: {
323: if ($this->isDummy(true)) {
324: return 0;
325: }
326:
327: return $this->getSimpleQtyToShip();
328: }
329:
330: /**
331: * Retrieve item qty available for ship
332: *
333: * @return float|integer
334: */
335: public function getSimpleQtyToShip()
336: {
337: $qty = $this->getQtyOrdered()
338: - $this->getQtyShipped()
339: - $this->getQtyRefunded()
340: - $this->getQtyCanceled();
341: return max($qty, 0);
342: }
343:
344: /**
345: * Retrieve item qty available for invoice
346: *
347: * @return float|integer
348: */
349: public function getQtyToInvoice()
350: {
351: if ($this->isDummy()) {
352: return 0;
353: }
354:
355: $qty = $this->getQtyOrdered()
356: - $this->getQtyInvoiced()
357: - $this->getQtyCanceled();
358: return max($qty, 0);
359: }
360:
361: /**
362: * Retrieve item qty available for refund
363: *
364: * @return float|integer
365: */
366: public function getQtyToRefund()
367: {
368: if ($this->isDummy()) {
369: return 0;
370: }
371:
372: return max($this->getQtyInvoiced()-$this->getQtyRefunded(), 0);
373: }
374:
375: /**
376: * Retrieve item qty available for cancel
377: *
378: * @return float|integer
379: */
380: public function getQtyToCancel()
381: {
382: $qtyToCancel = min($this->getQtyToInvoice(), $this->getQtyToShip());
383: return max($qtyToCancel, 0);
384: }
385:
386: /**
387: * Declare order
388: *
389: * @param Mage_Sales_Model_Order $order
390: * @return Mage_Sales_Model_Order_Item
391: */
392: public function setOrder(Mage_Sales_Model_Order $order)
393: {
394: $this->_order = $order;
395: $this->setOrderId($order->getId());
396: return $this;
397: }
398:
399: /**
400: * Retrieve order model object
401: *
402: * @return Mage_Sales_Model_Order
403: */
404: public function getOrder()
405: {
406: if (is_null($this->_order) && ($orderId = $this->getOrderId())) {
407: $order = Mage::getModel('sales/order');
408: $order->load($orderId);
409: $this->setOrder($order);
410: }
411: return $this->_order;
412: }
413:
414: /**
415: * Retrieve item status identifier
416: *
417: * @return int
418: */
419: public function getStatusId()
420: {
421: $backordered = (float)$this->getQtyBackordered();
422: if (!$backordered && $this->getHasChildren()) {
423: $backordered = (float)$this->_getQtyChildrenBackordered();
424: }
425: $canceled = (float)$this->getQtyCanceled();
426: $invoiced = (float)$this->getQtyInvoiced();
427: $ordered = (float)$this->getQtyOrdered();
428: $refunded = (float)$this->getQtyRefunded();
429: $shipped = (float)$this->getQtyShipped();
430:
431: $actuallyOrdered = $ordered - $canceled - $refunded;
432:
433: if (!$invoiced && !$shipped && !$refunded && !$canceled && !$backordered) {
434: return self::STATUS_PENDING;
435: }
436: if ($shipped && $invoiced && ($actuallyOrdered == $shipped)) {
437: return self::STATUS_SHIPPED;
438: }
439:
440: if ($invoiced && !$shipped && ($actuallyOrdered == $invoiced)) {
441: return self::STATUS_INVOICED;
442: }
443:
444: if ($backordered && ($actuallyOrdered == $backordered) ) {
445: return self::STATUS_BACKORDERED;
446: }
447:
448: if ($refunded && $ordered == $refunded) {
449: return self::STATUS_REFUNDED;
450: }
451:
452: if ($canceled && $ordered == $canceled) {
453: return self::STATUS_CANCELED;
454: }
455:
456: if (max($shipped, $invoiced) < $actuallyOrdered) {
457: return self::STATUS_PARTIAL;
458: }
459:
460: return self::STATUS_MIXED;
461: }
462:
463: /**
464: * Retrieve backordered qty of children items
465: *
466: * @return float|null
467: */
468: protected function _getQtyChildrenBackordered()
469: {
470: $backordered = null;
471: foreach ($this->_children as $childItem) {
472: $backordered += (float)$childItem->getQtyBackordered();
473: }
474:
475: return $backordered;
476: }
477:
478: /**
479: * Retrieve status
480: *
481: * @return string
482: */
483: public function getStatus()
484: {
485: return $this->getStatusName($this->getStatusId());
486: }
487:
488: /**
489: * Retrieve status name
490: *
491: * @return string
492: */
493: public static function getStatusName($statusId)
494: {
495: if (is_null(self::$_statuses)) {
496: self::getStatuses();
497: }
498: if (isset(self::$_statuses[$statusId])) {
499: return self::$_statuses[$statusId];
500: }
501: return Mage::helper('sales')->__('Unknown Status');
502: }
503:
504: /**
505: * Cancel order item
506: *
507: * @return Mage_Sales_Model_Order_Item
508: */
509: public function cancel()
510: {
511: if ($this->getStatusId() !== self::STATUS_CANCELED) {
512: Mage::dispatchEvent('sales_order_item_cancel', array('item'=>$this));
513: $this->setQtyCanceled($this->getQtyToCancel());
514: $this->setTaxCanceled($this->getTaxCanceled() + $this->getBaseTaxAmount() * $this->getQtyCanceled() / $this->getQtyOrdered());
515: $this->setHiddenTaxCanceled($this->getHiddenTaxCanceled() + $this->getHiddenTaxAmount() * $this->getQtyCanceled() / $this->getQtyOrdered());
516: }
517: return $this;
518: }
519:
520: /**
521: * Retrieve order item statuses array
522: *
523: * @return array
524: */
525: public static function getStatuses()
526: {
527: if (is_null(self::$_statuses)) {
528: self::$_statuses = array(
529: //self::STATUS_PENDING => Mage::helper('sales')->__('Pending'),
530: self::STATUS_PENDING => Mage::helper('sales')->__('Ordered'),
531: self::STATUS_SHIPPED => Mage::helper('sales')->__('Shipped'),
532: self::STATUS_INVOICED => Mage::helper('sales')->__('Invoiced'),
533: self::STATUS_BACKORDERED => Mage::helper('sales')->__('Backordered'),
534: self::STATUS_RETURNED => Mage::helper('sales')->__('Returned'),
535: self::STATUS_REFUNDED => Mage::helper('sales')->__('Refunded'),
536: self::STATUS_CANCELED => Mage::helper('sales')->__('Canceled'),
537: self::STATUS_PARTIAL => Mage::helper('sales')->__('Partial'),
538: self::STATUS_MIXED => Mage::helper('sales')->__('Mixed'),
539: );
540: }
541: return self::$_statuses;
542: }
543:
544: /**
545: * Redeclare getter for back compatibility
546: *
547: * @return float
548: */
549: public function getOriginalPrice()
550: {
551: $price = $this->getData('original_price');
552: if (is_null($price)) {
553: return $this->getPrice();
554: }
555: return $price;
556: }
557:
558: /**
559: * Set product options
560: *
561: * @param array $options
562: * @return Mage_Sales_Model_Order_Item
563: */
564: public function setProductOptions(array $options)
565: {
566: $this->setData('product_options', serialize($options));
567: return $this;
568: }
569:
570: /**
571: * Get product options array
572: *
573: * @return array
574: */
575: public function getProductOptions()
576: {
577: if ($options = $this->_getData('product_options')) {
578: return unserialize($options);
579: }
580: return array();
581: }
582:
583: /**
584: * Get product options array by code.
585: * If code is null return all options
586: *
587: * @param string $code
588: * @return array
589: */
590: public function getProductOptionByCode($code=null)
591: {
592: $options = $this->getProductOptions();
593: if (is_null($code)) {
594: return $options;
595: }
596: if (isset($options[$code])) {
597: return $options[$code];
598: }
599: return null;
600: }
601:
602: /**
603: * Return real product type of item or NULL if item is not composite
604: *
605: * @return string | null
606: */
607: public function getRealProductType()
608: {
609: if ($productType = $this->getProductOptionByCode('real_product_type')) {
610: return $productType;
611: }
612: return null;
613: }
614:
615: /**
616: * Adds child item to this item
617: *
618: * @param Mage_Sales_Model_Order_Item $item
619: */
620: public function addChildItem($item)
621: {
622: if ($item instanceof Mage_Sales_Model_Order_Item) {
623: $this->_children[] = $item;
624: } else if (is_array($item)) {
625: $this->_children = array_merge($this->_children, $item);
626: }
627: }
628:
629: /**
630: * Return chilgren items of this item
631: *
632: * @return array
633: */
634: public function getChildrenItems() {
635: return $this->_children;
636: }
637:
638: /**
639: * Return checking of what calculation
640: * type was for this product
641: *
642: * @return bool
643: */
644: public function isChildrenCalculated() {
645: if ($parentItem = $this->getParentItem()) {
646: $options = $parentItem->getProductOptions();
647: } else {
648: $options = $this->getProductOptions();
649: }
650:
651: if (isset($options['product_calculations']) &&
652: $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD) {
653: return true;
654: }
655: return false;
656: }
657: /**
658: * Check if discount has to be applied to parent item
659: *
660: * @return bool
661: */
662: public function getForceApplyDiscountToParentItem()
663: {
664: if ($this->getParentItem()) {
665: $product = $this->getParentItem()->getProduct();
666: } else {
667: $product = $this->getProduct();
668: }
669:
670: return $product->getTypeInstance()->getForceApplyDiscountToParentItem();
671: }
672:
673: /**
674: * Return checking of what shipment
675: * type was for this product
676: *
677: * @return bool
678: */
679: public function isShipSeparately() {
680: if ($parentItem = $this->getParentItem()) {
681: $options = $parentItem->getProductOptions();
682: } else {
683: $options = $this->getProductOptions();
684: }
685:
686: if (isset($options['shipment_type']) &&
687: $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY) {
688: return true;
689: }
690: return false;
691: }
692:
693: /**
694: * This is Dummy item or not
695: * if $shipment is true then we checking this for shipping situation if not
696: * then we checking this for calculation
697: *
698: * @param bool $shipment
699: * @return bool
700: */
701: public function isDummy($shipment = false){
702: if ($shipment) {
703: if ($this->getHasChildren() && $this->isShipSeparately()) {
704: return true;
705: }
706:
707: if ($this->getHasChildren() && !$this->isShipSeparately()) {
708: return false;
709: }
710:
711: if ($this->getParentItem() && $this->isShipSeparately()) {
712: return false;
713: }
714:
715: if ($this->getParentItem() && !$this->isShipSeparately()) {
716: return true;
717: }
718: } else {
719: if ($this->getHasChildren() && $this->isChildrenCalculated()) {
720: return true;
721: }
722:
723: if ($this->getHasChildren() && !$this->isChildrenCalculated()) {
724: return false;
725: }
726:
727: if ($this->getParentItem() && $this->isChildrenCalculated()) {
728: return false;
729: }
730:
731: if ($this->getParentItem() && !$this->isChildrenCalculated()) {
732: return true;
733: }
734: }
735: return false;
736: }
737:
738: /**
739: * Returns formatted buy request - object, holding request received from
740: * product view page with keys and options for configured product
741: *
742: * @return Varien_Object
743: */
744: public function getBuyRequest()
745: {
746: $option = $this->getProductOptionByCode('info_buyRequest');
747: if (!$option) {
748: $option = array();
749: }
750: $buyRequest = new Varien_Object($option);
751: $buyRequest->setQty($this->getQtyOrdered() * 1);
752: return $buyRequest;
753: }
754:
755: /**
756: * Retrieve product
757: *
758: * @return Mage_Catalog_Model_Product
759: */
760: public function getProduct()
761: {
762: if (!$this->getData('product')) {
763: $product = Mage::getModel('catalog/product')->load($this->getProductId());
764: $this->setProduct($product);
765: }
766:
767: return $this->getData('product');
768: }
769: }
770: