Jump to content
  • 0

PSWebServiceLibrary dodawanie produktu blad @ PrestaShop 1.6.1.17


Kamad

Question

Hey,
Mam problem z dodaniem produktu przez webservice
 

Kawalek mojego przykladowego kodu php do testu dodania produktu:

 

{...}

 

    $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
    
    $xml = $webService->get(array('url' => PS_SHOP_PATH.'/api/products?schema=blank'));
    $product = $xml->children()->children();
    
    

    $product->id_manufacturer ='1';
    $product->id_supplier ='1';
    $product->id_category_default ='1';
    $product->reference = 'test_abc';
    $product->name = 'test_abc_name';    
    $product->link_rewrite->language[0] = 'test_abc_name2';
    $product->link_rewrite->language[1] = 'test_abc_name2';

 

    $xml = $webService->add(array('resource' => 'products', 'postXml' => $xml->asXML()));
    echo "Successfully added.";

 

{...}

 

 

XML SENT
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<product>
<id/>
<id_manufacturer>1</id_manufacturer>
<id_supplier>1</id_supplier>
<id_category_default>1</id_category_default>
<new/>
<cache_default_attribute/>
<id_default_image/>
<id_default_combination/>
<id_tax_rules_group/>
<position_in_category/>
<type/>
<id_shop_default/>
<reference>test_abc</reference>
<supplier_reference/>
<location/>
<width/>
<height/>
<depth/>
<weight/>
<quantity_discount/>
<ean13/>
<upc/>
<cache_is_pack/>
<cache_has_attachments/>
<is_virtual/>
<on_sale/>
<online_only/>
<ecotax/>
<minimal_quantity/>
<price/>
<wholesale_price/>
<unity/>
<unit_price_ratio/>
<additional_shipping_cost/>
<customizable/>
<text_fields/>
<uploadable_files/>
<active/>
<redirect_type/>
<id_product_redirected/>
<available_for_order/>
<available_date/>
<condition/>
<show_price/>
<indexed/>
<visibility/>
<advanced_stock_management/>
<date_add/>
<date_upd/>
<pack_stock_type/>
<meta_description><language id="1"/><language id="2"/></meta_description>
<meta_keywords><language id="1"/><language id="2"/></meta_keywords>
<meta_title><language id="1"/><language id="2"/></meta_title>
<link_rewrite><language id="1">test_abc_name2</language><language id="2">test_abc_name2</language></link_rewrite>
<name>test_abc_name</name>
<description><language id="1"/><language id="2"/></description>
<description_short><language id="1"/><language id="2"/></description_short>
<available_now><language id="1"/><language id="2"/></available_now>
<available_later><language id="1"/><language id="2"/></available_later>
<associations>
<categories>
<category>
<id/>
</category>
</categories>
<images>
<image>
<id/>
</image>
</images>
<combinations>
<combination>
<id/>
</combination>
</combinations>
<product_option_values>
<product_option_value>
<id/>
</product_option_value>
</product_option_values>
<product_features>
<product_feature>
<id/>
<id_feature_value/>
</product_feature>
</product_features>
<tags>
<tag>
<id/>
</tag>
</tags>
<stock_availables>
<stock_available>
<id/>
<id_product_attribute/>
</stock_available>
</stock_availables>
<accessories>
<product>
<id/>
</product>
</accessories>
<product_bundle>
<product>
<id/>
<quantity/>
</product>
</product_bundle>
</associations>
</product>
</prestashop>


 

BŁĄD:

 

RETURN HTTP BODY
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<code><![CDATA[3]]></code>
<message><![CDATA[

 Invalid argument supplied for foreach() (/home/shop/classes/Product.php, line 6054)]]></message>
</error>
</errors>
</prestashop>

 

i zawartosc pliku, gdzie wystapil blad Product.php:

 

    /*
        Create the link rewrite if not exists or invalid on product creation
    */
    public function modifierWsLinkRewrite()
    {
LINE 6054->        foreach ($this->name as $id_lang => $name) {
            if (empty($this->link_rewrite[$id_lang])) {
                $this->link_rewrite[$id_lang] = Tools::link_rewrite($name);
            } elseif (!Validate::isLinkRewrite($this->link_rewrite[$id_lang])) {
                $this->link_rewrite[$id_lang] = Tools::link_rewrite($this->link_rewrite[$id_lang]);
            }
        }

        return true;
    }

 

Dzieki za pomoc

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...