Jump to content

Edit produit webservice


Recommended Posts

Bonjour,

 

Je dois modifier la valeur active  d'un produit sauf que le webservice me retourne toujours une erreur.

 

J'ai utulisé un exemple fournit par Prestashop  (https://github.com/PrestaShop/PrestaShop-webservice-lib)

 

J'ai essayer différente méthodes en enlevant certaine valeur comme :

 

 id_default_image
- position_in_category
- manufacturer_name
- unity
- date_add
- date_upd

 

Cela ne change rien.

 

Je vous soumets mon code si quelqu'un peut m'aider.

 

Il faut savoir que ce code est quasi le même que celui fournit dans l 'exemple de Prestashop que l'on trouve sur Guithub

 $webService = new PrestaShopWebservice($params_e_boutique['url_boutique'], $params_e_boutique['e_boutique_webservice_account_key'], TRUE);

        try {
            $opt = array('resource' => 'products');
            $opt['id'] = 8;
            $xml = $webService->get($opt);

            // Here we get the elements from children of customer markup which is children of prestashop root markup
            $resources = $xml->children()->children();
        } catch (PrestaShopWebserviceException $e) {
            // Here we are dealing with errors
            $trace = $e->getTrace();
            if ($trace[0]['args'][0] == 404)
                echo 'Bad ID';
            else if ($trace[0]['args'][0] == 401)
                echo 'Bad auth key';
            else
                echo 'Other error<br />' . $e->getMessage();
        }

// Second : We update the data and send it to the web service
        // Here we have XML before update, lets update XML with new values
        /* foreach ($resources as $nodeKey => $node) {
          $resources->$nodeKey = $_POST[$nodeKey];
          } */
        // And call the web service
        try {
            unset($resources->id_default_image);
            unset($resources->position_in_category);
            unset($resources->manufacturer_name);
            unset($resources->unity);
            unset($resources->date_add);
            unset($resources->date_upd);
            
            $opt = array('resource' => 'products');
            $opt['putXml'] = $xml->asXML();
            $opt['id'] = 8;
            $xml = $webService->edit($opt);
            // if WebService don't throw an exception the action worked well and we don't show the following message
            echo "Successfully updated.";
        } catch (PrestaShopWebserviceException $ex) {
            // Here we are dealing with errors
            $trace = $ex->getTrace();
            if ($trace[0]['args'][0] == 404)
                echo 'Bad ID';
            else if ($trace[0]['args'][0] == 401)
                echo 'Bad auth key';
            else
                echo 'Other error<br />' . $ex->getMessage();
        }

Voilà les valeurs retournés 



