Jump to content
paplo22

Dodanie produktu poprzez API

Recommended Posts

Witam

 

Walczę z dodaniem produktu do presty poprzez API, ale już nie mam pomysłu przeczytałem rożne fora zagranice/polskie, kopiowałem przykłady, tworzyłem własne i nic cały czas ten sam błąd: 

 Uncaught exception 'PrestaShopWebserviceException' with message 'Bad parameters given' in PSWebServiceLibrary.php:238 Stack trace: #0

Proszę o jakąs pomoc czego mi brakuje:

try
{
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG); // Starting webservice
$xml = $webService->get(array('resource' => 'products?schema=blank')); // Getting product schema
}
catch(PrestashopWebserviceException $ex){
echo $ex->getMessage();
return -1;
}

$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 = '2';
$resources->id_shop_default = '1';
$resources->id_tax_rules_group = '1';
$resources->minimal_quantity = '1';
$resources->supplier_reference = 'PP22222';
$resources->active = '0';
$resources->available_for_order = '1';
$resources->show_price = '1';
$resources->id_tax_rules_group = '1';


//$ProductName = 'Sukienka ladna';
//$link = $ProductName;
//$link = preg_replace('/[^a-zA-Z0-9]/', '-', $link);

$resources->link_rewrite->language[0][0] = 'Sukienka-ladna'; //$link;

$resources->name->language[0][0] = 'Sukienka UNIWERSAL'; //$ProductName;

$resources->description->language[0][0] = '...';

//$resources->associations->categories->category->id = '2';


$opt['postXml'] = $xml->asXML();
$response = $webService->add($opt);

najnowsze inspiracje:
https://www.prestashop.com/forums/topic/532659-webservice-add-product-along-with-the-attributes-and-combinations/
 

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

 

 

za bardzo nie rozumie co ma na myśli "using associations here to assign categories is supported" 

Edited by paplo22 (see edit history)

Share this post


Link to post
Share on other sites

Już ze wszystkimi problemami sobie poradziłem, dodawanie produktu kombinacji i ilości.

[temat zamknięty] 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More