Mage_Sales_Model_Quote Class Reference

Inheritance diagram for Mage_Sales_Model_Quote:

Mage_Core_Model_Abstract Varien_Object

List of all members.

Public Member Functions

 getStoreId ()
 getStore ()
 setStore (Mage_Core_Model_Store $store)
 getSharedStoreIds ()
 loadByCustomer ($customer)
 assignCustomer (Mage_Customer_Model_Customer $customer)
 setCustomer (Mage_Customer_Model_Customer $customer)
 getCustomer ()
 getCustomerTaxClassId ()
 getCheckoutMethod ($originalMethod=false)
 getAddressesCollection ()
 getBillingAddress ()
 getShippingAddress ()
 getAllShippingAddresses ()
 getAllAddresses ()
 getAddressById ($addressId)
 getAddressByCustomerAddressId ($addressId)
 getShippingAddressByCustomerAddressId ($addressId)
 removeAddress ($addressId)
 removeAllAddresses ()
 addAddress (Mage_Sales_Model_Quote_Address $address)
 setBillingAddress (Mage_Sales_Model_Quote_Address $address)
 setShippingAddress (Mage_Sales_Model_Quote_Address $address)
 addShippingAddress (Mage_Sales_Model_Quote_Address $address)
 getItemsCollection ($useCache=true)
 getAllItems ()
 getAllVisibleItems ()
 hasItems ()
 hasItemsWithDecimalQty ()
 getItemById ($itemId)
 removeItem ($itemId)
 addItem (Mage_Sales_Model_Quote_Item $item)
 addProduct (Mage_Catalog_Model_Product $product, $request=null)
 getItemByProduct ($product)
 getItemsSummaryQty ()
 getItemVirtualQty ()
 getPaymentsCollection ()
 getPayment ()
 getPaymentById ($paymentId)
 addPayment (Mage_Sales_Model_Quote_Payment $payment)
 setPayment (Mage_Sales_Model_Quote_Payment $payment)
 removePayment ()
 collectTotals ()
 getTotals ()
 addMessage ($message, $index='error')
 getMessages ()
 reserveOrderId ()
 validateMinimumAmount ($multishipping=false)
 isVirtual ()
 getIsVirtual ()
 hasVirtualItems ()
 isAllowedGuestCheckout ()
 merge (Mage_Sales_Model_Quote $quote)

Public Attributes

const CHECKOUT_METHOD_REGISTER = 'register'
const CHECKOUT_METHOD_GUEST = 'guest'
const CHECKOUT_METHOD_LOGIN_IN = 'login_in'

Protected Member Functions

 _construct ()
 _beforeSave ()
 _afterSave ()
 _getAddressByType ($type)
 _addCatalogProduct (Mage_Catalog_Model_Product $product, $qty=1)
 _validateCouponCode ()
 _afterLoad ()

Protected Attributes

 $_eventPrefix = 'sales_quote'
 $_eventObject = 'quote'
 $_customer
 $_addresses = null
 $_items = null
 $_payments = null


Detailed Description

Quote model

Supported events: sales_quote_load_after sales_quote_save_before sales_quote_save_after sales_quote_delete_before sales_quote_delete_after

Author:
Magento Core Team <core@magentocommerce.com>

Definition at line 39 of file Quote.php.


Member Function Documentation

_addCatalogProduct ( Mage_Catalog_Model_Product product,
qty = 1 
) [protected]

Adding catalog product object data to quote

Parameters:
Mage_Catalog_Model_Product $product
Returns:
Mage_Sales_Model_Quote_Item

We can't modify existing child items

Definition at line 729 of file Quote.php.

00730     {
00731 
00732         $item = $this->getItemByProduct($product);
00733         if (!$item) {
00734             $item = Mage::getModel('sales/quote_item');
00735             $item->setQuote($this);
00736         }
00737 
00738         /**
00739          * We can't modify existing child items
00740          */
00741         if ($item->getId() && $product->getParentProductId()) {
00742             return $item;
00743         }
00744 
00745         $item->setOptions($product->getCustomOptions())
00746             ->setProduct($product);
00747 
00748         $this->addItem($item);
00749 
00750         return $item;
00751     }

_afterLoad (  )  [protected]

Trigger collect totals after loading, if required

Returns:
Mage_Sales_Model_Quote

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 1213 of file Quote.php.

01214     {
01215         // collect totals and save me, if required
01216         if (1 == $this->getData('trigger_recollect')) {
01217             $this->collectTotals()->save();
01218         }
01219         return parent::_afterLoad();
01220     }

_afterSave (  )  [protected]

Save related items

Returns:
Mage_Sales_Model_Quote

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 205 of file Quote.php.

00206     {
00207         parent::_afterSave();
00208 
00209         if (null !== $this->_addresses) {
00210             $this->getAddressesCollection()->save();
00211         }
00212 
00213         if (null !== $this->_items) {
00214             $this->getItemsCollection()->save();
00215         }
00216 
00217         if (null !== $this->_payments) {
00218             $this->getPaymentsCollection()->save();
00219         }
00220         return $this;
00221     }

