Activity Forums Salesforce® Discussions How do I create a new product using the catalogProductCreate method in Magento?

  • Rajan

    Member
    May 1, 2018 at 7:28 am

    Hello Aman,

    following code are used ---

     

    $client = new SoapClient('http://magentohost/api/v2_soap/?wsdl');

    // If some stuff requires api authentification,
    // then get a session token
    $session = $client->login('apiUser', 'apiKey');

    // get attribute set
    $attributeSets = $client->catalogProductAttributeSetList($session);
    $attributeSet = current($attributeSets);

    $result = $client->catalogProductCreate($session, 'simple', $attributeSet->set_id, 'product_sku', array(
    'categories' => array(2),
    'websites' => array(1),
    'name' => 'Product name',
    'description' => 'Product description',
    'short_description' => 'Product short description',
    'weight' => '10',
    'status' => '1',
    'url_key' => 'product-url-key',
    'url_path' => 'product-url-path',
    'visibility' => '4',
    'price' => '100',
    'tax_class_id' => 1,
    'meta_title' => 'Product meta title',
    'meta_keyword' => 'Product meta keyword',
    'meta_description' => 'Product meta description'
    ));

  • Manpreet

    Member
    May 1, 2018 at 10:59 am

    Hi Aman,

    If your element is a product attribute, Magento is ready to handle with the Soap API. The catalogProductCreate method has additional_attributes parameter. You can use it to set one or more values to your attribute using single_data or multi_data.

    Example: Add a manufacturer info

    $newProduct->name = "product name";
    $newProduct->description = "description";
    $newProduct->short_description = "desc";
    $newProduct->status = "1";
    $newProduct->price = "99";
    $newProduct->tax_class_id = "2";

    $newProduct->additional_attributes = array(
    'single_data' => array(
    array(
    'key' => 'manufacturer',
    'value' => 'Company INC',
    ),
    )
    );
    /* you can add other additional attributes here like $manufacturer using multi_data parameters */

    Thanks.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos