magento导入csv文件到数据库脚本,magento中的一些手

2019-10-02 02:55 来源:未知

这是magento本子的别的一种写法。

1.加载某部attribute:

个体以为写的可以接受,高手莫见笑。

    $attributeCode=Mage::getModel('catalog/resource_eav_attribute')
                        ->load($attrbuteId)
                        ->getData("attribute_code");

用SplFileObject来拍卖大数量的csv文件作用高

2.获取有些attribute的具有option:

 

$attributeObject=Mage::getModel('eav/config')->getAttribute('catalog_product')->load($attributeId);
        $options = $attributeObject->setStoreId(Mage::app()->getStore()->getId())->getSource()->getAllOptions(false);
$table       = $attributeObject->getBackend()->getTable();

 代码如下

    public function getAttributeOptionsByAttributeCode($entityType, $attributeCode){
   
    $entityType = Mage::getSingleton('eav/config')->getEntityType($entityType);
         $attributeObject = Mage::getModel('customer/attribute')->loadByCode($entityType, $attributeCode);
         return $attributeObject->setStoreId(Mage::app()->getStore()->getId())->getSource()->getAllOptions(false);
   
    }

<?php
require_once 'shell/abstract.php';
class Faarao_Import_Customer extends Mage_Shell_Abstract
{
protected $_files = array();
protected $_datas = array();
public function __construct() {
parent::__construct();
set_time_limit(0);
if($this->getArg('file')) {
$this->_files = array_merge(
$this->_files,
array_map(
'trim',
explode(',', $this->getArg('file'))
)
);
foreach ($this->_files as $key=>$file) {
$extension = self::get_extension($file);
if($extension != 'csv'){
unset($this->_files[$key]);
}
}
}
if(empty($this->_files)){
die(self::usageHelp());
}
}
// Shell script point of entry
public function run() {
self::getDataFromCsv();
if(empty($this->_datas)){
die("not found data in csv ! \r\n");
}
$emailBooks = array();
foreach ($this->_datas as $name => $datas) {
echo "filename: {$name} =======================\r\n";
$importNum = 0;
foreach ($datas as $key => $data) {
if(empty(trim($data[4]))){
continue;
}
$customerData['firstname'] = trim($data[0]);
$customerData['lastname'] = trim($data[1]);
$customerData['phone'] = trim($data[2]);
$customerData['mobile'] = trim($data[3]);
$customerData['email'] = trim($data[4]);
$customerData['company'] = trim($data[5]);
$customerData['billing_address'] = $data[6] . $data[7] . $data[8];
$customerData['billing_postcode'] = sprintf("%05d",trim($data[9]));
$customerData['billing_city'] = trim($data[10]);
$customerData['billing_country'] = trim($data[11]);
$customerData['shipping_address'] = $data[12] . $data[13] .$data[14];
if(empty($data[15]) && is_numeric($data[16])){
$customerData['shipping_postcode'] = sprintf("%05d",trim($data[16]));
$customerData['shipping_city'] = trim($data[17]);
$customerData['shipping_country'] = trim($data[18]);
}else{
$customerData['shipping_postcode'] = sprintf("%05d", trim($data[15]));;
$customerData['shipping_city'] = trim($data[16]);
$customerData['shipping_country'] = trim($data[17]);
}
// $customerData['email'] = 'zouhongzhao@126.com';
$customerData['country'] = 'Finland';
$customerData['password'] = self::randomkeys(10);
 
 
 
echo "customer email {$customerData['email']} ...\r\n";
print_r($customerData);
$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($customerData['email']);
if(!$customer->getId()) {
echo "insert ... \r\n";
$customer->setEmail($customerData['email']);
$customer->setFirstname($customerData['firstname']);
$customer->setLastname($customerData['lastname']);
$customer->setPassword($customerData['password']);
}else{
echo "update ... \r\n";
}
try {
$customer->save();
$customer->setConfirmation(null);
$customer->save();
//Make a "login" of new customer
Mage::getSingleton('customer/session')->loginById($customer->getId());
$importNum ++;
$emailBooks[$customerData['email']] = array(
'firstname'=>$customerData['firstname'],
'lastname'=>$customerData['lastname'],
'customer_mage_id'=>$customer->getId(),
'passwd'=>$customerData['password']
);
 
echo "customer save ok !\r\n";
}
catch (Exception $ex) {
echo "customer save fail !\r\n";
continue;
}
 
if(trim($customerData['billing_address']) == trim($customerData['shipping_address'])
&& $customerData['billing_postcode'] == $customerData['shipping_postcode']
&& $customerData['billing_city'] == $customerData['shipping_city']){
$same_address = array (
'firstname' => $customerData['firstname'],
'lastname' => $customerData['lastname'],
'street' => $customerData['billing_address'],
'company' => $customerData['company'],
'city' => $customerData['billing_city'],
'region_id' => '',
'region' => '',
'postcode' => $customerData['billing_postcode'],
'country_id' => 'FI',
'telephone' => $customerData['phone'],
);
 
$customAddress = Mage::getModel('customer/address');
//$customAddress = new Mage_Customer_Model_Address();
$customAddress->setData($same_address)
->setCustomerId($customer->getId())
->setIsDefaultBilling('1')
->setIsDefaultShipping('1')
->setSaveInAddressBook('1');
try {
$customAddress->save();
echo "sameAddress save ok !\r\n";
}
catch (Exception $ex) {
echo "sameAddress save fail !\r\n";
continue;
}
}else{
$billing_address = array (
'firstname' => $customerData['firstname'],
'lastname' => $customerData['lastname'],
'street' => $customerData['billing_address'],
'company' => $customerData['company'],
'city' => $customerData['billing_city'],
'region_id' => '',
'region' => '',
'postcode' => $customerData['billing_postcode'],
'country_id' => 'FI',
'telephone' => $customerData['phone'],
 
);
self::setBillingAddress($billing_address,$customer);
$shipping_address = array (
'firstname' => $customerData['firstname'],
'lastname' => $customerData['lastname'],
'street' => $customerData['shipping_address'],
'company' => $customerData['company'],
'city' => $customerData['shipping_city'],
'region_id' => '',
'region' => '',
'postcode' => $customerData['shipping_postcode'],
'country_id' => 'FI',
'telephone' => $customerData['phone'],
);
self::setShippingAddress($shipping_address,$customer);
}
// die;
}
echo "import num: {$importNum} =======================\r\n";
}
//save passwd
$fp = fopen('customer_record.log', 'w');
fwrite($fp, json_encode($emailBooks));
fclose($fp);
 
}
 
public function setBillingAddress($data,$customer){
$customerAddress = Mage::getModel('customer/address');
 
if ($defaultShippingId = $customer->getDefaultBilling()){
$customerAddress->load($defaultShippingId);
} else {
$customerAddress
->setCustomerId($customer->getId())
->setIsDefaultBilling('1')
->setSaveInAddressBook('1')
;
 
$customer->addAddress($customerAddress);
}
 
try {
$customerAddress
->addData($data)
->save()
;
echo "BillingAddress save ok !\r\n";
} catch(Exception $e){
// Mage::log('Address Save Error::' . $e->getMessage());
echo "BillingAddress save fail !\r\n";
}
}
 
public function setShippingAddress($data,$customer){
$customerAddress = Mage::getModel('customer/address');
 
if ($defaultShippingId = $customer->getDefaultShipping()){
$customerAddress->load($defaultShippingId);
} else {
$customerAddress
->setCustomerId($customer->getId())
->setIsDefaultShipping('1')
->setSaveInAddressBook('1')
;
 
$customer->addAddress($customerAddress);
}
 
try {
$customerAddress
->addData($data)
->save()
;
echo "ShippingAddress save ok !\r\n";
} catch(Exception $e){
// Mage::log('Address Save Error::' . $e->getMessage());
echo "ShippingAddress save fail !\r\n";
}
}
 
public function randomkeys($length) {
$returnStr='';
$pattern = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ';
for($i = 0; $i < $length; $i ++) {
$returnStr .= $pattern {mt_rand ( 0, 61 )};
}
return $returnStr;
}
public function getDataFromCsv(){
$this->_files = array_unique($this->_files);
$csvCustomers = array();
foreach ($this->_files as $filename) {
echo "current file: {$filename}\r\n";
setlocale(LC_ALL, 'en_US.UTF-8');
$content = file_get_contents($filename);
$data = mb_detect_encoding()($content, 'UTF-8', true);
// $data = iconv("CP1257","UTF-8", $content);
file_put_contents($filename, $content);
 
// fclose($handle);
// print_r($content);die;
$basename = basename($filename,".csv");
$data = array();
$tmp = array();
$spl_object = new SplFileObject($filename, 'rb');
$spl_object->seek(filesize($filename));
$start = 0;
$num = $spl_object->key();
$spl_object->seek($start);
while ($num-- && !$spl_object->eof()) {
$data[] = $spl_object->fgetcsv();
$spl_object->next();
}
foreach ($data as $key => $values) {
if($key == 0){
continue;
}
$mergeValue = explode(';',implode(';', $values));
// if(count($mergeValue) != 20){
// continue;
// }
array_push($tmp,$mergeValue);
}
 
$this->_datas[$basename] = $tmp;
}
return $this;
}
 
public function get_extension($filename){
return pathinfo($filename,PATHINFO_EXTENSION);
}
// Usage instructions
public function usageHelp()
{
return <<<USAGE
Usage: php tetuan_customer_import.php --file a.csv,b.csv
\n
USAGE;
}
}
// Instantiate
$shell = new Faarao_Import_Customer();
// Initiate script
$shell->run();

