Skip to content

Commit 388f819

Browse files
committed
Merge branch 'develop' of github.com:magento/magento2ce into MAGNIMEX-SPRINT2
2 parents 3d780ff + 16d73f7 commit 388f819

File tree

62 files changed

+1836
-299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1836
-299
lines changed

app/code/Magento/Backend/view/adminhtml/templates/widget/grid.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ $numColumns = sizeof($block->getColumns());
3131

3232
<div class="admin__data-grid-header admin__data-grid-toolbar">
3333
<?php $massActionAvailable = $block->getChildBlock('grid.massaction') && $block->getChildBlock('grid.massaction')->isAvailable() ?>
34-
<?php if ($block->getPagerVisibility() || $block->getExportTypes() || $block->getChildBlock('grid.columnSet')->getFilterVisibility()): ?>
34+
<?php if ($block->getPagerVisibility() || $block->getExportTypes() || $block->getChildBlock('grid.columnSet')->getFilterVisibility() || $massActionAvailable): ?>
3535
<div class="admin__data-grid-header-row">
3636
<?php if ($massActionAvailable): ?>
3737
<?php echo $block->getMainButtonsHtml() ? '<div class="admin__filter-actions">' . $block->getMainButtonsHtml() . '</div>' : ''; ?>

app/code/Magento/Backend/view/adminhtml/templates/widget/grid/extended.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ $numColumns = sizeof($block->getColumns());
3030
<?php else: ?>
3131
<?php echo $block->getLayout()->getMessagesBlock()->getGroupedHtml() ?>
3232
<?php endif; ?>
33-
<?php if ($block->getPagerVisibility() || $block->getExportTypes() || $block->getFilterVisibility()): ?>
34-
<?php $massActionAvailable = $block->getMassactionBlock() && $block->getMassactionBlock()->isAvailable() ?>
33+
<?php $massActionAvailable = $block->getMassactionBlock() && $block->getMassactionBlock()->isAvailable() ?>
34+
<?php if ($block->getPagerVisibility() || $block->getExportTypes() || $block->getFilterVisibility() || $massActionAvailable): ?>
3535
<div class="admin__data-grid-header admin__data-grid-toolbar">
3636
<div class="admin__data-grid-header-row">
3737
<?php if ($massActionAvailable): ?>

app/code/Magento/Catalog/Block/Adminhtml/Product/Attribute/Edit/Tab/Front.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ protected function _prepareForm()
224224
)
225225
);
226226

227+
$this->setForm($form);
227228
$form->setValues($attributeObject->getData());
228229
$this->propertyLocker->lock($form);
229-
$this->setForm($form);
230230
return parent::_prepareForm();
231231
}
232232
}

