Skip to content

Commit a8199e6

Browse files
committed
ACP2E-778: REST API: Product names in cart always use default store view values
1 parent 6f82c70 commit a8199e6

File tree

8 files changed

+117
-17
lines changed

8 files changed

+117
-17
lines changed

app/code/Magento/Quote/Model/Quote/Plugin/UpdateQuoteStoreId.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Framework\Exception\NoSuchEntityException;
1111
use Magento\Quote\Model\Quote;
12+
use Magento\Store\Model\StoreCodeInRequestPathInterface;
1213
use Magento\Store\Model\StoreManagerInterface;
1314

1415
/**
@@ -21,13 +22,21 @@ class UpdateQuoteStoreId
2122
*/
2223
private $storeManager;
2324

25+
/**
26+
* @var StoreCodeInRequestPathInterface
27+
*/
28+
private $storeCoeInRequestPath;
29+
2430
/**
2531
* @param StoreManagerInterface $storeManager
32+
* @param StoreCodeInRequestPathInterface $storeCoeInRequestPath
2633
*/
2734
public function __construct(
28-
StoreManagerInterface $storeManager
35+
StoreManagerInterface $storeManager,
36+
StoreCodeInRequestPathInterface $storeCoeInRequestPath
2937
) {
3038
$this->storeManager = $storeManager;
39+
$this->storeCoeInRequestPath = $storeCoeInRequestPath;
3140
}
3241