_beforeSave (  )  [protected]

Prepare data before save

Returns:
Mage_Sales_Model_Quote

Currency logic

global - currency which is set for default in backend base - currency which is set for current website. all attributes that have 'base_' prefix saved in this currency store - all the time it was currency of website and all attributes with 'base_' were saved in this currency. From now on it is deprecated and will be duplication of base currency code. quote/order - currency which was selected by customer or configured by admin for current store. currency in which customer sees price thought all checkout.

Rates: store_to_base & store_to_quote/store_to_order - are deprecated base_to_global & base_to_quote/base_to_order - must be used instead

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 150 of file Quote.php.

00151     {
00152         /**
00153          * Currency logic
00154          *
00155          * global - currency which is set for default in backend
00156          * base - currency which is set for current website. all attributes that
00157          *      have 'base_' prefix saved in this currency
00158          * store - all the time it was currency of website and all attributes
00159          *      with 'base_' were saved in this currency. From now on it is
00160          *      deprecated and will be duplication of base currency code.
00161          * quote/order - currency which was selected by customer or configured by
00162          *      admin for current store. currency in which customer sees
00163          *      price thought all checkout.
00164          *
00165          * Rates:
00166          *      store_to_base & store_to_quote/store_to_order - are deprecated
00167          *      base_to_global & base_to_quote/base_to_order - must be used instead
00168          */
00169 
00170         $globalCurrencyCode  = Mage::app()->getBaseCurrencyCode();
00171         $baseCurrency = $this->getStore()->getBaseCurrency();
00172 
00173         if ($this->hasForcedCurrency()){
00174             $quoteCurrency = $this->getForcedCurrency();
00175         } else {
00176             $quoteCurrency = $this->getStore()->getCurrentCurrency();
00177         }
00178 
00179         $this->setGlobalCurrencyCode($globalCurrencyCode);
00180         $this->setBaseCurrencyCode($baseCurrency->getCode());
00181         $this->setStoreCurrencyCode($baseCurrency->getCode());
00182         $this->setQuoteCurrencyCode($quoteCurrency->getCode());
00183 
00184         //deprecated, read above
00185         $this->setStoreToBaseRate($baseCurrency->getRate($globalCurrencyCode));
00186         $this->setStoreToQuoteRate($baseCurrency->getRate($quoteCurrency));
00187 
00188         $this->setBaseToGlobalRate($baseCurrency->getRate($globalCurrencyCode));
00189         $this->setBaseToQuoteRate($baseCurrency->getRate($quoteCurrency));
00190 
00191         if (!$this->hasChangedFlag() || $this->getChangedFlag() == true) {
00192             $this->setIsChanged(1);
00193         } else {
00194             $this->setIsChanged(0);
00195         }
00196 
00197         parent::_beforeSave();
00198     }

_construct (  )  [protected]

Init resource model

Reimplemented from Varien_Object.

Definition at line 88 of file Quote.php.

00089     {
00090         $this->_init('sales/quote');
00091     }

_getAddressByType ( type  )  [protected]

Retrieve quote address by type

Parameters:
string $type
Returns:
Mage_Sales_Model_Quote_Address

Definition at line 359 of file Quote.php.

00360     {
00361         foreach ($this->getAddressesCollection() as $address) {
00362             if ($address->getAddressType() == $type && !$address->isDeleted()) {
00363                 return $address;
00364             }
00365         }
00366 
00367         $address = Mage::getModel('sales/quote_address')->setAddressType($type);
00368         $this->addAddress($address);
00369         return $address;
00370     }

_validateCouponCode (  )  [protected]

Definition at line 1188 of file Quote.php.

01189     {
01190         $code = $this->_getData('coupon_code');
01191         if ($code) {
01192             $addressHasCoupon = false;
01193             $addresses = $this->getAllAddresses();
01194             if (count($addresses)>0) {
01195                 foreach ($addresses as $address) {
01196                     if ($address->hasCouponCode()) {
01197                         $addressHasCoupon = true;
01198                     }
01199                 }
01200                 if (!$addressHasCoupon) {
01201                     $this->setCouponCode('');
01202                 }
01203             }
01204         }
01205         return $this;
01206     }

addAddress ( Mage_Sales_Model_Quote_Address address  ) 

Definition at line 470 of file Quote.php.

00471     {
00472         $address->setQuote($this);
00473         if (!$address->getId()) {
00474             $this->getAddressesCollection()->addItem($address);
00475         }
00476         return $this;
00477     }

addItem ( Mage_Sales_Model_Quote_Item item  ) 

Adding new item to quote

Parameters:
Mage_Sales_Model_Quote_Item $item
Returns:
Mage_Sales_Model_Quote

Definition at line 640 of file Quote.php.

00641     {
00642         $item->setQuote($this);
00643         if (!$item->getId()) {
00644             $this->getItemsCollection()->addItem($item);
00645             Mage::dispatchEvent('sales_quote_add_item', array('quote_item' => $item));
00646         }
00647         return $this;
00648     }

