Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.4-develop' into ACP2E-3127
Browse files Browse the repository at this point in the history
  • Loading branch information
Chhandak.Barua authored and Chhandak.Barua committed Jul 30, 2024
2 parents 3a1a00d + 140433c commit 42d6ed0
Show file tree
Hide file tree
Showing 17 changed files with 706 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,13 @@ define([
* @returns {Object} Chainable.
*/
initElements: function (data) {
var newData = this.getNewData(data),
recordIndex;
var newData = this.getNewData(data);

this.parsePagesData(data);

if (newData.length) {
if (this.insertData().length) {
recordIndex = data.length - newData.length - 1;

_.each(newData, function (newRecord) {
this.processingAddChild(newRecord, ++recordIndex, newRecord[this.identificationProperty]);
}, this);
this.parseProcessingAddChild(data, newData);
}
}

Expand Down Expand Up @@ -181,6 +176,23 @@ define([
this.reload();
}
}, this);
},

/**
* Parse and processing the add child method to update the latest records if the record index is not a number.
*
* @param {Array} data
* @param {Array} newData
*/
parseProcessingAddChild: function (data, newData) {
let recordIndex;

recordIndex = data.length - newData.length - 1;
if (!isNaN(recordIndex)) {
_.each(newData, function (newRecord) {
this.processingAddChild(newRecord, ++recordIndex, newRecord[this.identificationProperty]);
}, this);
}
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ define([
let bundleSelections = registry.get(this.name + '.' + index + '.' + this.bundleSelectionsName);

bundleSelections.destroyChildren();
bundleSelections._elems.clear();
},

/**
Expand Down
36 changes: 34 additions & 2 deletions app/code/Magento/CatalogGraphQl/Model/Resolver/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Catalog\Model\Layer\Resolver;
use Magento\CatalogGraphQl\DataProvider\Product\SearchCriteriaBuilder;
use Magento\Framework\GraphQl\Query\Uid;
use Magento\Framework\App\ObjectManager;

/**
* Products field resolver, used for GraphQL request processing.
Expand All @@ -31,17 +33,23 @@ class Products implements ResolverInterface
*/
private $searchApiCriteriaBuilder;

/** @var Uid */
private $uidEncoder;

/**
* @param ProductQueryInterface $searchQuery
* @param SearchCriteriaBuilder|null $searchApiCriteriaBuilder
* @param Uid|null $uidEncoder
*/
public function __construct(
ProductQueryInterface $searchQuery,
SearchCriteriaBuilder $searchApiCriteriaBuilder = null
SearchCriteriaBuilder $searchApiCriteriaBuilder = null,
Uid $uidEncoder = null
) {
$this->searchQuery = $searchQuery;
$this->searchApiCriteriaBuilder = $searchApiCriteriaBuilder ??
\Magento\Framework\App\ObjectManager::getInstance()->get(SearchCriteriaBuilder::class);
ObjectManager::getInstance()->get(SearchCriteriaBuilder::class);
$this->uidEncoder = $uidEncoder ?: ObjectManager::getInstance()->get(Uid::class);
}

/**
Expand Down Expand Up @@ -80,6 +88,10 @@ public function resolve(
'layer_type' => isset($args['search']) ? Resolver::CATALOG_LAYER_SEARCH : Resolver::CATALOG_LAYER_CATEGORY,
];

if (isset($args['filter']['category_uid'])) {
$args['filter']['category_id'] = $this->getFilterCategoryIdFromCategoryUid($args['filter']['category_uid']);
}

if (isset($args['filter']['category_id'])) {
$data['categories'] = $args['filter']['category_id']['eq'] ?? $args['filter']['category_id']['in'];
$data['categories'] = is_array($data['categories']) ? $data['categories'] : [$data['categories']];
Expand All @@ -88,6 +100,26 @@ public function resolve(
return $data;
}

/**
* Get filter category_id by category_uid
*
* @param array $filterCategoryUid
* @return array|null
*/
private function getFilterCategoryIdFromCategoryUid(array $filterCategoryUid): ?array
{
$filterCategoryId = null;
if (isset($filterCategoryUid['eq'])) {
$filterCategoryId['eq'] = $this->uidEncoder
->decode((string)$filterCategoryUid['eq']);
} elseif (!empty($filterCategoryUid['in'])) {
foreach ($filterCategoryUid['in'] as $uid) {
$filterCategoryId['in'][] = $this->uidEncoder->decode((string) $uid);
}
}
return $filterCategoryId;
}

/**
* Validate input arguments
*
Expand Down
6 changes: 3 additions & 3 deletions app/code/Magento/Quote/Model/Cart/ProductReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ProductReader implements ProductReaderInterface
/**
* @var ProductInterface[]
*/
private $productsBySku;
private array $productsBySku;

/**
* @var Config
Expand Down Expand Up @@ -65,7 +65,7 @@ public function loadProducts(array $skus, int $storeId): void
$this->productCollection->addOptionsToResult();
$this->productCollection->load();
foreach ($this->productCollection->getItems() as $productItem) {
$this->productsBySku[$productItem->getData(ProductInterface::SKU)] = $productItem;
$this->productsBySku[strtolower($productItem->getData(ProductInterface::SKU))] = $productItem;
}
}

Expand All @@ -74,6 +74,6 @@ public function loadProducts(array $skus, int $storeId): void
*/
public function getProductBySku(string $sku) : ?ProductInterface
{
return $this->productsBySku[$sku] ?? null;
return $this->productsBySku[strtolower($sku)] ?? null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value

try {
$this->updateCartItems->processCartItems($cart, $cartItems);
$this->cartRepository->save($cart);
$updatedCart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId);
$this->cartRepository->save($updatedCart);
} catch (NoSuchEntityException $e) {
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);
} catch (LocalizedException $e) {
Expand All @@ -96,7 +97,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value

return [
'cart' => [
'model' => $cart,
'model' => $updatedCart,
],
];
}
Expand Down
39 changes: 29 additions & 10 deletions app/code/Magento/Sales/Model/Service/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Magento\Framework\App\ObjectManager;
use Magento\Payment\Gateway\Command\CommandException;
use Magento\Sales\Api\OrderManagementInterface;
use Magento\Sales\Model\Order\Config;
use Magento\Sales\Model\OrderMutexInterface;
use Psr\Log\LoggerInterface;

Expand Down Expand Up @@ -66,6 +67,11 @@ class OrderService implements OrderManagementInterface
*/
private $orderMutex;

/**
* @var Config
*/
private $orderConfig;

/**
* Constructor
*
Expand All @@ -79,6 +85,7 @@ class OrderService implements OrderManagementInterface
* @param \Magento\Sales\Api\PaymentFailuresInterface $paymentFailures
* @param LoggerInterface $logger
* @param OrderMutexInterface|null $orderMutex
* @param Config|null $orderConfig
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -91,7 +98,8 @@ public function __construct(
\Magento\Sales\Model\Order\Email\Sender\OrderCommentSender $orderCommentSender,
\Magento\Sales\Api\PaymentFailuresInterface $paymentFailures,
LoggerInterface $logger,
?OrderMutexInterface $orderMutex = null
?OrderMutexInterface $orderMutex = null,
?Config $orderConfig = null
) {
$this->orderRepository = $orderRepository;
$this->historyRepository = $historyRepository;
Expand All @@ -103,6 +111,7 @@ public function __construct(
$this->paymentFailures = $paymentFailures;
$this->logger = $logger;
$this->orderMutex = $orderMutex ?: ObjectManager::getInstance()->get(OrderMutexInterface::class);
$this->orderConfig = $orderConfig ?: ObjectManager::getInstance()->get(Config::class);
}

/**
Expand Down Expand Up @@ -165,16 +174,26 @@ public function getCommentsList($id)
public function addComment($id, \Magento\Sales\Api\Data\OrderStatusHistoryInterface $statusHistory)
{
$order = $this->orderRepository->get($id);

/**
* change order status is not allowed during add comment to the order
*/
if ($statusHistory->getStatus() && $statusHistory->getStatus() != $order->getStatus()) {
throw new \Magento\Framework\Exception\LocalizedException(
__('Unable to add comment: The status "%1" is not part of the order
status history.', $statusHistory->getStatus())
);
$statuses = $this->orderConfig->getStateStatuses($order->getState());
$orderStatus = $order->getStatus();
$orderStatusHistory = $statusHistory->getStatus();
if ($orderStatusHistory) {
/**
* change order status in the scope of different state is not allowed during add comment to the order
*/
if (!array_key_exists($orderStatusHistory, $statuses)) {
throw new \Magento\Framework\Exception\LocalizedException(
__(
'Unable to add comment: The status "%1" is not part of the order status history.',
$orderStatusHistory
)
);
}
$orderStatus = $orderStatusHistory;
}
$statusHistory->setStatus($orderStatus);
$order->setStatus($orderStatus);

$order->addStatusHistory($statusHistory);
$this->orderRepository->save($order);
$notify = $statusHistory['is_customer_notified'] ?? false;
Expand Down
72 changes: 58 additions & 14 deletions app/code/Magento/Sales/Test/Unit/Model/Service/OrderServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Magento\Sales\Api\OrderStatusHistoryRepositoryInterface;
use Magento\Sales\Api\PaymentFailuresInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Config;
use Magento\Sales\Model\Order\Email\Sender\OrderCommentSender;
use Magento\Sales\Model\Order\Status\History;
use Magento\Sales\Model\OrderMutex;
Expand All @@ -28,12 +29,12 @@
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Magento\Framework\Phrase;
use Magento\Framework\Exception\LocalizedException;

/**
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyFields)
*/
class OrderServiceTest extends TestCase
{
Expand Down Expand Up @@ -112,6 +113,11 @@ class OrderServiceTest extends TestCase
*/
private $resourceConnectionMock;

/**
* @var MockObject|Config
*/
private $orderConfigMock;

protected function setUp(): void
{
$this->orderRepositoryMock = $this->getMockBuilder(
Expand Down Expand Up @@ -189,6 +195,10 @@ protected function setUp(): void
->disableOriginalConstructor()
->getMock();

$this->orderConfigMock = $this->getMockBuilder(Config::class)
->disableOriginalConstructor()
->getMock();

$this->orderService = new OrderService(
$this->orderRepositoryMock,
$this->orderStatusHistoryRepositoryMock,
Expand All @@ -199,7 +209,8 @@ protected function setUp(): void
$this->orderCommentSender,
$paymentFailures,
$logger,
new OrderMutex($this->resourceConnectionMock)
new OrderMutex($this->resourceConnectionMock),
$this->orderConfigMock
);
}

Expand Down Expand Up @@ -276,11 +287,15 @@ public function testGetCommentsList()

public function testAddComment()
{
$orderId = 123;
$clearComment = "Comment text here...";
$this->orderRepositoryMock->expects($this->once())
->method('get')
->with(123)
->willReturn($this->orderMock);
$this->mockCommentStatuses($orderId, Order::STATUS_FRAUD);
$this->orderMock->expects($this->once())
->method('setStatus')
->willReturn(Order::STATUS_FRAUD);
$this->orderStatusHistoryMock->expects($this->once())
->method('setStatus')
->willReturn(Order::STATUS_FRAUD);
$this->orderMock->expects($this->once())
->method('addStatusHistory')
->with($this->orderStatusHistoryMock)
Expand All @@ -294,23 +309,52 @@ public function testAddComment()
$this->orderCommentSender->expects($this->once())
->method('send')
->with($this->orderMock, false, $clearComment);
$this->assertTrue($this->orderService->addComment(123, $this->orderStatusHistoryMock));
$this->assertTrue($this->orderService->addComment($orderId, $this->orderStatusHistoryMock));
}

/**
* test for add comment with order status change case
*/
public function testAddCommentWithStatus()
{
$params = ['status' => 'holded'];
$inputException = new LocalizedException(
new Phrase('Unable to add comment: The status "%1" is not part of the order
status history.', $params)
$orderId = 123;
$inputException = __(
'Unable to add comment: The status "%1" is not part of the order status history.',
Order::STATE_NEW
);
$this->orderStatusHistoryMock->method('getStatus')
->willThrowException($inputException);
$this->mockCommentStatuses($orderId, Order::STATE_NEW);
$this->expectException(LocalizedException::class);
$this->orderService->addComment(123, $this->orderStatusHistoryMock);
$this->expectExceptionMessage((string)$inputException);
$this->orderService->addComment($orderId, $this->orderStatusHistoryMock);
}

/**
* @param $orderId
* @param $orderStatusHistory
*/
private function mockCommentStatuses($orderId, $orderStatusHistory): void
{
$this->orderRepositoryMock->expects($this->once())
->method('get')
->with($orderId)
->willReturn($this->orderMock);
$this->orderMock->expects($this->once())
->method('getState')
->willReturn(Order::STATE_PROCESSING);
$this->orderConfigMock->expects($this->once())
->method('getStateStatuses')
->with(Order::STATE_PROCESSING)
->willReturn([
Order::STATE_PROCESSING => 'Processing',
Order::STATUS_FRAUD => 'Suspected Fraud',
'test' => 'Tests'
]);
$this->orderMock->expects($this->once())
->method('getStatus')
->willReturn(Order::STATE_PROCESSING);
$this->orderStatusHistoryMock->expects($this->once())
->method('getStatus')
->willReturn($orderStatusHistory);
}

public function testNotify()
Expand Down
Loading

0 comments on commit 42d6ed0

Please sign in to comment.