2011-05-14 32 views

回答

0

標籤要導入的格式應該是這樣的

TagSpreadsheet

和地點有關電子表格root/tagimport/tagsheet.csv

並粘貼到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'; 
      } 
     } 
    } 
} 

運行上面下面的代碼php文件使用

www.yourdomain.com/tagimport/importtag.php