Mage_Sales_Model_Quote_Item_Abstract Class Reference

Inheritance diagram for Mage_Sales_Model_Quote_Item_Abstract:

Mage_Core_Model_Abstract Varien_Object Mage_Sales_Model_Quote_Address_Item Mage_Sales_Model_Quote_Item

List of all members.

Public Member Functions

 getQuote ()
 setParentItem ($parentItem)
 getParentItem ()
 getChildren ()
 addChild ($child)
 setMessage ($messages)
 addMessage ($message)
 getMessage ($string=true)
 getStore ()
 checkData ()
 calcRowTotal ()
 calcTaxAmount ()
 getCalculationPrice ()
 getBaseCalculationPrice ()
 getOriginalPrice ()
 getTaxAmount ()
 getPrice ()
 setCustomPrice ($value)
 setPrice ($value)
 __clone ()
 isChildrenCalculated ()
 isShipSeparately ()

Protected Member Functions

 _beforeSave ()
 _calculatePrice ($value, $saveTaxes=true)

Protected Attributes

 $_parentItem = null
 $_children = array()
 $_messages = array()


Detailed Description

Definition at line 34 of file Abstract.php.


Member Function Documentation

__clone (  ) 

Clone quote item

Returns:
Mage_Sales_Model_Quote_Item

Reimplemented in Mage_Sales_Model_Quote_Item.

Definition at line 502 of file Abstract.php.

00503     {
00504         $this->setId(null);
00505         $this->_parentItem  = null;
00506         $this->_children    = array();
00507         return $this;
00508     }

_beforeSave (  )  [protected]

Processing object before save data

Returns:
Mage_Core_Model_Abstract

Reimplemented from Mage_Core_Model_Abstract.

Reimplemented in Mage_Sales_Model_Quote_Address_Item, and Mage_Sales_Model_Quote_Item.

Definition at line 47 of file Abstract.php.

00048     {
00049         parent::_beforeSave();
00050         if ($this->getParentItem()) {
00051             $this->setParentItemId($this->getParentItem()->getId());
00052         }
00053         return $this;
00054     }

_calculatePrice ( value,
saveTaxes = true 
) [protected]

Definition at line 403 of file Abstract.php.

00404     {
00405         $store = $this->getQuote()->getStore();
00406 
00407         if (Mage::helper('tax')->priceIncludesTax($store)) {
00408             $bAddress = $this->getQuote()->getBillingAddress();
00409             $sAddress = $this->getQuote()->getShippingAddress();
00410 
00411             $address = $this->getAddress();
00412 
00413             if ($address) {
00414                 switch ($address->getAddressType()) {
00415                     case Mage_Sales_Model_Quote_Address::TYPE_BILLING:
00416                         $bAddress = $address;
00417                         break;
00418                     case Mage_Sales_Model_Quote_Address::TYPE_SHIPPING:
00419                         $sAddress = $address;
00420                         break;
00421                 }
00422             }
00423 
00424             if ($this->getProduct()->getIsVirtual()) {
00425                 $sAddress = $bAddress;
00426             }
00427 
00428             $priceExcludingTax = Mage::helper('tax')->getPrice(
00429                 $this->getProduct()->setTaxPercent(null),
00430                 $value,
00431                 false,
00432                 $sAddress,
00433                 $bAddress,
00434                 $this->getQuote()->getCustomerTaxClassId(),
00435                 $store
00436             );
00437 
00438             $priceIncludingTax = Mage::helper('tax')->getPrice(
00439                 $this->getProduct()->setTaxPercent(null),
00440                 $value,
00441                 true,
00442                 $sAddress,
00443                 $bAddress,
00444                 $this->getQuote()->getCustomerTaxClassId(),
00445                 $store
00446             );
00447 
00448             if ($saveTaxes) {
00449                 $qty = $this->getQty();
00450                 if ($this->getParentItem()) {
00451                     $qty = $qty*$this->getParentItem()->getQty();
00452                 }
00453 
00454                 if (Mage::helper('tax')->displayCartPriceInclTax($store)) {
00455                     $rowTotal = $value*$qty;
00456                     $rowTotalExcTax = Mage::helper('tax')->getPrice(
00457                         $this->getProduct()->setTaxPercent(null),
00458                         $rowTotal,
00459                         false,
00460                         $sAddress,
00461                         $bAddress,
00462                         $this->getQuote()->getCustomerTaxClassId(),
00463                         $store
00464                     );
00465                     $rowTotalIncTax = Mage::helper('tax')->getPrice(
00466                         $this->getProduct()->setTaxPercent(null),
00467                         $rowTotal,
00468                         true,
00469                         $sAddress,
00470                         $bAddress,
00471                         $this->getQuote()->getCustomerTaxClassId(),
00472                         $store
00473                     );
00474                     $totalBaseTax = $rowTotalIncTax-$rowTotalExcTax;
00475                     $this->setRowTotalExcTax($rowTotalExcTax);
00476                 }
00477                 else {
00478                     $taxAmount = $priceIncludingTax - $priceExcludingTax;
00479                     $this->setTaxPercent($this->getProduct()->getTaxPercent());
00480                     $totalBaseTax = $taxAmount*$qty;
00481                 }
00482 
00483                 $totalTax = $this->getStore()->convertPrice($totalBaseTax);
00484                 $this->setTaxBeforeDiscount($totalTax);
00485                 $this->setBaseTaxBeforeDiscount($totalBaseTax);
00486 
00487                 $this->setTaxAmount($totalTax);
00488                 $this->setBaseTaxAmount($totalBaseTax);
00489             }
00490 
00491             $value = $priceExcludingTax;
00492         }
00493 
00494         return $value;
00495     }

