Skip to content

Commit 0841891

Browse files
committed
MAGETWO-57868: Search fails with an error when used user-defined price attribute as searchable - for mainline
2 parents deb30e5 + fb6faf5 commit 0841891

File tree

142 files changed

+3480
-458
lines changed

Some content is hidden

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

142 files changed

+3480
-458
lines changed

app/code/Magento/Backend/Block/Widget/Form/Container.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ class Container extends \Magento\Backend\Block\Widget\Container
3737
* @var string
3838
*/
3939
protected $_blockGroup = 'Magento_Backend';
40+
41+
/**
42+
* @var string
43+
*/
44+
const PARAM_BLOCK_GROUP = 'block_group';
45+
46+
/**
47+
* @var string
48+
*/
49+
const PARAM_MODE = 'mode';
4050

4151
/**
4252
* @var string
@@ -49,6 +59,12 @@ class Container extends \Magento\Backend\Block\Widget\Container
4959
protected function _construct()
5060
{
5161
parent::_construct();
62+
if ($this->hasData(self::PARAM_BLOCK_GROUP)) {
63+
$this->_blockGroup = $this->_getData(self::PARAM_BLOCK_GROUP);
64+
}
65+
if ($this->hasData(self::PARAM_MODE)) {
66+
$this->_mode = $this->_getData(self::PARAM_MODE);
67+
}
5268

5369
$this->addButton(
5470
'back',

app/code/Magento/CacheInvalidate/Observer/InvalidateVarnishObserver.php

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\CacheInvalidate\Observer;
77

8+
use Magento\Framework\App\ObjectManager;
89
use Magento\Framework\Event\ObserverInterface;
910

1011
class InvalidateVarnishObserver implements ObserverInterface
@@ -21,6 +22,13 @@ class InvalidateVarnishObserver implements ObserverInterface
2122
*/
2223
protected $purgeCache;
2324

25+
/**
26+
* Invalidation tags resolver
27+
*
28+
* @var \Magento\Framework\App\Cache\Tag\Resolver
29+
*/
30+
private $tagResolver;
31+
2432
/**
2533
* @param \Magento\PageCache\Model\Config $config
2634
* @param \Magento\CacheInvalidate\Model\PurgeCache $purgeCache
@@ -42,18 +50,35 @@ public function __construct(
4250
*/
4351
public function execute(\Magento\Framework\Event\Observer $observer)
4452
{
53+
$object = $observer->getEvent()->getObject();
54+
if (!is_object($object)) {
55+
return;
56+
}
4557
if ($this->config->getType() == \Magento\PageCache\Model\Config::VARNISH && $this->config->isEnabled()) {
46-
$object = $observer->getEvent()->getObject();
47-
if ($object instanceof \Magento\Framework\DataObject\IdentityInterface) {
48-
$tags = [];
49-
$pattern = "((^|,)%s(,|$))";
50-
foreach ($object->getIdentities() as $tag) {
51-
$tags[] = sprintf($pattern, $tag);
52-
}
53-
if (!empty($tags)) {
54-
$this->purgeCache->sendPurgeRequest(implode('|', array_unique($tags)));
55-
}
58+
$bareTags = $this->getTagResolver()->getTags($object);
59+
60+
$tags = [];
61+
$pattern = "((^|,)%s(,|$))";
62+
foreach ($bareTags as $tag) {
63+
$tags[] = sprintf($pattern, $tag);
64+
}
65+
if (!empty($tags)) {
66+
$this->purgeCache->sendPurgeRequest(implode('|', array_unique($tags)));
5667
}
68+
69+
}
70+
}
71+
72+
/**
73+
* @deprecated
74+
* @return \Magento\Framework\App\Cache\Tag\Resolver
75+
*/
76+
private function getTagResolver()
77+
{
78+
if ($this->tagResolver === null) {
79+
$this->tagResolver = \Magento\Framework\App\ObjectManager::getInstance()
80+
->get(\Magento\Framework\App\Cache\Tag\Resolver::class);
5781
}
82+
return $this->tagResolver;
5883
}
5984
}

