Jump to content

Dodanie produktu poprzez API


paplo22

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)
Link to comment
Share on other sites

  • 1 month later...

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...