Mage_Sales_Model_Order_Item Class Reference

Inheritance diagram for Mage_Sales_Model_Order_Item:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 setParentItem ($item)
 getParentItem ()
 canInvoice ()
 canShip ()
 canRefund ()
 getQtyToShip ()
 getQtyToInvoice ()
 getQtyToRefund ()
 getQtyToCancel ()
 setOrder (Mage_Sales_Model_Order $order)
 getOrder ()
 getStatusId ()
 getStatus ()
 cancel ()
 getOriginalPrice ()
 setProductOptions (array $options)
 getProductOptions ()
 getProductOptionByCode ($code=null)
 getRealProductType ()
 addChildItem ($item)
 getChildrenItems ()
 isChildrenCalculated ()
 isShipSeparately ()
 isDummy ($shipment=false)

Static Public Member Functions

static getStatusName ($statusId)
static getStatuses ()

Public Attributes

const STATUS_PENDING = 1
const STATUS_SHIPPED = 2
const STATUS_INVOICED = 9
const STATUS_BACKORDERED = 3
const STATUS_CANCELED = 5
const STATUS_PARTIAL = 6
const STATUS_MIXED = 7
const STATUS_REFUNDED = 8
const STATUS_RETURNED = 4

Protected Member Functions

 _construct ()
 _beforeSave ()

Protected Attributes

 $_eventPrefix = 'sales_order_item'
 $_eventObject = 'item'
 $_order = null
 $_parentItem = null
 $_children = array()

Static Protected Attributes

static $_statuses = null


Detailed Description

Definition at line 34 of file Item.php.


Member Function Documentation

_beforeSave (  )  [protected]

Prepare data before save

Returns:
Mage_Sales_Model_Order_Item

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 75 of file Item.php.

00076     {
00077         parent::_beforeSave();
00078         if (!$this->getOrderId()) {
00079             $this->setOrderId($this->getOrder()->getId());
00080         }
00081         if ($this->getParentItem()) {
00082             $this->setParentItemId($this->getParentItem()->getId());
00083         }
00084         return $this;
00085     }

_construct (  )  [protected]

Init resource model

Reimplemented from Varien_Object.

Definition at line 65 of file Item.php.

00066     {
00067         $this->_init('sales/order_item');
00068     }

addChildItem ( item  ) 

Adds child item to this item

Parameters:
Mage_Sales_Model_Order_Item $item

Definition at line 417 of file Item.php.

00418     {
00419         if ($item instanceof Mage_Sales_Model_Order_Item) {
00420             $this->_children[] = $item;
00421         } else if (is_array($item)) {
00422             $this->_children = array_merge($this->_children, $item);
00423         }
00424     }

cancel (  ) 

Cancel order item

Returns:
Mage_Sales_Model_Order_Item

Definition at line 308 of file Item.php.

00309     {
00310         if ($this->getStatusId() !== self::STATUS_CANCELED) {
00311             Mage::dispatchEvent('sales_order_item_cancel', array('item'=>$this));
00312             $this->setQtyCanceled($this->getQtyToCancel());
00313         }
00314         return $this;
00315     }

canInvoice (  ) 

Check item invoice availability

Returns:
bool

Definition at line 118 of file Item.php.

00119     {
00120         return $this->getQtyToInvoice()>0;
00121     }

canRefund (  ) 

Check item refund availability

Returns:
bool

Definition at line 138 of file Item.php.

00139     {
00140         return $this->getQtyToRefund()>0;
00141     }

canShip (  ) 

Check item ship availability

Returns:
bool

Definition at line 128 of file Item.php.

00129     {
00130         return $this->getQtyToShip()>0;
00131     }

getChildrenItems (  ) 

Return chilgren items of this item

Returns:
array

Definition at line 431 of file Item.php.

00431                                        {
00432         return $this->_children;
00433     }

getOrder (  ) 

Retrieve order model object

Returns:
Mage_Sales_Model_Order

Definition at line 221 of file Item.php.

00222     {
00223         if (is_null($this->_order) && ($orderId = $this->getOrderId())) {
00224             $order = Mage::getModel('sales/order');
00225             $order->load($orderId);
00226             $this->setOrder($order);
00227         }
00228         return $this->_order;
00229     }

getOriginalPrice (  ) 

Redeclare getter for back compatibility

Returns:
float

Definition at line 346 of file Item.php.

00347     {
00348         $price = $this->getData('original_price');
00349         if (is_null($price)) {
00350             return $this->getPrice();
00351         }
00352         return $price;
00353     }

getParentItem (  ) 

Get parent item

Returns:
Mage_Sales_Model_Order_Item || null

Definition at line 108 of file Item.php.

00109     {
00110         return $this->_parentItem;
00111     }

getProductOptionByCode ( code = null  ) 

Get product options array by code. If code is null return all options

Parameters:
string $code
Returns:
array

Definition at line 387 of file Item.php.

00388     {
00389         $options = $this->getProductOptions();
00390         if (is_null($code)) {
00391             return $options;
00392         }
00393         if (isset($options[$code])) {
00394             return $options[$code];
00395         }
00396         return null;
00397     }