app/code/Magento/CacheInvalidate/Test/Unit/Observer/InvalidateVarnishObserverTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\CacheInvalidate\Test\Unit\Observer;
77

8+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
9+
810
class InvalidateVarnishObserverTest extends \PHPUnit_Framework_TestCase
911
{
1012
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\CacheInvalidate\Observer\InvalidateVarnishObserver */
@@ -22,11 +24,16 @@ class InvalidateVarnishObserverTest extends \PHPUnit_Framework_TestCase
2224
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\DataObject\ */
2325
protected $observerObject;
2426

27+
/** @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\App\Cache\Tag\Resolver */
28+
private $tagResolver;
29+
2530
/**
2631
* Set up all mocks and data for test
2732
*/
2833
protected function setUp()
2934
{
35+
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
36+
3037
$this->configMock = $this->getMock(
3138
\Magento\PageCache\Model\Config::class,
3239
['getType', 'isEnabled'],
@@ -39,6 +46,10 @@ protected function setUp()
3946
$this->configMock,
4047
$this->purgeCache
4148
);
49+
50+
$this->tagResolver = $this->getMock(\Magento\Framework\App\Cache\Tag\Resolver::class, [], [], '', false);
51+
$helper->setBackwardCompatibleProperty($this->model, 'tagResolver', $this->tagResolver);
52+
4253
$this->observerMock = $this->getMock(
4354
\Magento\Framework\Event\Observer::class,
4455
['getEvent'],
@@ -65,10 +76,12 @@ public function testInvalidateVarnish()
6576
)->will(
6677
$this->returnValue(\Magento\PageCache\Model\Config::VARNISH)
6778
);
79+
6880
$eventMock = $this->getMock(\Magento\Framework\Event::class, ['getObject'], [], '', false);
6981
$eventMock->expects($this->once())->method('getObject')->will($this->returnValue($this->observerObject));
7082
$this->observerMock->expects($this->once())->method('getEvent')->will($this->returnValue($eventMock));
71-
$this->observerObject->expects($this->once())->method('getIdentities')->will($this->returnValue($tags));
83+
$this->tagResolver->expects($this->once())->method('getTags')->with($this->observerObject)
84+
->will($this->returnValue($tags));
7285
$this->purgeCache->expects($this->once())->method('sendPurgeRequest')->with($pattern);
7386

7487
$this->model->execute($this->observerMock);

app/code/Magento/Catalog/Console/Command/ProductAttributesCleanUp.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
101101
$output->writeln("");
102102
$output->writeln("<info>Unused product attributes successfully cleaned up:</info>");
103103
$output->writeln("<comment> " . implode("\n ", $attributeTables) . "</comment>");
104+
return \Magento\Framework\Console\Cli::RETURN_SUCCESS;
104105
} catch (\Exception $exception) {
105106
$this->attributeResource->rollBack();
106107

107108
$output->writeln("");
108109
$output->writeln("<error>{$exception->getMessage()}</error>");
110+
// we must have an exit code higher than zero to indicate something was wrong
111+
return \Magento\Framework\Console\Cli::RETURN_FAILURE;
109112
}
110113
}
111114

app/code/Magento/Catalog/Controller/Adminhtml/Category.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ abstract class Category extends \Magento\Backend\App\Action
3131
*/
3232
protected function _initCategory($getRootInstead = false)
3333
{
34-
$categoryId = (int)$this->getRequest()->getParam('id', false);
34+
$categoryId = $this->resolveCategoryId();
3535
$storeId = (int)$this->getRequest()->getParam('store');
3636
$category = $this->_objectManager->create(\Magento\Catalog\Model\Category::class);
3737
$category->setStoreId($storeId);
@@ -62,6 +62,18 @@ protected function _initCategory($getRootInstead = false)
6262
return $category;
6363
}
6464

