Skip to content

Commit

Permalink
Merge branch 'merchant_beta' of github.corp.ebay.com:magento2/magento…
Browse files Browse the repository at this point in the history
…2ce into M2BetaBugfixes
  • Loading branch information
slopukhov committed Sep 22, 2015
2 parents 84ac843 + ca40259 commit 4b149ca
Show file tree
Hide file tree
Showing 24 changed files with 1,290 additions and 289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ public function getPagerUrl($params = [])
{
$urlParams = [];
$urlParams['_current'] = true;
$urlParams['_escape'] = true;
$urlParams['_escape'] = false;
$urlParams['_use_rewrite'] = true;
$urlParams['_query'] = $params;
return $this->getUrl('*/*/*', $urlParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ define([
var $checkbox = $(event.currentTarget);
var $imageContainer = $checkbox.closest('[data-role=dialog]').data('imageContainer');
$imageContainer.toggleClass('hidden-for-front', $checkbox.is(':checked'));
$imageContainer.find('[name*="disabled"]').val($checkbox.is(':checked') ? 1 : 0);
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
*/
namespace Magento\CatalogSearch\Model\Adapter\Mysql\Filter;

use Magento\Catalog\Model\Product;
use Magento\CatalogSearch\Model\Search\TableMapper;
use Magento\Eav\Model\Config;
use Magento\Framework\App\Resource;
use Magento\Framework\App\ScopeResolverInterface;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\Search\Adapter\Mysql\ConditionManager;
use Magento\Framework\Search\Adapter\Mysql\Filter\PreprocessorInterface;
use Magento\Framework\Search\Adapter\Mysql\Query\QueryContainer;
use Magento\Framework\Search\Request\FilterInterface;
use Magento\Store\Model\Store;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Preprocessor implements PreprocessorInterface
{
/**
Expand All @@ -32,117 +37,121 @@ class Preprocessor implements PreprocessorInterface
private $config;

/**
* @var Resource
* @var string
*/
private $resource;
private $attributePrefix;

/**
* @var string
* @var AdapterInterface
*/
private $attributePrefix;
private $connection;

/**
* @var TableMapper
*/
private $tableMapper;

/**
* @param ConditionManager $conditionManager
* @param ScopeResolverInterface $scopeResolver
* @param Config $config
* @param Resource $resource
* @param TableMapper $tableMapper
* @param string $attributePrefix
*/
public function __construct(
ConditionManager $conditionManager,
ScopeResolverInterface $scopeResolver,
Config $config,
Resource $resource,
TableMapper $tableMapper,
$attributePrefix
) {
$this->conditionManager = $conditionManager;
$this->scopeResolver = $scopeResolver;
$this->config = $config;
$this->resource = $resource;
$this->connection = $resource->getConnection(Resource::DEFAULT_READ_RESOURCE);
$this->attributePrefix = $attributePrefix;
$this->tableMapper = $tableMapper;
}

/**
* {@inheritdoc}
*/
public function process(FilterInterface $filter, $isNegation, $query, QueryContainer $queryContainer)
public function process(FilterInterface $filter, $isNegation, $query)
{
return $this->processQueryWithField($filter, $isNegation, $query, $queryContainer);
return $this->processQueryWithField($filter, $isNegation, $query);
}

/**
* @param FilterInterface $filter
* @param bool $isNegation
* @param string $query
* @param QueryContainer $queryContainer
* @return string
*/
private function processQueryWithField(FilterInterface $filter, $isNegation, $query, QueryContainer $queryContainer)
private function processQueryWithField(FilterInterface $filter, $isNegation, $query)
{
$currentStoreId = $this->scopeResolver->getScope()->getId();

$select = null;
/** @var \Magento\Catalog\Model\Resource\Eav\Attribute $attribute */
$attribute = $this->config->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $filter->getField());
$select = $this->getConnection()->select();
$table = $attribute->getBackendTable();
if ($filter->getField() == 'price') {
$query = str_replace('price', 'min_price', $query);
$select->from(['main_table' => $this->resource->getTableName('catalog_product_index_price')], 'entity_id')
->where($query);
} elseif ($filter->getField() == 'category_ids') {
return 'category_index.category_id = ' . $filter->getValue();
} else {
if ($attribute->isStatic()) {
$select->from(['main_table' => $table], 'entity_id')
->where($query);
if ($filter->getField() === 'price') {
$filterQuery = str_replace(
$this->connection->quoteIdentifier('price'),
$this->connection->quoteIdentifier('price_index.min_price'),
$query
);
return $filterQuery;
} elseif ($filter->getField() === 'category_ids') {
return 'category_ids_index.category_id = ' . $filter->getValue();
} elseif ($attribute->isStatic()) {
$alias = $this->tableMapper->getMappingAlias($filter);
$filterQuery = str_replace(
$this->connection->quoteIdentifier($attribute->getAttributeCode()),
$this->connection->quoteIdentifier($alias . '.' . $attribute->getAttributeCode()),
$query
);
return $filterQuery;
} elseif ($filter->getType() === FilterInterface::TYPE_TERM) {
$alias = $this->tableMapper->getMappingAlias($filter);
if (is_array($filter->getValue())) {
$value = sprintf(
'%s IN (%s)',
($isNegation ? 'NOT' : ''),
implode(',', $filter->getValue())
);
} else {
if ($filter->getType() == FilterInterface::TYPE_TERM) {
if (is_array($filter->getValue())) {
$value = sprintf(
'%s IN (%s)',
($isNegation ? 'NOT' : ''),
implode(',', $filter->getValue())
);
} else {
$value = ($isNegation ? '!' : '') . '= ' . $filter->getValue();
}
$filterQuery = sprintf(
'cpie.store_id = %d AND cpie.attribute_id = %d AND cpie.value %s',
$this->scopeResolver->getScope()->getId(),
$attribute->getId(),
$value
);
$queryContainer->addFilter($filterQuery);
return '';
}
$ifNullCondition = $this->getConnection()->getIfNullSql('current_store.value', 'main_table.value');

$select->from(['main_table' => $table], 'entity_id')
->joinLeft(
['current_store' => $table],
'current_store.attribute_id = main_table.attribute_id AND current_store.store_id = '
. $currentStoreId,
null
)
->columns([$filter->getField() => $ifNullCondition])
->where(
'main_table.attribute_id = ?',
$attribute->getAttributeId()
)
->where('main_table.store_id = ?', \Magento\Store\Model\Store::DEFAULT_STORE_ID)
->having($query);
$value = ($isNegation ? '!' : '') . '= ' . $filter->getValue();
}
$filterQuery = sprintf(
'%1$s.value %2$s',
$alias,
$value
);
return $filterQuery;
} else {
$select = $this->connection->select();
$ifNullCondition = $this->connection->getIfNullSql('current_store.value', 'main_table.value');

$select->from(['main_table' => $table], 'entity_id')
->joinLeft(
['current_store' => $table],
'current_store.attribute_id = main_table.attribute_id AND current_store.store_id = '
. $currentStoreId,
null
)
->columns([$filter->getField() => $ifNullCondition])
->where(
'main_table.attribute_id = ?',
$attribute->getAttributeId()
)
->where('main_table.store_id = ?', \Magento\Store\Model\Store::DEFAULT_STORE_ID)
->having($query);
}

return 'search_index.entity_id IN (
select entity_id from ' . $this->conditionManager->wrapBrackets($select) . ' as filter
)';
}

/**
* @return AdapterInterface
*/
private function getConnection()
{
return $this->resource->getConnection(Resource::DEFAULT_READ_RESOURCE);
}
}
33 changes: 10 additions & 23 deletions app/code/Magento/CatalogSearch/Model/Search/IndexBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,33 @@ class IndexBuilder implements IndexBuilderInterface
*/
private $conditionManager;

/**
* @var TableMapper
*/
private $tableMapper;

/**
* @param \Magento\Framework\App\Resource $resource
* @param ScopeConfigInterface $config
* @param StoreManagerInterface $storeManager
* @param ConditionManager $conditionManager
* @param IndexScopeResolver $scopeResolver
* @param TableMapper $tableMapper
*/
public function __construct(
Resource $resource,
ScopeConfigInterface $config,
StoreManagerInterface $storeManager,
ConditionManager $conditionManager,
IndexScopeResolver $scopeResolver
IndexScopeResolver $scopeResolver,
TableMapper $tableMapper
) {
$this->resource = $resource;
$this->config = $config;
$this->storeManager = $storeManager;
$this->conditionManager = $conditionManager;
$this->scopeResolver = $scopeResolver;
$this->tableMapper = $tableMapper;
}

/**
Expand All @@ -89,19 +97,7 @@ public function build(RequestInterface $request)
[]
);

if ($this->isNeedToAddFilters($request)) {
$select
->joinLeft(
['category_index' => $this->resource->getTableName('catalog_category_product_index')],
'search_index.entity_id = category_index.product_id',
[]
)
->joinLeft(
['cpie' => $this->resource->getTableName('catalog_product_index_eav')],
'search_index.entity_id = cpie.entity_id AND search_index.attribute_id = cpie.attribute_id',
[]
);
}
$select = $this->tableMapper->addTables($select, $request);

$select = $this->processDimensions($request, $select);

Expand Down Expand Up @@ -185,15 +181,6 @@ private function getSelect()
return $this->getReadConnection()->select();
}

/**
* @param RequestInterface $request
* @return bool
*/
private function isNeedToAddFilters(RequestInterface $request)
{
return $this->hasFilters($request->getQuery());
}

/**
* @param QueryInterface $query
* @return bool
Expand Down
Loading

0 comments on commit 4b149ca

Please sign in to comment.