或者:

补给:有一对对象使用的是excel文书档案,那样这几个顺序就不得以应用了,大家能够利用phpexcel插件来读取excel文件并写入到数据库中去哦。

$optionCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
                ->setAttributeFilter($attr_model->getId())
                ->setStoreFilter($storeId, false)
                ->load();

3.拿走有个别attribute的有所多语言label:

        $attributeLabelsArray= Mage::getResourceModel('eav/entity_attribute')
                        ->getStoreLabelsByAttributeId($attrbuteId);    

4.赢得具备的产品天性的attribute:

$attributes = Mage::getResourceModel ( 'catalog/product_attribute_collection' )
             ->addFieldToFilter ( "frontend_input", "select" )
             ->load ();

5.获得有个别product的富有attribute:

注:假诺是在collection中拿走自定义的attribute,必得加addAttributeToSelect(), 如下:

product=Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect("dropdownlistone");

6.使用静态block
<?php echo $this->getLayout()->createBlock('clientnumber/widget_name')
                    ->setObject($this->getAddress())
                    ->toHtml() ?>

7.到手某些项目标具备attribute:
$entityTypeId = Mage::getSingleton('eav/config')
                ->getEntityType('catalog_product')
                ->getEntityTypeId();
            $items = Mage::getResourceSingleton('catalog/product_attribute_collection')
                ->setEntityTypeFilter($entityTypeId)
                ->getItems();

