Magento类别模型未加载所有数据
我正在Magento中构建一个自定义导航菜单,其中显示来自不同商店的类别,其根类别与当前商店的根类别不同。某些类别应隐藏,因为它们的“包含在导航菜单中”设置为“否” 应该可以从类别模型中读取此属性,如本问题所述: 但是,$category->getIncludeInMenu()在我的Magento EE 1.11安装中为所有类别返回NULLMagento类别模型未加载所有数据,magento,Magento,我正在Magento中构建一个自定义导航菜单,其中显示来自不同商店的类别,其根类别与当前商店的根类别不同。某些类别应隐藏,因为它们的“包含在导航菜单中”设置为“否” 应该可以从类别模型中读取此属性,如本问题所述: 但是,$category->getIncludeInMenu()在我的Magento EE 1.11安装中为所有类别返回NULL // Load child categories for a specific root category $_uk_default_root_id = M
// Load child categories for a specific root category
$_uk_default_root_id = Mage::app()->getStore('uk_default')->getRootCategoryId();
$_uk_default_root_category = Mage::getModel('catalog/category')->load($_uk_default_root_id);
$_sub_categories = $_uk_default_root_category->getChildrenCategories();
// Loop through the categories
foreach ($_sub_categories as $_category)
{
if ($_category->getIsActive() && $_category->getIncludeInMenu())
{
<echo navigation link>
}
}
这是因为Magento延迟加载类别模型。
Mage\u Catalog\u Model\u Category
模型上的getChildrenCategories()
方法返回一组类别模型,Magento只加载核心模型数据,而不是每个模型的附加EAV数据。include\u in_菜单
属性存储在EAV数据存储中,尚未加载
通过调用$\u category->load(),可以强制加载每个类别代码>将强制Magento加载每个类别的附加EAV数据
// Loop through the categories
foreach ($_sub_categories as $_category)
{
$_category->load();
if ($_category->getIsActive() && $_category->getIncludeInMenu())
{
<echo navigation link>
}
}
为此:
array (size=33)
'entity_id' => string '16' (length=2)
'entity_type_id' => string '3' (length=1)
'attribute_set_id' => string '3' (length=1)
'parent_id' => string '15' (length=2)
'created_at' => string '2011-11-16 12:16:27' (length=19)
'updated_at' => string '2011-12-19 16:19:08' (length=19)
'path' => string '1/15/16' (length=7)
'position' => string '1' (length=1)
'level' => string '2' (length=1)
'children_count' => string '8' (length=1)
'is_active' => string '1' (length=1)
'request_path' => null
'name' => string 'Vacuum Cleaners' (length=15)
'url_key' => string 'vacuum-cleaners' (length=15)
'is_anchor' => string '1' (length=1)
'meta_title' => null
'display_mode' => string 'PRODUCTS' (length=8)
'custom_design' => null
'page_layout' => null
'url_path' => string 'vacuum-cleaners' (length=15)
'image' => string 'heading_vacuums_1.png' (length=21)
'include_in_menu' => string '1' (length=1)
'landing_page' => null
'custom_use_parent_settings' => string '0' (length=1)
'custom_apply_to_products' => string '0' (length=1)
'filter_price_range' => null
'description' => null
'meta_keywords' => null
'meta_description' => null
'custom_layout_update' => null
'available_sort_by' => null
'custom_design_from' => null
'custom_design_to' => null
其中包括include\u in\u菜单属性。您必须使用:
$\u category->load($\u category->getId())
为我工作;) 您的var转储不显示对象。$类别是什么对象?第一步是验证该对象是否具有您希望使用的属性/方法。该对象是Mage\u Catalog\u Model\u Category
。我已经更新了var转储以显示完整的对象。
array (size=15)
'entity_id' => string '16' (length=2)
'entity_type_id' => string '3' (length=1)
'attribute_set_id' => string '3' (length=1)
'parent_id' => string '15' (length=2)
'created_at' => string '2011-11-16 12:16:27' (length=19)
'updated_at' => string '2011-12-19 16:19:08' (length=19)
'path' => string '1/15/16' (length=7)
'position' => string '1' (length=1)
'level' => string '2' (length=1)
'children_count' => string '8' (length=1)
'is_active' => string '1' (length=1)
'request_path' => null
'name' => string 'Vacuum Cleaners' (length=15)
'url_key' => string 'vacuum-cleaners' (length=15)
'is_anchor' => string '1' (length=1)
array (size=33)
'entity_id' => string '16' (length=2)
'entity_type_id' => string '3' (length=1)
'attribute_set_id' => string '3' (length=1)
'parent_id' => string '15' (length=2)
'created_at' => string '2011-11-16 12:16:27' (length=19)
'updated_at' => string '2011-12-19 16:19:08' (length=19)
'path' => string '1/15/16' (length=7)
'position' => string '1' (length=1)
'level' => string '2' (length=1)
'children_count' => string '8' (length=1)
'is_active' => string '1' (length=1)
'request_path' => null
'name' => string 'Vacuum Cleaners' (length=15)
'url_key' => string 'vacuum-cleaners' (length=15)
'is_anchor' => string '1' (length=1)
'meta_title' => null
'display_mode' => string 'PRODUCTS' (length=8)
'custom_design' => null
'page_layout' => null
'url_path' => string 'vacuum-cleaners' (length=15)
'image' => string 'heading_vacuums_1.png' (length=21)
'include_in_menu' => string '1' (length=1)
'landing_page' => null
'custom_use_parent_settings' => string '0' (length=1)
'custom_apply_to_products' => string '0' (length=1)
'filter_price_range' => null
'description' => null
'meta_keywords' => null
'meta_description' => null
'custom_layout_update' => null
'available_sort_by' => null
'custom_design_from' => null
'custom_design_to' => null