浏览文章
文章信息
Magento2 Collection数据集合或查询 | OR 查询| Magento2 Collection OR Condition
10668
代码:
<?php namespace Aiweline\Checkout\Model\Config; use Magento\Framework\Option\ArrayInterface; class AttributesOptions implements ArrayInterface { /** * @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute */ private $attributeFactory; function __construct( \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attributeFactory ) { $this->attributeFactory = $attributeFactory; } /** * @inheritDoc */ public function toOptionArray() { $options = []; foreach ($this->getProductSizeAttribute() as $item) { $options[] = ['label' => $item->getData('frontend_label'), 'value' => $item->getData('attribute_id')]; } return $options; } function getProductSizeAttribute() { $attributes = $this->attributeFactory->getCollection(); $attributes->addFieldToFilter('frontend_label', [ ['like' => '%size%'], ['like' => '%Size%'] ]); return $attributes; } }