2011-11-09 2 views
3

제 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 
} 
?> 

답변

0

나는 결국이 일을 할 magmi을 선택했다고한다.

모든 것이 CSV에 입력되므로 다른 시스템에서 이전 데이터를 가져 오는 경우 프로그래밍 방식으로이 CSV를 만들어야합니다.

이 CSV가 어떻게 보일지의 예는 here

는, 단순히 제품의 행을 복사하고 아래를 복제, 하나 개의 제품에 대해 여러 설명을 코드로 저장 코드 필드/웹 사이트 필드를 변경하는 것입니다 사이트에 대한 설명이 필요하고 설명 입력란에 새 설명을 입력하십시오.

이제 Magmi와 함께 CSV를 업로드하면 관련 상점/웹 사이트와 관련된 2 가지 이상의 설명이 포함 된 제품 하나가 제공됩니다.

자유롭게 의견을 말하고 질문 해보십시오. 이것은 나에게 두통이었고 비슷한 좌절감을 덜어 주어 기뻤습니다.

1

웹 사이트, 상점 또는 상점보기를 사용하고 있습니까? 웹 사이트가 아닌 상점보기를 사용하는 경우 반드시 세금/VAT 및 가격을 '가격 포인트'로 설정할 필요가 없기 때문에 이는 중요합니다.

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

당신은 항상 '저장'열을 포함 간단하게 업데이트 할 필드에 넣어 제품을 수출, 이것에 대한 흐름 프로파일을 사용할 수 있습니다. 그것을 다시 올려 놓으십시오. 직업은 좋은 유엔입니다.

+0

감사합니다. 생각해 본 결과, CSV를 사용하여 제품을로드하기로 결정했습니다. 문제는 magento 1.6입니다. 카테고리는 ID가 아닌 이름으로 지정됩니다. Magento는 어느 제품을 내 제품에 넣을지 모르기 때문에 같은 이름의 카테고리가 있습니다. 이것은 정말로 나를 초조하게 만든다. category_ids 열을 대신 작성하여 카테고리 ID를 지정해 보았지만 magento는이를 무시했습니다. –

관련 문제