【问题标题】:Magento - Get product name for all languagesMagento - 获取所有语言的产品名称
【发布时间】:2012-06-19 03:19:16
【问题描述】:

在为导出扩展阅读所有 magento 产品时,我遇到了一个问题: 当尝试在加载的模型上使用 getName() 获取产品名称时,您只会获得活动语言名称,或者如果未设置产品的默认名称。但我需要获取默认、英语、德语、法语等的所有产品名称。 有没有人有这个问题的解决方案或想法如何解决它?

$model      = Mage::getModel('catalog/product');
$collection = $model->getCollection();
foreach ($collection as $product) {
   $id   = $product->getId();
   $model->load($id);
   $name = $model->getName(); // gives you only the active language name / default name
}

【问题讨论】:

    标签: magento export product


    【解决方案1】:

    由于您还想要 default 商店,我只知道一种工作方式:

    $aStoreHash = Mage::getModel('core/store')
        ->getCollection()
        ->setLoadDefault(true)
        ->toOptionHash();
    
    $aName = array();
    
    foreach ($aStoreHash as $iStoreId => $sStoreName) {
        Mage::app()->setCurrentStore($iStoreId);
        $oCollection = Mage::getModel('catalog/product')
            ->getCollection()
            // Uncomment next line for testing if you have thousands of products
            // ->addFieldToFilter('entity_id', array('from' => 1, 'to' => 5))
            ->addAttributeToSelect('name');
        foreach ($oCollection as $oProduct) {
            $aName[$oProduct->getId()][$iStoreId] = $oProduct->getName();
        }
    }
    var_dump($aName);
    

    如果您不需要 default 存储,则可以删除 Mage::app()->setCurrentStore($iStoreId); 并在集合上使用 ->addStoreFilter($iStoreId)

    【讨论】:

    • 谢谢,这正是我想要的。
    猜你喜欢
    • 2012-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多