2011-11-09 6 views
3

サードパーティのデータベースからマゼンタのサイトに商品をインポートしています。私はPHPでこれを行うための素晴らしいチュートリアルをオンラインで見つけました。複数の説明のある商品をマゼンタにインポートする方法

ただし、このチュートリアルでは、ストアに基づいて1つの製品に複数の説明を割り当てる方法については説明していません。

私の例では、私は英語とフランス語の両方の記述を持つ製品を持っています。 1つはフランスの店舗用、もう1つは英語用です。どのようにしてマゼンタにインポートできますか?

また、タイトル、urlkeyに対してこれを行い、ストアごとに異なるカテゴリを割り当てる必要があります。

ここにはチュートリアルのコードがあります。

<?php 
require_once('/path/to/magento/app/Mage.php'); 
umask(0); 

// Set an Admin Session 
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); 
Mage::getSingleton('core/session', array('name'=>'adminhtml')); 
$userModel = Mage::getModel('admin/user'); 
$userModel->setUserId(1); 
$session = Mage::getSingleton('admin/session'); 
$session->setUser($userModel); 
$session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl()); 

// Then we see if the product exists already, by SKU since that is unique to each product 
$product = Mage::getModel('catalog/product') 
->loadByAttribute('sku',$_product['sku']); 

if(!$product){ 
// product does not exist so we will be creating a new one. 

$product = new Mage_Catalog_Model_Product(); 

$product->setTypeId('simple'); 
$product->setWeight(1.0000); 
$product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH); 
$product->setStatus(1); 
$product->setSku('UNIQUESKUHERE'); 
$product->setTaxClassId(0); 
$product->setWebsiteIDs(array(0)); // your website ids 
$product->setStoreIDs(array(0)); // your store ids 
$product->setStockData(array(
    'is_in_stock' => 1, 
    'qty' => 99999, 
    'manage_stock' => 0, 
)); 
} 

// set the rest of the product information here that can be set on either new/update 
$product->setAttributeSetId(9); // the product attribute set to use 
$product->setName('Product Title'); 
$product->setCategoryIds(array(0,1,2,3)); // array of categories it will relate to 
$product->setDescription('Description'); 
$product->setShortDescription('Short Description'); 
$product->setPrice(9.99); 

// set the product images as such 
// $image is a full path to the image. I found it to only work when I put all the images I wanted to import into the {magento_path}/media/catalog/products - I just created my own folder called import and it read from those images on import. 
$image = '/path/to/magento/media/catalog/products/import/image.jpg'; 

$product->setMediaGallery (array('images'=>array(), 'values'=>array())); 
$product->addImageToMediaGallery ($image, array ('image'), false, false); 
$product->addImageToMediaGallery ($image, array ('small_image'), false, false); 
$product->addImageToMediaGallery ($image, array ('thumbnail'), false, false); 

// setting custom attributes. for example for a custom attribute called special_attribute 
// special_attribute will be used on all examples below for the various attribute types 
$product->setSpecialAttribute('value here'); 

// setting a Yes/No Attribute 
$product->setSpecialField(1); 

// setting a Selection Attribute 
$product->setSpecialAttribute($idOfAttributeOption); //specify the ID of the attribute option, eg you creteated an option called Blue in special_attribute it was assigned an ID of some number. Use that number. 

// setting a Mutli-Selection Attribute 
$data['special_attribute'] = '101 , 102 , 103'; // coma separated string of option IDs. As ID , ID (mind the spaces before and after coma, it worked for me like that) 
$product->setData($data); 

try{ 
$product->save(); 
} catch(Exception $e){ 
echo $e->getMessage(); 
//handle your error 
} 
?> 

答えて

0

私は最終的にこの仕事をするmagmiを選んだことありません。

すべてがCSVに入力されます。別のシステムから古いデータをインポートする場合は、プログラムでこのCSVを作成する必要があります。

このCSVにはどのように見えるかの例は、一つの製品に対して複数の説明を行うだけで、製品の行をコピーし、下にそれを複製し、コードに店舗コードフィールド/ウェブサイトのフィールドを変更するにはhere

です別の説明が必要なサイトの[説明]フィールドに新しい説明を入力します。

MagmiでCSVをアップロードすると、2つ以上の説明が関連するストア/ウェブサイトに関連付けられた1つの製品が表示されます。

これは私にとっては頭痛の種ですが、これ以上の質問やコメントはお気軽にお寄せください。私も同様の欲求不満を解消できてうれしいです。

1

ウェブサイト、ストア、またはストアビューを使用していますか?これは、ウェブサイトではなく店舗ビューを使用している場合、必ず税/付加価値税(VAT)と価格を「価格ポイント」に設定することができないため重要です。あなたはいつも単に「店の列を更新し、含めるフィールドに入れて、あなたの製品を輸出、このためにデータフロープロファイルを使用することができます

$product=Mage::getModel('catalog/product')->setWebsiteIds(whatever)->setStoreId(whatever)->load(whatever) 

。再びそれをロードして、仕事は良いunです。

+0

ありがとう、それについて考えた後、私はCSVを使用して製品を読み込むことにしました。問題はmagento 1.6です。カテゴリはIDではなく名前で指定されています。私は同じ名前のカテゴリを持っているので、Magentoはどの製品を私の下に置くか分からない。これは本当にイライラしています。代わりにcategory_idsカラムを作成してカテゴリIDを指定しようとしましたが、magentoはそれを無視しました。 –

関連する問題