Skip to content

Commit 9d60824

Browse files
committed
ACP2E-778: REST API: Product names in cart always use default store view values
1 parent b7ee736 commit 9d60824

File tree

2 files changed

+87
-2
lines changed

2 files changed

+87
-2
lines changed

app/code/Magento/Quote/Model/ResourceModel/Quote.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ public function loadByCustomerId($quote, $customerId)
104104
$data = $connection->fetchRow($select);
105105

106106
if ($data) {
107-
//Prevent current Store Id to be overridden
108-
if ($quote->getStoreId() !== null) {
107+
//Prevent current StoreId of the quote to be overridden
108+
$currentStoreId = $quote->getStoreId();
109+
if ($currentStoreId !== null && $currentStoreId !== $data['store_id']) {
109110
unset($data['store_id']);
110111
}
111112

dev/tests/api-functional/testsuite/Magento/Quote/Api/CartAddingItemsTest.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,4 +308,88 @@ private function getServiceInfoAddToCart(string $token): array
308308
]
309309
];
310310
}
311+
312+
/**
313+
* Test for product name in different store view
314+
*
315+
* @magentoConfigFixture web/url/use_store 1
316+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_multistore.php
317+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
318+
*
319+
* @param string $storeCode
320+
* @param string $expectedProductName
321+
*
322+
* @return void
323+
* @dataProvider dataProviderForMultiStoreView
324+
* @throws \Magento\Framework\Exception\AuthenticationException
325+
*/
326+
public function testForProductNameAsPerStoreView(string $storeCode, string $expectedProductName): void
327+
{
328+
$this->_markTestAsRestOnly();
329+
330+
// Get customer ID token
331+
/** @var CustomerTokenServiceInterface $customerTokenService */
332+
$customerTokenService = $this->objectManager->create(CustomerTokenServiceInterface::class);
333+
$token = $customerTokenService->createCustomerAccessToken(
334+
335+
'password'
336+
);
337+
338+
// Creating empty cart for registered customer.
339+
$serviceInfo = [
340+
'rest' => [
341+
'resourcePath' => '/V1/carts/mine',
342+
'httpMethod' => Request::HTTP_METHOD_POST,
343+
'token' => $token
344+
]
345+
];
346+
$quoteId = $this->_webApiCall($serviceInfo);
347+
$this->assertGreaterThan(0, $quoteId);
348+
349+
// Add product to cart
350+
$requestData = [
351+
'cartItem' => [
352+
'quote_id' => $quoteId,
353+
'sku' => 'simple',
354+
'qty' => 1
355+
]
356+
];
357+
$this->_webApiCall($this->getServiceInfoAddToCart($token), $requestData);
358+
359+
// Fetch Cart info
360+
$serviceInfo = [
361+
'rest' => [
362+
'resourcePath' => '/V1/carts/mine',
363+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
364+
'token' => $token
365+
]
366+
];
367+
/** @var \Magento\Quote\Api\Data\CartInterface $cart */
368+
$cart = $this->_webApiCall($serviceInfo, [], null, $storeCode);
369+
370+
$actualProductName = '';
371+
$carts = $cart['items'];
372+
foreach ($carts as $item) {
373+
$actualProductName = $item['name'];
374+
break;
375+
}
376+
$this->assertEquals($expectedProductName, $actualProductName);
377+
}
378+
379+
/**
380+
* @return array
381+
*/
382+
public function dataProviderForMultiStoreView(): array
383+
{
384+
return [
385+
'defaultStoreView' => [
386+
'default',
387+
'Simple Product One'
388+
],
389+
'secondStoreView' => [
390+
'fixturestore',
391+
'StoreTitle'
392+
],
393+
];
394+
}
311395
}

0 commit comments

Comments
 (0)