【问题标题】:Prestashop Webservices API: HTML in description gives an error 404Prestashop Webservices API:描述中的 HTML 给出错误 404
【发布时间】:2021-07-18 01:07:26
【问题描述】:

我正在使用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 &amp: test'); $updateProductXML->description->language[0][0]->addCData('juste normal text but in cdata');

有什么想法吗?

谢谢:)

Prestashop 版本:1.7.7.3,全新安装

【问题讨论】:

  • 通过在 PrestaShop Webservices 库中传递调试模式 true 来检查实际错误
  • @ArunVishwakarama 它已经打开,但它不返回错误,它会产生 404 错误(正常错误不是 web 服务错误,因此它返回 404 错误页面)。问题只是在描述中添加特殊字符时,没有它的相同代码可以工作,如果我在其他字段中输入不正确的数据,webservices会返回错误400
  • 调试我试过这个:它在对描述字段进行 urlencode 时起作用,然后在 WebserviceRequest.php 的第 1594 行周围进行特定的 urldecode
  • 那么CDATA肯定有问题,请打印数据确认是文件
  • @ArunVishwakarama 我把它贴在下面

标签: xml rest web-services prestashop prestashop-1.7


【解决方案1】:

按照要求,这是发送的 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>

【讨论】:

    【解决方案2】:

    $webService = new PrestaShopWebservice('https://mywebsite', 'MYKEY', false);

    只需将最后一个参数设为 true 即可启用调试模式并查看实际错误

    $webService = new PrestaShopWebservice('https://mywebsite', 'MYKEY', true);

    也从响应中取消设置 id 然后发布数据

    应该没问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-07
      • 1970-01-01
      • 2021-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-15
      相关资源
      最近更新 更多