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 \Magento\Catalog\Model\Layer\AvailabilityFlagInterface $subject * @param callable $proceed * @param \Magento\Catalog\Model\Layer $layer * @param array $filters * @return bool * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundIsEnabled(\Magento\Catalog\Model\Layer\AvailabilityFlagInterface $subject, \Closure $proceed, $layer, $filters) { $_isLNAllowedByEngine = $this->engineProvider->get()->isLayeredNavigationAllowed(); if (!$_isLNAllowedByEngine) { return false; } $availableResCount = (int) $this->scopeConfig->getValue(self::XML_PATH_DISPLAY_LAYER_COUNT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); if (!$availableResCount || $availableResCount > $layer->getProductCollection()->getSize()) { return $proceed($layer, $filters); } return false; }
/** * Save Multiply Product indexes * * @param int $storeId * @param array $productIndexes * @return $this */ protected function saveProductIndexes($storeId, $productIndexes) { if ($this->engineProvider->get()) { $this->engineProvider->get()->saveEntityIndexes($storeId, $productIndexes); } return $this; }
/** * Construct * * @param Context $context * @param Registry $registry * @param CollectionFactory $attributeCollectionFactory * @param Visibility $catalogProductVisibility * @param Config $catalogConfig * @param EngineProvider $engineProvider * @param CurrencyFactory $currencyFactory * @param ProductFactory $productFactory * @param StoreManagerInterface $storeManager * @param array $data */ public function __construct(Context $context, Registry $registry, CollectionFactory $attributeCollectionFactory, Visibility $catalogProductVisibility, Config $catalogConfig, EngineProvider $engineProvider, CurrencyFactory $currencyFactory, ProductFactory $productFactory, StoreManagerInterface $storeManager, array $data = array()) { $this->_attributeCollectionFactory = $attributeCollectionFactory; $this->_catalogProductVisibility = $catalogProductVisibility; $this->_catalogConfig = $catalogConfig; $this->_engine = $engineProvider->get(); $this->_currencyFactory = $currencyFactory; $this->_productFactory = $productFactory; $this->_storeManager = $storeManager; parent::__construct($context, $registry, $this->_engine->getResource(), $this->_engine->getResourceCollection(), $data); }
/** * @param \Magento\Framework\App\Resource $resource * @param \Magento\Catalog\Model\Product\Type $catalogProductType * @param \Magento\Eav\Model\Config $eavConfig * @param \Magento\Framework\Search\Request\Config $searchRequestConfig * @param \Magento\Catalog\Model\Product\Attribute\Source\Status $catalogProductStatus * @param \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $productAttributeCollectionFactory * @param \Magento\CatalogSearch\Model\Resource\EngineProvider $engineProvider * @param \Magento\CatalogSearch\Model\Indexer\IndexerHandlerFactory $indexHandlerFactory * @param \Magento\Framework\Event\ManagerInterface $eventManager * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Framework\Stdlib\DateTime $dateTime * @param \Magento\Framework\Locale\ResolverInterface $localeResolver * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate * @param \Magento\CatalogSearch\Model\Resource\Fulltext $fulltextResource * @param \Magento\Framework\Search\Request\DimensionFactory $dimensionFactory * @param \Magento\Indexer\Model\ConfigInterface $indexerConfig * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct(\Magento\Framework\App\Resource $resource, \Magento\Catalog\Model\Product\Type $catalogProductType, \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\Search\Request\Config $searchRequestConfig, \Magento\Catalog\Model\Product\Attribute\Source\Status $catalogProductStatus, \Magento\Catalog\Model\Resource\Product\Attribute\CollectionFactory $productAttributeCollectionFactory, \Magento\CatalogSearch\Model\Resource\EngineProvider $engineProvider, \Magento\CatalogSearch\Model\Indexer\IndexerHandlerFactory $indexHandlerFactory, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Stdlib\DateTime $dateTime, \Magento\Framework\Locale\ResolverInterface $localeResolver, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\CatalogSearch\Model\Resource\Fulltext $fulltextResource, \Magento\Framework\Search\Request\DimensionFactory $dimensionFactory, \Magento\Indexer\Model\ConfigInterface $indexerConfig) { $this->resource = $resource; $this->catalogProductType = $catalogProductType; $this->eavConfig = $eavConfig; $this->searchRequestConfig = $searchRequestConfig; $this->catalogProductStatus = $catalogProductStatus; $this->productAttributeCollectionFactory = $productAttributeCollectionFactory; $this->eventManager = $eventManager; $this->scopeConfig = $scopeConfig; $this->storeManager = $storeManager; $this->engine = $engineProvider->get(); $configData = $indexerConfig->getIndexer(Fulltext::INDEXER_ID); $this->indexHandler = $indexHandlerFactory->create(['data' => $configData]); $this->dateTime = $dateTime; $this->localeResolver = $localeResolver; $this->localeDate = $localeDate; $this->fulltextResource = $fulltextResource; $this->dimensionFactory = $dimensionFactory; }