addMessage ( message,
index = 'error' 
)

Definition at line 997 of file Quote.php.

00998     {
00999         $messages = $this->getData('messages');
01000         if (is_null($messages)) {
01001             $messages = array();
01002         }
01003 
01004         if (isset($messages[$index])) {
01005             return $this;
01006         }
01007 
01008         if (is_string($message)) {
01009             $message = Mage::getSingleton('core/message')->error($message);
01010         }
01011 
01012         $messages[$index] = $message;
01013         $this->setData('messages', $messages);
01014         return $this;
01015     }

addPayment ( Mage_Sales_Model_Quote_Payment payment  ) 

Definition at line 860 of file Quote.php.

00861     {
00862         $payment->setQuote($this);
00863         if (!$payment->getId()) {
00864             $this->getPaymentsCollection()->addItem($payment);
00865         }
00866         return $this;
00867     }

addProduct ( Mage_Catalog_Model_Product product,
request = null 
)

Add product to quote

return error message if product type instance can't prepare product

Parameters:
mixed $product
Returns:
Mage_Sales_Model_Quote_Item || string

Error message

If prepare process return one object

As parent item we should always use the item of first added product

We specify qty after we know about parent (for stock)

Definition at line 658 of file Quote.php.

00659     {
00660 
00661         if ($request === null) {
00662             $request = 1;
00663         }
00664         if (is_numeric($request)) {
00665             $request = new Varien_Object(array('qty'=>$request));
00666         }
00667         if (!($request instanceof Varien_Object)) {
00668             Mage::throwException(Mage::helper('sales')->__('Invalid request for adding product to quote'));
00669         }
00670 
00671         $cartCandidates = $product->getTypeInstance(true)
00672             ->prepareForCart($request, $product);
00673 
00674         /**
00675          * Error message
00676          */
00677 
00678         if (is_string($cartCandidates)) {
00679             return $cartCandidates;
00680         }
00681 
00682         /**
00683          * If prepare process return one object
00684          */
00685         if (!is_array($cartCandidates)) {
00686             $cartCandidates = array($cartCandidates);
00687         }
00688 
00689 
00690 
00691 
00692         $parentItem = null;
00693         $errors = array();
00694         foreach ($cartCandidates as $candidate) {
00695             $item = $this->_addCatalogProduct($candidate, $candidate->getCartQty());
00696 
00697             /**
00698              * As parent item we should always use the item of first added product
00699              */
00700             if (!$parentItem) {
00701                 $parentItem = $item;
00702             }
00703             if ($parentItem && $candidate->getParentProductId()) {
00704                 $item->setParentItem($parentItem);
00705             }
00706 
00707             /**
00708              * We specify qty after we know about parent (for stock)
00709              */
00710             $item->addQty($candidate->getCartQty());
00711 
00712             // collect errors instead of throwing first one
00713             if ($item->getHasError()) {
00714                 $errors[] = $item->getMessage();
00715             }
00716         }
00717         if (!empty($errors)) {
00718             Mage::throwException(implode("\n", $errors));
00719         }
00720         return $item;
00721     }

addShippingAddress ( Mage_Sales_Model_Quote_Address address  ) 

Definition at line 520 of file Quote.php.

00521     {
00522         $this->setShippingAddress($address);
00523         return $this;
00524     }

assignCustomer ( Mage_Customer_Model_Customer customer  ) 

Assign customer model object data to quote

Parameters:
Mage_Customer_Model_Customer $customer
Returns:
Mage_Sales_Model_Quote

Definition at line 248 of file Quote.php.

00249     {
00250         if ($customer->getId()) {
00251             $this->setCustomer($customer);
00252 
00253             $defaultBillingAddress = $customer->getDefaultBillingAddress();
00254             if ($defaultBillingAddress && $defaultBillingAddress->getId()) {
00255                 $billingAddress = Mage::getModel('sales/quote_address')
00256                     ->importCustomerAddress($defaultBillingAddress);
00257                 $this->setBillingAddress($billingAddress);
00258             }
00259 
00260             $defaultShippingAddress= $customer->getDefaultShippingAddress();
00261             if ($defaultShippingAddress && $defaultShippingAddress->getId()) {
00262                 $shippingAddress = Mage::getModel('sales/quote_address')
00263                 ->importCustomerAddress($defaultShippingAddress);
00264             }
00265             else {
00266                 $shippingAddress = Mage::getModel('sales/quote_address');
00267             }
00268             $this->setShippingAddress($shippingAddress);
00269         }
00270 
00271         return $this;
00272     }

collectTotals (  ) 

Collect totals

Returns:
Mage_Sales_Model_Quote

Definition at line 890 of file Quote.php.

