Skip to content

Commit 5b6121b

Browse files
merge magento/2.4-develop into magento-tsg/2.4-develop-pr39
2 parents ea532db + 134ef81 commit 5b6121b

File tree

34 files changed

+1558
-296
lines changed

34 files changed

+1558
-296
lines changed

app/code/Magento/CatalogUrlRewrite/Model/Category/Plugin/Store/View.php

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*
2020
* @see \Magento\Store\Model\ResourceModel\Store
2121
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
22-
* @package Magento\CatalogUrlRewrite\Model\Category\Plugin\Store
2322
*/
2423
class View
2524
{
@@ -39,7 +38,7 @@ class View
3938
protected $productFactory;
4039

4140
/**
42-
* @var \Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator
41+
* @var CategoryUrlRewriteGenerator
4342
*/
4443
protected $categoryUrlRewriteGenerator;
4544

@@ -75,6 +74,8 @@ public function __construct(
7574
}
7675

7776
/**
77+
* Setter for Orig Store data
78+
*
7879
* @param \Magento\Store\Model\ResourceModel\Store $object
7980
* @param AbstractModel $store
8081
* @return void
@@ -100,14 +101,13 @@ public function afterSave(
100101
\Magento\Store\Model\ResourceModel\Store $store
101102
) {
102103
if ($this->origStore->isObjectNew() || $this->origStore->dataHasChangedFor('group_id')) {
103-
if (!$this->origStore->isObjectNew()) {
104-
$this->urlPersist->deleteByData([UrlRewrite::STORE_ID => $this->origStore->getId()]);
105-
}
106-
107-
$this->urlPersist->replace(
108-
$this->generateCategoryUrls($this->origStore->getRootCategoryId(), $this->origStore->getId())
104+
$categoryRewriteUrls = $this->generateCategoryUrls(
105+
$this->origStore->getRootCategoryId(),
106+
$this->origStore->getId()
109107
);
110108

109+
$this->urlPersist->replace($categoryRewriteUrls);
110+
111111
$this->urlPersist->replace(
112112
$this->generateProductUrls(
113113
$this->origStore->getWebsiteId(),
@@ -139,33 +139,34 @@ protected function generateProductUrls($websiteId, $originWebsiteId, $storeId)
139139
->addAttributeToSelect(['name', 'url_path', 'url_key', 'visibility'])
140140
->addWebsiteFilter($websiteIds);
141141
foreach ($collection as $product) {
142-
$product->setStoreId($storeId);
143142
/** @var \Magento\Catalog\Model\Product $product */
144-
$urls = array_merge(
145-
$urls,
146-
$this->productUrlRewriteGenerator->generate($product)
147-
);
143+
$product->setStoreId($storeId);
144+
$urls[] = $this->productUrlRewriteGenerator->generate($product);
148145
}
146+
$urls = array_merge([], ...$urls);
147+
149148
return $urls;
150149
}
151150

152151
/**
152+
* Generate url rewrites for categories
153+
*
153154
* @param int $rootCategoryId
154155
* @param int $storeId
155156
* @return array
156157
*/
157158
protected function generateCategoryUrls($rootCategoryId, $storeId)
158159
{
159160
$urls = [];
160-
$categories = $this->categoryFactory->create()->getCategories($rootCategoryId, 1, false, true);
161+
$categories = $this->categoryFactory->create()->getCategories($rootCategoryId, 1, false, true, false);
162+
$categories->setStoreId($storeId);
161163
foreach ($categories as $category) {
162-
/** @var \Magento\Catalog\Model\Category $category */
164+
/** @var Category $category */
163165
$category->setStoreId($storeId);
164-
$urls = array_merge(
165-
$urls,
166-
$this->categoryUrlRewriteGenerator->generate($category)
167-
);
166+
$urls[] = $this->categoryUrlRewriteGenerator->generate($category);
168167
}
168+
$urls = array_merge([], ...$urls);
169+
169170
return $urls;
170171
}
171172

