6

I have tried to add a configurable product in using magento soap api. I am using the following code to add

 $product = array(
             'product_id' => 23,    // simple product id
             'sku' => 'H001-Yellow-22',
             'qty' => '1',

            'super_attribute' => Array( [92] => 10, [134] => 3 )  // color is yellow                                                 and
size is 22        

        );
$client->shoppingCartProductAdd($session,$cartId,array($product),'1');

Instead of superattribute, i gave like this also

'super_attribute' => array(
                0 => array(
                'key' => 92,
                'value' => 10
                ),
                1 => array(
                'key' => 134,
                'value' => 3
                )
            )

but the options are not added to the cart. Why the options are not added to the cart? How the options to be added?

2 Answers 2

3

finally my config product has added to cart using magento api

$product = array(
            'product_id' => 19,   // config product id
            'sku' => 'H001',
            'qty' => '1',

           'super_attribute' => array(
                0 => array(
                'key' => 92,        //attribute id
                'value' => 10       //value
                ),
                1 => array(
                'key' => 134,
                'value' => 3
                )
            )
        );  

$client->shoppingCartProductAdd($session,$cartId, array($product));
2
  • 1
    how can i get attribute id and value ?
    – mahdi
    Commented Nov 17, 2014 at 1:02
  • i use this code but it`s return me this message : please specify product options $product = array( 'product_id' => 1300, 'sku' => 'FC006', 'qty' => '1', 'super_attribute' => array( 0 => array( 'key' => 152, 'value' => 28 ) ), 'bundle_option' => null, 'bundle_option_qty' => null, 'links' => null ); $result=$proxy>shoppingCartProductAdd($sessionID,$cartID,array($product);
    – mahdi
    Commented Nov 17, 2014 at 8:41
3

It didn't work for me the way described in the accepted answer. So I browsed through the code in magento. It actually works just the same way as adding a product to cart works in the browser:

$proxy->call( $sessionId, 'cart_product.add', array( $shoppingCartIncrementId, [ [ 'product_id' => 83, 'qty' => 1, 'super_attribute' => [ '501' => '36', // attributeId => valueId '502' => '41' ] ] ] ) );

The keys of the super_attribute array are the attribute IDs of the configurable attributes (e.g. the color attribute's ID). The values are the the value IDs (e.g. the red value's ID).

This is a minimalistic example, I only used the required attributes for the SOAP call. I'm using SOAP API v1, but you could as well do it with SOAP API v2 using shoppingCartProductAdd.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.