Skip to content

Commit e0adfa1

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-71398' into PREPARE-PR-MAGETWO-71398
2 parents 51df1fe + 543848f commit e0adfa1

File tree

2 files changed

+97
-23
lines changed

2 files changed

+97
-23
lines changed

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

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,11 @@ public function getProductAttributes($storeId, array $productIds, array $attribu
286286
{
287287
$result = [];
288288
$selects = [];
289-
$ifStoreValue = $this->connection->getCheckSql('t_store.value_id > 0', 't_store.value', 't_default.value');
289+
$ifStoreValue = $this->connection->getCheckSql(
290+
'cpe_type.value_id > 0',
291+
'cpe_type.value',
292+
'cpe_type_default.value'
293+
);
290294
$linkField = $this->metadata->getLinkField();
291295
$productLinkFieldsToEntityIdMap = $this->connection->fetchPairs(
292296
$this->connection->select()->from(
@@ -300,28 +304,43 @@ public function getProductAttributes($storeId, array $productIds, array $attribu
300304
foreach ($attributeTypes as $backendType => $attributeIds) {
301305
if ($attributeIds) {
302306
$tableName = $this->getTable('catalog_product_entity_' . $backendType);
303-
$selects[] = $this->connection->select()->from(
304-
['t_default' => $tableName],
305-
[$linkField, 'attribute_id']
306-
)->joinLeft(
307-
['t_store' => $tableName],
308-
$this->connection->quoteInto(
309-
't_default.' . $linkField . '=t_store.' . $linkField .
310-
' AND t_default.attribute_id=t_store.attribute_id' .
311-
' AND t_store.store_id = ?',
312-
$storeId
313-
),
314-
['value' => $this->unifyField($ifStoreValue, $backendType)]
315-
)->where(
316-
't_default.store_id = ?',
317-
0
318-
)->where(
319-
't_default.attribute_id IN (?)',
320-
$attributeIds
321-
)->where(
322-
't_default.' . $linkField . ' IN (?)',
323-
array_keys($productLinkFieldsToEntityIdMap)
324-
);
307+
$selects[] = $this->connection->select()
308+
->from(
309+
['cpe' => $this->getTable('catalog_product_entity')],
310+
[]
311+
)->joinInner(
312+
['cea' => $this->getTable('catalog_eav_attribute')],
313+
'',
314+
[]
315+
)->joinLeft(
316+
['cpe_type' => $tableName],
317+
$this->connection->quoteInto(
318+
'cpe. ' . $linkField . ' = cpe_type.' . $linkField . ' AND cpe_type.store_id = ? '
319+
. 'AND cea.attribute_id = cpe_type.attribute_id',
320+
$storeId
321+
),
322+
[]
323+
)->joinLeft(
324+
['cpe_type_default' => $tableName],
325+
'cpe.' . $linkField . ' = cpe_type_default.' . $linkField
326+
. ' AND cpe_type_default.store_id = 0'
327+
. ' AND cea.attribute_id = cpe_type_default.attribute_id',
328+
[]
329+
)->where(
330+
'cea.attribute_id IN (?)',
331+
$attributeIds
332+
)->where(
333+
'cpe.' . $linkField . ' IN (?)',
334+
array_keys($productLinkFieldsToEntityIdMap)
335+
)->where(
336+
'cpe_type.attribute_id IS NOT NULL OR cpe_type_default.attribute_id IS NOT NULL'
337+
)->columns(
338+
[
339+
$linkField => 'cpe.' . $linkField,
340+
'attribute_id' => 'cea.attribute_id',
341+
'value' => $this->unifyField($ifStoreValue, $backendType)
342+
]
343+
);
325344
}
326345
}
327346

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogSearch\Model\Indexer\Fulltext\Action;
7+
8+
class DataProviderTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
12+
* @magentoDataFixture Magento/Store/_files/second_website_with_two_stores.php
13+
*/
14+
public function testRebuildStoreIndexConfigurable()
15+
{
16+
/** @var $objectManager \Magento\TestFramework\ObjectManager */
17+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
18+
$repository = $objectManager->create(
19+
\Magento\Catalog\Model\ProductRepository::class
20+
);
21+
/** @var \Magento\Store\Model\Store $store */
22+
$store = $objectManager->create(
23+
\Magento\Store\Model\Store::class
24+
);
25+
$globalStoreId = $store->load('admin')->getId();
26+
$secondStoreId = $store->load('fixture_second_store')->getId();
27+
$thirdStoreId = $store->load('fixture_third_store')->getId();
28+
/** @var \Magento\Catalog\Model\Product\Action $productAction */
29+
$productAction = $objectManager->create(
30+
\Magento\Catalog\Model\Product\Action::class
31+
);
32+
33+
$product = $repository->get('simple');
34+
$productId = $product->getId();
35+
$productResource = $product->getResource();
36+
$productAction->updateWebsites([$productId], [$store->load('fixture_second_store')->getWebsiteId()], 'add');
37+
$product->setOrigData();
38+
$product->setStoreId($secondStoreId);
39+
$product->setShortDescription('short description 2 store');
40+
$productResource->save($product);
41+
42+
$this->assertEquals(
43+
'Short description',
44+
$productResource->getAttributeRawValue($productId, 'short_description', $globalStoreId)
45+
);
46+
$this->assertEquals(
47+
'short description 2 store',
48+
$productResource->getAttributeRawValue($productId, 'short_description', $secondStoreId)
49+
);
50+
$this->assertEquals(
51+
'Short description',
52+
$productResource->getAttributeRawValue($productId, 'short_description', $thirdStoreId)
53+
);
54+
}
55+
}

0 commit comments

Comments
 (0)