8.获得有个别attribute_set的所有attribute:

$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
   ->setAttributeSetFilter($attribute_set_id)
   ->load();

 $attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_set_collection')
            ->load();

9.获取attribute 对象 by attribute code

$muarqspFrom = Mage::getSingleton('eav/config')->getAttribute('catalog_product', '
muarqsp_from');

$attrCollection = Mage::getResourceModel('eav/entity_attribute_collection')
               ->setCodeFilter($attributeCode)
               ->load();
  
10。get store id

$store_id=Mage::getModel('core/store')
    ->getCollection()
    ->addFieldToFilter ( "code", "france_fr" )
    ->getFirstItem()->getData('store_id');
 
or
Mage::getModel('core/store')->load('france_fr')->getId();  

11.product collection

        $collection = Mage::getResourceModel('catalog/product_collection')
            ->addStoreFilter()
            ->addAttributeToSelect("*")
            ->addAttributeToFilter('entity_id', array('in' => $products))
            ->setPageSize(10)
            ->setCurPage(1);

12.数据库操作

    $dbr = Mage::getSingleton ( 'core/resource' )->getConnection ( 'core_read' );
$sql = "select instructor_id,position from product_instructor_link where product_id = $productId";
$result = $dbr->fetchAll($sql);
//$result = $dbr->fetchOne($sql);
$instructors = array();
foreach($result as $item){
$instructors[$item['instructor_id']] = array('position' => $item['position']);
}

            $dbw = Mage::getSingleton('core/resource')->getConnection('core_write');

                  $sql="update catalog_product_entity_datetime set value=NULL where attribute_id=$special_from_date_attribute_id and store_id=$storeId and entity_id=$productId";
                  $dbw->query( $sql );

  1. 赢得quote中的全体的item

$quote=Mage::getSingleton('checkout/session')->getQuote();
        foreach ($quote->getAllItems() as $item) {
            $proId[]=$item->getProduct()->getId();
        }

  1. 拿到那些网址所表示的国家的代号(如:F翼虎)

Mage::getModel('directory/country')
              ->load(Mage::getStoreConfig('general/country/default'))->getIso2Code(),

  1. 获得后台的布局

Mage::getStoreConfig("clientnumber/total_config/service_ip",0); //get admin config

  1. 获取当前的时刻

$date = Mage::app()->getLocale()->date(Mage::getSingleton('core/date')->gmtTimestamp(), null, null);
$date = $date->toString('yyyy-MM-dd hh:m:s');

  1. generate skin url

Mage::getDesign()->getSkinUrl('images/our_shops/shop_logo_default.jpg');

  1. generate select html

$html = $this->getLayout()->createBlock('core/html_select')
            ->setName($name)
            ->setId($id)
            ->setTitle(Mage::helper('directory')->__($title))
            ->setClass('validate-select')
            ->setValue($defValue)
            ->setOptions($options)
            ->getHtml();

  1. 除去八个product的有所的images

//Get products gallery attribute
        $attributes = $product->getTypeInstance()->getSetAttributes();

        if (isset($attributes['media_gallery'])) {
            $gallery = $attributes['media_gallery'];
            //Get the images
            $galleryData = $product->getMediaGallery();

            foreach($galleryData['images'] as $image){
                //If image exists
                if ($gallery->getBackend()->getImage($product, $image['file'])) {
                    $gallery->getBackend()->removeImage($product, $image['file']);
                    $filename = Mage::getBaseDir('media') . DS . 'catalog'. DS .'product' . $image['file'];
                    debug('<span style="color: green;"><< unlinked previous image '.$image['file'].' from product '.$product->getSku().'</span>');
                    if (file_exists($filename) && is_file($filename) && is_writeable($filename)){
                        @unlink($filename);
                        debug('<span style="color: green;">(and deleted file '.$filename.')</span>');
                    }else
                        debug('<span style="color: red;">(but couldn't delete file '.$filename.')</span>');
                }
            }

        }

  1. 收获钦命level目录

$parent = Mage::app()->getStore()->getRootCategoryId();
        $categoryModel = Mage::getModel('catalog/category');
        $storeCategories = $categoryModel->getCategories($parent, 2); //获取level 2

  1. 出殡邮件

 $mailTransport = new Zend_Mail_Transport_Smtp(    '192.168.0.1'   );
 $mail = new Zend_Mail();
            $mail->setBodyText($content);
            $mail->setFrom("hello@example.com", 'Webmaster');
            $mail->addTo("bysoftgz@gmail.com", '');
            $mail->setSubject('Import attribute logs');
            $mail->send($mailTransport);

22.get website config
        
//$website can be string or id
        $import_type = Mage::getModel('core/website')->load($website)->getConfig('maps/stock_import/stock_limit');
        if( $import_type===false ){
   //get admin config
        $import_type=Mage::getStoreConfig('maps/stock_import/import_type',0);
        }

  1. 用block创造贰个template

<?php echo Mage::getBlockSingleton('inseecode/form')->getInseeFormHtml($this->getAddress(), 'customer');?>

public function getInseeFormHtml($address, $type) {
$this->setTemplate('inseecode/form.phtml');
return $this->toHtml();
}

获得对象的议程:get_class_methods($object)
回到对象的类名:get_class($object)

  1. controller 中 添加block

            $this->getLayout()
                ->createBlock('clientnumber/inputform', 'checkout.cart.inputclientnumber')
                ->setTemplate('clientnumber/input.phtml')
                ->toHtml()

  1. 在Configuation中添加validate

<validate>validate-number</validate>

  1. 获得当前的controller

$moduleName=Mage::app()->getRequest()->getModuleName();
    $controllerName=Mage::app()->getRequest()->getControllerName();
    $actionName=Mage::app()->getRequest()->getActionName();
   
        $fullActionName=$moduleName."_".$controllerName."_".$actionName;

  1. can't see load.gif in firefox6

so just remove or comment the id  "#loading-mas" about <!-- opacity: 0.8;-->,it will solve it

  1. get attributeSetId by attributeName

Mage::getResourceModel('eav/entity_attribute_set_collection')
            ->addFieldToFilter('attribute_set_name',$attributSetName)
            ->getFirstItem()->getId();

  1. get attributeSetName by attributeSetId

Mage::getModel('eav/entity_attribute_set')
            ->load($id)->getData("attribute_set_name");
           
31.修改数据库结构

$installer->getConnection()->addColumn(
    $installer->getTable('enterprise_giftcardaccount/giftcardaccount'),
    'gift_card_type',
    "VARCHAR(200) DEFAULT ''");

$installer->getConnection()->addColumn(
    $installer->getTable('enterprise_giftcardaccount/giftcardaccount'),
    'gift_card_type',
    "TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT  '0'");    

$installer->getConnection()->dropColumn($installer->getTable('eav_attribute'), 'use_in_super_product');
$installer->run("ALTER TABLE `sales_flat_order` CHANGE `is_synced` `is_synced` INT( 4 ) NOT NULL ");

  1. 赢得登陆的客商音讯

Mage::getSingleton('customer/session')->getCustomer()

  1. 格式化时间

Mage::app()->getLocale()->date($creditMemo->getCreatedAt())->toString('YYYY-MM-dd');

或:

$this->_filterDates($data, array('date_expires'));

    protected function _filterDates($array, $dateFields)
    {
        if (empty($dateFields)) {
            return $array;
        }
        $filterInput = new Zend_Filter_LocalizedToNormalized(array(
            'date_format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
        ));
        $filterInternal = new Zend_Filter_NormalizedToLocalized(array(
            'date_format' => Varien_Date::DATE_INTERNAL_FORMAT
        ));

        foreach ($dateFields as $dateField) {
            if (array_key_exists($dateField, $array) && !empty($dateField)) {
                $array[$dateField] = $filterInput->filter($array[$dateField]);
                $array[$dateField] = $filterInternal->filter($array[$dateField]);
            }
        }
        return $array;
    }

  1. 加减日期

Mage::app()->getLocale()->date()->sub("3",Zend_Date::DAY)->toString('YYYY-MM-dd HH:mm:ss');

  1. 打字与印刷php调节和测量检验信息的代码

    $array = debug_backtrace();
   //print_r($array);//音信很齐全
    unset($array[0]);
    foreach($array as $row)
    {
        $html .= $row['file'].':'.$row['line'].'行,调用方法:'.$row['function']."<p>";
    }
    echo $html;
    exit();

36.增加面包翘

在 controller中:

        $this->loadLayout();
        $breadCrumb = $this->getLayout()->getBlock('breadcrumbs'); //这是
        $breadCrumb->addCrumb('home', array(
            'label' => Mage::helper('catalog')->__('Home'),
            'title' => Mage::helper('catalog')->__('Go to Home Page'),
            'link'  => Mage::getBaseUrl(),
        ))->addCrumb('youhui', array(
            'label' => Mage::helper('catalog')->__('youhuihuodong'),
            'title' => Mage::helper('catalog')->__('youhuihuodong'),
            'link'  => $category->getId() ? Mage::getUrl('*/*') : NULL,
        ))
        ;

  1. filter in collection

$collection = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('status', array('eq'=>'pending'))
->addFieldToFilter('created_at', array('datetime' => true, 'from'=>"2011-10-10 00:00:00",'to' => Mage::app()->getLocale()->date()->sub("3",Zend_Date::DAY)->toString('YYYY-MM-dd HH:mm:ss')));

  1. 日子过滤

        $todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
        $this->_getProductCollection()
            ->addAttributeToFilter('news_from_date', array('or'=> array(
                0 => array('date' => true, 'to' => $todayDate),
                1 => array('is' => new Zend_Db_Expr('null')))
            ), 'left')
            ->addAttributeToFilter('news_to_date', array('or'=> array(
                0 => array('date' => true, 'from' => $todayDate),
                1 => array('is' => new Zend_Db_Expr('null')))
            ), 'left')
            ->addAttributeToFilter(
                array(
                    array('attribute' => 'news_from_date', 'is'=>new Zend_Db_Expr('not null')),
                    array('attribute' => 'news_to_date', 'is'=>new Zend_Db_Expr('not null'))
                )
            )
            ->addAttributeToFilter('visibility', array('in' => array(2, 4)))
            ->addAttributeToSort('news_from_date', 'desc')
            ->setPage(1, 4)
        ;

  1. 认清日期是还是不是可行

Mage::app()->getLocale()->isStoreDateInInterval(Mage::app()->getStore(), $special_from_date, $special_to_date)

40.test code for quote

$quote=Mage::getSingleton('checkout/session')->getQuote();
foreach ($quote->getAllVisibleItems() as $item) {
           echo $item->getProductId();

}

$quote->collectTotals()->save();

40.日子的相比

//get orders 15 days ago
$collection = Mage::getModel('sales/order')->getCollection()
    ->addFieldToFilter('status', array('eq' => 'pending'))
    ->addFieldToFilter('created_at', array('datetime' => true, 'from' => "2011-10-10 00:00:00", 'to' => Mage::app()->getLocale()
        ->date()
        ->sub("15", Zend_Date::DAY)
        ->toString('YYYY-MM-dd HH:mm:ss'))
    )
;

  1. delete confirm js

function confirmSetLocation(message, url){
   if( confirm(message) ) {
       setLocation(url);
   }
   return false;
}

function setLocation(url){
   window.location.href = url;
}

42.在controller中返回blocl html

$this->getResponse()->setBody($this->getLayout()->createBlock('invoicebill/account_content')
            ->setTemplate("bysoft/invoicebill/account/content.phtml")
            ->toHtml());  

  1. 收获有些action的url

Mage::getUrl('checkout/process/directOver', array('_secure'=>true));

  1. 添加customer attribute

$installer = $this;
$installer->startSetup();

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$entityTypeId     = $setup->getEntityTypeId('customer_address');
$attributeSetId   = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

/*
  add customer address attribute "mobile"
 */
$installer->addAttribute('customer_address', 'mobile1',array(
'label'             => 'Mobile',
'type' => 'varchar',
'input'             => 'text',
'used_in_forms'=> array('customer_register_address','customer_address_edit'),
'source'            => '',
'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible'           => true,
'required'          => true,
'user_defined'      => true,
'searchable'        => false,
'filterable'        => false,
'comparable'        => false,
'visible_on_front'  => true,
'visible_in_advanced_search' => false,
'unique'            => false
));
$setup->addAttributeToGroup(
 $entityTypeId,
 $attributeSetId,
 $attributeGroupId,
 'mobile1',
 '200'  //sort_order
);

$installer->endSetup();

  1. 获取product某个 option的label

    public function getProductOptionLable( $optionid=0 )
    {
        $tableName  = Mage::getSingleton('core/resource')->getTableName('eav_attribute_option_value');
$read =Mage::getSingleton('core/resource')->getConnection('core_read');
$storeid=Mage::app()->getStore()->getId();
if($optionid)
{
$sql=" select value from $tableName where option_id=$optionid and store_id=$storeid ";
$query=$read->query($sql);
$row = $query->fetch();

//if can't get value from default store view, then get data from admin store view
if( trim($row['value'])=="" ){
$sql=" select value from $tableName where option_id=$optionid and store_id=0 ";
$query=$read->query($sql);
$row = $query->fetch();
}
}
else
{
$row=array('value'=>'');
}

    return  $row['value'];  
    }

  1. 格式化某些日期

Mage::app()->getLocale()->date($_obj->getCreatedAt(), null, null)->toString('yyyy.MM.dd');

47.magento中只单独保存有个别attribute的点子

        $order->setData('customer_email',$address->getData("email"));
        $order->getResource()->saveAttribute($order, 'customer_email');

48.  常用的load

Mage::getModel('sales/order')->load();
Mage::getModel('customer/customer')->load();
Mage::getModel('catalog/product')->load();

TAG标签:
版权声明:本文由990888藏宝阁发布于计算机网络,转载请注明出处:magento导入csv文件到数据库脚本,magento中的一些手