有没有办法通过电子表格导入产品标签?
如果没有通过模块,可以通过脚本完成吗?
答案 0 :(得分:0)
Tags to be imported format should be like this
And place the about spreadsheet in root/tagimport/tagsheet.csv
and paste the following code in root/tagimport/importtag.php
<?php
define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/../app/Mage.php';
Mage::app();
$fileName = 'importtag.csv';
getAttributeCsv($fileName);
function getAttributeCsv($fileName){
$file = fopen($fileName,"r");
$RemoveLine = 0;
while(!feof($file)){
$data = fgetcsv($file);
if($RemoveLine != 0){
$labelText[] = $data[1];
}$RemoveLine++;
}createAttribute($labelText);
fclose($file);
}
function createAttribute($labelText)
{
foreach($labelText as $tag){
if($tag){
$quote = Mage::getModel('tag/tag');
$quote->loadByName($tag);
if(!$quote->getId()){
$quote->setName($tag);
$quote->setStatus(1);
$quote->setFirstStoreId(0);
$quote->setPopularity(0);
$quote->save();
##### Save product tags in "tag_properties"
$connectionresource = Mage::getSingleton('core/resource');
$connectionWrite = $connectionresource->getConnection('core_write');
$table = 'tag_properties';
$query = "insert into ".$table." "."(tag_id,store_id,base_popularity) values "."(:tag_id, :store_id, :base_popularity)";
$binds = array(
'tag_id' => $quote->getTagId(),
'store_id' => '1',
'base_popularity' => '0',
);
$connectionWrite->query($query, $binds);
echo 'Tags Imported Successfully';
}
}
}
}
run the above php file using
www.yourdomain.com/tagimport/importtag.php
答案 1 :(得分:0)
如果您具有如下所示的csv标签,(第一列是产品SKU,第二列是标签名称)
<v-file-input>
以下脚本将为您导入标签
8697550050245,White Egg
6291104283077,Organic Egg
6291100152520,Eco Veg Fed Egg
5701607588896,Organic Egg