Jump to content

Webservice - Combinations Does Not Work.


peorthyr

Recommended Posts

$colore = trim(str_replace("&", "e", $row["col_nome_tabella"]))." ".trim($row["col_codice"])." ".trim($row["col_nome_IT"]);

 $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
 $opt = array('resource' => 'product_option_values');
 $opt['filter[name]'] ="[".$colore."]";  
 $xml = $webService->get($opt);
 $colori_ws = $xml->children()->children();

 if ($colori_ws->product_option_value[@id] != ""){	
  //ho il colore.
  //echo $colori_ws->product_option_value[@id]." id colore <br>";
  $id_colore = $colori_ws->product_option_value[@id];

  for ($i = 1; $i <= 7; $i++) {

   $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
   $opt = array('resource' => 'product_option_values');
   $puntatore = "taglia_".$i;
   $quantita = "quantita_".$i;


   if ($row[$puntatore] != ""){

	$opt['filter[name]'] ="[".$row[$puntatore]."]";  
	$xml = $webService->get($opt);
	$taglia = $xml->children()->children();

	if ($taglia->product_option_value[@id] != ""){
	 //ho la taglia

	 if ($row[$quantita] > 0 ){ //se ho una quantità per questo colroe - taglia.
	  //echo $taglia->product_option_value[@id]." id taglia <br>";
	  $id_taglia = $taglia->product_option_value[@id];
	  $quantita_combinazione = $row[$quantita];

	  $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
	  $opt = array('resource' => 'products');
	  $opt['filter[name]'] ="[".$row_prodotto['prod_codice']."]";  
	  $xml = $webService->get($opt);
	  $prod = $xml->children()->children();		

	  $id_prodotto = $prod->product[@id];		

	  //inserisco la combinazione.
	  $webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
	  $opt = array('resource' => 'combinations');
	  $xml_ins = $webService->get(array('url' => PS_SHOP_PATH.'/api/combinations?schema=blank'));
	  $combinations = $xml_ins->children()->children();		
	  $combinations->id_product = $id_prodotto;	  
	  $combinations->quantity = $quantita_combinazione;
	  $combinations->minimal_quantity = '1';
	  $combinations->default_on = '1';

	  unset($combinations->associations->product_option_values->product_option_value);
	  $combinations->associations->product_option_values->addChild('product_option_value')->addChild('id', $id_colore);
	  $combinations->associations->product_option_values->addChild('product_option_value')->addChild('id', $id_taglia);	  

	  try
	  {
	   $opt = array('resource' => 'combinations');
	   $opt['postXml'] = $xml_ins->asXML();
	   $xml_ins = $webService->add($opt);		
	   echo "Combination Successfully added.";		



	  }
	  catch (PrestaShopWebserviceException $e)
	  {
	   echo '<b>Error : '.$e->getMessage().'</b>';

	  }
	 }
	}	  
   }
  }

 

xml sent:

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

<product_option_value><id>29</id></product_option_value><product_option_value><id>38</id></product_option_value></product_option_values>
<images>
<image>
<id/>
</image>
</images>
</associations>
</combination>
</prestashop>

 

 

return:

 

<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<code><![CDATA[46]]></code>
<message><![CDATA[unable to save resource]]></message>
</error>
</errors>
</prestashop>

 

any advice???

Edited by peorthyr (see edit history)
Link to comment
Share on other sites

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...