Note that there are some explanatory texts on larger screens.

plurals
  1. POMagento API duplicate SKU's
    text
    copied!<p>Using the Magento API to import ~60.000 products I manage to import duplicate SKU's in Magento, normally this throws an 'Duplicate SKU' exception but somehow it just add's double products. </p> <p>Anyone knows what's going wrong (some index caching or something?)?</p> <p>This is the (relevant) part of the code of the import script:</p> <pre><code>&lt;?php /** * @param $data * @param bool $retry * @return bool */ public function updateProduct($data, $retry = true) { //Calculate product hash $hash = md5(serialize($data)); try { $manageStock = 0; if($data-&gt;qty &lt;= 0) { $manageStock = 1; } $result = $this-&gt;client-&gt;catalogProductUpdate($this-&gt;session, $data-&gt;prefixed_sku, array( 'categories' =&gt; $data-&gt;categories, 'status' =&gt; empty($data-&gt;status) ? '1' : (int) $data-&gt;status, 'cost' =&gt; $data-&gt;cost, 'price' =&gt; $data-&gt;price, 'tax_class_id' =&gt; '2', 'visibility' =&gt; '4', 'stock_data' =&gt; array( 'qty' =&gt; $data-&gt;qty, 'is_in_stock' =&gt; $data-&gt;is_in_stock, 'manage_stock' =&gt; $manageStock ), 'additional_attributes' =&gt; array('cost' =&gt; $data-&gt;cost) ), null, 'sku'); } catch (Exception $e) { $result = $this-&gt;exceptionLogAndRetry($e, 'updateProduct', $retry, $data); } return $result; } /** * @param $data * @param bool $retry * @return bool */ public function addProduct($data, $retry = true) { //Calculate product hash $hash = md5(serialize($data)); if(!$this-&gt;attributeSet) { $attributeSets = $this-&gt;client-&gt;catalogProductAttributeSetList($this-&gt;session); foreach($attributeSets as $attributeSet) { if(strtolower($attributeSet-&gt;name) == 'default') { $this-&gt;attributeSet = $attributeSet; } } if(!$this-&gt;attributeSet) { $this-&gt;attributeSet = current($attributeSets); } } try { $stock = array( 'qty' =&gt; $data-&gt;qty, 'is_in_stock' =&gt; $data-&gt;is_in_stock, 'use_config_manage_stock' =&gt; $data-&gt;use_config_manage_stock ); if($data-&gt;qty &lt;= 0) { $stock['manage_stock'] = 1; } $result = $this-&gt;client-&gt;catalogProductCreate($this-&gt;session, 'simple', $this-&gt;attributeSet-&gt;set_id, $data-&gt;prefixed_sku, array( 'categories' =&gt; $data-&gt;categories, 'websites' =&gt; array($data-&gt;website_id), 'name' =&gt; $data-&gt;name, 'description' =&gt; $data-&gt;description, 'short_description' =&gt; $data-&gt;short_description, 'weight' =&gt; $data-&gt;weight, 'cost' =&gt; $data-&gt;cost, 'status' =&gt; empty($data-&gt;status) ? '1' : (int) $data-&gt;status, 'url_key' =&gt; $data-&gt;url_key, 'url_path' =&gt; $data-&gt;url_path, 'visibility' =&gt; '4', 'price' =&gt; $data-&gt;price, 'tax_class_id' =&gt; '2', 'meta_title' =&gt; $data-&gt;meta_title, 'meta_keyword' =&gt; $data-&gt;meta_keyword, 'meta_description' =&gt; $data-&gt;meta_description, 'stock_data' =&gt; $stock, 'additional_attributes' =&gt; array('cost' =&gt; $data-&gt;cost) )); } catch (Exception $e) { $result = $this-&gt;exceptionLogAndRetry($e, 'addProduct', $retry, $data); } for ($i = 1; $i &lt;= 5; $i++) { $cur = $i; if ($cur == 1) { $cur = ''; } if (!empty($data-&gt;{"product_image$cur"}) &amp;&amp; file_exists($data-&gt;{"product_image$cur"}) &amp;&amp; is_numeric($result)) { $file = array( 'content' =&gt; base64_encode(@file_get_contents($data-&gt;{"product_image$cur"})), 'mime' =&gt; $data-&gt;{'product_mime'.$cur} ); try { $imgRes = $this-&gt;client-&gt;catalogProductAttributeMediaCreate( $this-&gt;session, $result, array('file' =&gt; $file, 'label' =&gt; '', 'position' =&gt; '100', 'types' =&gt; array('thumbnail', 'small_image', 'image'), 'exclude' =&gt; 0) ); } catch (Exception $e) { //Do nothing } } } $return = $result; return $return; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload