Example #1
0
 /**
  * Add condition to collection
  *
  * @param \Magento\Catalog\Model\ResourceModel\Product\Collection $collection
  * @return $this
  */
 public function addToCollection($collection)
 {
     $attribute = $this->getAttributeObject();
     if ($collection->isEnabledFlat()) {
         $alias = array_keys($collection->getSelect()->getPart('from'))[0];
         $this->joinedAttributes[$attribute->getAttributeCode()] = $alias . '.' . $attribute->getAttributeCode();
         return $this;
     }
     if ('category_ids' == $attribute->getAttributeCode() || $attribute->isStatic()) {
         return $this;
     }
     if ($attribute->getBackend() && $attribute->isScopeGlobal()) {
         $this->addGlobalAttribute($attribute, $collection);
     } else {
         $this->addNotGlobalAttribute($attribute, $collection);
     }
     $attributes = $this->getRule()->getCollectedAttributes();
     $attributes[$attribute->getAttributeCode()] = true;
     $this->getRule()->setCollectedAttributes($attributes);
     return $this;
 }
 /**
  * Retrieve is flat enabled flag
  * Overwrite disable flat for compared item if required EAV resource
  *
  * @return bool
  */
 public function isEnabledFlat()
 {
     if (!$this->_catalogProductCompare->getAllowUsedFlat()) {
         return false;
     }
     return parent::isEnabledFlat();
 }