Skip to content

Commit

Permalink
Merge branch '2.8.x' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
romainruaud committed May 2, 2019
2 parents 62da070 + 0199ac1 commit 3dcea81
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(CollectionFactory $optimizerCollectionFactory, Optim
*/
public function getType()
{
return self::TYPE_ONLY_ONE;
return self::TYPE_ONLY;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct(CollectionFactory $optimizerCollectionFactory, Optim
*/
public function getType()
{
return self::TYPE_ONLY;
return self::TYPE_REPLACE;
}

/**
Expand All @@ -74,7 +74,6 @@ public function getCollection(ContainerConfigurationInterface $containerConfigur
'main_table.' . OptimizerInterface::OPTIMIZER_ID,
['neq' => $this->optimizer->getId()]
);
$this->optimizer->setId(null);
}

$collection->addItem($this->optimizer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace Smile\ElasticsuiteCatalogOptimizer\Model\Optimizer\Preview;

use Magento\Catalog\Api\Data\CategoryInterface;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Search\Request\QueryInterface;
use Smile\ElasticsuiteCore\Api\Search\Request\ContainerConfigurationInterface;
Expand All @@ -41,25 +40,25 @@ class CategoryQuery
private $queryBuilder;

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
* @var \Smile\ElasticsuiteCatalog\Model\Category\Filter\Provider
*/
private $scopeConfig;
private $categoryFilterProvider;

/**
* CategoryQuery constructor.
*
* @param \Smile\ElasticsuiteCore\Search\Request\Query\Builder $queryBuilder Query Builder
* @param \Smile\ElasticsuiteCore\Search\Request\Query\QueryFactory $queryFactory Query Factory
* @param ScopeConfigInterface $scopeConfig Scope Configuration
* @param \Smile\ElasticsuiteCore\Search\Request\Query\Builder $queryBuilder Query Builder
* @param \Smile\ElasticsuiteCore\Search\Request\Query\QueryFactory $queryFactory Query Factory
* @param \Smile\ElasticsuiteCatalog\Model\Category\Filter\Provider $categoryFilterProvider Category Filter Provider
*/
public function __construct(
QueryBuilder $queryBuilder,
QueryFactory $queryFactory,
ScopeConfigInterface $scopeConfig
\Smile\ElasticsuiteCatalog\Model\Category\Filter\Provider $categoryFilterProvider
) {
$this->queryBuilder = $queryBuilder;
$this->queryFactory = $queryFactory;
$this->scopeConfig = $scopeConfig;
$this->queryBuilder = $queryBuilder;
$this->queryFactory = $queryFactory;
$this->categoryFilterProvider = $categoryFilterProvider;
}

/**
Expand All @@ -74,21 +73,12 @@ public function getCategorySearchQuery(
ContainerConfigurationInterface $containerConfigurationInterface,
CategoryInterface $category
) {
$filterParams = [
'category.category_id' => $category->getId(),
'visibility' => [Visibility::VISIBILITY_IN_CATALOG, Visibility::VISIBILITY_BOTH],
];

if (!$this->isEnabledShowOutOfStock($category->getStoreId())) {
$filterParams['stock.is_in_stock'] = true;
}

if ($category->getVirtualRule()) { // Implicit dependency to Virtual Categories module.
$filterParams['category'] = $category->getVirtualRule()->getCategorySearchQuery($category);
unset($filterParams['category.category_id']);
}
$filters = array_merge(
['category' => $this->categoryFilterProvider->getQueryFilter($category)],
$containerConfigurationInterface->getFilters()
);

$filterQuery = $this->queryBuilder->createFilterQuery($containerConfigurationInterface, $filterParams);
$filterQuery = $this->queryBuilder->createFilterQuery($containerConfigurationInterface, $filters);

return $this->queryFactory->create(QueryInterface::TYPE_FILTER, ['filter' => $filterQuery]);
}
Expand All @@ -111,20 +101,4 @@ public function getCategorySortOrders(CategoryInterface $category)
],
];
}

/**
* Get config value for 'display out of stock' option
*
* @param int $storeId The Store Id
*
* @return bool
*/
private function isEnabledShowOutOfStock($storeId = null)
{
return $this->scopeConfig->isSetFlag(
'cataloginventory/options/show_out_of_stock',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$storeId
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
namespace Smile\ElasticsuiteCatalogOptimizer\Model\Optimizer\Preview;

use Magento\Catalog\Api\Data\CategoryInterface;
use Smile\ElasticsuiteCore\Api\Search\ContextInterface;
use Smile\ElasticsuiteCore\Api\Search\Request\ContainerConfigurationInterface;
use Smile\ElasticsuiteCore\Search\Request\Query\Builder as QueryBuilder;
use Smile\ElasticsuiteCore\Search\Request\Query\QueryFactory;
use Smile\ElasticsuiteCore\Search\Request\QueryInterface;
use Smile\ElasticsuiteCore\Search\Request\SortOrder\SortOrderBuilder;
use Smile\ElasticsuiteCore\Search\RequestFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@
*/
namespace Smile\ElasticsuiteCatalogOptimizer\Model\Optimizer\Preview;

use Magento\Catalog\Model\Product\Visibility;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Search\Request\QueryInterface;
use Smile\ElasticsuiteCore\Api\Search\Request\ContainerConfigurationInterface;
use Smile\ElasticsuiteCore\Search\Request\Query\Builder as QueryBuilder;
use Smile\ElasticsuiteCore\Search\Request\Query\QueryFactory;
use Smile\ElasticsuiteCore\Api\Search\Spellchecker\RequestInterfaceFactory as SpellcheckRequestFactory;
use Smile\ElasticsuiteCore\Api\Search\SpellcheckerInterface;
use Smile\ElasticsuiteCore\Search\Request\Query\Builder as QueryBuilder;
use Smile\ElasticsuiteCore\Search\Request\Query\QueryFactory;

/**
* Search Query Builder for Optimizer Preview
Expand All @@ -41,11 +39,6 @@ class SearchQuery
*/
private $queryBuilder;

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
private $scopeConfig;

/**
* @var \Smile\ElasticsuiteCore\Api\Search\Spellchecker\RequestInterfaceFactory
*/
Expand All @@ -63,20 +56,17 @@ class SearchQuery
* @param QueryFactory $queryFactory Query Factory
* @param SpellcheckRequestFactory $spellcheckRequestFactory Spellcheck Request Factory
* @param SpellcheckerInterface $spellchecker Spellchecker
* @param ScopeConfigInterface $scopeConfig Scope Configuration
*/
public function __construct(
QueryBuilder $queryBuilder,
QueryFactory $queryFactory,
SpellcheckRequestFactory $spellcheckRequestFactory,
SpellcheckerInterface $spellchecker,
ScopeConfigInterface $scopeConfig
SpellcheckerInterface $spellchecker
) {
$this->queryBuilder = $queryBuilder;
$this->queryFactory = $queryFactory;
$this->spellcheckRequestFactory = $spellcheckRequestFactory;
$this->spellchecker = $spellchecker;
$this->scopeConfig = $scopeConfig;
}

/**
Expand All @@ -91,16 +81,7 @@ public function getFullTextQuery($containerConfiguration, $queryText)
{
$spellingType = $this->getSpellingType($containerConfiguration, $queryText);
$query = $this->createFullTextQuery($containerConfiguration, $queryText, $spellingType);

$filterParams = [
'visibility' => [Visibility::VISIBILITY_IN_SEARCH, Visibility::VISIBILITY_BOTH],
];

if (!$this->isEnabledShowOutOfStock($containerConfiguration->getStoreId())) {
$filterParams['stock.is_in_stock'] = true;
}

$filterQuery = $this->queryBuilder->createFilterQuery($containerConfiguration, $filterParams);
$filterQuery = $this->queryBuilder->createFilterQuery($containerConfiguration, $containerConfiguration->getFilters());

return $this->queryFactory->create(QueryInterface::TYPE_FILTER, ['filter' => $filterQuery, 'query' => $query]);
}
Expand Down Expand Up @@ -152,20 +133,4 @@ private function getSpellingType(ContainerConfigurationInterface $containerConfi

return $spellingType;
}

/**
* Get config value for 'display out of stock' option
*
* @param int $storeId The Store Id
*
* @return bool
*/
private function isEnabledShowOutOfStock($storeId = null)
{
return $this->scopeConfig->isSetFlag(
'cataloginventory/options/show_out_of_stock',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$storeId
);
}
}

0 comments on commit 3dcea81

Please sign in to comment.