예제 #1
0
 /**
  * Prepare search condition for attribute
  *
  * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute
  * @param string|array $value
  * @return string|array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function prepareCondition($attribute, $value)
 {
     $condition = false;
     if (is_array($value)) {
         if ($attribute->getBackendType() == 'varchar') {
             // multiselect
             // multiselect
             $condition = ['in_set' => $value];
         } elseif (!isset($value['from']) && !isset($value['to'])) {
             // select
             // select
             $condition = ['in' => $value];
         } elseif (isset($value['from']) && '' !== $value['from'] || isset($value['to']) && '' !== $value['to']) {
             // range
             $condition = $value;
         }
     } else {
         if (strlen($value) > 0) {
             if (in_array($attribute->getBackendType(), ['varchar', 'text', 'static'])) {
                 $condition = ['like' => '%' . $value . '%'];
                 // text search
             } else {
                 $condition = $value;
             }
         }
     }
     return $condition;
 }
예제 #2
0
 /**
  * Get Attribute Filter Class Name
  *
  * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute
  * @return string
  */
 protected function getAttributeFilterClass(\Magento\Catalog\Model\Resource\Eav\Attribute $attribute)
 {
     $filterClassName = $this->filterTypes[self::ATTRIBUTE_FILTER];
     if ($attribute->getAttributeCode() == 'price') {
         $filterClassName = $this->filterTypes[self::PRICE_FILTER];
     } elseif ($attribute->getBackendType() == 'decimal') {
         $filterClassName = $this->filterTypes[self::DECIMAL_FILTER];
     }
     return $filterClassName;
 }
예제 #3
0
 /**
  * Return Google Content Attribute Type By Product Attribute
  *
  * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute
  * @return string Google Content Attribute Type
  */
 public function getGcontentAttributeType($attribute)
 {
     $typesMapping = ['price' => self::ATTRIBUTE_TYPE_FLOAT, 'decimal' => self::ATTRIBUTE_TYPE_INT];
     if (isset($typesMapping[$attribute->getFrontendInput()])) {
         return $typesMapping[$attribute->getFrontendInput()];
     } elseif (isset($typesMapping[$attribute->getBackendType()])) {
         return $typesMapping[$attribute->getBackendType()];
     } else {
         return self::ATTRIBUTE_TYPE_TEXT;
     }
 }
예제 #4
0
 /**
  * Create filter
  *
  * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute
  * @param \Magento\Catalog\Model\Layer $layer
  * @return mixed
  */
 protected function createAttributeFilter(\Magento\Catalog\Model\Resource\Eav\Attribute $attribute, \Magento\Catalog\Model\Layer $layer)
 {
     $filterClassName = $this->filterTypes[self::ATTRIBUTE_FILTER];
     if ($attribute->getAttributeCode() == 'price') {
         $filterClassName = $this->filterTypes[self::PRICE_FILTER];
     } elseif ($attribute->getBackendType() == 'decimal') {
         $filterClassName = $this->filterTypes[self::DECIMAL_FILTER];
     }
     $filter = $this->objectManager->create($filterClassName, array('data' => array('attribute_model' => $attribute), 'layer' => $layer));
     return $filter;
 }
예제 #5
0
 /**
  * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute
  * @param \Magento\Catalog\Model\Resource\Product\Collection $collection
  * @return $this
  */
 protected function addGlobalAttribute(\Magento\Catalog\Model\Resource\Eav\Attribute $attribute, \Magento\Catalog\Model\Resource\Product\Collection $collection)
 {
     $storeId = $this->storeManager->getStore()->getId();
     switch ($attribute->getBackendType()) {
         case 'decimal':
         case 'datetime':
         case 'int':
             $alias = 'at_' . $attribute->getAttributeCode();
             $collection->addAttributeToSelect($attribute->getAttributeCode(), 'inner');
             break;
         default:
             $alias = 'at_' . md5($this->getId()) . $attribute->getAttributeCode();
             $collection->getSelect()->join([$alias => $collection->getTable('catalog_product_index_eav')], "({$alias}.entity_id = e.entity_id) AND ({$alias}.store_id = {$storeId})" . " AND ({$alias}.attribute_id = {$attribute->getId()})", []);
     }
     $this->joinedAttributes[$attribute->getAttributeCode()] = $alias;
     return $this;
 }