0

尝试使用 CSV 导入产品时在控制台中出现以下错误我正在使用 magento 核心导入功能

    <b>Fatal error</b>:  Call to a member function getName() on a non-object in <b>/home/magentosite/public_html/store/app/code/core/Mage/ImportExport/Model/Import/Entity/Product.php</b> on line <b>377</b><br />

product.php 文件中第 377 行的函数没有更改核心文件

 /**
 * Initialize categories text-path to ID hash.
 *
 * @return Mage_ImportExport_Model_Import_Entity_Product
 */
protected function _initCategories()
{
    $collection = Mage::getResourceModel('catalog/category_collection')->addNameToResult();
    /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
    foreach ($collection as $category) {
        $structure = explode('/', $category->getPath());
        $pathSize  = count($structure);
        if ($pathSize > 2) {
            $path = array();
            for ($i = 2; $i < $pathSize; $i++) {
                $path[] = $collection->getItemById($structure[$i])->getName();  ---> **This is line no 377**
            }
            $this->_categories[implode('/', $path)] = $category->getId();
        }
    }
    return $this;
}

请问有人知道解决方案吗?我在 magento 1.6.2

:(

4

1 回答 1

0

如果您在注册表中没有类别并获取其名称,那么也会发生此错误,就像您访问直接产品链接并尝试通过注册表获取页面上的类别时发生此错误一样。检查类别是否存在的解决方案。

if (Mage::registry('current_category')) {
        $categoryName = Mage::registry('current_category')->getName();
    }
    else {
        $categoryIds = $_product->getCategoryIds();
        if (count($categoryIds)) {
            $firstCategoryId = $categoryIds[0];
            $_category = Mage::getModel('catalog/category')->load($firstCategoryId);
            $categoryName = $_category->getName();
        }
    }
于 2016-06-09T20:20:34.737 回答