00891     {
00892         Mage::dispatchEvent(
00893             $this->_eventPrefix . '_collect_totals_before',
00894             array(
00895                 $this->_eventObject=>$this
00896             )
00897         );
00898 
00899         $this->setSubtotal(0);
00900         $this->setBaseSubtotal(0);
00901 
00902         $this->setSubtotalWithDiscount(0);
00903         $this->setBaseSubtotalWithDiscount(0);
00904 
00905         $this->setGrandTotal(0);
00906         $this->setBaseGrandTotal(0);
00907 
00908         foreach ($this->getAllAddresses() as $address) {
00909             $address->setSubtotal(0);
00910             $address->setBaseSubtotal(0);
00911 
00912             $address->setSubtotalWithDiscount(0);
00913             $address->setBaseSubtotalWithDiscount(0);
00914 
00915             $address->setGrandTotal(0);
00916             $address->setBaseGrandTotal(0);
00917 
00918             $address->collectTotals();
00919 
00920             $this->setSubtotal((float) $this->getSubtotal()+$address->getSubtotal());
00921             $this->setBaseSubtotal((float) $this->getBaseSubtotal()+$address->getBaseSubtotal());
00922 
00923             $this->setSubtotalWithDiscount((float) $this->getSubtotalWithDiscount()+$address->getSubtotalWithDiscount());
00924             $this->setBaseSubtotalWithDiscount((float) $this->getBaseSubtotalWithDiscount()+$address->getBaseSubtotalWithDiscount());
00925 
00926             $this->setGrandTotal((float) $this->getGrandTotal()+$address->getGrandTotal());
00927             $this->setBaseGrandTotal((float) $this->getBaseGrandTotal()+$address->getBaseGrandTotal());
00928         }
00929 
00930         Mage::helper('sales')->checkQuoteAmount($this, $this->getGrandTotal());
00931         Mage::helper('sales')->checkQuoteAmount($this, $this->getBaseGrandTotal());
00932 
00933         $this->setItemsCount(0);
00934         $this->setItemsQty(0);
00935         $this->setVirtualItemsQty(0);
00936 
00937         foreach ($this->getAllVisibleItems() as $item) {
00938             if ($item->getParentItem()) {
00939                 continue;
00940             }
00941 
00942             if (($children = $item->getChildren()) && $item->isShipSeparately()) {
00943                 foreach ($children as $child) {
00944                     if ($child->getProduct()->getIsVirtual()) {
00945                         $this->setVirtualItemsQty($this->getVirtualItemsQty() + $child->getQty()*$item->getQty());
00946                     }
00947                 }
00948             }
00949 
00950             if ($item->getProduct()->getIsVirtual()) {
00951                 $this->setVirtualItemsQty($this->getVirtualItemsQty() + $item->getQty());
00952             }
00953             $this->setItemsCount($this->getItemsCount()+1);
00954             $this->setItemsQty((float) $this->getItemsQty()+$item->getQty());
00955         }
00956 
00957         $this->setData('trigger_recollect', 0);
00958         $this->_validateCouponCode();
00959 
00960         Mage::dispatchEvent(
00961             $this->_eventPrefix . '_collect_totals_after',
00962             array(
00963                 $this->_eventObject=>$this
00964             )
00965         );
00966 
00967         return $this;
00968     }

getAddressByCustomerAddressId ( addressId  ) 

Definition at line 430 of file Quote.php.

00431     {
00432         foreach ($this->getAddressesCollection() as $address) {
00433             if (!$address->isDeleted() && $address->getCustomerAddressId()==$addressId) {
00434                 return $address;
00435             }
00436         }
00437         return false;
00438     }

getAddressById ( addressId  ) 

Parameters:
int $addressId
Returns:
Mage_Sales_Model_Quote_Address

Definition at line 420 of file Quote.php.

00421     {
00422         foreach ($this->getAddressesCollection() as $address) {
00423             if ($address->getId()==$addressId) {
00424                 return $address;
00425             }
00426         }
00427         return false;
00428     }

getAddressesCollection (  ) 

Retrieve quote address collection

Returns:
Mage_Eav_Model_Entity_Collection_Abstract

Definition at line 338 of file Quote.php.

00339     {
00340         if (is_null($this->_addresses)) {
00341             $this->_addresses = Mage::getModel('sales/quote_address')->getCollection()
00342                 ->setQuoteFilter($this->getId());
00343 
00344             if ($this->getId()) {
00345                 foreach ($this->_addresses as $address) {
00346                     $address->setQuote($this);
00347                 }
00348             }
00349         }
00350         return $this->_addresses;
00351     }

getAllAddresses (  ) 

Definition at line 404 of file Quote.php.

00405     {
00406         $addresses = array();
00407         foreach ($this->getAddressesCollection() as $address) {
00408             if (!$address->isDeleted()) {
00409                 $addresses[] = $address;
00410             }
00411         }
00412         return $addresses;
00413     }

getAllItems (  ) 

Retrieve quote items array

Returns:
array

Definition at line 546 of file Quote.php.

00547     {
00548         $items = array();
00549         foreach ($this->getItemsCollection() as $item) {
00550             if (!$item->isDeleted()) {
00551                 $items[] =  $item;
00552             }
00553         }
00554         return $items;
00555     }

getAllShippingAddresses (  ) 

Definition at line 392 of file Quote.php.

