Zelf
Zelf

Reputation: 2250

Magento SOAP v1 cart_product.add - need to set price in options array for sku

$arrProducts = array(
    array(
        "sku" => "sku1",
        "qty" => 1,
        "options" => array(
            99 => '.50' // 99 is the price attribute id, I want to set this sku to $0.50
        )
    ),
    array(
        "sku" => "sku2",
        "quantity" => 1
    )
);

$resultCartProductAdd = $client->call($session, "cart_product.add", array($shoppingCartId, $arrProducts));

In the options array for sku1, how do I set the price to be added to the cart and calculated in totals for checkout?

The above options are not changing the price. The original price for the sku is still being added to the cart instead of $0.50. Looking at How do I create a product with additional attributes in Magento via Soap/Java I am still not understanding something.

I am on Magento EE 1.13 using SOAP V1 call

Upvotes: 0

Views: 1847

Answers (1)

Ashley Swatton
Ashley Swatton

Reputation: 2125

To set the price on the fly you could extend the API call for adding a product to the cart. The model file Mage_Checkout_Model_Cart_Product_Api would need to be extended and the add method overridden to cater for a price attribute. It would look something like this

class Namespace_Module_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,
)

The add call does issue a collectTotals() call on the quote so it should recalculate tax and currency etc based upon the custom price. You may need to modify the wsdl file to accept the new price attribute. Not tested but in theory should work.

Upvotes: 4

Related Questions