Skip to content

Commit

Permalink
Merge pull request #7840 from magento-gl/arrows_pr_18082022
Browse files Browse the repository at this point in the history
Arrows - Bugfix Delivery
  • Loading branch information
ishakhsuvarov authored Aug 30, 2022
2 parents 5dd75c7 + b8a8c15 commit 94154e7
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ define([
_.each(item.options, function (option) {
currentOption = utils.copy(option);

if (currentOption.hasOwnProperty('sort_order')) {
delete currentOption['sort_order'];
}

if (currentOption.hasOwnProperty('option_id')) {
delete currentOption['option_id'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
<?php if ($block->isLimitCurrent($_key)):?>
selected="selected"
<?php endif ?>>
<?= $block->escapeHtml($localeFormatter->formatNumber((int) $_limit)) ?>
<?= $block->escapeHtml(
is_numeric($_limit) ? $localeFormatter->formatNumber((int) $_limit) : $_limit
) ?>
</option>
<?php endforeach; ?>
</select>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function save(CartInterface $quote, CartItemInterface $item)
$buyRequestData = $this->cartItemOptionProcessor->getBuyRequest($productType, $item);
if (is_object($buyRequestData)) {
/** Update item product options */
if ($currentItem->getQty() !== $buyRequestData->getQty()) {
if ($quote->getIsActive()) {
$item = $quote->updateItem($itemId, $buyRequestData);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,121 @@

namespace Magento\Quote\Api;

use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Option;
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
use Magento\Framework\Webapi\Rest\Request;
use Magento\Quote\Model\Quote;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\TestCase\WebapiAbstract;

/**
* Class for testing adding and deleting items flow.
*/
class GuestCartAddingItemsTest extends WebapiAbstract
{
const SERVICE_VERSION = 'V1';
const SERVICE_NAME = 'quoteGuestCartManagementV1';
const RESOURCE_PATH = '/V1/guest-carts/';
private const SERVICE_VERSION = 'V1';
private const SERVICE_NAME = 'quoteGuestCartManagementV1';
private const RESOURCE_PATH = '/V1/guest-carts/';

/**
* @var \Magento\TestFramework\ObjectManager
*/
protected $objectManager;

/**
* @var ProductResource|mixed
*/
private mixed $productResource;

protected function setUp(): void
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->objectManager = Bootstrap::getObjectManager();
$this->productResource = $this->objectManager->get(ProductResource::class);
}

/**
* Test add to product with custom option and test with updating custom options.
*
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php
* @return void
*/
public function testAddtoCartWithCustomOptionsForCreatingQuoteFromEmptyCart()
{
$this->_markTestAsRestOnly();

$productId = $this->productResource->getIdBySku('simple_with_custom_options');
$product = $this->objectManager->create(Product::class)->load($productId);
$customOptionCollection = $this->objectManager->get(Option::class)
->getProductOptionCollection($product);
$customOptions = [];
foreach ($customOptionCollection as $option) {
$customOptions [] = [
'option_id' => $option->getId(),
'option_value' => $option->getType() !== 'field' ? 1 : 'test'
];
}

// Creating empty cart
$serviceInfoForCreatingEmptyCart = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH,
'httpMethod' => Request::HTTP_METHOD_POST,
]
];
$quoteId = $this->_webApiCall($serviceInfoForCreatingEmptyCart);

// Adding item to the cart
$serviceInfoForAddingProduct = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items',
'httpMethod' => Request::HTTP_METHOD_POST,
]
];

$requestData = [
'cartItem' => [
'quote_id' => $quoteId,
'sku' => 'simple_with_custom_options',
'qty' => 1,
'product_option' => [
'extension_attributes' => [
'custom_options' => $customOptions
]
]
]
];
$item = $this->_webApiCall($serviceInfoForAddingProduct, $requestData);
$this->assertNotEmpty($item);
foreach ($customOptionCollection as $option) {
$customOptions [] = [
'option_id' => $option->getId(),
'option_value' => $option->getType() != 'field' ? 2 : 'test2'
];
}
$requestData = [
'cartItem' => [
'quote_id' => $quoteId,
'sku' => 'simple_with_custom_options',
'qty' => 1,
'product_option' => [
'extension_attributes' => [
'custom_options' => $customOptions
]
]
]
];

// Update the item for the cart
$serviceInfoForUpdateProduct = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items/' . $item['item_id'],
'httpMethod' => Request::HTTP_METHOD_PUT,
]
];

$item = $this->_webApiCall($serviceInfoForUpdateProduct, $requestData);
$this->assertNotEmpty($item);
}

/**
Expand All @@ -40,7 +136,7 @@ public function testPriceForCreatingQuoteFromEmptyCart()
$serviceInfoForCreatingEmptyCart = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH,
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
'httpMethod' => Request::HTTP_METHOD_POST,
],
'soap' => [
'service' => self::SERVICE_NAME,
Expand All @@ -54,7 +150,7 @@ public function testPriceForCreatingQuoteFromEmptyCart()
$serviceInfoForAddingProduct = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items',
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
'httpMethod' => Request::HTTP_METHOD_POST,
],
'soap' => [
'service' => GuestCartItemRepositoryTest::SERVICE_NAME,
Expand All @@ -76,7 +172,7 @@ public function testPriceForCreatingQuoteFromEmptyCart()
$serviceInfoForDeleteProduct = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items/' . $item['item_id'],
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE,
'httpMethod' => Request::HTTP_METHOD_DELETE,
],
'soap' => [
'service' => GuestCartItemRepositoryTest::SERVICE_NAME,
Expand All @@ -93,7 +189,7 @@ public function testPriceForCreatingQuoteFromEmptyCart()
$serviceInfoForAddingProduct = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items',
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
'httpMethod' => Request::HTTP_METHOD_POST,
],
'soap' => [
'service' => GuestCartItemRepositoryTest::SERVICE_NAME,
Expand All @@ -112,8 +208,8 @@ public function testPriceForCreatingQuoteFromEmptyCart()
$this->assertNotEmpty($item);
$this->assertEquals($item['price'], 10);

/** @var \Magento\Quote\Model\Quote $quote */
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
/** @var Quote $quote */
$quote = $this->objectManager->create(Quote::class);
$quote->load($quoteId);
$quote->delete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
'use_config_manage_stock' => 1,
'qty' => 100,
'is_qty_decimal' => 0,
'is_in_stock' => 1,
'is_in_stock' => 2,
]
)->setCanSaveCustomOptions(true)
->setHasOptions(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ define([
data = [{
'options': [
{
'sort_order': 1,
'option_id': 1,
'option_type_id': 1,
'values': [{
Expand All @@ -36,7 +35,6 @@ define([
}]
},
{
'sort_order': 2,
'option_id': 2,
'option_type_id': 2,
'values': [{
Expand Down

0 comments on commit 94154e7

Please sign in to comment.