Magento API を使用して ~60.000 製品をインポートすると、Magento で重複した SKU をインポートできます。通常、これは「重複した SKU」例外をスローしますが、どういうわけか二重の製品を追加するだけです。
誰が何がうまくいかないのか知っていますか (インデックスのキャッシュか何か?)?
これは、インポート スクリプトのコードの (関連する) 部分です。
<?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->qty <= 0) {
$manageStock = 1;
}
$result = $this->client->catalogProductUpdate($this->session, $data->prefixed_sku, array(
'categories' => $data->categories,
'status' => empty($data->status) ? '1' : (int) $data->status,
'cost' => $data->cost,
'price' => $data->price,
'tax_class_id' => '2',
'visibility' => '4',
'stock_data' => array(
'qty' => $data->qty,
'is_in_stock' => $data->is_in_stock,
'manage_stock' => $manageStock
),
'additional_attributes' => array('cost' => $data->cost)
), null, 'sku');
}
catch (Exception $e) {
$result = $this->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->attributeSet) {
$attributeSets = $this->client->catalogProductAttributeSetList($this->session);
foreach($attributeSets as $attributeSet) {
if(strtolower($attributeSet->name) == 'default') {
$this->attributeSet = $attributeSet;
}
}
if(!$this->attributeSet) {
$this->attributeSet = current($attributeSets);
}
}
try {
$stock = array(
'qty' => $data->qty,
'is_in_stock' => $data->is_in_stock,
'use_config_manage_stock' => $data->use_config_manage_stock
);
if($data->qty <= 0) {
$stock['manage_stock'] = 1;
}
$result = $this->client->catalogProductCreate($this->session, 'simple', $this->attributeSet->set_id, $data->prefixed_sku, array(
'categories' => $data->categories,
'websites' => array($data->website_id),
'name' => $data->name,
'description' => $data->description,
'short_description' => $data->short_description,
'weight' => $data->weight,
'cost' => $data->cost,
'status' => empty($data->status) ? '1' : (int) $data->status,
'url_key' => $data->url_key,
'url_path' => $data->url_path,
'visibility' => '4',
'price' => $data->price,
'tax_class_id' => '2',
'meta_title' => $data->meta_title,
'meta_keyword' => $data->meta_keyword,
'meta_description' => $data->meta_description,
'stock_data' => $stock,
'additional_attributes' => array('cost' => $data->cost)
));
}
catch (Exception $e) {
$result = $this->exceptionLogAndRetry($e, 'addProduct', $retry, $data);
}
for ($i = 1; $i <= 5; $i++)
{
$cur = $i;
if ($cur == 1)
{
$cur = '';
}
if (!empty($data->{"product_image$cur"}) && file_exists($data->{"product_image$cur"}) && is_numeric($result))
{
$file = array(
'content' => base64_encode(@file_get_contents($data->{"product_image$cur"})),
'mime' => $data->{'product_mime'.$cur}
);
try {
$imgRes = $this->client->catalogProductAttributeMediaCreate(
$this->session,
$result,
array('file' => $file, 'label' => '', 'position' => '100', 'types' => array('thumbnail', 'small_image', 'image'), 'exclude' => 0)
);
}
catch (Exception $e) {
//Do nothing
}
}
}
$return = $result;
return $return;
}