Hello Everyone,
I have managed to create an order with simple and configurable products but I encountered an issue when I wanted to add a custom price. It worked for the simple product but not for the configurable one.
I'm using the code below
$product = Mage::getModel('catalog/product')->load($productDetails["product_id"]); if($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE){ $config = new Varien_Object([ 'product' => $productDetails["product_id"], 'qty' => $productDetails["qty"], 'super_attribute' => $productDetails["attributes"], ]); } $quote->addProduct($product, $config) ->setOriginalCustomPrice($productDetails["custom_price"]) ->setCustomPrice($productDetails["custom_price"]) ->setIsSuperMode(true);
What I think is that I do define the custom price for the simple item but since it's configurable magento always take the price from the parent item.
Is there any way I can force the custom price
Solved! Go to Solution.
@ayoubmoumg2deb Instead of setting the custom price on quote, you can set the item on quote and then set the custom price on item.
I have done the similiar type of work while adding product to cart.Please take the reference from the below code.
$item = $observer->getEvent()->getQuoteItem(); //instead of this you can get the current item from quote $item->setCustomPrice($discountedPrice); $item->setOriginalCustomPrice($discountedPrice); $item->getProduct()->setIsSuperMode(true);
Its a working code.
Let me know if you are still facing the issue.
Thanks
@ayoubmoumg2deb Instead of setting the custom price on quote, you can set the item on quote and then set the custom price on item.
I have done the similiar type of work while adding product to cart.Please take the reference from the below code.
$item = $observer->getEvent()->getQuoteItem(); //instead of this you can get the current item from quote $item->setCustomPrice($discountedPrice); $item->setOriginalCustomPrice($discountedPrice); $item->getProduct()->setIsSuperMode(true);
Its a working code.
Let me know if you are still facing the issue.
Thanks
I just tried it and it's working. Thank you for your help @rahul Gupta