I can add product with one feature corretly, but have problem when try add product with more features. How to do it from php? Now i have:
$webService = new PrestaShopWebservice(PS_SHOP_URL, PS_SHOP_API_KEY, true); $root_path = PS_SHOP_URL; $xml = $webService -> get(array('url' => $root_path.'api/products?schema=blank')); $resources = $xml->children()->children(); ... $categoriesList = array(2,10,11); //for categories this loop works perfectly foreach ($categoriesList as $category){ $resources->associations->categories->addChild('category')->addChild('id', $category); } unset($resources->associations->product_features); $featuresList[] = array('id' => 6, 'id_feature_value' => 40); $featuresList[] = array('id' => 7, 'id_feature_value' => 118); // this loop makes errors /* foreach ($featuresList as $feature){ $resources->associations->product_features->addChild('product_feature')->addChild('id', $feature['id']); $resources->associations->product_features->addChild('product_feature')->addChild('id_feature_value', $feature['id_feature_value']); } */ //this works only for one feature $resources->associations->product_features->product_feature->id = 6; $resources->associations->product_features->product_feature->id_feature_value = 40; ... $opt = array('resource' => 'products'); $opt['postXml'] = $xml -> asXML(); $xml = $webService -> add($opt); $id = $xml->product->id;
Respond when i sent one feature:
... <product_features nodeType="product_feature" api="product_features"> <product_feature xlink:href="https://mydomain/api/product_features/6"> <id><![CDATA[6]]></id> <id_feature_value xlink:href="https://maydomain/api/product_feature_values/40"><![CDATA[40]]></id_feature_value> </product_feature> </product_features> ...
How obtain some like this?:
... <product_features nodeType="product_feature" api="product_features"> <product_feature xlink:href="https://mydomain/api/product_features/6"> <id><![CDATA[6]]></id> <id_feature_value xlink:href="https://maydomain/api/product_feature_values/40"><![CDATA[40]]></id_feature_value> </product_feature> <product_feature xlink:href="https://mydomain/api/product_features/7"> <id><![CDATA[7]]></id> <id_feature_value xlink:href="https://maydomain/api/product_feature_values/118"><![CDATA[118]]></id_feature_value> </product_feature> </product_features> ...