cancel
Showing results for 
Search instead for 
Did you mean: 

set custom price for products in cart

set custom price for products in cart

I am working with magento 1.9.2.4 CE version. I am using this git repo https://github.com/fulfilio/python-magento to work with magento.

I am placing order programmatically. So while placing order I want to set custom price for items in the cart but I am unable to set it. I am adding the product data like this

 

product_data = [ {  
'sku': 'AZ8906',
'qty': 1,
"price":11.0 }
]

Then calling the `cart_product.add`  api to add the product to the cart hoping that the price that i entered will be reflected in the cart but it doesn't change the price, it shows the original price. how to set custom price for items in cart during checkout?
please help me.

 

1 REPLY 1

Re: set custom price for products in cart

use \Magento\Framework\Event\ObserverInterface;
/** * Class CustomPrice * @package Aureatelabs\CustomPrice\Observer * */
class CustomPrice implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{ $item = $observer->getEvent()->getData('quote_item'); // Get parent product if current product is child product
$item = ( $item->getParentItem() ? $item->getParentItem() : $item ); //Define your Custom price here
$price =
100; //Set custom price
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
$item->getProduct()->setIsSuperMode(
true);
}
}


and you can use the event 
checkout_cart_product_add_after