00393     {
00394         $addresses = array();
00395         foreach ($this->getAddressesCollection() as $address) {
00396             if ($address->getAddressType()==Mage_Sales_Model_Quote_Address::TYPE_SHIPPING
00397                 && !$address->isDeleted()) {
00398                 $addresses[] = $address;
00399             }
00400         }
00401         return $addresses;
00402     }

getAllVisibleItems (  ) 

Get array of all items what can be display directly

Returns:
array

Definition at line 562 of file Quote.php.

00563     {
00564         $items = array();
00565         foreach ($this->getItemsCollection() as $item) {
00566             if (!$item->isDeleted() && !$item->getParentItemId()) {
00567                 $items[] =  $item;
00568             }
00569         }
00570         return $items;
00571     }

getBillingAddress (  ) 

Retrieve quote billing address

Returns:
Mage_Sales_Model_Quote_Address

Definition at line 377 of file Quote.php.

getCheckoutMethod ( originalMethod = false  ) 

Return quote checkout method code

Parameters:
boolean $originalMethod if true return defined method from begining
Returns:
string

Definition at line 325 of file Quote.php.

00326     {
00327         if ($this->getCustomerId() && !$originalMethod) {
00328             return self::CHECKOUT_METHOD_LOGIN_IN;
00329         }
00330         return $this->_getData('checkout_method');
00331     }

getCustomer (  ) 

Retrieve customer model object

Returns:
Mage_Customer_Model_Customer

Definition at line 292 of file Quote.php.

00293     {
00294         if (is_null($this->_customer)) {
00295             $this->_customer = Mage::getModel('customer/customer');
00296             if ($customerId = $this->getCustomerId()) {
00297                 $this->_customer->load($customerId);
00298                 if (!$this->_customer->getId()) {
00299                     $this->_customer->setCustomerId(null);
00300                 }
00301             }
00302         }
00303         return $this->_customer;
00304     }

getCustomerTaxClassId (  ) 

Definition at line 306 of file Quote.php.

00307     {
00308         /*
00309         * tax class can vary at any time. so instead of using the value from session, we need to retrieve from db everytime
00310         * to get the correct tax class
00311         */
00312         //if (!$this->getData('customer_group_id') && !$this->getData('customer_tax_class_id')) {
00313             $classId = Mage::getModel('customer/group')->getTaxClassId($this->getCustomerGroupId());
00314             $this->setCustomerTaxClassId($classId);
00315         //}
00316         return $this->getData('customer_tax_class_id');
00317     }

getIsVirtual (  ) 

Check quote for virtual product only

Returns:
bool

Definition at line 1100 of file Quote.php.

01101     {
01102         return intval($this->isVirtual());
01103     }

getItemById ( itemId  ) 

Retrieve item model object by item identifier

Parameters:
int $itemId
Returns:
Mage_Sales_Model_Quote_Item

Definition at line 605 of file Quote.php.

00606     {
00607         return $this->getItemsCollection()->getItemById($itemId);
00608     }

getItemByProduct ( product  ) 

Retrieve quote item by product id

Parameters:
int $productId
Returns:
Mage_Sales_Model_Quote_Item || false

Definition at line 759 of file Quote.php.

00760     {
00761         foreach ($this->getAllItems() as $item) {
00762             if ($item->representProduct($product)) {
00763                 return $item;
00764             }
00765         }
00766         return false;
00767     }

getItemsCollection ( useCache = true  ) 

Retrieve quote items collection

Parameters:
bool $loaded
Returns:
Mage_Eav_Model_Entity_Collection_Abstract

Definition at line 532 of file Quote.php.

00533     {
00534         if (is_null($this->_items)) {
00535             $this->_items = Mage::getModel('sales/quote_item')->getCollection();
00536             $this->_items->setQuote($this);
00537         }
00538         return $this->_items;
00539     }

getItemsSummaryQty (  ) 

Definition at line 769 of file Quote.php.

00770     {
00771         $qty = $this->getData('all_items_qty');
00772         if (is_null($qty)) {
00773             $qty = 0;
00774             foreach ($this->getAllItems() as $item) {
00775                 if ($item->getParentItem()) {
00776                     continue;
00777                 }
00778 
00779                 if (($children = $item->getChildren()) && $item->isShipSeparately()) {
00780                     foreach ($children as $child) {
00781                         $qty+= $child->getQty()*$item->getQty();
00782                     }
00783                 } else {
00784                     $qty+= $item->getQty();
00785                 }
00786             }
00787             $this->setData('all_items_qty', $qty);
00788         }
00789         return $qty;
00790     }

getItemVirtualQty (  ) 

Definition at line 792 of file Quote.php.

00793     {
00794         $qty = $this->getData('virtual_items_qty');
00795         if (is_null($qty)) {
00796             $qty = 0;
00797             foreach ($this->getAllItems() as $item) {
00798                 if ($item->getParentItem()) {
00799                     continue;
00800                 }
00801 
00802                 if (($children = $item->getChildren()) && $item->isShipSeparately()) {
00803                     foreach ($children as $child) {
00804                         if ($child->getProduct()->getIsVirtual()) {
00805                             $qty+= $child->getQty();
00806                         }
00807                     }
00808                 } else {
00809                     if ($item->getProduct()->getIsVirtual()) {
00810                         $qty+= $item->getQty();
00811                     }
00812                 }
00813             }
00814             $this->setData('virtual_items_qty', $qty);
00815         }
00816         return $qty;
00817     }

