Skip to content

Commit

Permalink
[Updated: removeCoupon API added.]
Browse files Browse the repository at this point in the history
  • Loading branch information
vivek-webkul committed Jan 5, 2023
1 parent 386faeb commit 83d9d5a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The Bagisto GraphQL API is made in collaboration with <a href="https://www.ucraf

### 1. Requirements:

* **Bagisto**: v1.4.3
* **Bagisto**: v1.4.5

### 2. Installation:

Expand All @@ -32,6 +32,16 @@ php artisan bagisto_graphql:install

##### Find a file config/lighthouse.php from root and do the following changes:

* add these two middlewares inside the **middleware** index for the support of multi-locale and multi-currency:

~~~
// Validate Locale in request
\Webkul\GraphQLAPI\Http\Middleware\LocaleMiddleware::class,
// Validate Currency in request
\Webkul\GraphQLAPI\Http\Middleware\CurrencyMiddleware::class,
~~~

* change the **guard** index value from **api** to **admin-api** like below mentioned:

~~~
Expand Down
29 changes: 29 additions & 0 deletions src/Mutations/Shop/Customer/CheckoutMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,35 @@ public function applyCoupon($rootValue, array $args, GraphQLContext $context)
}
}

/**
* Remove Coupon from cart
*
* @param array $args
* @return \Illuminate\Http\Response
*/
public function removeCoupon($rootValue, array $args, GraphQLContext $context)
{
try {
if (Cart::getCart()->coupon_code) {
Cart::removeCouponCode()->collectTotals();

return [
'success' => true,
'message' => trans('bagisto_graphql::app.shop.response.coupon-removed'),
'cart' => Cart::getCart(),
];
}

return [
'success' => false,
'message' => trans('bagisto_graphql::app.shop.response.coupon-remove-failed'),
'cart' => Cart::getCart(),
];
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
}

/**
* Create order
*
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@
'invalid-guest-access' => 'Warning: Guest customer are not allow to get addresses with the help of billing/shipping address id.',
'guest-address-warning' => 'Warning: If you are trying as a guest, then try without Authorization token.',
'warning-num-already-used' => 'Warning: This :phone number is registered using different email address.',
'coupon-removed' => 'Success: coupon removed from cart successfully.',
'coupon-remove-failed' => 'Warning: there are some error in removing coupon from cart or coupon not found.',
]
]
];
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Shop\Checkout\ApplyCoupon Related API
# Shop\Checkout\Coupon Related API
extend type Mutation {
applyCoupon(
input: ApplyCouponInput!
): CouponResponse @field(resolver: "Webkul\\GraphQLAPI\\Mutations\\Shop\\Customer\\CheckoutMutation@applyCoupon")

removeCoupon: CouponResponse @field(resolver: "Webkul\\GraphQLAPI\\Mutations\\Shop\\Customer\\CheckoutMutation@removeCoupon")
}

input ApplyCouponInput {
Expand Down

0 comments on commit 83d9d5a

Please sign in to comment.