3342
/**
@@ -41,9 +50,11 @@ public function __construct(
4150
*/
4251
public function afterLoadByIdWithoutStore(Quote $subject, Quote $result): Quote
4352
{
44-
$storeId = $this->storeManager->getStore()->getId();
45-
if ((int)$storeId !== $result->getStoreId()) {
46-
$result->setStoreId($storeId);
53+
if ($this->storeCoeInRequestPath->hasStoreCodeInRequestPath()) {
54+
$storeId = $this->storeManager->getStore()->getId();
55+
if ((int)$storeId !== $result->getStoreId()) {
56+
$result->setStoreId($storeId);
57+
}
4758
}
4859

4960
return $result;
@@ -60,9 +71,11 @@ public function afterLoadByIdWithoutStore(Quote $subject, Quote $result): Quote
6071
*/
6172
public function afterLoadByCustomer(Quote $subject, Quote $result): Quote
6273
{
63-
$storeId = $this->storeManager->getStore()->getId();
64-
if ((int)$storeId !== $result->getStoreId()) {
65-
$result->setStoreId($storeId);
74+
if ($this->storeCoeInRequestPath->hasStoreCodeInRequestPath()) {
75+
$storeId = $this->storeManager->getStore()->getId();
76+
if ((int)$storeId !== $result->getStoreId()) {
77+
$result->setStoreId($storeId);
78+
}
6679
}
6780

6881
return $result;

app/code/Magento/Quote/etc/webapi_rest/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
<type name="Magento\Quote\Model\Quote">
2020
<plugin name="updateQuoteStoreId" type="Magento\Quote\Model\Quote\Plugin\UpdateQuoteStoreId" />
2121
</type>
22+
<preference for="Magento\Store\Model\StoreCodeInRequestPathInterface" type="Magento\Store\Model\StoreCodeInRequestPath" />
2223
</config>

app/code/Magento/Quote/etc/webapi_soap/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
<type name="Magento\Quote\Model\Quote">
1717
<plugin name="updateQuoteStoreId" type="Magento\Quote\Model\Quote\Plugin\UpdateQuoteStoreId" />
1818
</type>
19+
<preference for="Magento\Store\Model\StoreCodeInRequestPathInterface" type="Magento\Store\Model\StoreCodeInRequestPath" />
1920
</config>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Store\Model;
9+
10+
/**
11+
* Request path getters and setters for store code
12+
*/
13+
class StoreCodeInRequestPath implements StoreCodeInRequestPathInterface
14+
{
15+
/**
16+
* Flag to check store code in request path
17+
*
18+
* @var bool
19+
*/
20+
private bool $isStoreCodeInRequestPath = false;
21+
22+
/**
23+
* Set flag, if store code is in request path ot not
24+
*
25+
* @param bool $status
26+
*/
27+
public function setStoreCodeInRequestPath(bool $status): void
28+
{
29+
$this->isStoreCodeInRequestPath = $status;
30+
}
31+
32+
/**
33+
* Get flag, if request path has store code or not
34+
*
35+
* @return bool
36+
*/
37+
public function hasStoreCodeInRequestPath(): bool
38+
{
39+
return $this->isStoreCodeInRequestPath;
40+
}
41+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Store\Model;
9+
10+
/**
11+
* Store code in http request path interface
12+
*/
13+
interface StoreCodeInRequestPathInterface
14+
{
15+
/**
16+
* Set flag, if store code is in request path ot not
17+
*
18+
* @param bool $status
19+
*/
20+
public function setStoreCodeInRequestPath(bool $status): void;
21+
22+
/**
23+
* Get flag, if request path has store code or not
24+
*
25+
* @return bool
26+
*/
27+
public function hasStoreCodeInRequestPath() : bool;
28+
}

app/code/Magento/Webapi/Controller/PathProcessor.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,49 @@
88

99
use Magento\Framework\App\ObjectManager;
1010
use Magento\Framework\Exception\NoSuchEntityException;
11+
use Magento\Framework\Locale\ResolverInterface;
12+
use Magento\Store\Model\StoreCodeInRequestPathInterface;
13+
use Magento\Store\Model\StoreManagerInterface;
1114

1215
/**
1316
* Class PathProcessor
1417
*/
1518
class PathProcessor
1619
{
1720
/** Store code alias to indicate that all stores should be affected by action */
18-
const ALL_STORE_CODE = 'all';
21+
public const ALL_STORE_CODE = 'all';
1922

2023
/**
21-
* @var \Magento\Store\Model\StoreManagerInterface
24+
* @var StoreManagerInterface
2225
*/
2326
private $storeManager;
2427

2528
/**
26-
* @var \Magento\Framework\Locale\ResolverInterface
29+
* @var ResolverInterface
2730
*/
2831
private $localeResolver;
2932

3033
/**
31-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
32-
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
34+
* @var StoreCodeInRequestPathInterface
35+
*/
36+
private $storeCoeInRequestPath;
37+
38+
/**
39+
* @param StoreManagerInterface $storeManager
40+
* @param ResolverInterface|null $localeResolver
41+
* @param StoreCodeInRequestPathInterface|null $storeCoeInRequestPath
3342
*/
3443
public function __construct(
35-
\Magento\Store\Model\StoreManagerInterface $storeManager,
36-
\Magento\Framework\Locale\ResolverInterface $localeResolver = null
44+
StoreManagerInterface $storeManager,
45+
ResolverInterface $localeResolver = null,
46+
?StoreCodeInRequestPathInterface $storeCoeInRequestPath = null
3747
) {
3848
$this->storeManager = $storeManager;
3949
$this->localeResolver = $localeResolver ?: ObjectManager::getInstance()->get(
40-
\Magento\Framework\Locale\ResolverInterface::class
50+
ResolverInterface::class
51+
);
52+
$this->storeCoeInRequestPath = $storeCoeInRequestPath ?: ObjectManager::getInstance()->get(
53+
StoreCodeInRequestPathInterface::class
4154
);
4255
}
4356

@@ -68,13 +81,14 @@ public function process($pathInfo)
6881
$storeCode = current($pathParts);
6982
$stores = $this->storeManager->getStores(false, true);
7083
if (isset($stores[$storeCode])) {
84+
$this->storeCoeInRequestPath->setStoreCodeInRequestPath(true);
7185
$this->storeManager->setCurrentStore($storeCode);
7286
$this->localeResolver->emulate($this->storeManager->getStore()->getId());
73-
$path = '/' . (isset($pathParts[1]) ? $pathParts[1] : '');
87+
$path = '/' . ($pathParts[1] ?? '');
7488
} elseif ($storeCode === self::ALL_STORE_CODE) {
7589
$this->storeManager->setCurrentStore(\Magento\Store\Model\Store::ADMIN_CODE);
7690
$this->localeResolver->emulate($this->storeManager->getStore()->getId());
77-
$path = '/' . (isset($pathParts[1]) ? $pathParts[1] : '');
91+
$path = '/' . ($pathParts[1] ?? '');
7892
} else {
7993
$path = '/' . implode('/', $pathParts);
8094
}

app/code/Magento/Webapi/etc/webapi_rest/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,5 @@
8383
<type name="Magento\Store\Model\Validation\StoreCodeValidator">
8484
<plugin name="check_if_parsed_store_code_is_valid" type="Magento\Webapi\Model\Plugin\Store\Model\Validation\StoreCodeValidator"/>
8585
</type>
86+
<preference for="Magento\Store\Model\StoreCodeInRequestPathInterface" type="Magento\Store\Model\StoreCodeInRequestPath" />
8687
</config>

app/code/Magento/Webapi/etc/webapi_soap/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@
6565
<type name="Magento\Store\Model\Validation\StoreCodeValidator">
6666
<plugin name="check_if_parsed_store_code_is_valid" type="Magento\Webapi\Model\Plugin\Store\Model\Validation\StoreCodeValidator"/>
6767
</type>
68+
<preference for="Magento\Store\Model\StoreCodeInRequestPathInterface" type="Magento\Store\Model\StoreCodeInRequestPath" />
6869
</config>

0 commit comments

Comments
 (0)