getProductOptions (  ) 

Get product options array

Returns:
array

Definition at line 372 of file Item.php.

00373     {
00374         if ($options = $this->_getData('product_options')) {
00375             return unserialize($options);
00376         }
00377         return array();
00378     }

getQtyToCancel (  ) 

Retrieve item qty available for cancel

Returns:
float|integer

Definition at line 197 of file Item.php.

00198     {
00199         $qtyToCancel = min($this->getQtyToInvoice(), $this->getQtyToShip());
00200         return max($qtyToCancel, 0);
00201     }

getQtyToInvoice (  ) 

Retrieve item qty available for invoice

Returns:
float|integer

Definition at line 166 of file Item.php.

00167     {
00168         if ($this->isDummy()) {
00169             return 0;
00170         }
00171 
00172         $qty = $this->getQtyOrdered()
00173             - $this->getQtyInvoiced()
00174             - $this->getQtyCanceled();
00175         return max($qty, 0);
00176     }

getQtyToRefund (  ) 

Retrieve item qty available for refund

Returns:
float|integer

Definition at line 183 of file Item.php.

00184     {
00185         if ($this->isDummy()) {
00186             return 0;
00187         }
00188 
00189         return max($this->getQtyInvoiced()-$this->getQtyRefunded(), 0);
00190     }

getQtyToShip (  ) 

Retrieve item qty available for ship

Returns:
float|integer

Definition at line 148 of file Item.php.

00149     {
00150         if ($this->isDummy(true)) {
00151             return 0;
00152         }
00153 
00154         $qty = $this->getQtyOrdered()
00155             - $this->getQtyShipped()
00156             - $this->getQtyRefunded()
00157             - $this->getQtyCanceled();
00158         return max($qty, 0);
00159     }

getRealProductType (  ) 

Return real product type of item or NULL if item is not composite

Returns:
string | null

Definition at line 404 of file Item.php.

00405     {
00406         if ($productType = $this->getProductOptionByCode('real_product_type')) {
00407             return $productType;
00408         }
00409         return null;
00410     }

getStatus (  ) 

Retrieve status

Returns:
string

Definition at line 282 of file Item.php.

00283     {
00284         return $this->getStatusName($this->getStatusId());
00285     }

static getStatuses (  )  [static]

Retrieve order item statuses array

Returns:
array

Definition at line 322 of file Item.php.

00323     {
00324         if (is_null(self::$_statuses)) {
00325             self::$_statuses = array(
00326                 //self::STATUS_PENDING        => Mage::helper('sales')->__('Pending'),
00327                 self::STATUS_PENDING        => Mage::helper('sales')->__('Ordered'),
00328                 self::STATUS_SHIPPED        => Mage::helper('sales')->__('Shipped'),
00329                 self::STATUS_INVOICED       => Mage::helper('sales')->__('Invoiced'),
00330                 self::STATUS_BACKORDERED    => Mage::helper('sales')->__('Backordered'),
00331                 self::STATUS_RETURNED       => Mage::helper('sales')->__('Returned'),
00332                 self::STATUS_REFUNDED       => Mage::helper('sales')->__('Refunded'),
00333                 self::STATUS_CANCELED       => Mage::helper('sales')->__('Canceled'),
00334                 self::STATUS_PARTIAL        => Mage::helper('sales')->__('Partial'),
00335                 self::STATUS_MIXED          => Mage::helper('sales')->__('Mixed'),
00336             );
00337         }
00338         return self::$_statuses;
00339     }

getStatusId (  ) 

Retrieve item status identifier

Returns:
int

Definition at line 236 of file Item.php.

00237     {
00238         $backordered = (float)$this->getQtyBackordered();
00239         $canceled    = (float)$this->getQtyCanceled();
00240         $invoiced    = (float)$this->getQtyInvoiced();
00241         $ordered     = (float)$this->getQtyOrdered();
00242         $refunded    = (float)$this->getQtyRefunded();
00243         $shipped     = (float)$this->getQtyShipped();
00244 
00245         $actuallyOrdered = $ordered - $canceled - $refunded;
00246 
00247         if (!$invoiced && !$shipped && !$refunded && !$canceled && !$backordered) {
00248             return self::STATUS_PENDING;
00249         }
00250         if ($shipped && !$invoiced && ($actuallyOrdered == $shipped)) {
00251             return self::STATUS_SHIPPED;
00252         }
00253 
00254         if ($invoiced && !$shipped && ($actuallyOrdered == $invoiced)) {
00255             return self::STATUS_INVOICED;
00256         }
00257 
00258         if ($backordered && ($actuallyOrdered == $backordered) ) {
00259             return self::STATUS_BACKORDERED;
00260         }
00261 
00262         if ($refunded && $ordered == $refunded) {
00263             return self::STATUS_REFUNDED;
00264         }
00265 
00266         if ($canceled && $ordered == $canceled) {
00267             return self::STATUS_CANCELED;
00268         }
00269 
00270         if (max($shipped, $invoiced) < $actuallyOrdered) {
00271             return self::STATUS_PARTIAL;
00272         }
00273 
00274         return self::STATUS_MIXED;
00275     }

