/** * ES field used in attribute autocomplete. * * @param \Magento\Catalog\Model\ResourceModel\Product\Attribute $attribute Attribute. * * @return string */ public function getAttributeAutocompleteField(\Magento\Catalog\Api\Data\ProductAttributeInterface $attribute) { $fieldName = $attribute->getAttributeCode(); if ($attribute->usesSource()) { $fieldName = $this->mappingHelper->getOptionTextFieldName($fieldName); } return $fieldName; }
/** * Retrieve attribute collection prefiltered with only attribute usable in rules. * * @return \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection */ public function getAttributeCollection() { if ($this->attributeCollection === null) { $this->attributeCollection = $this->attributeCollectionFactory->create(); $mapping = $this->getMapping(); $attributeNameMapping = array_flip($this->fieldNameMapping); $arrayNameCb = function (FieldInterface $field) use($attributeNameMapping) { $attributeName = $field->getName(); if (isset($attributeNameMapping[$attributeName])) { $attributeName = $attributeNameMapping[$attributeName]; } return $attributeName; }; $attributeFilterCb = function (FieldInterface $field) use($mapping) { try { $fieldName = $field->getName(); $optionTextFieldName = $this->mappingHelper->getOptionTextFieldName($fieldName); $field = $mapping->getField($optionTextFieldName); } catch (\Exception $e) { } return $field->isFilterable() || $field->isSearchable(); }; $fieldNames = array_map($arrayNameCb, array_filter($this->getMapping()->getFields(), $attributeFilterCb)); $this->attributeCollection->addFieldToFilter('attribute_code', $fieldNames)->addFieldToFilter('backend_type', ['neq' => 'datetime']); } return $this->attributeCollection; }
/** * @param Context $context Helper context. * @param ObjectManagerInterface $objectManager The object manager * @param AttributeFactory $attributeFactory Factory used to create attributes. * @param string $collectionFactory Factory class name to use for create attribute collections. */ public function __construct(Context $context, ObjectManagerInterface $objectManager, AttributeFactory $attributeFactory, $collectionFactory) { parent::__construct($context); $this->attributeFactory = $attributeFactory; $this->objectManager = $objectManager; $this->attributeCollectionFactory = $this->objectManager->get($collectionFactory); }
/** * Retrieve ES filter field. * * @return string */ protected function getFilterField() { $field = $this->getAttributeModel()->getAttributeCode(); if ($this->getAttributeModel()->usesSource()) { $field = $this->mappingHelper->getOptionTextFieldName($field); } return $field; }