From 510f6e6f63be290b26673c44a82b2ea511c087de Mon Sep 17 00:00:00 2001 From: prashant-webkul Date: Mon, 3 Dec 2018 18:37:29 +0530 Subject: [PATCH] minor fixes in the merge cart function of cart --- config/jwt.php | 173 -------------------------- config/test.php | 5 - packages/Webkul/Checkout/src/Cart.php | 10 +- 3 files changed, 8 insertions(+), 180 deletions(-) delete mode 100644 config/jwt.php delete mode 100644 config/test.php diff --git a/config/jwt.php b/config/jwt.php deleted file mode 100644 index f83b6f796..000000000 --- a/config/jwt.php +++ /dev/null @@ -1,173 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -return [ - - /* - |-------------------------------------------------------------------------- - | JWT Authentication Secret - |-------------------------------------------------------------------------- - | - | Don't forget to set this, as it will be used to sign your tokens. - | A helper command is provided for this: `php artisan jwt:generate` - | - */ - - 'secret' => env('JWT_SECRET', 'changeme'), - - /* - |-------------------------------------------------------------------------- - | JWT time to live - |-------------------------------------------------------------------------- - | - | Specify the length of time (in minutes) that the token will be valid for. - | Defaults to 1 hour - | - */ - - 'ttl' => env('JWT_TTL', 120), - - /* - |-------------------------------------------------------------------------- - | Refresh time to live - |-------------------------------------------------------------------------- - | - | Specify the length of time (in minutes) that the token can be refreshed - | within. I.E. The user can refresh their token within a 2 week window of - | the original token being created until they must re-authenticate. - | Defaults to 2 weeks - | - */ - - 'refresh_ttl' => env('JWT_REFRESH_TTL', 86400), - - /* - |-------------------------------------------------------------------------- - | JWT hashing algorithm - |-------------------------------------------------------------------------- - | - | Specify the hashing algorithm that will be used to sign the token. - | - | See here: https://github.com/namshi/jose/tree/2.2.0/src/Namshi/JOSE/Signer - | for possible values - | - */ - - 'algo' => 'HS256', - - /* - |-------------------------------------------------------------------------- - | User Model namespace - |-------------------------------------------------------------------------- - | - | Specify the full namespace to your User model. - | e.g. 'Acme\Entities\User' - | - */ - - 'user' => 'App\User', - - /* - |-------------------------------------------------------------------------- - | User identifier - |-------------------------------------------------------------------------- - | - | Specify a unique property of the user that will be added as the 'sub' - | claim of the token payload. - | - */ - - 'identifier' => 'id', - - /* - |-------------------------------------------------------------------------- - | Required Claims - |-------------------------------------------------------------------------- - | - | Specify the required claims that must exist in any token. - | A TokenInvalidException will be thrown if any of these claims are not - | present in the payload. - | - */ - - 'required_claims' => ['iss', 'iat', 'exp', 'nbf', 'sub', 'jti'], - - /* - |-------------------------------------------------------------------------- - | Blacklist Enabled - |-------------------------------------------------------------------------- - | - | In order to invalidate tokens, you must have the blacklist enabled. - | If you do not want or need this functionality, then set this to false. - | - */ - - 'blacklist_enabled' => env('JWT_BLACKLIST_ENABLED', true), - - /* - |-------------------------------------------------------------------------- - | Providers - |-------------------------------------------------------------------------- - | - | Specify the various providers used throughout the package. - | - */ - - 'providers' => [ - - /* - |-------------------------------------------------------------------------- - | User Provider - |-------------------------------------------------------------------------- - | - | Specify the provider that is used to find the user based - | on the subject claim - | - */ - - 'user' => 'Tymon\JWTAuth\Providers\User\EloquentUserAdapter', - - /* - |-------------------------------------------------------------------------- - | JWT Provider - |-------------------------------------------------------------------------- - | - | Specify the provider that is used to create and decode the tokens. - | - */ - - 'jwt' => 'Tymon\JWTAuth\Providers\JWT\Namshi', - - /* - |-------------------------------------------------------------------------- - | Authentication Provider - |-------------------------------------------------------------------------- - | - | Specify the provider that is used to authenticate users. - | - */ - - 'auth' => 'Tymon\JWTAuth\Providers\Auth\Illuminate', - - /* - |-------------------------------------------------------------------------- - | Storage Provider - |-------------------------------------------------------------------------- - | - | Specify the provider that is used to store tokens in the blacklist - | - */ - - 'storage' => 'Tymon\JWTAuth\Providers\Storage\Illuminate' - - ], - -]; diff --git a/config/test.php b/config/test.php deleted file mode 100644 index c205929e6..000000000 --- a/config/test.php +++ /dev/null @@ -1,5 +0,0 @@ - 'Test' -]; diff --git a/packages/Webkul/Checkout/src/Cart.php b/packages/Webkul/Checkout/src/Cart.php index 87645d105..aeca264d3 100644 --- a/packages/Webkul/Checkout/src/Cart.php +++ b/packages/Webkul/Checkout/src/Cart.php @@ -409,12 +409,18 @@ class Cart { public function mergeCart() { if(session()->has('cart')) { - $cart = $this->cart->findOneByField('customer_id', auth()->guard('customer')->user()->id); + $cart = $this->cart->findWhere(['customer_id' => auth()->guard('customer')->user()->id, 'is_active' => 1]); + + if($cart->count()) { + $cart = $cart->first(); + } else { + $cart = false; + } $guestCart = session()->get('cart'); //when the logged in customer is not having any of the cart instance previously and are active. - if(!isset($cart)) { + if(!$cart) { $guestCart->update([ 'customer_id' => auth()->guard('customer')->user()->id, 'is_guest' => 0,