2016-12-02 10 views
1

私は、製品をPrestashopストアに追加するための小さなスクリプトを作成しました。 今、製品にコンビネーションを追加しようとする問題に直面しています。 ここに私のコードがどのようになっているかを示します。私はここに製品を追加した後 は.. $のPRODUCT_IDが私の新しく作成された製品Prestashop製品の組み合わせを追加

$xml = $webService->get(array('url' => SITE_URL.'/api/combinations?schema=blank')); 
$combinations = $xml->children()->children(); 
$combinations->id_product = $product_id; 

$combinations->minimal_quantity = 1; 
$combinations->reference = 'dada'; 
$combinations->price = 99; 
$combinations->default_on = 1; 
$combinations->associations->product_option_values->product_option_value->id = 1; 
$opt = array('resource' => 'products'); 
$opt['postXml'] = $xml->asXML(); 

であり、これはサーバからの応答で、I`mがやって何

<?xml version="1.0" encoding="UTF-8"?> 
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink"> 
<combination> 
<id></id> 
<id_product></id_product> 
<location></location> 
<ean13></ean13> 
<upc></upc> 
<quantity></quantity> 
<reference></reference> 
<supplier_reference></supplier_reference> 
<wholesale_price></wholesale_price> 
<price></price> 
<ecotax></ecotax> 
<weight></weight> 
<unit_price_impact></unit_price_impact> 
<minimal_quantity></minimal_quantity> 
<default_on></default_on> 
<available_date></available_date> 
<associations> 
<product_option_values> 
<product_option_value> 
<id></id> 
</product_option_value> 
</product_option_values> 
<images> 
<image> 
<id></id> 
</image> 
</images> 
</associations> 
</combination> 
</prestashop> 
+0

問題を説明できますか?エラーメッセージを送信できますか? –

+0

エラーメッセージはありません。 – nikksan

答えて

0

作業コードが見つかりました。ウェブサービスを使用していません。

$product = new Product($product_id); 
$combinationAttributes = array(); 
$combinationAttributes[] = $combination_id; 
$idProductAttribute = $product->addProductAttribute(
       (float)1, //price 
       (float)1, //weight 
       1,  //unit_impact 
       null , //ecotax 
       (int)1, //quantity 
       "",  //id_images 
       "" , //reference 
       strval(""), //suppliers 
       strval(""), //ean13 
       NULL, //default 
       NULL, //location 
       NULL //upc 
       ); 
       $product->addAttributeCombinaison($idProductAttribute,      $combinationAttributes); 
+0

'addAttributeCombinaison()'は1.5.0.7から廃止されました。私は今正しいメソッドが 'addCombinationEntity()'だと思います。 – LostMyGlasses

0

次のコードを使用してみてください製品の組み合わせを追加する:詳細については

$product = new Product($id_product); 

$id_product_attribute = $product->addCombinationEntity(
           Tools::getValue('attribute_wholesale_price'), 
           Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), 
           Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), 
           Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'), 
           Tools::getValue('attribute_ecotax'), 
           0, 
           Tools::getValue('id_image_attr'), 
           Tools::getValue('attribute_reference'), 
           null, 
           Tools::getValue('attribute_ean13'), 
           Tools::getValue('attribute_default'), 
           Tools::getValue('attribute_location'), 
           Tools::getValue('attribute_upc'), 
           Tools::getValue('attribute_minimal_quantity'), 
           array(), 
           Tools::getValue('available_date_attribute') 
          ); 

をあなたはProduct.phpクラスファイル内addCombinationEntity()関数の定義を確認することができます。

上記の関数は、生成されたcombination_idを返します。

関連する問題