Web服务添加/更新组合Prestashop

时间:2013-02-09 13:44:22

标签: web-services combinations prestashop

我试过,我试着看看有关如何通过web服务添加/更新组合的信息,在presta 1.5.3中,但我仍然不知道该怎么做。

有人能帮助我吗?

2 个答案:

答案 0 :(得分:1)

通过Webservice为产品分配组合是一个多步操作(与CSV导入不同)。

  • 给出带有id_product的产品
  • 添加product_options(BO 属性名称
  • 将product_option_values(BO 属性值)添加到product_options
  • 在指定id_product
  • 时添加组合

首先使用DEBUG = true初始化PrestaShopWebservice:

$api = new PrestaShopWebservice($psShopUrl, $psAuthKey, $psDebug);

不是从头开始构建XML,而是获取所需资源的模板,如下所示:

$sxml = $api->get(array('url' => $psShopUrl.'api/'.$resource.'?schema=blank'));

响应是一个SimpleXMLElement,比DOM更容易操作。

NB:响应包含所有包装器节点,您必须在请求中发回相同内容,即PSWebServiceLibrary将为您重新创建它们。

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<combination>
...
</combination>
</prestashop>

SXML操作示例:

$schema = $api->get(array('url' => $psShopUrl.'api/product_options?schema=blank'));
$data = $schema->children()->children();
$data->is_color_group = false;
$data->group_type = $group_type;   // radio, select
$data->name->language[0] = 'attribute private name';
$data->public_name->language[0] = 'attribute public name';
$xml = $schema->asXML();    // all of it!
$ret = $api->add(array('resource' => 'product_options', 'postXml' => $xml));
$id_attribute_group = (int)$ret->children()->children()->id;    // save for next step

然后获取product_option_values架构,设置数据和上一步的id_attribute_group。等等。

更新是相同的,除非您{em> id 然后get edit资源:

$sxml = $api->get(array('resource' => $resource, 'id' => $id));
...
$ret = $api->edit(array('resource' => $resource, 'id' => $id, 'putXml' => $xml));

至于向product_option_values资源中的combinations节点添加多个 id 值,您可以使用array_push快捷方式[]

$data->associations->product_option_values->product_option_values[]->id = 123;
$data->associations->product_option_values->product_option_values[]->id = 456;

答案 1 :(得分:0)

这对我来说很好用:

$webService = new PrestaShopWebservice($url, $api_key, FALSE);
$xml = $webService->get(array('url' => $url .'/api/combinations?schema=blank'));

$resources = $xml->children()->children();

$resources->id_product          = $ps_product_id;
$resources->wholesale_price     = $wholesale_price;
$resources->price               = $price;
$resources->unit_price_impact   = $unit_price_impact;
$resources->minimal_quantity    = $minimal_quantity;
$resources->quantity            = $quantity;
$resources->weight              = $weight;

$resources->associations->product_option_values->product_option_value[0]->id = $color_id;
$resources->associations->product_option_values->product_option_value[1]->id = $size_id;

$request = $xml->asXML();

//This is a function that curl request to specific URL using method (POST)
$response = ps_curl($url . '/api/combinations', $request, 'POST', $api_key);

$xml_load  = simplexml_load_string($response);
$id        = $xml_load->combination->id;

我希望这有用:)