Skip to content

Commit 606c3e8

Browse files
authored
Merge pull request #5268 from magento-tsg-csl3/2.4-develop-pr11
[TSG-CSL3] For 2.4 (pr11)
2 parents 2268edc + 3fb3420 commit 606c3e8

File tree

52 files changed

+1469
-280
lines changed

Some content is hidden

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

52 files changed

+1469
-280
lines changed

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ define([
269269
*/
270270
onError: function () {
271271
self.showError($t('Payment ' + self.getTitle() + ' can\'t be initialized'));
272+
self.reInitPayPal();
272273
}
273274
}, self.paypalButtonSelector);
274275
},

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/Model/ResourceModel/Product/Action.php

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Catalog\Model\ResourceModel\Product;
77

8+
use Magento\Catalog\Api\Data\ProductInterface;
89
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
910

1011
/**
@@ -14,6 +15,32 @@
1415
*/
1516
class Action extends \Magento\Catalog\Model\ResourceModel\AbstractResource
1617
{
18+
/**
19+
* @var \Magento\Framework\Stdlib\DateTime\DateTime
20+
*/
21+
private $dateTime;
22+
23+
/**
24+
* @param \Magento\Eav\Model\Entity\Context $context
25+
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
26+
* @param \Magento\Catalog\Model\Factory $modelFactory
27+
* @param \Magento\Eav\Model\Entity\Attribute\UniqueValidationInterface $uniqueValidator
28+
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
29+
* @param array $data
30+
*/
31+
public function __construct(
32+
\Magento\Eav\Model\Entity\Context $context,
33+
\Magento\Store\Model\StoreManagerInterface $storeManager,
34+
\Magento\Catalog\Model\Factory $modelFactory,
35+
\Magento\Eav\Model\Entity\Attribute\UniqueValidationInterface $uniqueValidator,
36+
\Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
37+
$data = []
38+
) {
39+
parent::__construct($context, $storeManager, $modelFactory, $data, $uniqueValidator);
40+
41+
$this->dateTime = $dateTime;
42+
}
43+
1744
/**
1845
* Initialize connection
1946
*
@@ -43,6 +70,7 @@ public function updateAttributes($entityIds, $attrData, $storeId)
4370
$object = new \Magento\Framework\DataObject();
4471
$object->setStoreId($storeId);
4572

73+
$attrData[ProductInterface::UPDATED_AT] = $this->dateTime->gmtDate();
4674
$this->getConnection()->beginTransaction();
4775
try {
4876
foreach ($attrData as $attrCode => $value) {
@@ -95,7 +123,7 @@ protected function _saveAttributeValue($object, $attribute, $value)
95123
* for default store id
96124
* In this case we clear all not default values
97125
*/
98-
if ($this->_storeManager->hasSingleStore()) {
126+
if ($this->_storeManager->hasSingleStore() && !$attribute->isStatic()) {
99127
$storeId = $this->getDefaultStoreId();
100128
$connection->delete(
101129
$table,
@@ -107,17 +135,24 @@ protected function _saveAttributeValue($object, $attribute, $value)
107135
);
108136
}
109137

110-
$data = new \Magento\Framework\DataObject(
111-
[
112-
'attribute_id' => $attribute->getAttributeId(),
113-
'store_id' => $storeId,
114-
$this->getLinkField() => $entityId,
115-
'value' => $this->_prepareValueForSave($value, $attribute),
116-
]
117-
);
138+
$data = $attribute->isStatic()
139+
? new \Magento\Framework\DataObject(
140+
[
141+
$this->getLinkField() => $entityId,
142+
$attribute->getAttributeCode() => $this->_prepareValueForSave($value, $attribute),
143+
]
144+
)
145+
: new \Magento\Framework\DataObject(
146+
[
147+
'attribute_id' => $attribute->getAttributeId(),
148+
'store_id' => $storeId,
149+
$this->getLinkField() => $entityId,
150+
'value' => $this->_prepareValueForSave($value, $attribute),
151+
]
152+
);
118153
$bind = $this->_prepareDataForTable($data, $table);
119154

120-
if ($attribute->isScopeStore()) {
155+
if ($attribute->isScopeStore() || $attribute->isStatic()) {
121156
/**
122157
* Update attribute value for store
123158
*/
@@ -143,6 +178,8 @@ protected function _saveAttributeValue($object, $attribute, $value)
143178
}
144179

145180
/**
181+
* Resolve entity id
182+
*
146183
* @param int $entityId
147184
* @return int
148185
*/

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

0 commit comments

Comments
 (0)