Skip to content

Commit

Permalink
GraphQL-37: [Cart Operations] Manage Cart Items
Browse files Browse the repository at this point in the history
-- Refactoring
  • Loading branch information
naydav committed Mar 5, 2019
1 parent 19cc640 commit faacfe0
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 72 deletions.
58 changes: 0 additions & 58 deletions app/code/Magento/QuoteGraphQl/Model/Cart/UpdateCartItems.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ public function __construct(
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (!isset($args['input']['cart_id'])) {
if (!isset($args['input']['cart_id']) || empty($args['input']['cart_id'])) {
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
}
$maskedCartId = $args['input']['cart_id'];

if (!isset($args['input']['coupon_code'])) {
if (!isset($args['input']['coupon_code']) || empty($args['input']['coupon_code'])) {
throw new GraphQlInputException(__('Required parameter "coupon_code" is missing'));
}
$couponCode = $args['input']['coupon_code'];
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/QuoteGraphQl/Model/Resolver/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct(
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (!isset($args['cart_id'])) {
if (!isset($args['cart_id']) || empty($args['cart_id'])) {
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
}
$maskedCartId = $args['cart_id'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct(
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (!isset($args['input']['cart_id'])) {
if (!isset($args['input']['cart_id']) || empty($args['input']['cart_id'])) {
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
}
$maskedCartId = $args['input']['cart_id'];
Expand Down
20 changes: 10 additions & 10 deletions app/code/Magento/QuoteGraphQl/Model/Resolver/RemoveItemFromCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,38 @@
class RemoveItemFromCart implements ResolverInterface
{
/**
* @var GuestCartItemRepositoryInterface
* @var GetCartForUser
*/
private $guestCartItemRepository;
private $getCartForUser;

/**
* @var GetCartForUser
* @var GuestCartItemRepositoryInterface
*/
private $getCartForUser;
private $guestCartItemRepository;

/**
* @param GuestCartItemRepositoryInterface $guestCartItemRepository
* @param GetCartForUser $getCartForUser
* @param GuestCartItemRepositoryInterface $guestCartItemRepository
*/
public function __construct(
GuestCartItemRepositoryInterface $guestCartItemRepository,
GetCartForUser $getCartForUser
GetCartForUser $getCartForUser,
GuestCartItemRepositoryInterface $guestCartItemRepository
) {
$this->guestCartItemRepository = $guestCartItemRepository;
$this->getCartForUser = $getCartForUser;
$this->guestCartItemRepository = $guestCartItemRepository;
}

/**
* @inheritdoc
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (!isset($args['input']['cart_id'])) {
if (!isset($args['input']['cart_id']) || empty($args['input']['cart_id'])) {
throw new GraphQlInputException(__('Required parameter "cart_id" is missing'));
}
$maskedCartId = $args['input']['cart_id'];

if (!isset($args['input']['cart_item_id'])) {
if (!isset($args['input']['cart_item_id']) || empty($args['input']['cart_item_id'])) {
throw new GraphQlInputException(__('Required parameter "cart_item_id" is missing'));
}
$itemId = $args['input']['cart_item_id'];
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/QuoteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Mutation {
addVirtualProductsToCart(input: AddVirtualProductsToCartInput): AddVirtualProductsToCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddSimpleProductsToCart")
applyCouponToCart(input: ApplyCouponToCartInput): ApplyCouponToCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\ApplyCouponToCart")
removeCouponFromCart(input: RemoveCouponFromCartInput): RemoveCouponFromCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\RemoveCouponFromCart")
updateCartItems(input: UpdateCartItemsInput): UpdateCartItemsOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\UpdateCartItems")
removeItemFromCart(input: RemoveItemFromCartInput): RemoveItemFromCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\RemoveItemFromCart")
setShippingAddressesOnCart(input: SetShippingAddressesOnCartInput): SetShippingAddressesOnCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetShippingAddressesOnCart")
setBillingAddressOnCart(input: SetBillingAddressOnCartInput): SetBillingAddressOnCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetBillingAddressOnCart")
Expand Down

0 comments on commit faacfe0

Please sign in to comment.