Skip to content

Commit f5b36d4

Browse files
committed
Merge remote-tracking branch 'origin/MC-30794' into 2.4-develop-pr11
2 parents 15142f8 + 49eceb8 commit f5b36d4

File tree

12 files changed

+145
-37
lines changed

12 files changed

+145
-37
lines changed

app/code/Magento/Catalog/Block/Ui/ProductViewCounter.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
namespace Magento\Catalog\Block\Ui;
77

88
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Catalog\Model\ProductRenderFactory;
10+
use Magento\Catalog\Model\ProductRepository;
911
use Magento\Catalog\Ui\DataProvider\Product\ProductRenderCollectorComposite;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\App\ObjectManager;
14+
use Magento\Framework\EntityManager\Hydrator;
1015
use Magento\Framework\Registry;
1116
use Magento\Framework\Serialize\SerializerInterface;
1217
use Magento\Framework\Url;
1318
use Magento\Framework\View\Element\Template;
1419
use Magento\Store\Model\Store;
15-
use Magento\Catalog\Model\ProductRenderFactory;
16-
use Magento\Catalog\Model\ProductRepository;
17-
use Magento\Framework\EntityManager\Hydrator;
1820
use Magento\Store\Model\StoreManager;
1921

2022
/**
@@ -25,6 +27,7 @@
2527
*
2628
* @api
2729
* @since 101.1.0
30+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2831
*/
2932
class ProductViewCounter extends Template
3033
{
@@ -68,6 +71,13 @@ class ProductViewCounter extends Template
6871
*/
6972
private $registry;
7073

74+
/**
75+
* Core store config
76+
*
77+
* @var ScopeConfigInterface
78+
*/
79+
private $scopeConfig;
80+
7181
/**
7282
* @param Template\Context $context
7383
* @param ProductRepository $productRepository
@@ -78,6 +88,8 @@ class ProductViewCounter extends Template
7888
* @param SerializerInterface $serialize
7989
* @param Url $url
8090
* @param Registry $registry
91+
* @param ScopeConfigInterface|null $scopeConfig
92+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8193
*/
8294
public function __construct(
8395
Template\Context $context,
@@ -88,7 +100,8 @@ public function __construct(
88100
Hydrator $hydrator,
89101
SerializerInterface $serialize,
90102
Url $url,
91-
Registry $registry
103+
Registry $registry,
104+
?ScopeConfigInterface $scopeConfig = null
92105
) {
93106
parent::__construct($context);
94107
$this->productRepository = $productRepository;
@@ -99,6 +112,7 @@ public function __construct(
99112
$this->serialize = $serialize;
100113
$this->url = $url;
101114
$this->registry = $registry;
115+
$this->scopeConfig = $scopeConfig ?? ObjectManager::getInstance()->get(ScopeConfigInterface::class);
102116
}
103117

104118
/**
@@ -116,14 +130,19 @@ public function getCurrentProductData()
116130
{
117131
/** @var ProductInterface $product */
118132
$product = $this->registry->registry('product');
133+
$productsScope = $this->scopeConfig->getValue(
134+
'catalog/recently_products/scope',
135+
\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE
136+
);
119137
/** @var Store $store */
120138
$store = $this->storeManager->getStore();
121139

122140
if (!$product || !$product->getId()) {
123141
return $this->serialize->serialize([
124142
'items' => [],
125143
'store' => $store->getId(),
126-
'currency' => $store->getCurrentCurrency()->getCode()
144+
'currency' => $store->getCurrentCurrency()->getCode(),
145+
'productCurrentScope' => $productsScope
127146
]);
128147
}
129148

@@ -140,7 +159,8 @@ public function getCurrentProductData()
140159
$product->getId() => $data
141160
],
142161
'store' => $store->getId(),
143-
'currency' => $store->getCurrentCurrency()->getCode()
162+
'currency' => $store->getCurrentCurrency()->getCode(),
163+
'productCurrentScope' => $productsScope
144164
];
145165

146166
return $this->serialize->serialize($currentProductData);

app/code/Magento/Catalog/CustomerData/CompareProducts.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
namespace Magento\Catalog\CustomerData;
77

88
use Magento\Customer\CustomerData\SectionSourceInterface;
9+
use Magento\Framework\App\Config\ScopeConfigInterface;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Exception\LocalizedException;
912

13+
/**
14+
* Catalog Product Compare Widget
15+
*/
1016
class CompareProducts implements SectionSourceInterface
1117
{
1218
/**
@@ -24,23 +30,33 @@ class CompareProducts implements SectionSourceInterface
2430
*/
2531
private $outputHelper;
2632

33+
/**
34+
* Core store config
35+
*
36+
* @var ScopeConfigInterface
37+
*/
38+
private $scopeConfig;
39+
2740
/**
2841
* @param \Magento\Catalog\Helper\Product\Compare $helper
2942
* @param \Magento\Catalog\Model\Product\Url $productUrl
3043
* @param \Magento\Catalog\Helper\Output $outputHelper
44+
* @param ScopeConfigInterface|null $scopeConfig
3145
*/
3246
public function __construct(
3347
\Magento\Catalog\Helper\Product\Compare $helper,
3448
\Magento\Catalog\Model\Product\Url $productUrl,
35-
\Magento\Catalog\Helper\Output $outputHelper
49+
\Magento\Catalog\Helper\Output $outputHelper,
50+
?ScopeConfigInterface $scopeConfig = null
3651
) {
3752
$this->helper = $helper;
3853
$this->productUrl = $productUrl;
3954
$this->outputHelper = $outputHelper;
55+
$this->scopeConfig = $scopeConfig ?? ObjectManager::getInstance()->get(ScopeConfigInterface::class);
4056
}
4157

4258
/**
43-
* {@inheritdoc}
59+
* @inheritdoc
4460
*/
4561
public function getSectionData()
4662
{
@@ -54,18 +70,26 @@ public function getSectionData()
5470
}
5571

5672
/**
73+
* Get the list of compared product items
74+
*
5775
* @return array
76+
* @throws LocalizedException
5877
*/
5978
protected function getItems()
6079
{
6180
$items = [];
81+
$productsScope = $this->scopeConfig->getValue(
82+
'catalog/recently_products/scope',
83+
\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE
84+
);
6285
/** @var \Magento\Catalog\Model\Product $item */
6386
foreach ($this->helper->getItemCollection() as $item) {
6487
$items[] = [
6588
'id' => $item->getId(),
6689
'product_url' => $this->productUrl->getUrl($item),
6790
'name' => $this->outputHelper->productAttribute($item, $item->getName(), 'name'),
6891
'remove_url' => $this->helper->getPostDataRemove($item),
92+
'productScope' => $productsScope
6993
];
7094
}
7195
return $items;

app/code/Magento/Catalog/Test/Unit/Block/Ui/ProductViewCounterTest.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66

77
namespace Magento\Catalog\Test\Unit\Block\Ui;
88

9+
use Magento\Catalog\Api\Data\ProductInterface;
10+
use Magento\Catalog\Api\Data\ProductRenderInterface;
11+
use Magento\Catalog\Block\Ui\ProductViewCounter;
12+
use Magento\Catalog\Model\ProductRenderFactory;
913
use Magento\Catalog\Model\ProductRepository;
1014
use Magento\Catalog\Ui\DataProvider\Product\ProductRenderCollectorComposite;
11-
use Magento\Catalog\Model\ProductRenderFactory;
15+
use Magento\Framework\App\Config\ScopeConfigInterface;
1216
use Magento\Framework\EntityManager\Hydrator;
17+
use Magento\Framework\Registry;
1318
use Magento\Framework\Serialize\SerializerInterface;
1419
use Magento\Framework\Url;
1520
use Magento\Framework\View\Element\Template\Context;
16-
use Magento\Store\Model\StoreManager;
1721
use Magento\Store\Model\Store;
18-
use Magento\Framework\Registry;
19-
use Magento\Catalog\Api\Data\ProductInterface;
20-
use Magento\Catalog\Api\Data\ProductRenderInterface;
21-
use Magento\Catalog\Block\Ui\ProductViewCounter;
22+
use Magento\Store\Model\StoreManager;
2223

2324
/**
2425
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -70,6 +71,11 @@ class ProductViewCounterTest extends \PHPUnit\Framework\TestCase
7071
*/
7172
private $storeManagerMock;
7273

74+
/**
75+
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
76+
*/
77+
private $scopeConfigMock;
78+
7379
/**
7480
* @var ProductRenderFactory|\PHPUnit_Framework_MockObject_MockObject
7581
*/
@@ -104,6 +110,9 @@ protected function setUp()
104110
$this->storeManagerMock = $this->getMockBuilder(StoreManager::class)
105111
->disableOriginalConstructor()
106112
->getMock();
113+
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
114+
->disableOriginalConstructor()
115+
->getMock();
107116

108117
$this->productViewCounter = new ProductViewCounter(
109118
$this->contextMock,
@@ -114,7 +123,8 @@ protected function setUp()
114123
$this->hydratorMock,
115124
$this->serializeMock,
116125
$this->urlMock,
117-
$this->registryMock
126+
$this->registryMock,
127+
$this->scopeConfigMock
118128
);
119129
}
120130

app/code/Magento/Catalog/Test/Unit/CustomerData/CompareProductsTest.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Catalog\Model\Product;
1616
use Magento\Catalog\Model\Product\Url;
1717
use Magento\Catalog\Model\ResourceModel\Product\Compare\Item\Collection;
18+
use Magento\Framework\App\Config\ScopeConfigInterface;
1819
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1920

2021
class CompareProductsTest extends \PHPUnit\Framework\TestCase
@@ -44,6 +45,11 @@ class CompareProductsTest extends \PHPUnit\Framework\TestCase
4445
*/
4546
private $objectManagerHelper;
4647

48+
/**
49+
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
50+
*/
51+
private $scopeConfigMock;
52+
4753
/**
4854
* @var array
4955
*/
@@ -65,6 +71,9 @@ protected function setUp()
6571
$this->outputHelperMock = $this->getMockBuilder(Output::class)
6672
->disableOriginalConstructor()
6773
->getMock();
74+
$this->scopeConfigMock = $this->getMockBuilder(ScopeConfigInterface::class)
75+
->disableOriginalConstructor()
76+
->getMock();
6877

6978
$this->objectManagerHelper = new ObjectManagerHelper($this);
7079

@@ -73,7 +82,8 @@ protected function setUp()
7382
[
7483
'helper' => $this->helperMock,
7584
'productUrl' => $this->productUrlMock,
76-
'outputHelper' => $this->outputHelperMock
85+
'outputHelper' => $this->outputHelperMock,
86+
'scopeConfig' => $this->scopeConfigMock
7787
]
7888
);
7989
}
@@ -109,6 +119,7 @@ private function prepareProductsWithCorrespondingMocks(array $dataSet) : array
109119
$urlMap = [];
110120
$outputMap = [];
111121
$helperMap = [];
122+
$productScopeMap = [];
112123