getMessages (  ) 

Definition at line 1017 of file Quote.php.

01018     {
01019         $messages = $this->getData('messages');
01020         if (is_null($messages)) {
01021             $messages = array();
01022             $this->setData('messages', $messages);
01023         }
01024         return $messages;
01025     }

getPayment (  ) 

Returns:
Mage_Sales_Model_Quote_Payment

Definition at line 838 of file Quote.php.

00839     {
00840         foreach ($this->getPaymentsCollection() as $payment) {
00841             if (!$payment->isDeleted()) {
00842                 return $payment;
00843             }
00844         }
00845         $payment = Mage::getModel('sales/quote_payment');
00846         $this->addPayment($payment);
00847         return $payment;
00848     }

getPaymentById ( paymentId  ) 

Definition at line 850 of file Quote.php.

00851     {
00852         foreach ($this->getPaymentsCollection() as $payment) {
00853             if ($payment->getId()==$paymentId) {
00854                 return $payment;
00855             }
00856         }
00857         return false;
00858     }

getPaymentsCollection (  ) 

Definition at line 820 of file Quote.php.

00821     {
00822         if (is_null($this->_payments)) {
00823             $this->_payments = Mage::getModel('sales/quote_payment')->getCollection()
00824                 ->setQuoteFilter($this->getId());
00825 
00826             if ($this->getId()) {
00827                 foreach ($this->_payments as $payment) {
00828                     $payment->setQuote($this);
00829                 }
00830             }
00831         }
00832         return $this->_payments;
00833     }

getSharedStoreIds (  ) 

Get all available store ids for quote

Returns:
array

Definition at line 133 of file Quote.php.

00134     {
00135         $ids = $this->_getData('shared_store_ids');
00136         if (is_null($ids) || !is_array($ids)) {
00137             if ($website = $this->getWebsite()) {
00138                 return $website->getStoreIds();
00139             }
00140             return $this->getStore()->getWebsite()->getStoreIds();
00141         }
00142         return $ids;
00143     }

getShippingAddress (  ) 

retrieve quote shipping address

Returns:
Mage_Sales_Model_Quote_Address

Definition at line 387 of file Quote.php.

getShippingAddressByCustomerAddressId ( addressId  ) 

Definition at line 440 of file Quote.php.

00441     {
00442         foreach ($this->getAddressesCollection() as $address) {
00443             if (!$address->isDeleted() && $address->getAddressType()==Mage_Sales_Model_Quote_Address::TYPE_SHIPPING
00444                 && $address->getCustomerAddressId()==$addressId) {
00445                 return $address;
00446             }
00447         }
00448         return false;
00449     }

getStore (  ) 

Get quote store model object

Returns:
Mage_Core_Model_Store

Definition at line 111 of file Quote.php.

00112     {
00113         return Mage::app()->getStore($this->getStoreId());
00114     }

getStoreId (  ) 

Get quote store identifier

Returns:
int

Definition at line 98 of file Quote.php.

00099     {
00100         if (!$this->hasStoreId()) {
00101             return Mage::app()->getStore()->getId();
00102         }
00103         return $this->_getData('store_id');
00104     }

getTotals (  ) 

Get all quote totals (sorted by priority)

Returns:
array

Definition at line 975 of file Quote.php.

00976     {
00977         $totals = $this->getShippingAddress()->getTotals();
00978         foreach ($this->getBillingAddress()->getTotals() as $code => $total) {
00979             if (isset($totals[$code])) {
00980                 $totals[$code]->setValue($totals[$code]->getValue()+$total->getValue());
00981             }
00982             else {
00983                 $totals[$code] = $total;
00984             }
00985         }
00986 
00987         $sortedTotals = array();
00988         foreach ($this->getBillingAddress()->getTotalModels() as $total) {
00989             /* @var $total Mage_Sales_Model_Quote_Address_Total_Abstract */
00990             if (isset($totals[$total->getCode()])) {
00991                 $sortedTotals[$total->getCode()] = $totals[$total->getCode()];
00992             }
00993         }
00994         return $sortedTotals;
00995     }

hasItems (  ) 

Checking items availability

Returns:
bool

Definition at line 578 of file Quote.php.

00579     {
00580         return sizeof($this->getAllItems())>0;
00581     }

hasItemsWithDecimalQty (  ) 

Checking availability of items with decimal qty

Returns:
bool

Definition at line 588 of file Quote.php.

00589     {
00590         foreach ($this->getAllItems() as $item) {
00591             if ($item->getProduct()->getStockItem()
00592                 && $item->getProduct()->getStockItem()->getIsQtyDecimal()) {
00593                 return true;
00594             }
00595         }
00596         return false;
00597     }

hasVirtualItems (  ) 

