Ejemplo n.º 1
0
 public function testAddAttributeGrouping()
 {
     $select = $this->_model->getSelect();
     $this->assertEmpty($select->getPart(\Magento\Framework\DB\Select::GROUP));
     $this->_model->addAttributeGrouping();
     $this->assertEquals(['main_table.attribute_id'], $select->getPart(\Magento\Framework\DB\Select::GROUP));
 }
 /**
  * Allow to filter an attribute collection on attributes that are indexed into the search engine.
  *
  * @param AttributeCollection $attributeCollection Attribute collection (not loaded).
  *
  * @return AttributeCollection
  */
 public function addIndexedFilterToAttributeCollection(AttributeCollection $attributeCollection)
 {
     $conditions = [];
     foreach ($this->indexedAttributesConditions as $fieldName => $condition) {
         if ($condition['operator'] == 'IN' || is_array($condition['value'])) {
             $conditionString = sprintf('%s %s (?)', $fieldName, $condition['operator']);
             $conditions[] = $this->connection->quoteInto($conditionString, $condition['value']);
         } elseif (!is_array($condition['value'])) {
             $conditions[] = sprintf('%s %s %s', $fieldName, $condition['operator'], $condition['value']);
         }
     }
     if (!empty($conditions)) {
         $select = $attributeCollection->getSelect();
         $select->where(implode(' OR ', $conditions));
     }
     return $attributeCollection;
 }