app/code/Magento/Catalog/Model/Product.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,8 @@ public function getTypeId()
598598
*/
599599
public function getStatus()
600600
{
601-
if ($this->_getData(self::STATUS) === null) {
602-
$this->setData(self::STATUS, \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
603-
}
604-
return $this->_getData(self::STATUS);
601+
$status = $this->_getData(self::STATUS);
602+
return $status !== null ? $status : \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED;
605603
}
606604

607605
/**
@@ -1003,6 +1001,9 @@ public function afterDeleteCommit()
10031001
*/
10041002
protected function _afterLoad()
10051003
{
1004+
if (!$this->hasData(self::STATUS)) {
1005+
$this->setData(self::STATUS, \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
1006+
}
10061007
parent::_afterLoad();
10071008
/**
10081009
* Load product options
@@ -2306,8 +2307,8 @@ public function getIdentities()
23062307
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
23072308
}
23082309
}
2309-
if ($this->getOrigData('status') > $this->getData('status')) {
2310-
foreach ($this->getData('category_ids') as $categoryId) {
2310+
if ($this->getOrigData('status') != $this->getData('status')) {
2311+
foreach ($this->getCategoryIds() as $categoryId) {
23112312
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
23122313
}
23132314
}

app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Catalog\Model\Product;
1212
use Magento\Framework\Api\Data\ImageContentInterface;
1313
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
14+
use Magento\Catalog\Model\Product\Attribute\Source\Status as Status;
1415

1516
/**
1617
* Product Test
@@ -157,6 +158,11 @@ class ProductTest extends \PHPUnit_Framework_TestCase
157158
*/
158159
protected $entityCollectionProviderMock;
159160

161+
/**
162+
* @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject
163+
*/
164+
protected $eventManagerMock;
165+
160166
/**
161167
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
162168
*/
@@ -204,7 +210,7 @@ public function setUp()
204210
->method('getAreaCode')
205211
->will($this->returnValue(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE));
206212

207-
$eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface');
213+
$this->eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface');
208214
$actionValidatorMock = $this->getMock(
209215
'\Magento\Framework\Model\ActionValidator\RemoveAction',
210216
[],
@@ -220,7 +226,9 @@ public function setUp()
220226
['getEventDispatcher', 'getCacheManager', 'getAppState', 'getActionValidator'], [], '', false
221227
);
222228
$contextMock->expects($this->any())->method('getAppState')->will($this->returnValue($stateMock));
223-
$contextMock->expects($this->any())->method('getEventDispatcher')->will($this->returnValue($eventManagerMock));
229+
$contextMock->expects($this->any())
230+
->method('getEventDispatcher')
231+
->will($this->returnValue($this->eventManagerMock));
224232
$contextMock->expects($this->any())
225233
->method('getCacheManager')
226234
->will($this->returnValue($cacheInterfaceMock));
@@ -499,16 +507,20 @@ public function testGetCategoryIds()
499507
$this->assertEquals([], $this->model->getCategoryIds());
500508
}
501509

510+
public function testGetStatusInitial()
511+
{
512+
$this->assertEquals(Status::STATUS_ENABLED, $this->model->getStatus());
513+
}
514+
502515
public function testGetStatus()
503516
{
504517
$this->model->setStatus(null);
505-
$expected = \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED;
506-
$this->assertEquals($expected, $this->model->getStatus());
518+
$this->assertEquals(Status::STATUS_ENABLED, $this->model->getStatus());
507519
}
508520

509521
public function testIsInStock()
510522
{
511-
$this->model->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
523+
$this->model->setStatus(Status::STATUS_ENABLED);
512524
$this->assertTrue($this->model->isInStock());
513525
}
514526

@@ -605,12 +617,12 @@ public function testGetIdentities($expected, $origData, $data, $isDeleted = fals
605617
public function getIdentitiesProvider()
606618
{
607619
return [
608-
[
620+
'no changes' => [
609621
['catalog_product_1'],
610622
['id' => 1, 'name' => 'value', 'category_ids' => [1]],
611623
['id' => 1, 'name' => 'value', 'category_ids' => [1]],
612624
],
613-
[
625+
'new product' => [
614626
['catalog_product_1', 'catalog_category_product_1'],
615627
null,
616628
[
@@ -621,24 +633,57 @@ public function getIdentitiesProvider()
621633
'is_changed_categories' => true
622634
]
623635
],
624-
[
625-
[0 => 'catalog_product_1', 1 => 'catalog_category_product_1'],
636+
'status and category change' => [
637+
[0 => 'catalog_product_1', 1 => 'catalog_category_product_1', 2 => 'catalog_category_product_2'],
626638
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 2],
627-
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
639+
[
640+
'id' => 1,
641+
'name' => 'value',
642+
'category_ids' => [2],
643+
'status' => 1,
644+
'affected_category_ids' => [1, 2],
645+
'is_changed_categories' => true
646+
],
628647
],
629-
[
630-
[0 => 'catalog_product_1'],
631-
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
632-
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 2],
648+
'status change only' => [
649+
[0 => 'catalog_product_1', 1 => 'catalog_category_product_7'],
650+
['id' => 1, 'name' => 'value', 'category_ids' => [7], 'status' => 1],
651+
['id' => 1, 'name' => 'value', 'category_ids' => [7], 'status' => 2],
633652
],
634-
[
653+
'status changed, category unassigned' => [
654+
[0 => 'catalog_product_1', 1 => 'catalog_category_product_5'],
655+
['id' => 1, 'name' => 'value', 'category_ids' => [5], 'status' => 2],
656+
[
657+
'id' => 1,
658+
'name' => 'value',
659+
'category_ids' => [],
660+
'status' => 1,
661+
'is_changed_categories' => true,
662+
'affected_category_ids' => [5]
663+
],
664+
],
665+
'no status changes' => [
635666
[0 => 'catalog_product_1'],
636-
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 2],
637-
['id' => 1, 'name' => 'value', 'category_ids' => [], 'status' => 1],
667+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
668+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
638669
]
639670
];
640671
}
641672

673+
public function testStatusAfterLoad()
674+
{
675+
$this->resource->expects($this->once())->method('load')->with($this->model, 1, null);
676+
$this->eventManagerMock->expects($this->exactly(4))->method('dispatch');
677+
$this->model->load(1);
678+
$this->assertEquals(
679+
Status::STATUS_ENABLED,
680+
$this->model->getData(\Magento\Catalog\Model\Product::STATUS)
681+
);
682+
$this->assertFalse($this->model->hasDataChanges());
683+
$this->model->setStatus(Status::STATUS_DISABLED);
684+
$this->assertTrue($this->model->hasDataChanges());
685+
}
686+
642687
/**
643688
* Test retrieving price Info
644689
*/

app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Field/Resolver.php

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,63 @@
55
*/
66
namespace Magento\CatalogSearch\Model\Adapter\Mysql\Field;
77

8+
use Magento\Catalog\Model\Resource\Product\Attribute\Collection as AttributeCollection;
9+
use Magento\Framework\Search\Adapter\Mysql\Field\FieldFactory;
10+
use Magento\Framework\Search\Adapter\Mysql\Field\FieldInterface;
811
use Magento\Framework\Search\Adapter\Mysql\Field\ResolverInterface;
912

1013
class Resolver implements ResolverInterface
1114
{
15+
/**
16+
* @var AttributeCollection
17+
*/
18+
private $attributeCollection;
19+
/**
20+
* @var FieldFactory
21+
*/
22+
private $fieldFactory;
23+
24+
/**
25+
* @param AttributeCollection $attributeCollection
26+
* @param FieldFactory $fieldFactory
27+
*/
28+
public function __construct(
29+
AttributeCollection $attributeCollection,
30+
FieldFactory $fieldFactory
31+
) {
32+
$this->attributeCollection = $attributeCollection;
33+
$this->fieldFactory = $fieldFactory;
34+
}
35+
1236
/**
1337
* {@inheritdoc}
1438
*/
15-
public function resolve($fields)
39+
public function resolve(array $fields)
1640
{
17-
return 'data_index';
41+
$resolvedFields = [];
42+
foreach ($fields as $field) {
43+
if ('*' === $field) {
44+
$resolvedFields = [
45+
$this->fieldFactory->create(
46+
[
47+
'attributeId' => null,
48+
'column' => 'data_index',
49+
'type' => FieldInterface::TYPE_FULLTEXT
50+
]
51+
)
52+
];
53+
break;
54+
}
55+
$attribute = $this->attributeCollection->getItemByColumnValue('attribute_code', $field);
56+
$attributeId = $attribute ? $attribute->getId() : 0;
57+
$resolvedFields[$field] = $this->fieldFactory->create(
58+
[
59+
'attributeId' => $attributeId,
60+
'column' => 'data_index',
61+
'type' => FieldInterface::TYPE_FULLTEXT
62+
]
63+
);
64+
}
65+
return $resolvedFields;
1866
}
1967
}

app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Filter/Preprocessor.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\DB\Adapter\AdapterInterface;
1212
use Magento\Framework\Search\Adapter\Mysql\ConditionManager;
1313
use Magento\Framework\Search\Adapter\Mysql\Filter\PreprocessorInterface;
14+
use Magento\Framework\Search\Adapter\Mysql\Query\QueryContainer;
1415
use Magento\Framework\Search\Request\FilterInterface;
1516

1617
class Preprocessor implements PreprocessorInterface
@@ -65,24 +66,24 @@ public function __construct(
6566
* {@inheritdoc}
6667
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
6768
*/
68-
public function process(FilterInterface $filter, $isNegation, $query)
69+
public function process(FilterInterface $filter, $isNegation, $query, QueryContainer $queryContainer)
6970
{
70-
return $resultQuery = $this->processQueryWithField($filter, $isNegation, $query);
71+
return $resultQuery = $this->processQueryWithField($filter, $isNegation, $query, $queryContainer);
7172
}
7273

7374
/**
7475
* @param FilterInterface $filter
7576
* @param bool $isNegation
7677
* @param string $query
78+
* @param QueryContainer $queryContainer
7779
* @return string
78-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
7980
*/
80-
private function processQueryWithField(FilterInterface $filter, $isNegation, $query)
81+
private function processQueryWithField(FilterInterface $filter, $isNegation, $query, QueryContainer $queryContainer)
8182
{
8283
$currentStoreId = $this->scopeResolver->getScope()->getId();
8384

8485
$attribute = $this->config->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $filter->getField());
85-
$select = $this->getSelect();
86+
$select = $this->getConnection()->select();
8687
$table = $attribute->getBackendTable();
8788
if ($filter->getField() == 'price') {
8889
$query = str_replace('price', 'min_price', $query);
@@ -96,17 +97,23 @@ private function processQueryWithField(FilterInterface $filter, $isNegation, $qu
9697
->where($query);
9798
} else {
9899
if ($filter->getType() == FilterInterface::TYPE_TERM) {
99-
$field = $filter->getField();
100-
$mapper = function ($value) use ($field, $isNegation) {
101-
return ($isNegation ? '-' : '') . $this->attributePrefix . $field . '_' . $value;
102-
};
103100
if (is_array($filter->getValue())) {
104-
$value = implode(' ', array_map($mapper, $filter->getValue()));
101+
$value = sprintf(
102+
'%s IN (%s)',
103+
($isNegation ? 'NOT' : ''),
104+
implode(',', $filter->getValue())
105+
);
105106
} else {
106-
$value = $mapper($filter->getValue());
107+
$value = ($isNegation ? '!' : '') . '= ' . $filter->getValue();
107108
}
108-
109-
return 'MATCH (data_index) AGAINST (' . $this->getConnection()->quote($value) . ' IN BOOLEAN MODE)';
109+
$filterQuery = sprintf(
110+
'cpie.store_id = %d AND cpie.attribute_id = %d AND cpie.value %s',
111+
$this->scopeResolver->getScope()->getId(),
112+
$attribute->getId(),
113+
$value
114+
);
115+
$queryContainer->addFilter($filterQuery);
116+
return '';
110117
}
111118
$ifNullCondition = $this->getConnection()->getIfNullSql('current_store.value', 'main_table.value');
112119

@@ -139,12 +146,4 @@ private function getConnection()
139146
{
140147
return $this->resource->getConnection(Resource::DEFAULT_READ_RESOURCE);
141148
}
142-
143-
/**
144-
* @return \Magento\Framework\DB\Select
145-
*/
146-
private function getSelect()
147-
{
148-
return $this->getConnection()->select();
149-
}
150149
}

0 commit comments

Comments
 (0)