Has a virtual products on quote

Returns:
bool

Definition at line 1110 of file Quote.php.

01111     {
01112         $hasVirtual = false;
01113         foreach ($this->getItemsCollection() as $_item) {
01114             if ($_item->getParentItemId()) {
01115                 continue;
01116             }
01117             if ($_item->getProduct()->isVirtual()) {
01118                 $hasVirtual = true;
01119             }
01120         }
01121         return $hasVirtual;
01122     }

isAllowedGuestCheckout (  ) 

Check is allow Guest Checkout

Returns:
bool

Definition at line 1129 of file Quote.php.

01130     {
01131         return Mage::helper('checkout')->isAllowedGuestCheckout($this, $this->getStoreId());
01132     }

isVirtual (  ) 

Check quote for virtual product only

Returns:
bool

Definition at line 1078 of file Quote.php.

01079     {
01080         $isVirtual = true;
01081         $countItems = 0;
01082         foreach ($this->getItemsCollection() as $_item) {
01083             /* @var $_item Mage_Sales_Model_Quote_Item */
01084             if ($_item->isDeleted() || $_item->getParentItemId()) {
01085                 continue;
01086             }
01087             $countItems ++;
01088             if (!$_item->getProduct()->getIsVirtual()) {
01089                 $isVirtual = false;
01090             }
01091         }
01092         return $countItems == 0 ? false : $isVirtual;
01093     }

loadByCustomer ( customer  ) 

Loading quote data by customer

Returns:
Mage_Sales_Model_Quote

Definition at line 228 of file Quote.php.

00229     {
00230         if ($customer instanceof Mage_Customer_Model_Customer) {
00231             $customerId = $customer->getId();
00232             $this->setStoreId($customer->getStoreId());
00233         }
00234         else {
00235             $customerId = (int) $customer;
00236         }
00237         $this->_getResource()->loadByCustomerId($this, $customerId);
00238         $this->_afterLoad();
00239         return $this;
00240     }

merge ( Mage_Sales_Model_Quote quote  ) 

Merge quotes

Parameters:
Mage_Sales_Model_Quote $quote
Returns:
Mage_Sales_Model_Quote

Definition at line 1140 of file Quote.php.

01141     {
01142         Mage::dispatchEvent(
01143             $this->_eventPrefix . '_merge_before',
01144             array(
01145                 $this->_eventObject=>$this,
01146                 'source'=>$quote
01147             )
01148         );
01149 
01150         foreach ($quote->getAllVisibleItems() as $item) {
01151             $found = false;
01152             foreach ($this->getAllItems() as $quoteItem) {
01153                 if ($quoteItem->compare($item)) {
01154                     $quoteItem->setQty($quoteItem->getQty() + $item->getQty());
01155                     $found = true;
01156                     break;
01157                 }
01158             }
01159 
01160             if (!$found) {
01161                 $newItem = clone $item;
01162                 $this->addItem($newItem);
01163                 if ($item->getHasChildren()) {
01164                     foreach ($item->getChildren() as $child) {
01165                         $newChild = clone $child;
01166                         $newChild->setParentItem($newItem);
01167                         $this->addItem($newChild);
01168                     }
01169                 }
01170             }
01171         }
01172 
01173         if ($quote->getCouponCode()) {
01174             $this->setCouponCode($quote->getCouponCode());
01175         }
01176 
01177         Mage::dispatchEvent(
01178             $this->_eventPrefix . '_merge_after',
01179             array(
01180                 $this->_eventObject=>$this,
01181                 'source'=>$quote
01182             )
01183         );
01184 
01185         return $this;
01186     }

removeAddress ( addressId  ) 

Definition at line 451 of file Quote.php.

00452     {
00453         foreach ($this->getAddressesCollection() as $address) {
00454             if ($address->getId()==$addressId) {
00455                 $address->isDeleted(true);
00456                 break;
00457             }
00458         }
00459         return $this;
00460     }

removeAllAddresses (  ) 

Definition at line 462 of file Quote.php.

00463     {
00464         foreach ($this->getAddressesCollection() as $address) {
00465             $address->isDeleted(true);
00466         }
00467         return $this;
00468     }

removeItem ( itemId  ) 

Remove quote item by item identifier

Parameters:
int $itemId
Returns:
Mage_Sales_Model_Quote

If we remove item from quote - we can't use multishipping mode

Definition at line 616 of file Quote.php.

00617     {
00618         if ($item = $this->getItemById($itemId)) {
00619             /**
00620              * If we remove item from quote - we can't use multishipping mode
00621              */
00622             $this->setIsMultiShipping(false);
00623             $item->isDeleted(true);
00624             if ($item->getHasChildren()) {
00625                 foreach ($item->getChildren() as $child) {
00626                     $child->isDeleted(true);
00627                 }
00628             }
00629             Mage::dispatchEvent('sales_quote_remove_item', array('quote_item' => $item));
00630         }
00631         return $this;
00632     }

removePayment (  ) 

Definition at line 879 of file Quote.php.

00880     {
00881         $this->getPayment()->isDeleted(true);
00882         return $this;
00883     }