65+
/**
66+
* Resolve Category Id (from get or from post)
67+
*
68+
* @return int
69+
*/
70+
private function resolveCategoryId()
71+
{
72+
$categoryId = (int)$this->getRequest()->getParam('id', false);
73+
74+
return $categoryId ?: (int)$this->getRequest()->getParam('entity_id', false);
75+
}
76+
6577
/**
6678
* Build response for ajax request
6779
*

app/code/Magento/Catalog/Controller/Adminhtml/Category/Move.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function execute()
8080
}
8181

8282
if (!$error) {
83-
$this->messageManager->addSuccess(__('You moved the category'));
83+
$this->messageManager->addSuccess(__('You moved the category.'));
8484
}
8585

8686
$block->setMessages($this->messageManager->getMessages(true));

app/code/Magento/Catalog/Helper/Product/Compare.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,9 @@ public function getRemoveUrl()
228228
*/
229229
public function getPostDataRemove($product)
230230
{
231-
$listCleanUrl = $this->getEncodedUrl($this->_getUrl('catalog/product_compare'));
232231
$data = [
233-
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => $listCleanUrl,
234-
'product' => $product->getId()
232+
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => '',
233+
'product' => $product->getId(),
235234
];
236235
return $this->postHelper->getPostData($this->getRemoveUrl(), $data);
237236
}
@@ -253,9 +252,8 @@ public function getClearListUrl()
253252
*/
254253
public function getPostDataClearList()
255254
{
256-
$refererUrl = $this->_getRequest()->getServer('HTTP_REFERER');
257255
$params = [
258-
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => $this->urlEncoder->encode($refererUrl)
256+
\Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => '',
259257
];
260258
return $this->postHelper->getPostData($this->getClearListUrl(), $params);
261259
}

app/code/Magento/Catalog/Model/Indexer/Category/Product/Action/Full.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77

88
class Full extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractAction
99
{
10+
/**
11+
* Whether to use main or temporary index table
12+
*
13+
* @var bool
14+
*/
15+
protected $useTempTable = false;
16+
1017
/**
1118
* Refresh entities index
1219
*

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,7 +2274,7 @@ public function getIdentities()
22742274
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
22752275
}
22762276
}
2277-
2277+
22782278
if (($this->getOrigData('status') != $this->getData('status')) || $this->isStockStatusChanged()) {
22792279
foreach ($this->getCategoryIds() as $categoryId) {
22802280
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
@@ -2289,7 +2289,7 @@ public function getIdentities()
22892289

22902290
/**
22912291
* Check whether stock status changed
2292-
*
2292+
*
22932293
* @return bool
22942294
*/
22952295
private function isStockStatusChanged()
@@ -2307,7 +2307,7 @@ private function isStockStatusChanged()
23072307
&& ($stockItem->getIsInStock() != $stockData['is_in_stock'])
23082308
);
23092309
}
2310-
2310+
23112311
/**
23122312
* Reload PriceInfo object
23132313
*

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,15 +313,22 @@ protected function initializeProductData(array $productData, $createNew)
313313
*/
314314
private function assignProductToWebsites(\Magento\Catalog\Model\Product $product)
315315
{
316+
$websiteIds = $product->getWebsiteIds();
317+
316318
if (!$this->storeManager->hasSingleStore()) {
317-
if ($this->storeManager->getStore()->getCode() == \Magento\Store\Model\Store::ADMIN_CODE) {
318-
$websiteIds = array_keys($this->storeManager->getWebsites());
319-
} else {
320-
$websiteIds = [$this->storeManager->getStore()->getWebsiteId()];
321-
}
319+
$websiteIds = array_unique(
320+
array_merge(
321+
$websiteIds,
322+
[$this->storeManager->getStore()->getWebsiteId()]
323+
)
324+
);
325+
}
322326

323-
$product->setWebsiteIds(array_unique(array_merge($product->getWebsiteIds(), $websiteIds)));
327+
if ($this->storeManager->getStore(true)->getCode() == \Magento\Store\Model\Store::ADMIN_CODE) {
328+
$websiteIds = array_keys($this->storeManager->getWebsites());
324329
}
330+
331+
$product->setWebsiteIds($websiteIds);
325332
}
326333

327334
/**

0 commit comments

Comments
 (0)