How can I set custom price in Checkout API
-
13-12-2019 - |
Question
Is there a way I can apply a custom price in checkout cart using APIv2?
$product = array();
$product['sku'] = 'test'
$product['qty'] = 5;
// $product['price'] = 15;
$client->shoppingCartProductAdd($session, $cart, array($product));
Solution
Default magento not provided this functionality. If you are required then customization default shoppingCartProductAdd
api like this way.
class Namespace_Modulename_Model_Cart_Product_Api extends Mage_Checkout_Model_Cart_Product_Api
{
public function add($quoteId, $productsData, $store=null)
{
...
$result = $quote->addProduct($productByItem, $productRequest);
if(isset($productItem['price']) && $productItem['price'] != null) {
$result->setOriginalCustomPrice($productItem['price']);
}
...
}
}
You could then add price into the array of data in your API call like this.
array(
"sku" => "sku1",
"qty" => 1,
"price" => 0.50,
)
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange