Skip to content

Commit 1b21d93

Browse files
author
Vitaliy Honcharenko
committed
Merge branch 'develop' of https://github.corp.ebay.com/magento2/magento2ce into develop
2 parents dc1d806 + 16d73f7 commit 1b21d93

File tree

53 files changed

+1761
-276
lines changed

Some content is hidden

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

53 files changed

+1761
-276
lines changed

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
@@ -586,10 +586,8 @@ public function getTypeId()
586586
*/
587587
public function getStatus()
588588
{
589-
if ($this->_getData(self::STATUS) === null) {
590-
$this->setData(self::STATUS, \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
591-
}
592-
return $this->_getData(self::STATUS);
589+
$status = $this->_getData(self::STATUS);
590+
return $status !== null ? $status : \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED;
593591
}
594592

595593
/**
@@ -974,6 +972,9 @@ public function afterDeleteCommit()
974972
*/
975973
protected function _afterLoad()
976974
{
975+
if (!$this->hasData(self::STATUS)) {
976+
$this->setData(self::STATUS, \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
977+
}
977978
parent::_afterLoad();
978979
/**
979980
* Load product options
@@ -2277,8 +2278,8 @@ public function getIdentities()
22772278
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
22782279
}
22792280
}
2280-
if ($this->getOrigData('status') > $this->getData('status')) {
2281-
foreach ($this->getData('category_ids') as $categoryId) {
2281+
if ($this->getOrigData('status') != $this->getData('status')) {
2282+
foreach ($this->getCategoryIds() as $categoryId) {
22822283
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
22832284
}
22842285
}

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
@@ -156,6 +157,11 @@ class ProductTest extends \PHPUnit_Framework_TestCase
156157
*/
157158
protected $entityCollectionProviderMock;
158159

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

206-
$eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface');
212+
$this->eventManagerMock = $this->getMock('Magento\Framework\Event\ManagerInterface');
207213
$actionValidatorMock = $this->getMock(
208214
'\Magento\Framework\Model\ActionValidator\RemoveAction',
209215
[],
@@ -219,7 +225,9 @@ public function setUp()
219225
['getEventDispatcher', 'getCacheManager', 'getAppState', 'getActionValidator'], [], '', false
220226
);
221227
$contextMock->expects($this->any())->method('getAppState')->will($this->returnValue($stateMock));
222-
$contextMock->expects($this->any())->method('getEventDispatcher')->will($this->returnValue($eventManagerMock));
228+
$contextMock->expects($this->any())
229+
->method('getEventDispatcher')
230+
->will($this->returnValue($this->eventManagerMock));
223231
$contextMock->expects($this->any())
224232
->method('getCacheManager')
225233
->will($this->returnValue($cacheInterfaceMock));
@@ -415,16 +423,20 @@ public function testGetCategoryIds()
415423
$this->assertEquals([], $this->model->getCategoryIds());
416424
}
417425

426+
public function testGetStatusInitial()
427+
{
428+
$this->assertEquals(Status::STATUS_ENABLED, $this->model->getStatus());
429+
}
430+
418431
public function testGetStatus()
419432
{
420433
$this->model->setStatus(null);
421-
$expected = \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED;
422-
$this->assertEquals($expected, $this->model->getStatus());
434+
$this->assertEquals(Status::STATUS_ENABLED, $this->model->getStatus());
423435
}
424436

425437
public function testIsInStock()
426438
{
427-
$this->model->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
439+
$this->model->setStatus(Status::STATUS_ENABLED);
428440
$this->assertTrue($this->model->isInStock());
429441
}
430442

@@ -521,12 +533,12 @@ public function testGetIdentities($expected, $origData, $data, $isDeleted = fals
521533
public function getIdentitiesProvider()
522534
{
523535
return [
524-
[
536+
'no changes' => [
525537
['catalog_product_1'],
526538
['id' => 1, 'name' => 'value', 'category_ids' => [1]],
527539
['id' => 1, 'name' => 'value', 'category_ids' => [1]],
528540
],
529-
[
541+
'new product' => [
530542
['catalog_product_1', 'catalog_category_product_1'],
531543
null,
532544
[
@@ -537,24 +549,57 @@ public function getIdentitiesProvider()
537549
'is_changed_categories' => true
538550
]
539551
],
540-
[
541-
[0 => 'catalog_product_1', 1 => 'catalog_category_product_1'],
552+
'status and category change' => [
553+
[0 => 'catalog_product_1', 1 => 'catalog_category_product_1', 2 => 'catalog_category_product_2'],
542554
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 2],
543-
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
555+
[
556+
'id' => 1,
557+
'name' => 'value',
558+
'category_ids' => [2],
559+
'status' => 1,
560+
'affected_category_ids' => [1, 2],
561+
'is_changed_categories' => true
562+
],
544563
],
545-
[
546-
[0 => 'catalog_product_1'],
547-
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
548-
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 2],
564+
'status change only' => [
565+
[0 => 'catalog_product_1', 1 => 'catalog_category_product_7'],
566+
['id' => 1, 'name' => 'value', 'category_ids' => [7], 'status' => 1],
567+
['id' => 1, 'name' => 'value', 'category_ids' => [7], 'status' => 2],
549568
],
550-
[
569+
'status changed, category unassigned' => [
570+
[0 => 'catalog_product_1', 1 => 'catalog_category_product_5'],
571+
['id' => 1, 'name' => 'value', 'category_ids' => [5], 'status' => 2],
572+
[
573+
'id' => 1,
574+
'name' => 'value',
575+
'category_ids' => [],
576+
'status' => 1,
577+
'is_changed_categories' => true,
578+
'affected_category_ids' => [5]
579+
],
580+
],
581+
'no status changes' => [
551582
[0 => 'catalog_product_1'],
552-
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 2],
553-
['id' => 1, 'name' => 'value', 'category_ids' => [], 'status' => 1],
583+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
584+
['id' => 1, 'name' => 'value', 'category_ids' => [1], 'status' => 1],
554585
]
555586
];
556587
}
557588

589+
public function testStatusAfterLoad()
590+
{
591+
$this->resource->expects($this->once())->method('load')->with($this->model, 1, null);
592+
$this->eventManagerMock->expects($this->exactly(4))->method('dispatch');
593+
$this->model->load(1);
594+
$this->assertEquals(
595+
Status::STATUS_ENABLED,
596+
$this->model->getData(\Magento\Catalog\Model\Product::STATUS)
597+
);
598+
$this->assertFalse($this->model->hasDataChanges());
599+
$this->model->setStatus(Status::STATUS_DISABLED);
600+
$this->assertTrue($this->model->hasDataChanges());
601+
}
602+
558603
/**
559604
* Test retrieving price Info
560605
*/

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
}

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/Full.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -651,15 +651,20 @@ protected function prepareProductIndex($indexData, $productData, $storeId)
651651
$attributeCode = $attribute->getAttributeCode();
652652

653653
if (isset($productData[$attributeCode])) {
654+
655+
if ('store_id' === $attributeCode) {
656+
continue;
657+
}
658+
654659
$value = $this->getAttributeValue($attribute->getId(), $productData[$attributeCode], $storeId);
655660
if ($value) {
656-
if (isset($index[$attributeCode])) {
657-
if (!is_array($index[$attributeCode])) {
658-
$index[$attributeCode] = [$index[$attributeCode]];
661+
if (isset($index[$attribute->getId()])) {
662+
if (!is_array($index[$attribute->getId()])) {
663+
$index[$attribute->getId()] = [$index[$attribute->getId()]];
659664
}
660-
$index[$attributeCode][] = $value;
665+
$index[$attribute->getId()][] = $value;
661666
} else {
662-
$index[$attributeCode] = $value;
667+
$index[$attribute->getId()] = $value;
663668
}
664669
}
665670
}
@@ -669,12 +674,10 @@ protected function prepareProductIndex($indexData, $productData, $storeId)
669674
foreach ($attributeData as $attributeId => $attributeValue) {
670675
$value = $this->getAttributeValue($attributeId, $attributeValue, $storeId);
671676
if (!empty($value)) {
672-
$attributeCode = $this->getSearchableAttribute($attributeId)->getAttributeCode();
673-
674-
if (isset($index[$attributeCode])) {
675-
$index[$attributeCode][$entityId] = $value;
677+
if (isset($index[$attributeId])) {
678+
$index[$attributeId][$entityId] = $value;
676679
} else {
677-
$index[$attributeCode] = [$entityId => $value];
680+
$index[$attributeId] = [$entityId => $value];
678681
}
679682
}
680683
}

0 commit comments

Comments
 (0)