v1.6-v1.7 Webservice specific_prices problem

rimas06

Member
XNullUser
Joined
Feb 22, 2022
Messages
187
Reaction score
4
Points
18
NullCash
3
Hi, i'm trying to add a specific price with webservice, but return me an erorr: "ERROR: This call to PrestaShop Web Services failed and returned an HTTP status of 500. That means: Internal Server Error." Why?





This is my code:

try{

$webService = $this->connPS();
$opt = array('resource' => 'specific_prices');
$xml = $webService->get(array('url' => PS_SHOP_PATH . '/api/specific_prices?schema=blank'));
$product = $xml->children()->children();


unset($product->id);
//unset($product->id_shop_group);

$product->id_shop = 1;
$product->id_cart = 0;
$product->id_product = 553;
$product->id_currency = 0;
$product->id_country = 0;
$product->id_group = 0;
$product->id_customer = 0;

$product->id_shop_group = 0;
$product->id_product_attribute = 0;
$product->id_specific_price_rule = 0;
$product->reduction = 1;
$product->reduction_tax = 1;
$product->reduction_type = 'amount';
$product->price = -1;
$product->from_quantity = 1;
$product->from = "0000-00-00 00:00:00";
$product->to = "0000-00-00 00:00:00";

$opt = array('resource' => 'specific_prices');
$opt['postXml'] = $xml->asXML();
$xml = $webService->add($opt);
$product_price = $xml->specific_prices;


} catch (PrestaShopWebserviceException $e){
// Here we are dealing with errors
$trace = $e->getTrace();
if ($trace[0]['args'][0] == 404) return 'Bad ID';
else if ($trace[0]['args'][0] == 401) return 'Bad auth key';
else return '<b>ERROR:</b> ' . $e->getMessage();
}
 

freiserk

Well-known member
Pro
Master
Diamond
Elite
Joined
Jan 24, 2019
Messages
3,455
Reaction score
6,445
Points
113
NullCash
35,187
Next time put on request section, please.

Thanks.
 

Sillumin

Well-known member
Pro
Master
Diamond
Elite
Joined
Jun 18, 2021
Messages
3,620
Reaction score
743
Points
113
NullCash
5,953
In future, put your requests in appropriate section of the forum, please.
 

d-shilko

Well-known member
Pro
Master
Diamond
Elite
Joined
Jun 10, 2021
Messages
2,485
Reaction score
1,398
Points
113
NullCash
6,229
Hi, i'm trying to add a specific price with webservice, but return me an erorr: "ERROR: This call to PrestaShop Web Services failed and returned an HTTP status of 500. That means: Internal Server Error." Why?





This is my code:

try{

$webService = $this->connPS();
$opt = array('resource' => 'specific_prices');
$xml = $webService->get(array('url' => PS_SHOP_PATH . '/api/specific_prices?schema=blank'));
$product = $xml->children()->children();


unset($product->id);
//unset($product->id_shop_group);

$product->id_shop = 1;
$product->id_cart = 0;
$product->id_product = 553;
$product->id_currency = 0;
$product->id_country = 0;
$product->id_group = 0;
$product->id_customer = 0;

$product->id_shop_group = 0;
$product->id_product_attribute = 0;
$product->id_specific_price_rule = 0;
$product->reduction = 1;
$product->reduction_tax = 1;
$product->reduction_type = 'amount';
$product->price = -1;
$product->from_quantity = 1;
$product->from = "0000-00-00 00:00:00";
$product->to = "0000-00-00 00:00:00";

$opt = array('resource' => 'specific_prices');
$opt['postXml'] = $xml->asXML();
$xml = $webService->add($opt);
$product_price = $xml->specific_prices;


} catch (PrestaShopWebserviceException $e){
// Here we are dealing with errors
$trace = $e->getTrace();
if ($trace[0]['args'][0] == 404) return 'Bad ID';
else if ($trace[0]['args'][0] == 401) return 'Bad auth key';
else return '<b>ERROR:</b> ' . $e->getMessage();
}
Because this is not WebService code. Are you a WordPress developer?

//We create a class object by specifying the store url and the created secret key from the admin panel
$webService = new PrestaShopWebservice($shop_url, $secret_key, $debug);

//Note that the products method without ?schema=synopsis outputs a list of products
$xml_product = $webService->get(array('resource' => 'products?schema=synopsis'));

//After receiving the blank, fill in the XML fields
$resources_product = $new_product->children()->children();
$resources_product->name->language[0][0] = "Test product";
$resources_product->link_rewrite->language[0][0] = "tstproduct";
$resources_product->active = 1; $resources_product->available_for_order = 1;
$resources_product->show_price = 1;
$resources_product->out_of_stock = 2;
If the item is out of stock, the default action.

//If the item is out of stock, the default action.
//If you do not specify a category, the product will not be visible in the admin panel, this is important


$resources_product->associations->categories->category[0]->id = 1;
//Send the completed workpiece for addition
$created_product = $webService->add(array('resource' => 'products', 'postXml' => $new_product->asXML()));
 
Top