使用WebService将产品添加到PrestaShop 1.6.1.1

时间:2015-10-20 19:03:38

标签: xml prestashop cdata prestashop-1.6 prestashop-1.5

我正在尝试将产品添加到我的PS 1.6.1.1支持的商店。我的代码:

   <?php
    ini_set('display_errors',1);
        ini_set('display_startup_errors',1);
        error_reporting(-1);
        define('_PS_DEBUG_SQL', true);  
    define('DEBUG', true);
    define('PS_SHOP_PATH', 'http://www.alandro.cz');
    define('PS_WS_AUTH_KEY', 'VU4K4BY9N8DR7XYIIGAAUCKX62D119CL');
    require_once('./PSWebServiceLibrary.php');
    $psXML = <<<XML
    <prestashop>
    <product>
        <id/>
        <id_manufacturer>0</id_manufacturer>
        <id_supplier>24</id_supplier>
        <id_category_default>2</id_category_default>
        <new/>
        <cache_default_attribute>0</cache_default_attribute>
        <id_default_image/>
        <id_default_combination notFilterable="true"/>
        <id_tax_rules_group>1</id_tax_rules_group>
        <position_in_category/>
        <type>simple</type>
        <id_shop_default>1</id_shop_default>
        <reference/>
        <supplier_reference>reference</supplier_reference>
        <location/>
        <width/>
        <height/>
        <depth/>
        <weight>0.1</weight>
        <quantity notFilterable="true">0</quantity>
        <quantity_discount>0</quantity_discount>
        <ean13/>
        <upc/>
        <cache_is_pack>0</cache_is_pack>
        <cache_has_attachments>0</cache_has_attachments>
        <is_virtual>0</is_virtual>
        <on_sale>0</on_sale>
        <online_only>0</online_only>
        <ecotax>0.000000</ecotax>
        <minimal_quantity>1</minimal_quantity>
        <price>0.000000</price>
        <wholesale_price>0.000000</wholesale_price>
        <unity/>
        <unit_price_ratio>0.000000</unit_price_ratio>
        <additional_shipping_cost>0.00</additional_shipping_cost>
        <customizable>0</customizable>
        <text_fields>0</text_fields>
        <uploadable_files>0</uploadable_files>
        <active>1</active>
        <redirect_type>404</redirect_type>
        <id_product_redirected>0</id_product_redirected>
        <available_for_order>1</available_for_order>
        <available_date>0000-00-00</available_date>
        <condition>new</condition>
        <show_price>1</show_price>
        <indexed>1</indexed>
        <visibility>both</visibility>
        <advanced_stock_management>0</advanced_stock_management>
        <date_add/>
        <date_upd/>
        <meta_description/>
        <meta_keywords/>
        <meta_title/>
        <link_rewrite/>
        <name><language id='1'>nazev produktu</language></name>
        <description><language id='1'>dlouhy popis</language></description>
        <description_short><language id='1'>kratky popis</language></description_short>
        <available_now><language id='1'>skladem</language></available_now>
        <available_later><language id='1'>do 9 prac. dnů</language></available_later>

    </product>
    </prestashop>
    XML;
    try
    {
        $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
        $xml = new SimpleXMLElement($psXML);
        $opt = array( 'resource' => 'carts' );
        $opt['postXml'] = $xml->asXML();
        $xml = $webService->add( $opt );
    }
    catch (PrestaShopWebserviceException $ex) {
        // Shows a message related to the error
        echo 'Other error: <br />' . $ex->getMessage();
    }

    ?>

但我只收到“这次对PrestaShop Web服务的调用失败并返回了400状态的HTTP状态。这意味着:错误的请求。”

有人可以帮我吗?我怎么能解决它?

非常感谢你 彼得

1 个答案:

答案 0 :(得分:0)

您的脚本需要进行2项更改,请按照以下建议进行操作

  1. 您正在尝试添加产品,但您已经使用过购物车资源,请更改代码

    $ opt = array('resource'=&gt;'carts');

  2. $opt = array( 'resource' => 'products' );
    
    1. 删除数量,因为在添加产品(不可写)时无法设置