addChild ( child  ) 

Add child item

Parameters:
Mage_Sales_Model_Quote_Item_Abstract $child
Returns:
Mage_Sales_Model_Quote_Item_Abstract

Definition at line 98 of file Abstract.php.

00099     {
00100         $this->setHasChildren(true);
00101         $this->_children[] = $child;
00102         return $this;
00103     }

addMessage ( message  ) 

Add message of quote item to array of messages

Parameters:
string $message
Returns:
Mage_Sales_Model_Quote_Item_Abstract

Definition at line 127 of file Abstract.php.

00128     {
00129         $this->_messages[] = $message;
00130         return $this;
00131     }

calcRowTotal (  ) 

Calculate item row total price

Returns:
Mage_Sales_Model_Quote_Item

Definition at line 201 of file Abstract.php.

00202     {
00203         $qty = $this->getQty();
00204 
00205         if ($this->getParentItem()) {
00206             $qty = $qty*$this->getParentItem()->getQty();
00207         }
00208 
00209         if ($rowTotal = $this->getRowTotalExcTax()) {
00210             $baseTotal = $rowTotal;
00211             $total = $this->getStore()->convertPrice($baseTotal);
00212         }
00213         else {
00214             $total      = $this->getCalculationPrice()*$qty;
00215             $baseTotal  = $this->getBaseCalculationPrice()*$qty;
00216         }
00217 
00218         $this->setRowTotal($this->getStore()->roundPrice($total));
00219         $this->setBaseRowTotal($this->getStore()->roundPrice($baseTotal));
00220 
00221         return $this;
00222     }

calcTaxAmount (  ) 

Calculate item tax amount

Returns:
Mage_Sales_Model_Quote_Item

Definition at line 229 of file Abstract.php.

00230     {
00231         $store = $this->getStore();
00232 
00233         if (!Mage::helper('tax')->priceIncludesTax($store)) {
00234             if (Mage::helper('tax')->applyTaxAfterDiscount($store)) {
00235                 $rowTotal       = $this->getRowTotalWithDiscount();
00236                 $rowBaseTotal   = $this->getBaseRowTotalWithDiscount();
00237             } else {
00238                 $rowTotal       = $this->getRowTotal();
00239                 $rowBaseTotal   = $this->getBaseRowTotal();
00240             }
00241 
00242             $taxPercent = $this->getTaxPercent()/100;
00243 
00244             $this->setTaxAmount($store->roundPrice($rowTotal * $taxPercent));
00245             $this->setBaseTaxAmount($store->roundPrice($rowBaseTotal * $taxPercent));
00246 
00247             $rowTotal       = $this->getRowTotal();
00248             $rowBaseTotal   = $this->getBaseRowTotal();
00249             $this->setTaxBeforeDiscount($store->roundPrice($rowTotal * $taxPercent));
00250             $this->setBaseTaxBeforeDiscount($store->roundPrice($rowBaseTotal * $taxPercent));
00251         } else {
00252             if (Mage::helper('tax')->applyTaxAfterDiscount($store)) {
00253                 $totalBaseTax = $this->getBaseTaxAmount();
00254                 $totalTax = $this->getTaxAmount();
00255 
00256                 if ($totalTax && $totalBaseTax) {
00257                     $totalTax -= $this->getDiscountAmount()*($this->getTaxPercent()/100);
00258                     $totalBaseTax -= $this->getBaseDiscountAmount()*($this->getTaxPercent()/100);
00259 
00260                     $this->setBaseTaxAmount($store->roundPrice($totalBaseTax));
00261                     $this->setTaxAmount($store->roundPrice($totalTax));
00262                 }
00263             }
00264         }
00265 
00266         if (Mage::helper('tax')->discountTax($store) && !Mage::helper('tax')->applyTaxAfterDiscount($store)) {
00267             if ($this->getDiscountPercent()) {
00268                 $baseTaxAmount =  $this->getBaseTaxBeforeDiscount();
00269                 $taxAmount = $this->getTaxBeforeDiscount();
00270 
00271                 $baseDiscountDisposition = $baseTaxAmount/100*$this->getDiscountPercent();
00272                 $discountDisposition = $taxAmount/100*$this->getDiscountPercent();
00273 
00274                 $this->setDiscountAmount($this->getDiscountAmount()+$discountDisposition);
00275                 $this->setBaseDiscountAmount($this->getBaseDiscountAmount()+$baseDiscountDisposition);
00276             }
00277         }
00278 
00279         return $this;
00280     }

