Magento unfortunately has virtually no documentation on the V2 API. I needed to prove to someone today that using the V2 API, you can indeed create a product, assign it to 2 or more websites, and set the product price to different values for each website (as long as you’ve set the price scope to “Website” instead of the default “Global” which is in System > Configuration > Catalog > Price).
In this example, I set the initial product data to create, and run the API method ‘catalogProductCreate’. After the product has been created, I then set the product price for the wholesale website, and then run the ‘catalogProductUpdate’ method. The key here is passing in the correct store view code. Ultimately, the product is created with the price of $45. Then the wholesale website is updated to set a price of $20.
<?php //error_reporting(E_ALL); //ini_set('display_errors', '1'); /** * Get API Session */ $client = new SoapClient('http://core.local/api/v2_soap?wsdl=1'); $session = $client->login('augustash', 'password'); /** * Set Product Data */ $newProductData = new stdClass(); $newProductData->name = 'Product Name'; $newProductData->description = 'Description'; $newProductData->short_description = 'Short Description'; $newProductData->websites = array(1,2); $newProductData->categories = array(7,15); $newProductData->status = 1; $newProductData->price = 45; $newProductData->tax_class_id = 2; $newProductData->weight = 1; /** * Create Product Using V2 API */ $result = $client->catalogProductCreate( $session, // Soap Session 'simple', // Product Type 4, // Attribute Set Id (Default) 'product-sku', // Product Sku $newProductData // Product Data ); /** * Set Price for Wholesale Website */ $newProductData = new stdClass(); $newProductData->price = 20; /** * Update Product with Wholesale Price using V2 API */ $result = $client->catalogProductUpdate( $session, // Soap Session 'product-sku', // Product Sku $newProductData, // Product Data 'wholesale' // Store View Code ); /** * End Session */ $client->endSession($session);
If you are wondering where to look to find out what values you can pass in, and what parameters are needed when making V2 API calls, you’ll need to look at the wsdl. In app/code/core/Mage/Catalog/etc/wsdl.xml, you’ll find the product API info. I’ve extracted the product data fields that you can pass in when creating a product:
<complexType name="catalogProductCreateEntity"> <all> <element name="categories" type="typens:ArrayOfString" minOccurs="0" /> <element name="websites" type="typens:ArrayOfString" minOccurs="0" /> <element name="name" type="xsd:string" minOccurs="0" /> <element name="description" type="xsd:string" minOccurs="0" /> <element name="short_description" type="xsd:string" minOccurs="0" /> <element name="weight" type="xsd:string" minOccurs="0" /> <element name="status" type="xsd:string" minOccurs="0" /> <element name="url_key" type="xsd:string" minOccurs="0" /> <element name="url_path" type="xsd:string" minOccurs="0" /> <element name="visibility" type="xsd:string" minOccurs="0" /> <element name="category_ids" type="typens:ArrayOfString" minOccurs="0" /> <element name="website_ids" type="typens:ArrayOfString" minOccurs="0" /> <element name="has_options" type="xsd:string" minOccurs="0" /> <element name="gift_message_available" type="xsd:string" minOccurs="0" /> <element name="price" type="xsd:string" minOccurs="0" /> <element name="special_price" type="xsd:string" minOccurs="0" /> <element name="special_from_date" type="xsd:string" minOccurs="0" /> <element name="special_to_date" type="xsd:string" minOccurs="0" /> <element name="tax_class_id" type="xsd:string" minOccurs="0" /> <element name="tier_price" type="typens:catalogProductTierPriceEntityArray" minOccurs="0" /> <element name="meta_title" type="xsd:string" minOccurs="0" /> <element name="meta_keyword" type="xsd:string" minOccurs="0" /> <element name="meta_description" type="xsd:string" minOccurs="0" /> <element name="custom_design" type="xsd:string" minOccurs="0" /> <element name="custom_layout_update" type="xsd:string" minOccurs="0" /> <element name="options_container" type="xsd:string" minOccurs="0" /> <element name="additional_attributes" type="typens:associativeArray" minOccurs="0" /> </all> </complexType>
Here are the parameters that can be passed in when using the create and update methods:
<message name="catalogProductCreateRequest"> <part name="sessionId" type="xsd:string" /> <part name="type" type="xsd:string" /> <part name="set" type="xsd:string" /> <part name="sku" type="xsd:string" /> <part name="productData" type="typens:catalogProductCreateEntity" /> </message> <message name="catalogProductUpdateRequest"> <part name="sessionId" type="xsd:string" /> <part name="product" type="xsd:string" /> <part name="productData" type="typens:catalogProductCreateEntity" /> <part name="storeView" type="xsd:string" /> <part name="productIdentifierType" type="xsd:string" /> </message>
This is great documentation! thanks so much.