Skip to content

Commit

Permalink
fixup! API now allows for cart overwrite during login
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaholesz committed Jan 10, 2024
1 parent 407aff1 commit 91c6766
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ LoginInputDecorator:
type: "[Uuid!]!"
description: "Uuids of product lists that should be merged to the product lists of the user"
defaultValue: []
shouldOverwriteCustomerUserCart:
type: "Boolean!"
description: "A boolean pointer to indicate if the current customer user cart should be overwritten by the cart with cartUuid"
defaultValue: false
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,3 @@ LoginInput:
type: "Uuid"
description: "Uuid of the cart that should be merged to the cart of the user"
defaultValue: null
shouldOverwriteCustomerUserCart:
type: "Boolean"
description: "A boolean pointer to indicate if the current customer user cart should be overwritten by the cart with cartUuid"
defaultValue: false
2 changes: 1 addition & 1 deletion project-base/app/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ input LoginInput {
"Uuids of product lists that should be merged to the product lists of the user"
productListsUuids: [Uuid!]! = []
"A boolean pointer to indicate if the current customer user cart should be overwritten by the cart with cartUuid"
shouldOverwriteCustomerUserCart: Boolean = false
shouldOverwriteCustomerUserCart: Boolean! = false
}

type LoginResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public function overwriteCustomerCartWithCartByUuid(string $cartUuid, CustomerUs
$customerCart = $this->cartFacade->getCartCreateIfNotExists($customerUser, null);

$oldCart->assignCartToCustomerUser($customerUser);
$oldCart->setModifiedNow();

$this->entityManager->flush();

Expand Down
1 change: 1 addition & 0 deletions project-base/app/src/Model/Cart/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,5 +325,6 @@ public function assignCartToCustomerUser(?CustomerUser $customerUser): void
{
$this->customerUser = $customerUser;
$this->cartIdentifier = '';
$this->setModifiedNow();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,44 +98,35 @@ public function testCartIsMergedAfterLogin(): void

public function testCartIsOverwrittenAfterLogin(): void
{
/** @var \App\Model\Product\Product $anonymouslyAddedProduct */
$anonymouslyAddedProduct = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . '5');
$anonymouslyAddedProductQuantity = 6;
$this->addProductToCustomerCart($anonymouslyAddedProduct, $anonymouslyAddedProductQuantity);
/** @var \App\Model\Product\Product $productAddedToCustomerUserCart */
$productAddedToCustomerUserCart = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . '5');
$productAddedToCustomerUserCartQuantity = 6;
$this->addProductToCustomerCart($productAddedToCustomerUserCart, $productAddedToCustomerUserCartQuantity);

/** @var \App\Model\Product\Product $anonymouslyAddedProduct2 */
$anonymouslyAddedProduct2 = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . '1');
$anonymouslyAddedProductQuantity2 = 1;
$this->addProductToCustomerCart($anonymouslyAddedProduct2, $anonymouslyAddedProductQuantity2);
/** @var \App\Model\Product\Product $productAddedToCustomerUserCart */
$productAddedToCustomerUserCart2 = $this->getReference(ProductDataFixture::PRODUCT_PREFIX . '1');
$productAddedToCustomerUserCart2Quantity = 1;
$this->addProductToCustomerCart($productAddedToCustomerUserCart2, $productAddedToCustomerUserCart2Quantity);

$testCartUuid = CartDataFixture::CART_UUID;

$loginMutationWithCartUuid = 'mutation {
Login(input: {
email: "no-reply@shopsys.com"
password: "user123"
cartUuid: "' . $testCartUuid . '"
shouldOverwriteCustomerUserCart: true
}) {
tokens {
accessToken
refreshToken
}
showCartMergeInfo
}
}
';

$response = $this->getResponseDataForGraphQlType(
$this->getResponseContentForQuery($loginMutationWithCartUuid),
'Login',
$response = $this->getResponseContentForGql(
__DIR__ . '/graphql/OverwriteCartAfterLogin.graphql',
[
'email' => "no-reply@shopsys.com",
'password' => "user123",
'cartUuid' => $testCartUuid,
'shouldOverwriteCustomerUserCart' => true,
],
);

$data = $this->getResponseDataForGraphQlType($response, 'Login');

$cart = $this->findCartOfCurrentCustomer();

self::assertNotNull($cart);

self::assertFalse($response['showCartMergeInfo']);
self::assertFalse($data['showCartMergeInfo']);

$cartItems = $cart->getItems();
self::assertCount(2, $cartItems);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
mutation OverwriteCartAfterLogin(
$email: String!
$password: Password!
$cartUuid: Uuid
$shouldOverwriteCustomerUserCart: Boolean!
) {
Login(
input: {
email: $email
password: $password
cartUuid: $cartUuid
shouldOverwriteCustomerUserCart: $shouldOverwriteCustomerUserCart
}
) {
tokens {
accessToken
refreshToken
}
showCartMergeInfo
}
}
2 changes: 1 addition & 1 deletion project-base/storefront/graphql/docs/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -8621,7 +8621,7 @@ Uuids of product lists that should be merged to the product lists of the user
</tr>
<tr>
<td colspan="2" valign="top"><strong>shouldOverwriteCustomerUserCart</strong></td>
<td valign="top"><a href="#boolean">Boolean</a></td>
<td valign="top"><a href="#boolean">Boolean</a>!</td>
<td>

A boolean pointer to indicate if the current customer user cart should be overwritten by the cart with cartUuid
Expand Down
2 changes: 1 addition & 1 deletion project-base/storefront/graphql/generated/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ export type LoginInputApi = {
/** Uuids of product lists that should be merged to the product lists of the user */
productListsUuids: Array<Scalars['Uuid']['input']>;
/** A boolean pointer to indicate if the current customer user cart should be overwritten by the cart with cartUuid */
shouldOverwriteCustomerUserCart: InputMaybe<Scalars['Boolean']['input']>;
shouldOverwriteCustomerUserCart: Scalars['Boolean']['input'];
};

export type LoginResultApi = {
Expand Down
2 changes: 1 addition & 1 deletion project-base/storefront/schema.graphql.json

Large diffs are not rendered by default.

0 comments on commit 91c6766

Please sign in to comment.