app/code/Magento/CatalogUrlRewrite/Test/Unit/Model/Category/Plugin/Store/ViewTest.php

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

88
namespace Magento\CatalogUrlRewrite\Test\Unit\Model\Category\Plugin\Store;
99

10+
use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection;
1011
use Magento\Catalog\Model\Category;
1112
use Magento\Catalog\Model\CategoryFactory;
1213
use Magento\Catalog\Model\Product;
@@ -87,6 +88,9 @@ class ViewTest extends TestCase
8788
*/
8889
private $productMock;
8990

91+
/**
92+
* @inheritdoc
93+
*/
9094
protected function setUp(): void
9195
{
9296
$this->objectManager = new ObjectManager($this);
@@ -139,7 +143,12 @@ protected function setUp(): void
139143
);
140144
}
141145

142-
public function testAfterSave()
146+
/**
147+
* Test after save
148+
*
149+
* @return void
150+
*/
151+
public function testAfterSave(): void
143152
{
144153
$origStoreMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
145154
->disableOriginalConstructor()
@@ -155,9 +164,16 @@ public function testAfterSave()
155164
$this->abstractModelMock->expects($this->any())
156165
->method('isObjectNew')
157166
->willReturn(true);
167+
$categoryCollection = $this->getMockBuilder(CategoryCollection::class)
168+
->disableOriginalConstructor()
169+
->setMethods(['getIterator'])
170+
->getMock();
171+
$categoryCollection->expects($this->any())
172+
->method('getIterator')
173+
->willReturn(new \ArrayIterator([]));
158174
$this->categoryMock->expects($this->once())
159175
->method('getCategories')
160-
->willReturn([]);
176+
->willReturn($categoryCollection);
161177
$this->categoryFactoryMock->expects($this->once())
162178
->method('create')
163179
->willReturn($this->categoryMock);
@@ -191,7 +207,12 @@ public function testAfterSave()
191207
);
192208
}
193209

194-
public function testAfterDelete()
210+
/**
211+
* Test after delete
212+
*
213+
* @return void
214+
*/
215+
public function testAfterDelete(): void
195216
{
196217
$this->urlPersistMock->expects($this->once())
197218
->method('deleteByData');

app/code/Magento/Checkout/Controller/Cart/Add.php

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
1010
use Magento\Catalog\Api\ProductRepositoryInterface;
1111
use Magento\Checkout\Model\Cart as CustomerCart;
12+
use Magento\Framework\App\ResponseInterface;
13+
use Magento\Framework\Controller\ResultInterface;
1214
use Magento\Framework\Exception\NoSuchEntityException;
1315

1416
/**
@@ -77,7 +79,7 @@ protected function _initProduct()
7779
/**
7880
* Add product to shopping cart action
7981
*
80-
* @return \Magento\Framework\Controller\Result\Redirect
82+
* @return ResponseInterface|ResultInterface
8183
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
8284
*/
8385
public function execute()
@@ -90,7 +92,6 @@ public function execute()
9092
}
9193

