00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Sales_Model_Entity_Quote extends Mage_Eav_Model_Entity_Abstract
00035 {
00036
00037 public function __construct()
00038 {
00039 $resource = Mage::getSingleton('core/resource');
00040 $this->setType('quote')->setConnection(
00041 $resource->getConnection('sales_read'),
00042 $resource->getConnection('sales_write')
00043 );
00044 }
00045
00046
00047
00048
00049
00050
00051
00052
00053 protected function _getLoadRowSelect($object, $rowId)
00054 {
00055 $select = parent::_getLoadRowSelect($object, $rowId);
00056 if ($object->getSharedStoreIds()) {
00057 $select->where('store_id IN (?)', $object->getSharedStoreIds());
00058 }
00059 return $select;
00060 }
00061
00062
00063
00064
00065
00066
00067
00068 public function loadByCustomerId($quote, $customerId)
00069 {
00070 $collection = Mage::getResourceModel('sales/quote_collection')
00071 ->addAttributeToSelect('entity_id')
00072 ->addAttributeToFilter('customer_id', $customerId)
00073 ->addAttributeToFilter('is_active', 1);
00074
00075 if ($quote->getSharedStoreIds()) {
00076 $collection->addAttributeToFilter('store_id', array('in', $quote->getSharedStoreIds()));
00077 }
00078
00079 $collection->setOrder('updated_at', 'desc')
00080 ->setPageSize(1)
00081 ->load();
00082
00083 if ($collection->getSize()) {
00084 foreach ($collection as $item) {
00085 $this->load($quote, $item->getId());
00086 return $this;
00087 }
00088 }
00089 return $this;
00090 }
00091
00092 public function getReservedOrderId($quote)
00093 {
00094 return Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($quote->getStoreId());
00095 }
00096 }