1
votes

i'm trying to add product with custom options using SOAP v1 cart_product.add

  • Product ID = 1497
  • qty = 1
  • store ID = 2
  • option ID = 2296 (type = textfield)
  • option value = 10001
  • is required = TRUE

Everything looks oke but still give an error Fatal error: Uncaught SoapFault exception: [1022] Please specify the product required option(s).

Here is the PHP code

$shoppingCartIncrementId = $proxy->call( $sessionId, 'cart.create',array( 2 ));

$arrProducts = array(
        'product_id' => '1497',
        'quantity' => 1,
        'options' => array ( 
                0 => array(
                        'key' =>  2296,
                        'value' =>  '1001'
                    )
                 )

);


print "<pre>";
print_r($arrProducts);
print "</pre>";


$resultCartProductAdd = $proxy->call(
$sessionId,
"cart_product.add",
array(
    $shoppingCartIncrementId,
    array($arrProducts),
    2
)
);

And this is my Array Result looks like :

Array
(
    [product_id] => 1497
    [quantity] => 1
    [options] => Array
        (
            [0] => Array
                (
                    [key] => 2296
                    [value] => 1001
                )

        )

)

Am i missing something? Is my array correct?

Please help, Thanks

2

2 Answers

0
votes

After digging into the core files, I found the problem and a simple way to patch it.

The problem is that the SOAP API for "cart_product.add" / "shoppingCartProductAdd" accepts an array of product options and super attributes with the key "options", as you've done above, yet the code that prepares the product to be added to the cart looks for this information using the key "super_attribute", instead. To patch, I simply just copied the the "options" array to a "super_attribute" array in the cart_product.add api.

I put the patch file here which may help: https://github.com/mezzi/magento-api-patches/blob/master/0001-fix-soap-api-configurable-product-options.patch

0
votes

After much fiddling and reading other posts, I found the following worked for custom products in Magento 1.8 and SOAP v1 (the "super_attribute" fix suggested by Mezzi below no longer seemed to work):

$arrProducts[$j] = 
        array (
        'product_id' => "$productID",
        'quantity' => "$quantity_item",
        'options' => 
        array (
        $option_ID => $option_value)
);