jarek.skuder Posted June 2, 2016 Share Posted June 2, 2016 I am sending products from my DB to Prestashop DB via PrestaShopWebservice. The product is now sending and along with the product creates one attribute. The question is how to send product combinations or attributes? In Prestashop admin panel you can create combinations when you edit your product, it's easy. But how to do that via webservice?I made this so far, i really thought that it should worked: $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, true); // Starting webservice$xml = $webService->get(array('resource' => 'products?schema=blank')); // Getting product schema $resources = $xml->children()->children();unset($resources->position_in_category);unset($resources->manufacturer_name);unset($resources->id_default_combination);unset($resources->quantity);$resources->id_category_default = '3';$resources->id_shop_default = '1';$resources->id_tax_rules_group = '1';$resources->ean13 = $product->getEan13();$resources->minimal_quantity = '1';$resources->price = floatval($price['price']);$resources->supplier_reference = $product->getMatNr();$resources->active = '1';$resources->available_for_order = '1';$resources->show_price = '1';$link = $this->remove_accent($prekesKortelesName);$link = preg_replace('/[^a-zA-Z0-9]/', '_', $link);$resources->link_rewrite->language[0][0] = $link;$resources->link_rewrite->language[1][0] = $link;$resources->link_rewrite->language[2][0] = $link;$resources->name->language[0][0] = $prekesKortelesName;$resources->name->language[1][0] = $prekesKortelesName;$resources->name->language[2][0] = $prekesKortelesName;$resources->description->language[0][0] = $product->getDescription();$resources->id_tax_rules_group = '1'; $resources->associations->categories->category->id = $category->category->id;$resources->id_category_default = $category->category->id;$resources->associations->product_option_values->product_option_values->id = '1';$resources->associations->product_features->product_feature->id = '1';$resources->associations->product_features->product_feature->id_feature_value = '1';$resources->associations->tags->tag->id = '1';$resources->associations->stock_availables->stock_available->id = '1';$resources->associations->stock_availables->stock_available->id_product_attribute = '905';$resources->associations->accessories->product->id = '1';$resources->associations->product_bundle->products->id = '1';$opt['postXml'] = $xml->asXML();$response = $webService->add($opt);$resources = $response->children()->children();$id_created_product = $resources->product->id;$this->sendImage($product,$id_created_product);// Product options$xml = $webService->get(array('resource' => 'product_options?schema=blank'));$resources->is_color_group = true;$resources->group_type = 'color';$resources->name->language[0][0] = $link;$resources->name->language[1][0] = $link;$resources->name->language[2][0] = $link;$resources->public_name->language[0][0] = $prekesKortelesName;$resources->public_name->language[1][0] = $prekesKortelesName;$resources->public_name->language[2][0] = $prekesKortelesName;$opt['postXml'] = $xml->asXML();$response = $webService->add($opt);$resources = $response->children()->children();$id_attribute_group = $resources->id;// Product option values$xml = $webService->get(array('resource' => 'product_option_values?schema=blank'));$resources->id_attribute_group = $id_attribute_group;$resources->name->language[0][0] = $link;$resources->name->language[1][0] = $link;$resources->name->language[2][0] = $link;$opt['postXml'] = $xml->asXML();$response = $webService->add($opt);$resources = $response->children()->children();$id_product_option = $resources->id;// Combinations$xml = $webService->get(array('resource' => 'combinations?schema=blank'));$resources->id_product = $id_created_product;$resources->associations->product_option_values->product_option_values->id = $id_product_option;$resources->minimal_quantity = '1';$opt['postXml'] = $xml->asXML();$response = $webService->add($opt);$resources = $response->children()->children(); What i am missing??? Link to comment Share on other sites More sharing options...
roband Posted June 2, 2016 Share Posted June 2, 2016 The main problem is that you assume the webservice API allows you to insert or update using associations. Except for a few badly documented cases it doesn't. So you need to split your post calls. First write products (using associations here to assign categories is supported) Then write combinations (using associations here to assign product option values is supported) Then write stock_availables and any other things you need that refer back to products and combinations Link to comment Share on other sites More sharing options...
jarek.skuder Posted June 3, 2016 Author Share Posted June 3, 2016 Sorry can you help me here. So as i understood corectlly, i must add product, categories, combinations, product_option_values and stock_availables? Link to comment Share on other sites More sharing options...
roband Posted June 3, 2016 Share Posted June 3, 2016 Yes, you need to add the different entities one by one using separate calls to the webservice add, you cannot group it all up in one call like you did in your settings of $resources->associations before writing the product. I see I did one mistake in my previous reply, I didn't notice you created product_option_values as well. So you then need to call the webservice add in this sequence: product_option_values (then get back the IDs as you need them later) products (you may set associations for categories. also get back the ID as you need it later) images combinations (you may set associations for product_option_values and images. also get back the IDs as you need them later) stock_availables This is all really badly documented by PrestaShop. I had to basically read their sourcecode and do a lot of trial and error to figure it all out. 1 Link to comment Share on other sites More sharing options...
jarek.skuder Posted June 3, 2016 Author Share Posted June 3, 2016 Ok thank you, i will try. Link to comment Share on other sites More sharing options...
carolinalour Posted September 5, 2016 Share Posted September 5, 2016 (edited) Hi, Were you able to do this successfully? Are you running this with python or PHP? Can you give me a draft/example of what you came up with? Thanks! Edited September 11, 2016 by carolinalour (see edit history) Link to comment Share on other sites More sharing options...
carolinalour Posted September 11, 2016 Share Posted September 11, 2016 Hi, could you please help? I've been trying to do this with python but the library isn't working. could you tell me how you did? Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now