简体   繁体   中英

how to add custom option on magento api?

how to add custom option like color and size on magento api soap? this is my code:

public function addProduct($data)
    {
        $newProductData = array(
            'name'              => $data['name'],
            'websites'          => array( 1 ),
            'short_description' => $data['short_description'],
            'description'       => $data['description'],
            'status'            => 1,
            'weight'            => 0,
            'tax_class_id'      => 1,
            'categories'        => array( 3 ),
            'price'             => $data['price'],
        );

        return $this->APIcreateNewProduct( $newProductData );
    }

/* * Creates product by one parameter which is array with new product data */

 public function APIcreateNewProduct( $newProductData ) {

        $error = array();

        if( empty( $newProductData ) ) {
                $error[] = 'Empty product data';
        }

        if( empty( $error ) ) {

                $token = $this->_getToken();
                $client = $this->_getClient();
                $set = $this->_APIgetAttributeSets();

                $productId = $client->call($token, self::CREATE_PRODUCT, array('simple', $set['set_id'], rand().'sku_of_product', $newProductData));
                return $productId;

        } else {
                return $this->_apiJsonResult( $error );
        }

}

When you want to add custom options to product by API. You need to create this product. Method catalogProductCreate returns (int)$productId

http://www.magentocommerce.com/api/soap/catalog/catalogProduct/catalog_product.create.html

Then you need to use this: http://www.magentocommerce.com/api/soap/catalog/catalogProductCustomOption/catalogProductCustomOption.html to add to your product any number of custom options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM