简体   繁体   中英

Issue in creating product “Brand” feature in cs cart using PHP API

I am getting issue while creating "Brand" feature in cs cart using cs cart API.

I am using like below:

$URL= http://example.com/api/products/250

$data = '{"product_features": {"28": {"feature_type": "E", "value": "test"}}}';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $URL);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_POST, TRUE);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");

curl_setopt($ch, CURLOPT_POSTFIELDS,$data);

curl_setopt($ch, CURLOPT_HTTPHEADER,$header);

// curl_setopt($ch, CURLOPT_HEADER,true);

$result=curl_exec($ch);

curl_close($ch);

 $re = json_decode($result,true);

  print_r($re); 

getting "product_id" in response but no feature is adding. I have checked the feature id again and it is ok. Please help me to sort the issue Thanks in advance

Working with products features in CS-Cart API is a little bit tricky, because they didn't provide enough documentation for it.

"Brand" is a feature with type "E" (Extended), each brand is different "variant", you should know "variant_id" of each brand, before you update it.

Here is a little example how your data should look.

$feature_id = 'ID_OF_BRAND_FEATURE';
$brand_id = 'VARIANT_ID_OF_YOUR_BRAND';

$product_data = [
    'status' => 'A' // Just some param when you update
];

$product_features = [
   $feature_id => [
       'feature_id' => $feature_id,
       'feature_type' => 'E',
       'variant_id' => $brand_id,
     ]
];

$product_data['product_features'] = $product_features;

You can use this CS-Cart API wrapper to make your life easier https://github.com/drahosistvan/cscartapi

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