checkData (  ) 

Checking item data

Returns:
Mage_Sales_Model_Quote_Item_Abstract

Definition at line 161 of file Abstract.php.

00162     {
00163         $this->setHasError(false);
00164         $this->unsMessage();
00165 
00166         $qty = $this->getData('qty');
00167         try {
00168             $this->setQty($qty);
00169         }
00170         catch (Mage_Core_Exception $e){
00171             $this->setHasError(true);
00172             $this->setMessage($e->getMessage());
00173         }
00174         catch (Exception $e){
00175             $this->setHasError(true);
00176             $this->setMessage(Mage::helper('sales')->__('Item qty declare error'));
00177         }
00178 
00179         try {
00180             $this->getProduct()->getTypeInstance(true)->checkProductBuyState($this->getProduct());
00181         } catch (Mage_Core_Exception $e) {
00182             $this->setHasError(true);
00183             $this->setMessage($e->getMessage());
00184             $this->getQuote()->setHasError(true);
00185             $this->getQuote()->addMessage(Mage::helper('sales')->__('Some of the products below don\'t have all the required options. Please remove them and add again with all the required options.'));
00186         } catch (Exception $e) {
00187             $this->setHasError(true);
00188             $this->setMessage(Mage::helper('sales')->__('Item options declare error'));
00189             $this->getQuote()->setHasError(true);
00190             $this->getQuote()->addMessage(Mage::helper('sales')->__('Items options declare error.'));
00191         }
00192 
00193         return $this;
00194     }

getBaseCalculationPrice (  ) 

Retrieve calculation price in base currency

Returns:
unknown

Definition at line 307 of file Abstract.php.

00308     {
00309         if (!$this->hasBaseCalculationPrice()) {
00310             if ($this->hasCustomPrice()) {
00311                 if ($price = (float) $this->getCustomPrice()) {
00312                     $rate = $this->getStore()->convertPrice($price) / $price;
00313                     $price = $price / $rate;
00314                 }
00315                 else {
00316                     $price = $this->getCustomPrice();
00317                 }
00318             } else {
00319                 $price = $this->getPrice();
00320             }
00321             $this->setBaseCalculationPrice($price);
00322         }
00323         return $this->getData('base_calculation_price');
00324     }

getCalculationPrice (  ) 

Retrieve item price used for calculation

Returns:
unknown

Definition at line 287 of file Abstract.php.

00288     {
00289         $price = $this->getData('calculation_price');
00290         if (is_null($price)) {
00291             if ($this->hasCustomPrice()) {
00292                 $price = $this->getCustomPrice();
00293             }
00294             else {
00295                 $price = $this->getOriginalPrice();
00296             }
00297             $this->setData('calculation_price', $price);
00298         }
00299         return $price;
00300     }

getChildren (  ) 

Get chil items

Returns:
array

Definition at line 87 of file Abstract.php.

00088     {
00089         return $this->_children;
00090     }

getMessage ( string = true  ) 

Get messages array of quote item

Returns:
array

Definition at line 138 of file Abstract.php.

00139     {
00140         if ($string) {
00141             return join("\n", $this->_messages);
00142         }
00143         return $this->_messages;
00144     }

getOriginalPrice (  ) 

Retrieve original price (retrieved from product) for item

Returns:
float

Definition at line 331 of file Abstract.php.

00332     {
00333         $price = $this->getData('original_price');
00334         if (is_null($price)) {
00335             $price = $this->getStore()->convertPrice($this->getPrice());
00336             $this->setData('original_price', $price);
00337         }
00338         return $price;
00339     }

getParentItem (  ) 

Get parent item

Returns:
Mage_Sales_Model_Quote_Item

Definition at line 77 of file Abstract.php.

00078     {
00079         return $this->_parentItem;
00080     }

getPrice (  ) 

Get item price (item price always exclude price)

Returns:
decimal

Definition at line 366 of file Abstract.php.

