4

I'm having some troubles adding configurable products to the shopping cart via shoppingCartProductAdd. Lets say that I have:

  • a Configurable product with the sku configurable-shirt
  • that has options size (optionId 92) and color (optionId 134)
  • that has an associated (simple) product with option selection for the size ExtraLarge (selectionid 20) and for the color Green (selectionid 5)
  • the color Green has a fixed price configured at 5eur

As I understand, I should add the configurable-shirt to the shopping cart as follows:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:Magento">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:shoppingCartProductAddRequestParam>
         <sessionId>91b24f514cfc125bac900a682586ecd0</sessionId>
         <quoteId>254</quoteId>
         <productsData>
            <complexObjectArray>
               <sku>configurable-shirt</sku>
               <qty>1.0</qty>
               <options>
                  <complexObjectArray>
                     <key>92</key> <!-- size -->
                     <value>20</value> <!-- ExtraLarge -->
                  </complexObjectArray>
                  <complexObjectArray>
                     <key>134</key> <!-- color -->
                     <value>5</value> <!-- Green -->
                  </complexObjectArray>
               </options>
            </complexObjectArray>
         </productsData>
         <store>default</store>
      </urn:shoppingCartProductAddRequestParam>
   </soapenv:Body>
</soapenv:Envelope>

But all I get is a response telling me to define the product options which, if you ask me, I just did in the soap message.

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
   <SOAP-ENV:Body>
      <SOAP-ENV:Fault>
         <faultcode>1022</faultcode>
         <faultstring>Please specify the product's option(s).</faultstring>
      </SOAP-ENV:Fault>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

If I however use the sku of the associated simple product whis is configurable-shirt-Green-ExtraLarge the products is added to the shopping cart, but the 5eur price addition to color green is not added to the products total sum.

The configurable product works as expected if I use the magento frontend. I'm using 1.8.0.0

  • Were you able to resolve this? Please share. – Dayson Nov 12 '13 at 4:46
4

Found solution to this, but since Magento has missed this point in the default Soap functionality so had to create a custom module to over-ride the default wsdl of checkout in magento.

You can find my complete solution with the custom module-code at the below URL: http://www.magentocommerce.com/boards/viewthread/829246/

Solution: I checked what parameters do magento sent to product add function when configurable product is added to cart from front-end. The post parameters contained an array

[super_attribute] => Array( [92] => 248, [175] => 249 )

But Magento do not include this element in the default WSDL and WSI xml file, which is located at path /rootfolder/app/code/core/Mage/Checkout/etc

"WSI.XML FILE"
<xsd:complexType name="shoppingCartProductEntity">
                <xsd:sequence>
                    <xsd:element name="product_id" type="xsd:string" minOccurs="0"/>
                    <xsd:element name="sku" type="xsd:string" minOccurs="0"/>
                    <xsd:element name="qty" type="xsd:double" minOccurs="0"/>
                    <xsd:element name="options" type="typens:associativeArray" minOccurs="0"/>
                    <xsd:element name="bundle_option" type="typens:associativeArray" minOccurs="0"/>
                    <xsd:element name="bundle_option_qty" type="typens:associativeArray" minOccurs="0"/>
                    <xsd:element name="links" type="typens:ArrayOfString" minOccurs="0"/>
                </xsd:sequence>
            </xsd:complexType>

"WSDL.XML FILE"
<complexType name="shoppingCartProductEntity">
                <all>
                    <element name="product_id" type="xsd:string" minOccurs="0"/>
                    <element name="sku" type="xsd:string" minOccurs="0"/>
                    <element name="qty" type="xsd:double" minOccurs="0"/>
                    <element name="options" type="typens:associativeArray" minOccurs="0"/>
                    <element name="bundle_option" type="typens:associativeArray" minOccurs="0"/>
                    <element name="bundle_option_qty" type="typens:associativeArray" minOccurs="0"/>
                    <element name="links" type="typens:ArrayOfString" minOccurs="0"/>
                </all>
            </complexType>

What i did is i over-ride the default “wsdl.xml” and “wsi.xml”, by creating a custom module and added the new element name “super_attribute” to the xml under my custom module etc folder.

"My module WSDL file"
<complexType name="shoppingCartProductEntity">
    <all>
        <element name="super_attribute" type="typens:associativeArray" minOccurs="0"/>
    </all>
</complexType>

"My Module WSI file"
<xsd:complexType name="shoppingCartProductEntity">
         <xsd:sequence>
        <xsd:element name="super_attribute" type="typens:associativeArray" minOccurs="0"/>
    </xsd:sequence>
</xsd:complexType>

This will add this new element to the main wsdl and you can confirm it by running the following URL: http://yourhost.com/index.php/api/v2_soap/?wsdl and search for string like “shoppingCartProductEntity”

Now adding a product to cart using Magento’s Soap request, i added product to cart using below code

$product = array(
            'product_id' => 'product-id',
            'sku' => 'product-sku',
            'qty' => '1',
            'super_attribute' => array(
                0 => array(
                'key' => attribute-id,
                'value' => attribute-value
                ),
                1 => array(
                'key' => attribute-id,
                'value' => attribute-value
                )
            ),
            'bundle_option' => null,
            'bundle_option_qty' => null,
            'links' => null
        );
$productAdded = $soapObject->shoppingCartProductAdd($sessionId,$quoteId,array($product),'1');

By this the configurable product was added to cart.

Hope this helps.

| improve this answer | |
  • Feel free to copy the solution on this site also. As sadly links can die. – David Manners Jan 9 '14 at 13:46
  • Hi David, complete solution added :) – Rahul Tyagi Jan 13 '14 at 6:26
  • i have added super attribute 'super_attribute' => array( 0 => array( 'key' => 92, 'value' => 10 ), 1 => array( 'key' => 134, 'value' => 3 ) ), but the product is not added to cart. kindly tell me how to add the option values. – alamelu Jul 8 '14 at 13:53
  • @RahulTyagi Hi,i add your custom madule to magento and then try to add confugure able product to cart but it`s return me this message : please specify product option(s) – mahdi Nov 23 '14 at 7:12
  • 1
    If you are changing wsdl, be sure wsdl caching is off. SoapClient(Mage::getBaseUrl() . 'index.php/api/v2_soap/?wsdl', array('cache_wsdl' => WSDL_CACHE_NONE)); – james.c.funk May 22 '17 at 21:45

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