static getStatusName ( statusId  )  [static]

Retrieve status name

Returns:
string

Definition at line 292 of file Item.php.

00293     {
00294         if (is_null(self::$_statuses)) {
00295             self::getStatuses();
00296         }
00297         if (isset(self::$_statuses[$statusId])) {
00298             return self::$_statuses[$statusId];
00299         }
00300         return Mage::helper('sales')->__('Unknown Status');
00301     }

isChildrenCalculated (  ) 

Return checking of what calculation type was for this product

Returns:
bool

Definition at line 441 of file Item.php.

00441                                            {
00442         if ($parentItem = $this->getParentItem()) {
00443             $options = $parentItem->getProductOptions();
00444         } else {
00445             $options = $this->getProductOptions();
00446         }
00447 
00448         if (isset($options['product_calculations']) &&
00449              $options['product_calculations'] == Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD) {
00450                 return true;
00451         }
00452         return false;
00453     }

isDummy ( shipment = false  ) 

This is Dummy item or not if $shipment is true then we checking this for shipping situation if not then we checking this for calculation

Parameters:
bool $shipment
Returns:
bool

Definition at line 483 of file Item.php.

00483                                               {
00484         if ($shipment) {
00485             if ($this->getHasChildren() && $this->isShipSeparately()) {
00486                 return true;
00487             }
00488 
00489             if ($this->getHasChildren() && !$this->isShipSeparately()) {
00490                 return false;
00491             }
00492 
00493             if ($this->getParentItem() && $this->isShipSeparately()) {
00494                 return false;
00495             }
00496 
00497             if ($this->getParentItem() && !$this->isShipSeparately()) {
00498                 return true;
00499             }
00500         } else {
00501             if ($this->getHasChildren() && $this->isChildrenCalculated()) {
00502                 return true;
00503             }
00504 
00505             if ($this->getHasChildren() && !$this->isChildrenCalculated()) {
00506                 return false;
00507             }
00508 
00509             if ($this->getParentItem() && $this->isChildrenCalculated()) {
00510                 return false;
00511             }
00512 
00513             if ($this->getParentItem() && !$this->isChildrenCalculated()) {
00514                 return true;
00515             }
00516         }
00517         return false;
00518     }

isShipSeparately (  ) 

Return checking of what shipment type was for this product

Returns:
bool

Definition at line 461 of file Item.php.

00461                                        {
00462         if ($parentItem = $this->getParentItem()) {
00463             $options = $parentItem->getProductOptions();
00464         } else {
00465             $options = $this->getProductOptions();
00466         }
00467 
00468         if (isset($options['shipment_type']) &&
00469              $options['shipment_type'] == Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY) {
00470                 return true;
00471         }
00472         return false;
00473     }

setOrder ( Mage_Sales_Model_Order order  ) 

Declare order

Parameters:
Mage_Sales_Model_Order $order
Returns:
Mage_Sales_Model_Order_Item

Definition at line 209 of file Item.php.

00210     {
00211         $this->_order = $order;
00212         $this->setOrderId($order->getId());
00213         return $this;
00214     }

setParentItem ( item  ) 

Set parent item

Parameters:
Mage_Sales_Model_Order_Item $item
Returns:
Mage_Sales_Model_Order_Item

Definition at line 93 of file Item.php.

00094     {
00095         if ($item) {
00096             $this->_parentItem = $item;
00097             $item->setHasChildren(true);
00098             $item->addChildItem($this);
00099         }
00100         return $this;
00101     }

setProductOptions ( array options  ) 

Set product options

Parameters:
array $options
Returns:
Mage_Sales_Model_Order_Item

Definition at line 361 of file Item.php.

00362     {
00363         $this->setData('product_options', serialize($options));
00364         return $this;
00365     }


Member Data Documentation

$_children = array() [protected]

Definition at line 60 of file Item.php.

$_eventObject = 'item' [protected]

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 49 of file Item.php.

$_eventPrefix = 'sales_order_item' [protected]

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 48 of file Item.php.

$_order = null [protected]

Definition at line 58 of file Item.php.

$_parentItem = null [protected]

Definition at line 59 of file Item.php.

$_statuses = null [static, protected]

Definition at line 51 of file Item.php.

const STATUS_BACKORDERED = 3

Definition at line 40 of file Item.php.

const STATUS_CANCELED = 5

Definition at line 41 of file Item.php.

const STATUS_INVOICED = 9

Definition at line 39 of file Item.php.

const STATUS_MIXED = 7

Definition at line 43 of file Item.php.

const STATUS_PARTIAL = 6

Definition at line 42 of file Item.php.

const STATUS_PENDING = 1

Definition at line 37 of file Item.php.

const STATUS_REFUNDED = 8

Definition at line 44 of file Item.php.

const STATUS_RETURNED = 4

Definition at line 46 of file Item.php.

const STATUS_SHIPPED = 2

Definition at line 38 of file Item.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:47 2009 for Magento by  doxygen 1.5.8