0

I am creating a rest api for cart.

 $product = Mage::getModel('catalog/product')->load(1);
 $quote = Mage::getModel('sales/quote');
 $quote->addProduct($product, $qty);
 $quote->collectTotals()->save();

Quote is generated as expected. The only issue is with price. Item price is not set in quote_item table. Also in quote tables base_price, subtotal, etc are not set.

4
  • Please try by setting store as $quote->setStoreId(1)->addProduct($product, $qty) May 25, 2018 at 8:14
  • Still not working
    – V G.
    May 25, 2018 at 9:31
  • can u please try $quote->setTotalsCollectedFlag(false)->collectTotals()->save(); May 25, 2018 at 9:38
  • Same Issue exist. I am trying to add products in cart. Billing and shipping address is not required at this point. When product is added from website(frontend) and then add product to same quote from API, it is working as expected. The only issue exist when quote is created from API.
    – V G.
    May 25, 2018 at 10:38

1 Answer 1

0

Found solution.

Changed following code to

$product = Mage::getModel('catalog/product')->load(1);
$quote = Mage::getModel('sales/quote');
$quote->addProduct($product, $qty);
$quote->collectTotals()->save();

To

$product = Mage::getModel('catalog/product')->load(1);
$quote = Mage::getModel('sales/quote');
$quote->addProduct($product, $qty);
$quote->setIsActive(false)->setIsMultiShipping(false);
$quote->getBillingAddress();
$quote->getShippingAddress()->setCollectShippingRates(true);
$quote->collectTotals()->save();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.