113124
$count = count($dataSet);
114125

@@ -119,6 +130,7 @@ private function prepareProductsWithCorrespondingMocks(array $dataSet) : array
119130
$outputMap[] = [$item, $data['name'], 'name', 'productName#' . $data['id']];
120131
$helperMap[] = [$item, 'http://remove.url/' . $data['id']];
121132
$urlMap[] = [$item, [], 'http://product.url/' . $data['id']];
133+
$productScopeMap[] = [$item, 'store-' . $data['id']];
122134
}
123135

124136
$this->productUrlMock->expects($this->exactly($count))
@@ -193,19 +205,22 @@ public function testGetSectionData()
193205
'id' => 1,
194206
'product_url' => 'http://product.url/1',
195207
'name' => 'productName#1',
196-
'remove_url' => 'http://remove.url/1'
208+
'remove_url' => 'http://remove.url/1',
209+
'productScope' => null
197210
],
198211
[
199212
'id' => 2,
200213
'product_url' => 'http://product.url/2',
201214
'name' => 'productName#2',
202-
'remove_url' => 'http://remove.url/2'
215+
'remove_url' => 'http://remove.url/2',
216+
'productScope' => null
203217
],
204218
[
205219
'id' => 3,
206220
'product_url' => 'http://product.url/3',
207221
'name' => 'productName#3',
208-
'remove_url' => 'http://remove.url/3'
222+
'remove_url' => 'http://remove.url/3',
223+
'productScope' => null
209224
]
210225
]
211226
],
@@ -276,7 +291,8 @@ public function testGetSectionDataSingleItem()
276291
'id' => 12345,
277292
'product_url' => 'http://product.url/12345',
278293
'name' => 'productName#12345',
279-
'remove_url' => 'http://remove.url/12345'
294+
'remove_url' => 'http://remove.url/12345',
295+
'productScope' => null
280296
]
281297
]
282298
],