HTTP RESPONSE HEADER

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<product>
	<id><![CDATA[8]]></id>
	<id_manufacturer><![CDATA[0]]></id_manufacturer>
	<id_supplier><![CDATA[0]]></id_supplier>
	<id_category_default xlink:href="https://localhost/shop/api/categories/4"><![CDATA[4]]></id_category_default>
	<new/>
	<cache_default_attribute><![CDATA[0]]></cache_default_attribute>

	<id_default_combination not_filterable="true"/>
	<id_tax_rules_group xlink:href="https://localhost/shop/api/tax_rule_groups/1"><![CDATA[1]]></id_tax_rules_group>


	<quantity not_filterable="true"><![CDATA[0]]></quantity>
	<type not_filterable="true"><![CDATA[virtual]]></type>
	<id_shop_default><![CDATA[1]]></id_shop_default>
	<reference><![CDATA[M1H]]></reference>
	<supplier_reference/>
	<location/>
	<width><![CDATA[0.000000]]></width>
	<height><![CDATA[0.000000]]></height>
	<depth><![CDATA[0.000000]]></depth>
	<weight><![CDATA[0.000000]]></weight>
	<quantity_discount><![CDATA[0]]></quantity_discount>
	<ean13/>
	<upc/>
	<cache_is_pack><![CDATA[0]]></cache_is_pack>
	<cache_has_attachments><![CDATA[0]]></cache_has_attachments>
	<is_virtual><![CDATA[1]]></is_virtual>
	<on_sale><![CDATA[0]]></on_sale>
	<online_only><![CDATA[0]]></online_only>
	<ecotax><![CDATA[0.000000]]></ecotax>
	<minimal_quantity><![CDATA[1]]></minimal_quantity>
	<price><![CDATA[6.000000]]></price>
	<wholesale_price><![CDATA[0.000000]]></wholesale_price>

	<unit_price_ratio><![CDATA[0.000000]]></unit_price_ratio>
	<additional_shipping_cost><![CDATA[0.00]]></additional_shipping_cost>
	<customizable><![CDATA[0]]></customizable>
	<text_fields><![CDATA[0]]></text_fields>
	<uploadable_files><![CDATA[0]]></uploadable_files>
	<active><![CDATA[1]]></active>
	<redirect_type><![CDATA[404]]></redirect_type>
	<id_product_redirected><![CDATA[0]]></id_product_redirected>
	<available_for_order><![CDATA[1]]></available_for_order>
	<available_date><![CDATA[0000-00-00]]></available_date>
	<condition><![CDATA[new]]></condition>
	<show_price><![CDATA[1]]></show_price>
	<indexed><![CDATA[1]]></indexed>
	<visibility><![CDATA[both]]></visibility>
	<advanced_stock_management><![CDATA[0]]></advanced_stock_management>


	<meta_description><language id="1" xlink:href="https://localhost/shop/api/languages/1"><![CDATA[]]></language><language id="2" xlink:href="https://localhost/shop/api/languages/2"><![CDATA[]]></language></meta_description>
	<meta_keywords><language id="1" xlink:href="https://localhost/shop/api/languages/1"><![CDATA[]]></language><language id="2" xlink:href="https://localhost/shop/api/languages/2"><![CDATA[]]></language></meta_keywords>
	<meta_title><language id="1" xlink:href="https://localhost/shop/api/languages/1"><![CDATA[]]></language><language id="2" xlink:href="https://localhost/shop/api/languages/2"><![CDATA[]]></language></meta_title>
	<link_rewrite><language id="1" xlink:href="https://localhost/shop/api/languages/1"><![CDATA[1-heure]]></language><language id="2" xlink:href="https://localhost/shop/api/languages/2"><![CDATA[1-heure]]></language></link_rewrite>
	<name><language id="1" xlink:href="https://localhost/shop/api/languages/1"><![CDATA[1 heure]]></language><language id="2" xlink:href="https://localhost/shop/api/languages/2"><![CDATA[1 hour]]></language></name>
	<description><language id="1" xlink:href="https://localhost/shop/api/languages/1"><![CDATA[<p>60 minutes de connexion utilisables jusqu'à épuisement du crédit-temps, dans la limite de 150 jours à partir de la première connexion. Ce forfait est utilisable sur un seul terminal simultanément.</p>]]></language><language id="2" xlink:href="https://localhost/shop/api/languages/2"><![CDATA[]]></language></description>
	<description_short><language id="1" xlink:href="https://localhost/shop/api/languages/1"><![CDATA[<p>60 minutes de connexion utilisables jusqu'à épuisement du crédit-temps, dans la limite de 150 jours à partir de la première connexion. Ce forfait est utilisable sur un seul terminal simultanément.</p>]]></language><language id="2" xlink:href="https://localhost/shop/api/languages/2"><![CDATA[]]></language></description_short>
	<available_now><language id="1" xlink:href="https://localhost/shop/api/languages/1"><![CDATA[]]></language><language id="2" xlink:href="https://localhost/shop/api/languages/2"><![CDATA[]]></language></available_now>
	<available_later><language id="1" xlink:href="https://localhost/shop/api/languages/1"><![CDATA[]]></language><language id="2" xlink:href="https://localhost/shop/api/languages/2"><![CDATA[]]></language></available_later>
<associations>
<categories node_type="categories">
	<categories xlink:href="https://localhost/shop/api/categories/4">
	<id><![CDATA[4]]></id>
	</categories>
</categories>
<images node_type="images">
	<images xlink:href="https://localhost/shop/api/images/products/8/24">
	<id><![CDATA[24]]></id>
	</images>
</images>
<combinations node_type="combinations"/>
<product_option_values node_type="product_option_values"/>
<product_features node_type="product_features">
	<product_features xlink:href="https://localhost/shop/api/product_features/3">
	<id><![CDATA[3]]></id>
	<custom><![CDATA[0]]></custom>
	<id_feature_value xlink:href="https://localhost/shop/api/product_feature_values/3"><![CDATA[3]]></id_feature_value>
	</product_features>
</product_features>
<tags node_type="tags"/>
<stock_availables node_type="stock_availables"/>
<accessories node_type="products"/>
<product_bundle node_type="products"/>
</associations>
</product>
</prestashop>
RETURN HTTP BODY
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<message><![CDATA[Internal error. To see this error please display the PHP errors.]]></message>
</error>
</errors>
</prestashop>

Merci d'avance de votre aide.

Link to comment
Share on other sites

Merci de votre aide .

 

J'ai modifie cela, je tombe sur l'erreur suivante.

 

<code><![CDATA[85]]></code>
<message><![CDATA[Error occurred while setting the product_bundle value]]></message>

 

Il faut savoir que je suis en mode multiboutique. 

 

La je veux modifier un produit d'une boutique spécifique.

Link to comment
Share on other sites

Juste une dernière question après je ferme le post.

 

Pourquoi certaines informations du XML récuperer avec la méthode "get" ne peuvent pas être envoyer en "edit" ?

Exemple :

-manufacturer_name

-quantity

-product_bundle

 

Autre question quand j'édit mon produit :

 

 

Je récupère mon prix de 5€ qui est TTC

Quand j'envoie après edition mon prix HT est 5€ et mon TTC est passé à 6€ soit la TVA française.

L e champ price dans le XML correspond au prix HT ? 

 

Merci

Edited by devneptune (see edit history)
Link to comment
Share on other sites

  • 7 months later...

Bonjour à tous,

C'est bien gentil de donner des informations sur la création de produits avec web service mais comme je suis débutant j'aurais besoin de la structure du module à développer avec la partie get.

 

Quelqu'un peut-il maider ?

 

Merci d'avance,

Jean-Marie

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...