I’ve been fiddl开发者_高级运维ing with the Magento shopping cart API (Magento v.1.5) and found that when a cart is created (and products added) that the “is_active” value in the “sales_flat_quote” table is set to “0”. In contrast, if you use the “Add to cart” button in the store interface, the “is_active” value is set to “1”.
I did some digging and discovered that the API sets “is_active” in app/code/core/Mage/Checkout/Model/Cart/Api.php.
Here’s the relevant block of code:
public function create($store = null)
{
$storeId = $this->_getStoreId($store);
try {
/*@var $quote Mage_Sales_Model_Quote*/
$quote = Mage::getModel('sales/quote');
$quote->setStoreId($storeId)
->setIsActive(false)
->setIsMultiShipping(false)
->save();
} catch (Mage_Core_Exception $e) {
$this->_fault('create_quote_fault', $e->getMessage());
}
return (int) $quote->getId();
}
So I'm not sure what the intent is to make it false. Is there a reason for the behavior difference between the store interface and the API? Or is there something additional that must be done through the API to make the cart active?
My best guess, and it is a guess as I cannot read the original developers minds, would be they were trying to prevent API generated quotes from showing up in abandoned cart reports.
The is_active flag is used to indicate an active quote for a customer and a customer should only ever have a single active quote. The flag is also used to know when a quote can be auto-removed from the system, the theory being that if the quote is not active it has been converted to an order and is no longer needed. If the Mage_Checkout Cart API is setting the flag to false then the quote is subject to auto-cleanup, possibly before you have converted it to an order. By setting the flag to false, it is also preventing you from using the API to create a live quote that a customer can use on the frontend.
So, I would say, if you are using the API to create a quote for a customer that you would need to add a publish() method. If you are using the API to modify the customer's existing quote, you won't run into the problem as it only shows up when creating a new quote.
In any case, I would personally think the current behavior is a bug due to the cleanup routines using that flag to indicate removable quotes.
精彩评论