Skip to content

Commit bc9d3f6

Browse files
Merge branch '2.4-develop' into 2.4-develop-prs
2 parents 2cc56b5 + 94154e7 commit bc9d3f6

File tree

6 files changed

+111
-19
lines changed

6 files changed

+111
-19
lines changed

app/code/Magento/Catalog/view/adminhtml/web/js/components/dynamic-rows-import-custom-options.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ define([
4040
_.each(item.options, function (option) {
4141
currentOption = utils.copy(option);
4242

43-
if (currentOption.hasOwnProperty('sort_order')) {
44-
delete currentOption['sort_order'];
45-
}
46-
4743
if (currentOption.hasOwnProperty('option_id')) {
4844
delete currentOption['option_id'];
4945
}

app/code/Magento/Catalog/view/frontend/templates/product/list/toolbar/limiter.phtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
<?php if ($block->isLimitCurrent($_key)):?>
2424
selected="selected"
2525
<?php endif ?>>
26-
<?= $block->escapeHtml($localeFormatter->formatNumber((int) $_limit)) ?>
26+
<?= $block->escapeHtml(
27+
is_numeric($_limit) ? $localeFormatter->formatNumber((int) $_limit) : $_limit
28+
) ?>
2729
</option>
2830
<?php endforeach; ?>
2931
</select>

app/code/Magento/Quote/Model/Quote/Item/CartItemPersister.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function save(CartInterface $quote, CartItemInterface $item)
7575
$buyRequestData = $this->cartItemOptionProcessor->getBuyRequest($productType, $item);
7676
if (is_object($buyRequestData)) {
7777
/** Update item product options */
78-
if ($currentItem->getQty() !== $buyRequestData->getQty()) {
78+
if ($quote->getIsActive()) {
7979
$item = $quote->updateItem($itemId, $buyRequestData);
8080
}
8181
} else {

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

Lines changed: 106 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,121 @@
77

88
namespace Magento\Quote\Api;
99

10+
use Magento\Catalog\Model\Product;
11+
use Magento\Catalog\Model\Product\Option;
12+
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
13+
use Magento\Framework\Webapi\Rest\Request;
14+
use Magento\Quote\Model\Quote;
15+
use Magento\TestFramework\Helper\Bootstrap;
1016
use Magento\TestFramework\TestCase\WebapiAbstract;
1117

1218
/**
1319
* Class for testing adding and deleting items flow.
1420
*/
1521
class GuestCartAddingItemsTest extends WebapiAbstract
1622
{
17-
const SERVICE_VERSION = 'V1';
18-
const SERVICE_NAME = 'quoteGuestCartManagementV1';
19-
const RESOURCE_PATH = '/V1/guest-carts/';
23+
private const SERVICE_VERSION = 'V1';
24+
private const SERVICE_NAME = 'quoteGuestCartManagementV1';
25+
private const RESOURCE_PATH = '/V1/guest-carts/';
2026

2127
/**
2228
* @var \Magento\TestFramework\ObjectManager
2329
*/
2430
protected $objectManager;
31+
32+
/**
33+
* @var ProductResource|mixed
34+
*/
35+
private mixed $productResource;
2536

2637
protected function setUp(): void
2738
{
28-
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
39+
$this->objectManager = Bootstrap::getObjectManager();
40+
$this->productResource = $this->objectManager->get(ProductResource::class);
41+
}
42+
43+
/**
44+
* Test add to product with custom option and test with updating custom options.
45+
*
46+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php
47+
* @return void
48+
*/
49+
public function testAddtoCartWithCustomOptionsForCreatingQuoteFromEmptyCart()
50+
{
51+
$this->_markTestAsRestOnly();
52+
53+
$productId = $this->productResource->getIdBySku('simple_with_custom_options');
54+
$product = $this->objectManager->create(Product::class)->load($productId);
55+
$customOptionCollection = $this->objectManager->get(Option::class)
56+
->getProductOptionCollection($product);
57+
$customOptions = [];
58+
foreach ($customOptionCollection as $option) {
59+
$customOptions [] = [
60+
'option_id' => $option->getId(),
61+
'option_value' => $option->getType() !== 'field' ? 1 : 'test'
62+
];
63+
}
64+
65+
// Creating empty cart
66+
$serviceInfoForCreatingEmptyCart = [
67+
'rest' => [
68+
'resourcePath' => self::RESOURCE_PATH,
69+
'httpMethod' => Request::HTTP_METHOD_POST,
70+
]
71+
];
72+
$quoteId = $this->_webApiCall($serviceInfoForCreatingEmptyCart);
73+
74+
// Adding item to the cart
75+
$serviceInfoForAddingProduct = [
76+
'rest' => [
77+
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items',
78+
'httpMethod' => Request::HTTP_METHOD_POST,
79+
]
80+
];
81+
82+
$requestData = [
83+
'cartItem' => [
84+
'quote_id' => $quoteId,
85+
'sku' => 'simple_with_custom_options',
86+
'qty' => 1,
87+
'product_option' => [
88+
'extension_attributes' => [
89+
'custom_options' => $customOptions
90+
]
91+
]
92+
]
93+
];
94+
$item = $this->_webApiCall($serviceInfoForAddingProduct, $requestData);
95+
$this->assertNotEmpty($item);
96+
foreach ($customOptionCollection as $option) {
97+
$customOptions [] = [
98+
'option_id' => $option->getId(),
99+
'option_value' => $option->getType() != 'field' ? 2 : 'test2'
100+
];
101+
}
102+
$requestData = [
103+
'cartItem' => [
104+
'quote_id' => $quoteId,
105+
'sku' => 'simple_with_custom_options',
106+
'qty' => 1,
107+
'product_option' => [
108+
'extension_attributes' => [
109+
'custom_options' => $customOptions
110+
]
111+
]
112+
]
113+
];
114+
115+
// Update the item for the cart
116+
$serviceInfoForUpdateProduct = [
117+
'rest' => [
118+
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items/' . $item['item_id'],
119+
'httpMethod' => Request::HTTP_METHOD_PUT,
120+
]
121+
];
122+
123+
$item = $this->_webApiCall($serviceInfoForUpdateProduct, $requestData);
124+
$this->assertNotEmpty($item);
29125
}
30126

31127
/**
@@ -40,7 +136,7 @@ public function testPriceForCreatingQuoteFromEmptyCart()
40136
$serviceInfoForCreatingEmptyCart = [
41137
'rest' => [
42138
'resourcePath' => self::RESOURCE_PATH,
43-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
139+
'httpMethod' => Request::HTTP_METHOD_POST,
44140
],
45141
'soap' => [
46142
'service' => self::SERVICE_NAME,
@@ -54,7 +150,7 @@ public function testPriceForCreatingQuoteFromEmptyCart()
54150
$serviceInfoForAddingProduct = [
55151
'rest' => [
56152
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items',
57-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
153+
'httpMethod' => Request::HTTP_METHOD_POST,
58154
],
59155
'soap' => [
60156
'service' => GuestCartItemRepositoryTest::SERVICE_NAME,
@@ -76,7 +172,7 @@ public function testPriceForCreatingQuoteFromEmptyCart()
76172
$serviceInfoForDeleteProduct = [
77173
'rest' => [
78174
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items/' . $item['item_id'],
79-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE,
175+
'httpMethod' => Request::HTTP_METHOD_DELETE,
80176
],
81177
'soap' => [
82178
'service' => GuestCartItemRepositoryTest::SERVICE_NAME,
@@ -93,7 +189,7 @@ public function testPriceForCreatingQuoteFromEmptyCart()
93189
$serviceInfoForAddingProduct = [
94190
'rest' => [
95191
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items',
96-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
192+
'httpMethod' => Request::HTTP_METHOD_POST,
97193
],
98194
'soap' => [
99195
'service' => GuestCartItemRepositoryTest::SERVICE_NAME,
@@ -112,8 +208,8 @@ public function testPriceForCreatingQuoteFromEmptyCart()
112208
$this->assertNotEmpty($item);
113209
$this->assertEquals($item['price'], 10);
114210

115-
/** @var \Magento\Quote\Model\Quote $quote */
116-
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
211+
/** @var Quote $quote */
212+
$quote = $this->objectManager->create(Quote::class);
117213
$quote->load($quoteId);
118214
$quote->delete();
119215
}

dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_custom_options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
'use_config_manage_stock' => 1,
3636
'qty' => 100,
3737
'is_qty_decimal' => 0,
38-
'is_in_stock' => 1,
38+
'is_in_stock' => 2,
3939
]
4040
)->setCanSaveCustomOptions(true)
4141
->setHasOptions(true);

dev/tests/js/jasmine/tests/app/code/Magento/Catalog/adminhtml/js/components/dynamic-rows-import-custom-options.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ define([
2626
data = [{
2727
'options': [
2828
{
29-
'sort_order': 1,
3029
'option_id': 1,
3130
'option_type_id': 1,
3231
'values': [{
@@ -36,7 +35,6 @@ define([
3635
}]
3736
},
3837
{
39-
'sort_order': 2,
4038
'option_id': 2,
4139
'option_type_id': 2,
4240
'values': [{

0 commit comments

Comments
 (0)