如何解决Prestashop Webservices API:描述中的 HTML 给出错误 404
我正在使用 Prestashop Webservices Library 创建和更新产品。 我在创建它们时没有问题,但在更新时,即使我在创建产品时没有问题,它也会在将 HTML 添加到描述字段时给我一个错误 404。
如果我删除了 html,我可以更新产品,但它也应该可以使用它。 我在 Prestashop 库中extended SimpleXMLElement to add a CDATA,但结果是一样的
require_once('class/PSWebServiceLibrary.PHP');
try {
$webService = new PrestaShopWebservice('https://mywebsite','MYKEY',false);
$idProduct = 30;
$xmlResponse = $webService->get(['resource' => 'products','id' => $idProduct]);
$updateProductXML = $xmlResponse->product[0];
unset($updateProductXML->manufacturer_name); //Not writable,remove them
unset($updateProductXML->position_in_category);
unset($updateProductXML->quantity);
$updateProductXML->name->language[0][0] = "TEST";
$updateProductXML->description->language[0][0] = "This is not working if I add this: & ";
$response = $webService->edit([
'resource' => 'products','id' => (int) $updateProductXML->id,'putXml' => $xmlResponse->asXML(),]);
} catch ( PrestaShopWebserviceException $e){
echo $e->getMessage();
}
如果我删除描述字段中的 &
,它会起作用并更新产品,否则即使描述位于 CData 节点中,它也会返回 404 错误):
效果不佳:
$updateProductXML->description->language[0][0]->addCData('test &: test');
$updateProductXML->description->language[0][0]->addCData('juste normal text but in cdata');
有什么想法吗?
谢谢:)
Prestashop 版本:1.7.7.3,全新安装
解决方法
如所问,这是发送的 XML,即使使用 CData,它的格式也正确:
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<product>
<id>30</id>
<id_manufacturer>0</id_manufacturer>
<id_supplier>0</id_supplier>
<id_category_default xlink:href="https://mywebsiteurl/api/categories/31">31</id_category_default>
<new></new>
<cache_default_attribute>0</cache_default_attribute>
<id_default_image notFilterable="true" />
<id_default_combination notFilterable="true">0</id_default_combination>
<id_tax_rules_group xlink:href="https://mywebsiteurl/api/tax_rule_groups/53">53</id_tax_rules_group>
<type notFilterable="true">simple</type>
<id_shop_default>1</id_shop_default>
<reference>mySKU</reference>
<supplier_reference />
<location />
<width>0.000000</width>
<height>0.000000</height>
<depth>0.000000</depth>
<weight>0.000000</weight>
<quantity_discount>0</quantity_discount>
<ean13 />
<isbn />
<upc />
<mpn />
<cache_is_pack>0</cache_is_pack>
<cache_has_attachments>0</cache_has_attachments>
<is_virtual>0</is_virtual>
<state>1</state>
<additional_delivery_times>0</additional_delivery_times>
<delivery_in_stock>
<language id="2" xlink:href="https://mywebsiteurl/api/languages/2">in stock</language>
</delivery_in_stock>
<delivery_out_stock>
<language id="2" xlink:href="https://mywebsiteurl/api/languages/2">out of stock</language>
</delivery_out_stock>
<on_sale>0</on_sale>
<online_only>0</online_only>
<ecotax>0.000000</ecotax>
<minimal_quantity>0</minimal_quantity>
<low_stock_threshold>0</low_stock_threshold>
<low_stock_alert>0</low_stock_alert>
<price>27.900000</price>
<wholesale_price>0.000000</wholesale_price>
<unity />
<unit_price_ratio>0.000000</unit_price_ratio>
<additional_shipping_cost>0.000000</additional_shipping_cost>
<customizable>0</customizable>
<text_fields>0</text_fields>
<uploadable_files>0</uploadable_files>
<active>1</active>
<redirect_type>301-category</redirect_type>
<id_type_redirected>0</id_type_redirected>
<available_for_order>0</available_for_order>
<available_date>0000-00-00</available_date>
<show_condition>0</show_condition>
<condition>new</condition>
<show_price>0</show_price>
<indexed>1</indexed>
<visibility>both</visibility>
<advanced_stock_management>0</advanced_stock_management>
<date_add>2021-04-23 19:04:53</date_add>
<date_upd>2021-04-26 08:58:22</date_upd>
<pack_stock_type>0</pack_stock_type>
<meta_description>
<language id="2" xlink:href="https://mywebsiteurl/api/languages/2">TEST</language>
</meta_description>
<meta_keywords>
<language id="2" xlink:href="https://mywebsiteurl/api/languages/2">TEST</language>
</meta_keywords>
<meta_title>
<language id="2" xlink:href="https://mywebsiteurl/api/languages/2">TEST</language>
</meta_title>
<link_rewrite>
<language id="2" xlink:href="https://mywebsiteurl/api/languages/2">testttt</language>
</link_rewrite>
<name>
<language id="2" xlink:href="https://mywebsiteurl/api/languages/2">My test product</language>
</name>
<description>
<language id="2" xlink:href="https://mywebsiteurl/api/languages/2">
<![CDATA[test test]]>
</language>
</description>
<description_short>
<language id="2" xlink:href="https://mywebsiteurl/api/languages/2">TEST</language>
</description_short>
<available_now>
<language id="2" xlink:href="https://mywebsiteurl/api/languages/2">TEST</language>
</available_now>
<available_later>
<language id="2" xlink:href="https://mywebsiteurl/api/languages/2">TEST</language>
</available_later>
<associations>
<categories nodeType="category" api="categories">
<category xlink:href="https://mywebsiteurl/api/categories/19">
<id>19</id>
</category>
<category xlink:href="https://mywebsiteurl/api/categories/31">
<id>31</id>
</category>
<category xlink:href="https://mywebsiteurl/api/categories/95">
<id>95</id>
</category>
<category xlink:href="https://mywebsiteurl/api/categories/100">
<id>100</id>
</category>
</categories>
<images nodeType="image" api="images" />
<combinations nodeType="combination" api="combinations" />
<product_option_values nodeType="product_option_value" api="product_option_values" />
<product_features nodeType="product_feature" api="product_features">
<product_feature xlink:href="https://mywebsiteurl/api/product_features/6">
<id>6</id>
<id_feature_value xlink:href="https://mywebsiteurl/api/product_feature_values/12">12
</id_feature_value>
</product_feature>
</product_features>
<tags nodeType="tag" api="tags" />
<stock_availables nodeType="stock_available" api="stock_availables">
<stock_available xlink:href="https://mywebsiteurl/api/stock_availables/104">
<id>104</id>
<id_product_attribute>0</id_product_attribute>
</stock_available>
</stock_availables>
<accessories nodeType="product" api="products" />
<product_bundle nodeType="product" api="products" />
</associations>
</product>
</prestashop>
,
$webService = new PrestaShopWebservice('https://mywebsite','MYKEY',false);
只需将最后一个参数设为 true 即可启用调试模式并查看实际错误
$webService = new PrestaShopWebservice('https://mywebsite',true);
也从响应中取消设置 id 然后发布数据
应该没问题
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。