prestashop 添加组合内部服务器错误

prestashop add combination internal server error

我创建了一个产品,并尝试将组合 (color/size) 分配给他。

但是只有第一个组合添加成功!然后我收到内部服务器错误 (500)

我就是这么用的:

$combination =
'<?xml version="1.0" encoding="utf-8"?>
<prestashop>
    <combination>
        <id xmlns=""></id>
        <id_product xmlns="">'.$id.'</id_product>
        <quantity xmlns="">' . $quantity . '</quantity>
        <supplier_reference xmlns="">Inditex</supplier_reference>
        <price xmlns="">' . $price . '</price>
        <wholesale_price xmlns="">' . $price . '</wholesale_price>
        <minimal_quantity xmlns="">1</minimal_quantity>
        <default_on xmlns="">1</default_on>

        <associations xmlns="">
            <product_option_values xmlns="">
                <product_option_value><id>'.$color_id.'</id></product_option_value>
                <product_option_value><id>'.$size_id.'</id></product_option_value>
            </product_option_values>
        </associations>
    </combination>
</prestashop>';
$response = curlCall($url . '/api/combinations/products/'.$id, $combination, 'POST', $api_key);
$load_string = simplexml_load_string($response);
$combination_id = $load_string->combination->id;

只有当产品没有组合时,该代码才能正常工作。 (color_id 和 size_id 已验证,我不使用相同的 ID)

请救救我:)

我用了另一种方法,效果很好:

$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;

对于阅读此问题的其他人来说,方法的改变并不是解决方案。问题是您使用的url。

第一种和第二种方法是一样的,只是构建方法不同xml,唯一不同的是url:

  • $url.'/api/combinations/products/'.$id

  • $url.'/api/combinations

首先url不要调用 Prestashop 网络服务中的有效资源。 我建议使用库 https://github.com/PrestaShop/PrestaShop-webservice-lib/blob/master/PSWebServiceLibrary.php 来帮助防止这种情况。