app/code/Magento/Catalog/Ui/DataProvider/Product/Listing/DataProvider.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
use Magento\Framework\Api\FilterBuilder;
1010
use Magento\Framework\Api\Search\SearchCriteriaBuilder;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
1112
use Magento\Framework\App\RequestInterface;
1213
use Magento\Framework\View\Element\UiComponent\DataProvider\Reporting;
1314
use Magento\Store\Model\StoreManager;
1415

1516
/**
1617
* Provide information about current store and currency for product listing ui component
18+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1719
*/
1820
class DataProvider extends \Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider
1921
{
@@ -22,6 +24,13 @@ class DataProvider extends \Magento\Framework\View\Element\UiComponent\DataProvi
2224
*/
2325
private $storeManager;
2426

27+
/**
28+
* Core store config
29+
*
30+
* @var ScopeConfigInterface
31+
*/
32+
private $scopeConfig;
33+
2534
/**
2635
* @param string $name
2736
* @param Reporting $reporting
@@ -56,6 +65,7 @@ public function __construct(
5665

5766
$this->name = $name;
5867
$this->storeManager = $storeManager;
68+
$this->scopeConfig = $data['config']['scopeConfig'];
5969
}
6070

6171
/**
@@ -65,9 +75,13 @@ public function getData()
6575
{
6676
$data = [];
6777
$store = $this->storeManager->getStore();
78+
$productsScope = $this->scopeConfig->getValue(
79+
'catalog/recently_products/scope',
80+
\Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE
81+
);
6882
$data['store'] = $store->getId();
6983
$data['currency'] = $store->getCurrentCurrency()->getCode();
70-
84+
$data['productCurrentScope'] = $productsScope;
7185
return $data;
7286
}
7387
}

app/code/Magento/Catalog/view/frontend/ui_component/widget_recently_compared.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<item name="namespace" xsi:type="string">recently_compared_product</item>
3333
<item name="provider" xsi:type="string">compare-products</item>
3434
</item>
35+
<item name="scopeConfig" xsi:type="object">Magento\Framework\App\Config\ScopeConfigInterface</item>
3536
</item>
3637
</argument>
3738
</argument>

app/code/Magento/Catalog/view/frontend/ui_component/widget_recently_viewed.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<item name="identifiersConfig" xsi:type="array">
3232
<item name="namespace" xsi:type="string">recently_viewed_product</item>
3333
</item>
34+
<item name="scopeConfig" xsi:type="object">Magento\Framework\App\Config\ScopeConfigInterface</item>
3435
</item>
3536
</argument>
3637
</argument>

0 commit comments

Comments
 (0)