Skip to content

Commit f19f727

Browse files
author
Prabhu Ram
committed
MC-22213: Implementation - Merge cart
- review fixes
1 parent 9e00108 commit f19f727

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/MergeCarts.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\GraphQl\Query\ResolverInterface;
1313
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1414
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
15+
use Magento\Quote\Api\CartRepositoryInterface;
1516

1617
/**
1718
* Merge Carts Resolver
@@ -23,13 +24,21 @@ class MergeCarts implements ResolverInterface
2324
*/
2425
private $getCartForUser;
2526

27+
/**
28+
* @var CartRepositoryInterface
29+
*/
30+
private $cartRepository;
31+
2632
/**
2733
* @param GetCartForUser $getCartForUser
34+
* @param CartRepositoryInterface $cartRepository
2835
*/
2936
public function __construct(
30-
GetCartForUser $getCartForUser
37+
GetCartForUser $getCartForUser,
38+
CartRepositoryInterface $cartRepository
3139
) {
3240
$this->getCartForUser = $getCartForUser;
41+
$this->cartRepository = $cartRepository;
3342
}
3443

3544
/**
@@ -38,7 +47,7 @@ public function __construct(
3847
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
3948
{
4049
if (empty($args['source_cart_id'])) {
41-
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
50+
throw new GraphQlInputException(__('Required parameter "source_cart_id" is missing'));
4251
}
4352

4453
if (empty($args['destination_cart_id'])) {
@@ -49,12 +58,14 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
4958
$customerMaskedCartId = $args['destination_cart_id'];
5059

5160
$currentUserId = $context->getUserId();
52-
$storeId = $storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
61+
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
5362
// passing customerId as null enforces source cart should always be a guestcart
5463
$guestCart = $this->getCartForUser->execute($guestMaskedCartId, null, $storeId);
5564
$customerCart = $this->getCartForUser->execute($customerMaskedCartId, $currentUserId, $storeId);
5665
$customerCart->merge($guestCart);
57-
66+
$guestCart->setIsActive(false);
67+
$this->cartRepository->save($customerCart);
68+
$this->cartRepository->save($guestCart);
5869
return [
5970
'model' => $customerCart,
6071
];

app/code/Magento/QuoteGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Mutation {
1919
setPaymentMethodOnCart(input: SetPaymentMethodOnCartInput): SetPaymentMethodOnCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\SetPaymentMethodOnCart")
2020
setGuestEmailOnCart(input: SetGuestEmailOnCartInput): SetGuestEmailOnCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\SetGuestEmailOnCart")
2121
setPaymentMethodAndPlaceOrder(input: SetPaymentMethodAndPlaceOrderInput): PlaceOrderOutput @deprecated(reason: "Should use setPaymentMethodOnCart and placeOrder mutations in single request.") @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetPaymentAndPlaceOrder")
22-
mergeCarts(source_cart_id: String, destination_cart_id: String): Cart! @doc(description:"Merges source cart into the destination cart") @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\MergeCarts")
22+
mergeCarts(source_cart_id: String!, destination_cart_id: String!): Cart! @doc(description:"Merges the source cart into the destination cart") @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\MergeCarts")
2323
placeOrder(input: PlaceOrderInput): PlaceOrderOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\PlaceOrder")
2424
}
2525

0 commit comments

Comments
 (0)