Magento Cart API not showing prices

偶尔善良 提交于 2019-12-03 13:29:12

Just so it can be an officially answered question, here is the solution found, http://magentocommerce.com/boards/viewthread/227044 I spent two days searching for this, and today come up with an obscure search term to try and find the solution

I've been looking at this issue for a couple days now. It didn't make sense to me that if you add a product to your cart through the normal web interface [ie Mage_Checkout_CartController::addAction() ]. It knows the price without you providing an address. I finally found the difference between the two. In addAction() they create an instance of Mage_Checkout_Model_Cart, add the product to that, and save it. In the api they use Mage_Sales_Model_Quote instead. If you look at Mage_Checkout_Model_Cart::save() you will see these two lines:

$this->getQuote()->getBillingAddress();
$this->getQuote()->getShippingAddress();

These two lines actually create empty Mage_Sales_Model_Quote_Address objects that get saved into the db.

If you are willing/able to modify magento's code, you can modify Mage_Checkout_Model_Cart_Api::create() and add a call to these two methods before $quote->save() and the api and the web interface will work the same way.

I have only tested this a little bit, but I really think this is a bug and not a feature. I'll see about getting this in front of actual magento devs and maybe they'll include it in the next release.

Magento frontend and API both are different. In frontend after registering customer it creates quote for customer and also set address with that created quote id. But in API it creates only quote using shoppingCartCreate service. For proper we need to customize create service. I did and it worked for me.

Here am providing solution:

Edit function in file - Mage/Checkout/Model/Cart/Api.php

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();

/* Customized this for saving default address for quote and it will show price in cart info*/
 $quote->getBillingAddress();
    $quote->getShippingAddress()->setCollectShippingRates(true);
    $quote->collectTotals();
    $quote->save();

/* End cart here */

    } catch (Mage_Core_Exception $e) {
        $this->_fault('create_quote_fault', $e->getMessage());
    }
    return (int) $quote->getId();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!