Magento2 如何在Magento 2中获取类别的自定义属性
我正在尝试获取Magento2中某个类别的Magento2 如何在Magento 2中获取类别的自定义属性,magento2,Magento2,我正在尝试获取Magento2中某个类别的品牌标签。这是我目前的代码: $categoryObj = $this->categoryRepository->get($parent_category_id); $Categories = $categoryObj->getChildrenCategories()->addAttributeToFilter('include_in_menu', array('eq' => 1)); $categoryArray = [
品牌标签。这是我目前的代码:
$categoryObj = $this->categoryRepository->get($parent_category_id);
$Categories = $categoryObj->getChildrenCategories()->addAttributeToFilter('include_in_menu', array('eq' => 1));
$categoryArray = [];
foreach($Categories as $category){
$categoryObject->brand_label = $category->getCustomAttribute('brand_label');
array_push($categoryArray,$categoryObject);
}
$categoryObject->brand_标签返回null您可以使用以下方法从类别中检索数据:
$category = $this->categoryRepository->get($categoryId);
$category->getData('brand_label');
或:
确保您的类别属性代码为品牌标签,例如,您可以尝试在Magento StackExchange找到答案,
$category = $this->categoryRepository->get($categoryId);
$category->getBrandLabel();