제 3 자 데이터베이스에서 my magento 사이트로 제품을 가져옵니다. 나는 PHP에서 이것을하기위한 훌륭한 튜토리얼을 온라인에서 발견했다.여러 설명이있는 제품을 magento로 가져 오는 방법
그러나이 자습서에서는 상점을 기반으로 한 단일 제품에 여러 설명을 지정하는 f}을 설명하지 않습니다.
필자의 예에서는 영어와 프랑스어로 된 설명이 있습니다. 프랑스 매장과 영어 용으로 각각 어떻게 Magento로 가져올 수 있습니까?
또한이 작업은 제목 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
}
?>
감사합니다. 생각해 본 결과, CSV를 사용하여 제품을로드하기로 결정했습니다. 문제는 magento 1.6입니다. 카테고리는 ID가 아닌 이름으로 지정됩니다. Magento는 어느 제품을 내 제품에 넣을지 모르기 때문에 같은 이름의 카테고리가 있습니다. 이것은 정말로 나를 초조하게 만든다. category_ids 열을 대신 작성하여 카테고리 ID를 지정해 보았지만 magento는이를 무시했습니다. –