/** * Add Join with option value for collection select * * @param \Magento\Eav\Model\Entity\Collection\AbstractCollection $collection * @param \Magento\Eav\Model\Entity\Attribute $attribute * @param \Zend_Db_Expr $valueExpr * @return $this */ public function addOptionValueToCollection($collection, $attribute, $valueExpr) { $adapter = $this->_getReadAdapter(); $attributeCode = $attribute->getAttributeCode(); $optionTable1 = $attributeCode . '_option_value_t1'; $optionTable2 = $attributeCode . '_option_value_t2'; $tableJoinCond1 = "{$optionTable1}.option_id={$valueExpr} AND {$optionTable1}.store_id=0"; $tableJoinCond2 = $adapter->quoteInto("{$optionTable2}.option_id={$valueExpr} AND {$optionTable2}.store_id=?", $collection->getStoreId()); $valueExpr = $adapter->getCheckSql("{$optionTable2}.value_id IS NULL", "{$optionTable1}.value", "{$optionTable2}.value"); $collection->getSelect()->joinLeft([$optionTable1 => $this->getTable('eav_attribute_option_value')], $tableJoinCond1, [])->joinLeft([$optionTable2 => $this->getTable('eav_attribute_option_value')], $tableJoinCond2, [$attributeCode => $valueExpr]); return $this; }
/** * Determine filter type for static attribute. * * @static * @param \Magento\Eav\Model\Entity\Attribute $attribute * @return string */ public static function getStaticAttributeFilterType(\Magento\Eav\Model\Entity\Attribute $attribute) { if (in_array($attribute->getAttributeCode(), ['category_ids', 'media_gallery'])) { return self::FILTER_TYPE_INPUT; } $columns = $attribute->getFlatColumns(); switch ($columns[$attribute->getAttributeCode()]['type']) { case \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER: case \Magento\Framework\DB\Ddl\Table::TYPE_BIGINT: $type = self::FILTER_TYPE_NUMBER; break; case \Magento\Framework\DB\Ddl\Table::TYPE_DATE: case \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME: case \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP: $type = self::FILTER_TYPE_DATE; break; default: $type = self::FILTER_TYPE_INPUT; } return $type; }
/** * Build attribute representation * * @param \Magento\Eav\Model\Entity\Attribute $attribute * @return array */ public function map(\Magento\Eav\Model\Entity\Attribute $attribute) { $isUnassignable = !in_array($attribute->getAttributeCode(), $this->unassignableAttributes); return ['text' => $attribute->getAttributeCode(), 'id' => $attribute->getAttributeId(), 'cls' => $isUnassignable ? 'leaf' : 'system-leaf', 'allowDrop' => false, 'allowDrag' => true, 'leaf' => true, 'is_user_defined' => $attribute->getIsUserDefined(), 'is_unassignable' => $isUnassignable, 'entity_id' => $attribute->getEntityAttributeId()]; }
/** * Set attribute model to filter * * @param \Magento\Eav\Model\Entity\Attribute $attribute * @return \Magento\Catalog\Model\Layer\Filter\AbstractFilter */ public function setAttributeModel($attribute) { $this->setRequestVar($attribute->getAttributeCode()); $this->setData('attribute_model', $attribute); return $this; }
/** * Retrieve attribute field name * * * @param Attribute $attribute * @return string */ public function getAttributeFieldName($attribute) { $name = $attribute->getAttributeCode(); if ($suffix = $this->getForm()->getFieldNameSuffix()) { $name = $this->getForm()->addSuffixToName($name, $suffix); } return $name; }
public function setAttributeObj(\Magento\Eav\Model\Entity\Attribute $obj) { $this->attributeObj = $obj; $this->code = $obj->getAttributeCode(); return $this; }
/** * Create filter fields for 'Filter' column. * * @param mixed $value * @param Attribute $row * @param \Magento\Framework\DataObject $column * @param boolean $isExport * @return string * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function decorateFilter($value, Attribute $row, \Magento\Framework\DataObject $column, $isExport) { $value = null; $values = $column->getValues(); if (is_array($values) && isset($values[$row->getAttributeCode()])) { $value = $values[$row->getAttributeCode()]; } $code = $row->getAttributeCode(); if (isset($this->_filterTypeByAttrCode[$code])) { $filterType = $this->_filterTypeByAttrCode[$code]; } else { $filterType = \Magento\ImportExport\Model\Export::getAttributeFilterType($row); } switch ($filterType) { case \Magento\ImportExport\Model\Export::FILTER_TYPE_SELECT: $cell = $this->_getSelectHtmlWithValue($row, $value); break; case \Magento\ImportExport\Model\Export::FILTER_TYPE_INPUT: $cell = $this->_getInputHtmlWithValue($row, $value); break; case \Magento\ImportExport\Model\Export::FILTER_TYPE_DATE: $cell = $this->_getDateFromToHtmlWithValue($row, $value); break; case \Magento\ImportExport\Model\Export::FILTER_TYPE_NUMBER: $cell = $this->_getNumberFromToHtmlWithValue($row, $value); break; default: $cell = __('Unknown attribute filter type'); } return $cell; }