Example #1
0
 public function testAddFiltersVerifyAddConditionsToRegistry()
 {
     $registry = new \Magento\Framework\Registry();
     $values = array('sku' => 'simple');
     $this->skuAttribute->expects($this->once())->method('getTable')->will($this->returnValue('catalog_product_entity'));
     $this->collection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('setStore')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addMinimalPrice')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addTaxPercents')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addStoreFilter')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('setVisibility')->will($this->returnSelf());
     $this->resource->expects($this->any())->method('prepareCondition')->will($this->returnValue(array('like' => '%simple%')));
     $this->resource->expects($this->any())->method('getIdFieldName')->will($this->returnValue('entity_id'));
     $this->engine->expects($this->any())->method('getResource')->will($this->returnValue($this->resource));
     $this->engine->expects($this->any())->method('getAdvancedResultCollection')->will($this->returnValue($this->collection));
     $this->engineProvider->expects($this->any())->method('get')->will($this->returnValue($this->engine));
     $this->attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue('sku'));
     $this->attribute->expects($this->any())->method('getStoreLabel')->will($this->returnValue('SKU'));
     $this->attribute->expects($this->any())->method('getFrontendInput')->will($this->returnValue('text'));
     $this->attribute->expects($this->any())->method('getBackend')->will($this->returnValue($this->skuAttribute));
     $this->attribute->expects($this->any())->method('getBackendType')->will($this->returnValue('static'));
     $this->dataCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator(array($this->attribute))));
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     /** @var \Magento\CatalogSearch\Model\Advanced $instance */
     $instance = $objectManager->getObject('Magento\\CatalogSearch\\Model\\Advanced', array('registry' => $registry, 'engineProvider' => $this->engineProvider, 'data' => array('attributes' => $this->dataCollection)));
     $instance->addFilters($values);
     $this->assertNotNull($registry->registry('advanced_search_conditions'));
 }
 /**
  * @param array $attributes
  * @param array $values
  * @param string $currentCurrencyCode
  * @param string $baseCurrencyCode
  * @dataProvider addFiltersDataProvider
  */
 public function testAddFiltersVerifyAddConditionsToRegistry(array $attributes, array $values, $currentCurrencyCode = 'GBP', $baseCurrencyCode = 'USD')
 {
     $registry = new \Magento\Framework\Registry();
     $this->collection->expects($this->any())->method('addAttributeToSelect')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('setStore')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addMinimalPrice')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addTaxPercents')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('addStoreFilter')->will($this->returnSelf());
     $this->collection->expects($this->any())->method('setVisibility')->will($this->returnSelf());
     $this->resource->expects($this->any())->method('prepareCondition')->will($this->returnValue(['like' => '%simple%']));
     $this->resource->expects($this->any())->method('getIdFieldName')->will($this->returnValue('entity_id'));
     $this->dataCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator($attributes)));
     $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $advancedFactory = $this->getMockBuilder('Magento\\CatalogSearch\\Model\\Resource\\AdvancedFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $advancedFactory->expects($this->once())->method('create')->willReturn($this->resource);
     $productCollectionFactory = $this->getMockBuilder('Magento\\Catalog\\Model\\Resource\\Product\\CollectionFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $productCollectionFactory->expects($this->any())->method('create')->willReturn($this->collection);
     $this->store->expects($this->any())->method('getCurrentCurrencyCode')->willReturn($currentCurrencyCode);
     $this->store->expects($this->any())->method('getBaseCurrencyCode')->willReturn($baseCurrencyCode);
     $this->currency->expects($this->any())->method('getRate')->with($currentCurrencyCode)->willReturn(1.5);
     $currency = $this->getMockBuilder('Magento\\Directory\\Model\\Currency')->setMethods(['load', 'format'])->disableOriginalConstructor()->getMock();
     $currency->expects($this->any())->method('load')->willReturnSelf();
     $currency->expects($this->any())->method('format')->willReturnArgument(0);
     $currencyFactory = $this->getMockBuilder('Magento\\Directory\\Model\\CurrencyFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
     $currencyFactory->expects($this->any())->method('create')->willReturn($currency);
     /** @var \Magento\CatalogSearch\Model\Advanced $instance */
     $instance = $objectManager->getObject('Magento\\CatalogSearch\\Model\\Advanced', ['registry' => $registry, 'resourceProvider' => $this->resourceProvider, 'data' => ['attributes' => $this->dataCollection], 'advancedFactory' => $advancedFactory, 'productCollectionFactory' => $productCollectionFactory, 'storeManager' => $this->storeManager, 'currencyFactory' => $currencyFactory]);
     $instance->addFilters($values);
     $this->assertNotNull($registry->registry('advanced_search_conditions'));
 }
Example #3
0
 /**
  * Prepare product collection
  *
  * @param Collection $collection
  * @return $this
  */
 public function prepareProductCollection($collection)
 {
     $collection->addAttributeToSelect($this->_catalogConfig->getProductAttributes())->setStore($this->_storeManager->getStore())->addMinimalPrice()->addTaxPercents()->addStoreFilter()->setVisibility($this->_catalogProductVisibility->getVisibleInSearchIds());
     return $this;
 }
Example #4
0
 /**
  * Add filter by indexable attribute
  *
  * @param \Magento\CatalogSearch\Model\Resource\Advanced\Collection $collection
  * @param \Magento\Catalog\Model\Resource\Eav\Attribute $attribute
  * @param string|array $value
  * @return bool
  */
 public function addIndexableAttributeModifiedFilter($collection, $attribute, $value)
 {
     if ($attribute->getIndexType() == 'decimal') {
         $table = $this->getTable('catalog_product_index_eav_decimal');
     } else {
         $table = $this->getTable('catalog_product_index_eav');
     }
     $tableAlias = 'a_' . $attribute->getAttributeId();
     $storeId = $this->_storeManager->getStore()->getId();
     $select = $collection->getSelect();
     if (is_array($value)) {
         if (isset($value['from']) && isset($value['to'])) {
             if (empty($value['from']) && empty($value['to'])) {
                 return false;
             }
         }
     }
     $select->distinct(true);
     $select->join(array($tableAlias => $table), "e.entity_id={$tableAlias}.entity_id " . " AND {$tableAlias}.attribute_id={$attribute->getAttributeId()}" . " AND {$tableAlias}.store_id={$storeId}", array());
     if (is_array($value) && (isset($value['from']) || isset($value['to']))) {
         if (isset($value['from']) && !empty($value['from'])) {
             $select->where("{$tableAlias}.value >= ?", $value['from']);
         }
         if (isset($value['to']) && !empty($value['to'])) {
             $select->where("{$tableAlias}.value <= ?", $value['to']);
         }
         return true;
     }
     $select->where("{$tableAlias}.value IN(?)", $value);
     return true;
 }