00367     {
00368         $priceType = $this->getProduct()->getPriceType();
00369         if ($this->getHasChildren() && (null !== $priceType) && (int)$priceType === Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD) {
00370             $price = $this->_getData('price');
00371             /*
00372             foreach ($this->getChildren() as $child) {
00373                 $price+= $child->getPrice()*$child->getQty();
00374             }
00375             */
00376             return $price;
00377         }
00378         else {
00379             return $this->_getData('price');
00380         }
00381     }

getQuote (  )  [abstract]

Retrieve Quote instance

Returns:
Mage_Sales_Model_Quote

Reimplemented in Mage_Sales_Model_Quote_Address_Item, and Mage_Sales_Model_Quote_Item.

getStore (  ) 

Retrieve store model object

Returns:
Mage_Core_Model_Store

Definition at line 151 of file Abstract.php.

00152     {
00153         return $this->getQuote()->getStore();
00154     }

getTaxAmount (  ) 

Get item tax amount

Returns:
decimal

Definition at line 346 of file Abstract.php.

00347     {
00348         $priceType = $this->getProduct()->getPriceType();
00349         if ($this->getHasChildren() && (null !== $priceType) && (int)$priceType === Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD) {
00350             $amount = 0;
00351             foreach ($this->getChildren() as $child) {
00352                 $amount+= $child->getTaxAmount();
00353             }
00354             return $amount;
00355         }
00356         else {
00357             return $this->_getData('tax_amount');
00358         }
00359     }

isChildrenCalculated (  ) 

Checking if there children calculated or parent item when we have parent quote item and its children

Returns:
bool

Definition at line 516 of file Abstract.php.

00516                                            {
00517         if ($this->getParentItem()) {
00518             $calculate = $this->getParentItem()->getProduct()->getPriceType();
00519         } else {
00520             $calculate = $this->getProduct()->getPriceType();
00521         }
00522 
00523         if ((null !== $calculate) && (int)$calculate === Mage_Catalog_Model_Product_Type_Abstract::CALCULATE_CHILD) {
00524             return true;
00525         }
00526         return false;
00527     }

isShipSeparately (  ) 

Checking can we ship product separatelly (each child separately) or each parent product item can be shipped only like one item

Returns:
bool

Definition at line 536 of file Abstract.php.

00536                                        {
00537         if ($this->getParentItem()) {
00538             $shipmentType = $this->getParentItem()->getProduct()->getShipmentType();
00539         } else {
00540             $shipmentType = $this->getProduct()->getShipmentType();
00541         }
00542 
00543         if ((null !== $shipmentType) && (int)$shipmentType === Mage_Catalog_Model_Product_Type_Abstract::SHIPMENT_SEPARATELY) {
00544             return true;
00545         }
00546         return false;
00547     }

setCustomPrice ( value  ) 

Definition at line 383 of file Abstract.php.

00384     {
00385         if (is_null($value)) {
00386             return $this->setData('custom_price', $value);
00387         }
00388 
00389         $excludingTax = $this->_calculatePrice($value, Mage::helper('tax')->applyTaxOnCustomPrice());
00390         $this->setData('original_custom_price', $value);
00391         return $this->setData('custom_price', $excludingTax);
00392     }

setMessage ( messages  ) 

Set masseges for quote item

Parameters:
mixed $messages
Returns:
Mage_Sales_Model_Quote_Item_Abstract

Definition at line 111 of file Abstract.php.

00111                                           {
00112         if (!is_array($messages)) {
00113             $messages = array($messages);
00114         }
00115         foreach ($messages as $message) {
00116             $this->addMessage($message);
00117         }
00118         return $this;
00119     }

setParentItem ( parentItem  ) 

Set parent item

Parameters:
Mage_Sales_Model_Quote_Item $parentItem
Returns:
Mage_Sales_Model_Quote_Item

Definition at line 63 of file Abstract.php.

00064     {
00065         if ($parentItem) {
00066             $this->_parentItem = $parentItem;
00067             $parentItem->addChild($this);
00068         }
00069         return $this;
00070     }

setPrice ( value  ) 

Definition at line 394 of file Abstract.php.

00395     {
00396         $saveTaxes = true;
00397         if (Mage::helper('tax')->applyTaxOnCustomPrice() && $this->hasCustomPrice()) {
00398             $saveTaxes = false;
00399         }
00400         return $this->setData('price', $this->_calculatePrice($value, $saveTaxes));
00401     }


Member Data Documentation

$_children = array() [protected]

Definition at line 37 of file Abstract.php.

$_messages = array() [protected]

Definition at line 38 of file Abstract.php.

$_parentItem = null [protected]

Definition at line 36 of file Abstract.php.


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

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