Skip to content

Commit

Permalink
Merge pull request #26 from magento-dragons/PR
Browse files Browse the repository at this point in the history
[DRAGONS] Bugs
  • Loading branch information
dkvashninbay committed Oct 22, 2015
2 parents 0be91a5 + f34eb55 commit e0a56a7
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\CatalogSearch\Model\Adapter\Mysql\Filter;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
use Magento\CatalogSearch\Model\Search\TableMapper;
use Magento\Eav\Model\Config;
use Magento\Framework\App\ResourceConnection;
Expand Down Expand Up @@ -97,7 +98,7 @@ public function process(FilterInterface $filter, $isNegation, $query)
*/
private function processQueryWithField(FilterInterface $filter, $isNegation, $query)
{
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
/** @var Attribute $attribute */
$attribute = $this->config->getAttribute(Product::ENTITY, $filter->getField());
if ($filter->getField() === 'price') {
$resultQuery = str_replace(
Expand All @@ -114,24 +115,16 @@ private function processQueryWithField(FilterInterface $filter, $isNegation, $qu
$this->connection->quoteIdentifier($alias . '.' . $attribute->getAttributeCode()),
$query
);
} elseif ($filter->getType() === FilterInterface::TYPE_TERM
&& in_array($attribute->getFrontendInput(), ['select', 'multiselect'], true)
} elseif (
$filter->getType() === FilterInterface::TYPE_TERM &&
in_array($attribute->getFrontendInput(), ['select', 'multiselect'], true)
) {
$alias = $this->tableMapper->getMappingAlias($filter);
if (is_array($filter->getValue())) {
$value = sprintf(
'%s IN (%s)',
($isNegation ? 'NOT' : ''),
implode(',', $filter->getValue())
);
} else {
$value = ($isNegation ? '!' : '') . '= ' . $filter->getValue();
}
$resultQuery = sprintf(
'%1$s.value %2$s',
$alias,
$value
);
$resultQuery = $this->processTermSelect($filter, $isNegation);
} elseif (
$filter->getType() === FilterInterface::TYPE_RANGE &&
in_array($attribute->getBackendType(), ['decimal', 'int'], true)
) {
$resultQuery = $this->processRangeNumeric($filter, $query, $attribute);
} else {
$table = $attribute->getBackendTable();
$select = $this->connection->select();
Expand Down Expand Up @@ -161,4 +154,57 @@ private function processQueryWithField(FilterInterface $filter, $isNegation, $qu

return $resultQuery;
}

/**
* @param FilterInterface $filter
* @param string $query
* @param Attribute $attribute
* @return string
*/
private function processRangeNumeric(FilterInterface $filter, $query, $attribute)
{
$tableSuffix = $attribute->getBackendType() === 'decimal' ? '_decimal' : '';
$table = $this->resource->getTableName("catalog_product_index_eav{$tableSuffix}");
$select = $this->connection->select();

$currentStoreId = $this->scopeResolver->getScope()->getId();

$select->from(['main_table' => $table], 'entity_id')
->columns([$filter->getField() => 'main_table.value'])
->where('main_table.attribute_id = ?', $attribute->getAttributeId())
->where('main_table.store_id = ?', $currentStoreId)
->having($query);

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

return $resultQuery;
}

/**
* @param FilterInterface $filter
* @param bool $isNegation
* @return string
*/
private function processTermSelect(FilterInterface $filter, $isNegation)
{
$alias = $this->tableMapper->getMappingAlias($filter);
if (is_array($filter->getValue())) {
$value = sprintf(
'%s IN (%s)',
($isNegation ? 'NOT' : ''),
implode(',', $filter->getValue())
);
} else {
$value = ($isNegation ? '!' : '') . '= ' . $filter->getValue();
}
$resultQuery = sprintf(
'%1$s.value %2$s',
$alias,
$value
);

return $resultQuery;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@
<arguments>
<argument name="id" xsi:type="string">grouped_grid_popup</argument>
</arguments>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="entity_id">
<block class="Magento\Backend\Block\Widget\Grid\Column" as="entity_ids">
<arguments>
<argument name="header" xsi:type="string" translate="true">ID</argument>
<argument name="type" xsi:type="string">skip-list</argument>
<argument name="renderer" xsi:type="string">Magento\Backend\Block\Widget\Grid\Column\Renderer\Checkbox</argument>
<argument name="name" xsi:type="string">entity_ids</argument>
<argument name="index" xsi:type="string">entity_id</argument>
</arguments>
</block>
<block class="Magento\Backend\Block\Widget\Grid\Column" as="entity_id">
<arguments>
<argument name="header" xsi:type="string" translate="true">ID</argument>
<argument name="index" xsi:type="string">entity_id</argument>
</arguments>
</block>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ define([

if (!target.is('input')) {
target.closest('[data-role=row]')
.find('[data-column=entity_id] input')
.find('[data-column=entity_ids] input')
.prop('checked', function (element, value) {
return !value;
})
Expand All @@ -142,7 +142,7 @@ define([

popup.on(
'change',
'[data-role=row] [data-column=entity_id] input',
'[data-role=row] [data-column=entity_ids] input',
$.proxy(function (event) {
var element = $(event.target),
product = {};
Expand Down Expand Up @@ -175,12 +175,12 @@ define([
return $(element).val();
}).toArray();
ajaxSettings.data.filter = $.extend(ajaxSettings.data.filter || {}, {
'entity_id': ids
'entity_ids': ids
});
})
.on('gridajax', function (event, ajaxRequest) {
ajaxRequest.done(function () {
popup.find('[data-role=row] [data-column=entity_id] input')
popup.find('[data-role=row] [data-column=entity_ids] input')
.each(function (index, element) {
var $element = $(element);
$element.prop('checked', !!selectedProductList[$element.val()]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@
<constraint name="Magento\Catalog\Test\Constraint\AssertProductVisibleInCategory" />
<constraint name="Magento\Bundle\Test\Constraint\AssertBundleProductPage" />
<constraint name="Magento\Catalog\Test\Constraint\AssertProductInStock" />
<constraint name="Magento\Bundle\Test\Constraint\AssertGroupedPriceOnBundleProductPage" />
<constraint name="Magento\Bundle\Test\Constraint\AssertBundleItemsOnProductPage" />
<constraint name="Magento\Bundle\Test\Constraint\AssertBundlePriceView" />
<constraint name="Magento\Bundle\Test\Constraint\AssertBundlePriceType" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function processAssert(
. "\nActual: " . $actualPrice . "\n"
);
}
$checkoutCartPage->getTotalsBlock()->waitForShippingPriceBlock();
$actualPrices['sub_total'] = $checkoutCartPage->getTotalsBlock()->getSubtotal();
$actualPrices['grand_total'] = $checkoutCartPage->getTotalsBlock()->getGrandTotal();
$expectedPrices['sub_total'] = $cartPrice['sub_total'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,14 @@ public function waitForUpdatedTotals()
sleep(1);
$this->waitForElementNotVisible($this->blockWaitElement);
}

/**
* Wait for shipping block to appear
*
* @return bool|null
*/
public function waitForShippingPriceBlock()
{
$this->waitForElementVisible($this->shippingPriceBlockSelector, Locator::SELECTOR_CSS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Grid extends GridInterface
*
* @var string
*/
protected $selectItem = '[data-column=entity_id] input';
protected $selectItem = '[data-column=entity_ids] input';

/**
* Press 'Add Selected Products' button
Expand Down

0 comments on commit e0a56a7

Please sign in to comment.