2015-10-20 113 views
0

我試圖將產品添加到由PS 1.6.1.1提供支持的我的商店。我的代碼:使用WebService將產品添加到PrestaShop 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狀態:錯誤的請求。」

請問有人可以幫我嗎?我怎麼修復它?

非常感謝您 切赫

回答

0

有2個變化需做你的腳本,請你的建議如下

  1. 您要添加的產品,但你必須使用車資源,請更改代碼

    $ opt = array('resource'=>'carts');

$opt = array('resource' => 'products'); 
  • 移除量,因爲這不能被設置,同時添加的產品(未寫)