9294
$params = $this->getRequest()->getParams();
93-
9495
try {
9596
if (isset($params['qty'])) {
9697
$filter = new \Zend_Filter_LocalizedToNormalized(
@@ -104,9 +105,7 @@ public function execute()
104105
$product = $this->_initProduct();
105106
$related = $this->getRequest()->getParam('related_product');
106107

107-
/**
108-
* Check product availability
109-
*/
108+
/** Check product availability */
110109
if (!$product) {
111110
return $this->goBack();
112111
}
@@ -115,7 +114,6 @@ public function execute()
115114
if (!empty($related)) {
116115
$this->cart->addProductsByIds(explode(',', $related));
117116
}
118-
119117
$this->cart->save();
120118

121119
/**
@@ -127,21 +125,25 @@ public function execute()
127125
);
128126

129127
if (!$this->_checkoutSession->getNoCartRedirect(true)) {
130-
if (!$this->cart->getQuote()->getHasError()) {
131-
if ($this->shouldRedirectToCart()) {
132-
$message = __(
133-
'You added %1 to your shopping cart.',
134-
$product->getName()
135-
);
136-
$this->messageManager->addSuccessMessage($message);
137-
} else {
138-
$this->messageManager->addComplexSuccessMessage(
139-
'addCartSuccessMessage',
140-
[
141-
'product_name' => $product->getName(),
142-
'cart_url' => $this->getCartUrl(),
143-
]
144-
);
128+
if ($this->shouldRedirectToCart()) {
129+
$message = __(
130+
'You added %1 to your shopping cart.',
131+
$product->getName()
132+
);
133+
$this->messageManager->addSuccessMessage($message);
134+
} else {
135+
$this->messageManager->addComplexSuccessMessage(
136+
'addCartSuccessMessage',
137+
[
138+
'product_name' => $product->getName(),
139+
'cart_url' => $this->getCartUrl(),
140+
]
141+
);
142+
}
143+
if ($this->cart->getQuote()->getHasError()) {
144+
$errors = $this->cart->getQuote()->getErrors();
145+
foreach ($errors as $error) {
146+
$this->messageManager->addErrorMessage($error->getText());
145147
}
146148
}
147149
return $this->goBack(null, $product);
@@ -161,7 +163,6 @@ public function execute()
161163
}
162164

163165
$url = $this->_checkoutSession->getRedirectUrl(true);
164-
165166
if (!$url) {
166167
$url = $this->_redirect->getRedirectUrl($this->getCartUrl());
167168
}
@@ -175,14 +176,16 @@ public function execute()
175176
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
176177
return $this->goBack();
177178
}
179+
180+
return $this->getResponse();
178181
}
179182

180183
/**
181184
* Resolve response
182185
*
183186
* @param string $backUrl
184187
* @param \Magento\Catalog\Model\Product $product
185-
* @return $this|\Magento\Framework\Controller\Result\Redirect
188+
* @return ResponseInterface|ResultInterface
186189
*/
187190
protected function goBack($backUrl = null, $product = null)
188191
{
@@ -205,6 +208,8 @@ protected function goBack($backUrl = null, $product = null)
205208
$this->getResponse()->representJson(
206209
$this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($result)
207210
);
211+
212+
return $this->getResponse();
208213
}
209214

210215
/**

app/code/Magento/Checkout/view/frontend/web/js/view/form/element/email.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,6 @@ define([
192192
* @returns {Boolean} - initial visibility state.
193193
*/
194194
resolveInitialPasswordVisibility: function () {
195-
if (checkoutData.getInputFieldEmailValue() !== '' && checkoutData.getCheckedEmailValue() === '') {
196-
return true;
197-
}
198-
199195
if (checkoutData.getInputFieldEmailValue() !== '') {
200196
return checkoutData.getInputFieldEmailValue() === checkoutData.getCheckedEmailValue();
201197
}

app/code/Magento/Checkout/view/frontend/web/template/form/element/email.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
data-bind="
2222
textInput: email,
2323
hasFocus: emailFocused,
24+
afterRender: emailHasChanged,
2425
mageInit: {'mage/trim-input':{}}"
2526
name="username"
2627
data-validate="{required:true, 'validate-email':true}"

app/code/Magento/Elasticsearch/Model/Adapter/BatchDataMapper/ProductDataMapper.php

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ private function convertToProductData(int $productId, array $indexData, int $sto
190190
$attributeValues = [$productId => $attributeValues];
191191
}
192192
$attributeValues = $this->prepareAttributeValues($productId, $attribute, $attributeValues, $storeId);
193-
$productAttributes += $this->convertAttribute($attribute, $attributeValues);
193+
$productAttributes += $this->convertAttribute($attribute, $attributeValues, $storeId);
194194
}
195195

196196
return $productAttributes;
@@ -201,9 +201,10 @@ private function convertToProductData(int $productId, array $indexData, int $sto
201201
*
202202
* @param Attribute $attribute
203203
* @param array $attributeValues
204+
* @param int $storeId
204205
* @return array
205206
*/
206-
private function convertAttribute(Attribute $attribute, array $attributeValues): array
207+
private function convertAttribute(Attribute $attribute, array $attributeValues, int $storeId): array
207208
{
208209
$productAttributes = [];
209210

@@ -212,7 +213,7 @@ private function convertAttribute(Attribute $attribute, array $attributeValues):
212213
$productAttributes[$attribute->getAttributeCode()] = $retrievedValue;
213214

214215
if ($attribute->getIsSearchable()) {
215-
$attributeLabels = $this->getValuesLabels($attribute, $attributeValues);
216+
$attributeLabels = $this->getValuesLabels($attribute, $attributeValues, $storeId);
216217
$retrievedLabel = $this->retrieveFieldValue($attributeLabels);
217218
if ($retrievedLabel) {
218219
$productAttributes[$attribute->getAttributeCode() . '_value'] = $retrievedLabel;
@@ -299,20 +300,21 @@ private function isAttributeDate(Attribute $attribute): bool
299300
*
300301
* @param Attribute $attribute
301302
* @param array $attributeValues
303+
* @param int $storeId
302304
* @return array
303305
*/
304-
private function getValuesLabels(Attribute $attribute, array $attributeValues): array
306+
private function getValuesLabels(Attribute $attribute, array $attributeValues, int $storeId): array
305307
{
306308
$attributeLabels = [];
307309

308-
$options = $this->getAttributeOptions($attribute);
310+
$options = $this->getAttributeOptions($attribute, $storeId);
309311
if (empty($options)) {
310312
return $attributeLabels;
311313
}
312314

313-
foreach ($attributeValues as $attributeValue) {
314-
if (isset($options[$attributeValue])) {
315-
$attributeLabels[] = $options[$attributeValue]->getLabel();
315+
foreach ($options as $option) {
316+
if (\in_array($option['value'], $attributeValues)) {
317+
$attributeLabels[] = $option['label'];
316318
}
317319
}
318320

@@ -323,20 +325,23 @@ private function getValuesLabels(Attribute $attribute, array $attributeValues):
323325
* Retrieve options for attribute
324326
*
325327
* @param Attribute $attribute
328+
* @param int $storeId
326329
* @return array
327330
*/
328-
private function getAttributeOptions(Attribute $attribute): array
331+
private function getAttributeOptions(Attribute $attribute, int $storeId): array
329332
{
330-
if (!isset($this->attributeOptionsCache[$attribute->getId()])) {
331-
$options = $attribute->getOptions() ?? [];
332-
$optionsByValue = [];
333-
foreach ($options as $option) {
334-
$optionsByValue[$option->getValue()] = $option;
335-
}
336-
$this->attributeOptionsCache[$attribute->getId()] = $optionsByValue;
333+
if (!isset($this->attributeOptionsCache[$storeId][$attribute->getId()])) {
334+
$attributeStoreId = $attribute->getStoreId();
335+
/**
336+
* Load array format of options.
337+
* $attribute->getOptions() loads options into data objects which can be costly.
338+
*/
339+
$options = $attribute->usesSource() ? $attribute->setStoreId($storeId)->getSource()->getAllOptions() : [];
340+
$this->attributeOptionsCache[$storeId][$attribute->getId()] = $options;
341+
$attribute->setStoreId($attributeStoreId);
337342
}
338343

339-
return $this->attributeOptionsCache[$attribute->getId()];
344+
return $this->attributeOptionsCache[$storeId][$attribute->getId()];
340345
}
341346

342347
/**

0 commit comments

Comments
 (0)