reserveOrderId (  ) 

Definition at line 1027 of file Quote.php.

01028     {
01029         if (!$this->getReservedOrderId()) {
01030             $this->setReservedOrderId($this->_getResource()->getReservedOrderId($this));
01031         } else {
01032             //checking if reserved order id was already used for some order
01033             //if yes reserving new one if not using old one
01034             if ($this->_getResource()->isOrderIncrementIdUsed($this->getReservedOrderId())) {
01035                 $this->setReservedOrderId($this->_getResource()->getReservedOrderId($this));
01036             }
01037         }
01038         return $this;
01039     }

setBillingAddress ( Mage_Sales_Model_Quote_Address address  ) 

Enter description here...

Parameters:
Mage_Sales_Model_Quote_Address $address
Returns:
Mage_Sales_Model_Quote

Definition at line 485 of file Quote.php.

00486     {
00487         $old = $this->getBillingAddress();
00488 
00489         if (!empty($old)) {
00490             $old->addData($address->getData());
00491         } else {
00492             $this->addAddress($address->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING));
00493         }
00494         return $this;
00495     }

setCustomer ( Mage_Customer_Model_Customer customer  ) 

Define customer object

Parameters:
Mage_Customer_Model_Customer $customer
Returns:
Mage_Sales_Model_Quote

Definition at line 280 of file Quote.php.

00281     {
00282         $this->_customer = $customer;
00283         Mage::helper('core')->copyFieldset('customer_account', 'to_quote', $customer, $this);
00284         return $this;
00285     }

setPayment ( Mage_Sales_Model_Quote_Payment payment  ) 

Definition at line 869 of file Quote.php.

00870     {
00871         if (!$this->getIsMultiPayment() && ($old = $this->getPayment())) {
00872             $payment->setId($old->getId());
00873         }
00874         $this->addPayment($payment);
00875 
00876         return $payment;
00877     }

setShippingAddress ( Mage_Sales_Model_Quote_Address address  ) 

Enter description here...

Parameters:
Mage_Sales_Model_Quote_Address $address
Returns:
Mage_Sales_Model_Quote

Definition at line 503 of file Quote.php.

00504     {
00505         if ($this->getIsMultiShipping()) {
00506             $this->addAddress($address->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING));
00507         }
00508         else {
00509             $old = $this->getShippingAddress();
00510 
00511             if (!empty($old)) {
00512                 $old->addData($address->getData());
00513             } else {
00514                 $this->addAddress($address->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING));
00515             }
00516         }
00517         return $this;
00518     }

setStore ( Mage_Core_Model_Store store  ) 

Declare quote store model

Parameters:
Mage_Core_Model_Store $store
Returns:
Mage_Sales_Model_Quote

Definition at line 122 of file Quote.php.

00123     {
00124         $this->setStoreId($store->getId());
00125         return $this;
00126     }

validateMinimumAmount ( multishipping = false  ) 

Definition at line 1041 of file Quote.php.

01042     {
01043         $storeId = $this->getStoreId();
01044         $minOrderActive = Mage::getStoreConfigFlag('sales/minimum_order/active', $storeId);
01045         $minOrderMulti  = Mage::getStoreConfigFlag('sales/minimum_order/multi_address', $storeId);
01046 
01047         if (!$minOrderActive) {
01048             return true;
01049         }
01050 
01051         if ($multishipping && !$minOrderMulti) {
01052             $baseTotal = 0;
01053             foreach ($this->getAllAddresses() as $address) {
01054                 /* @var $address Mage_Sales_Model_Quote_Address */
01055                 $baseTotal += $address->getBaseSubtotalWithDiscount();
01056             }
01057 
01058             if ($baseTotal < Mage::getStoreConfig('sales/minimum_order/amount', $storeId)) {
01059                 return false;
01060             }
01061         }
01062         else {
01063             foreach ($this->getAllAddresses() as $address) {
01064                 /* @var $address Mage_Sales_Model_Quote_Address */
01065                 if (!$address->validateMinimumAmount()) {
01066                     return false;
01067                 }
01068             }
01069         }
01070         return true;
01071     }


Member Data Documentation

$_addresses = null [protected]

Definition at line 69 of file Quote.php.

$_customer [protected]

Definition at line 62 of file Quote.php.

$_eventObject = 'quote' [protected]

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 55 of file Quote.php.

$_eventPrefix = 'sales_quote' [protected]

Performance +30% without cache

Reimplemented from Mage_Core_Model_Abstract.

Definition at line 54 of file Quote.php.

$_items = null [protected]

Definition at line 76 of file Quote.php.

$_payments = null [protected]

Definition at line 83 of file Quote.php.

const CHECKOUT_METHOD_GUEST = 'guest'

Definition at line 45 of file Quote.php.

const CHECKOUT_METHOD_LOGIN_IN = 'login_in'

Definition at line 46 of file Quote.php.

const CHECKOUT_METHOD_REGISTER = 'register'

Checkout methods

Definition at line 44 of file Quote.php.


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

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