【问题标题】:How to import products with multiple descriptions into magento如何将具有多个描述的产品导入magento
【发布时间】:2011-12-05 01:19:55
【问题描述】:

我正在将产品从 3rd 方数据库导入我的 magento 网站。我在网上找到了一个很棒的 PHP 教程。

但是,本教程没有描述如何根据商店为单个产品分配多个描述。

在我的示例中,我有一个同时具有英语和法语描述的产品。一个用于我的法国商店,一个用于英文商店,我如何将两者都导入 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
}
?>

【问题讨论】:

    标签: magento import


    【解决方案1】:

    Magmi 这样做

    【讨论】:

      【解决方案2】:

      您使用的是网站、商店还是商店视图?这很重要,因为如果您使用的是商店视图而不是网站,则不一定要将税/增值税和定价设置为“价格点”。

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

      您始终可以为此使用数据流配置文件,只需导出您的产品,输入要更新的字段并包含一个“商店”列。重新加载它,工作就很好了。

      【讨论】:

      • 谢谢,在考虑之后,我决定使用 CSV 加载产品。麻烦在于 magento 1.6 中的类别是由名称而不是 id 指定的。我有同名的类别,所以 magento 不知道将我的产品放在哪个类别下。这真的让我很沮丧。我尝试通过创建 category_ids 列来指定类别 ID,但 magento 忽略了它。
      【解决方案3】:

      我最终选择了 magmi 来做这项工作。

      所有内容都输入 CSV,如果您要从另一个系统导入旧数据,则需要以编程方式创建此 CSV。

      这个 CSV 应该是什么样子的一个例子是 here

      要为一个产品做多个描述,只需复制产品的行并在下面复制,将商店代码字段/网站字段更改为您需要不同描述的网站代码,然后在描述字段。

      现在,当您使用 Magmi 上传 CSV 文件时,您将获得一款产品,其中包含与相关商店/网站相关的 2 个或更多描述。

      请随时发表评论并提出更多问题,这让我很头疼,我很乐意为您解除类似的挫败感。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-09-01
        • 1970-01-01
        • 2016-04-13
        • 1970-01-01
        • 1970-01-01
        • 2013-04-23
        • 1970-01-01
        相关资源
        最近更新 更多