magento2 - 如何在 Magento 2 中获取类别的自定义属性
问题描述
我正在尝试brand_label
在 Magento2 中获得一个类别。这是我目前的代码:
$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_label
返回 null
解决方案
您可以使用以下方式从类别中检索数据:
$category = $this->categoryRepository->get($categoryId);
$category->getData('brand_label');
或者:
$category = $this->categoryRepository->get($categoryId);
$category->getBrandLabel();
确保您的类别属性代码是brand_label
推荐阅读
- spring - 如何在 itemProcessor 中接收 application.properties 值
- java - JAVA_HOME 不适用于 sudo mvn
- keras - 构建多类语义分割的u-net模型
- python - Django:视图调用另一个模板(分页)
- python - 计算每个集群的时间序列数据的季节性和趋势
- php - Laravel 5.6 在路由问题中获取用户
- maps - 哪些 geopandas 数据集(地图)可用?
- api - 收敛 API 错误代码 4000
- oracle - BI-Publisher 11g - 使用不同的数据源创建报告
- sql - 在 SSRS 中使用日期选择器中的值