From 5191890e1e16e99ff1d0093cf3f707d45dc70529 Mon Sep 17 00:00:00 2001 From: Devansh Date: Mon, 15 Nov 2021 14:05:05 +0530 Subject: [PATCH] Shared Wishlist View Completed --- .../Http/Controllers/WishlistController.php | 25 ++++---- .../Webkul/Customer/src/Models/Customer.php | 26 +++----- .../src/Repositories/WishlistRepository.php | 14 +++++ .../Shop/src/Routes/customer-routes.php | 2 +- .../wishlist/shared-wishlist.blade.php | 9 --- .../wishlist/wishlist-products.blade.php | 62 +++++++++++++++++++ .../wishlist/wishlist-shared.blade.php | 37 +++++++++++ .../account/wishlist/wishlist.blade.php | 53 ++++++++-------- .../views/shop/products/list/card.blade.php | 20 ++++-- 9 files changed, 176 insertions(+), 72 deletions(-) delete mode 100644 packages/Webkul/Velocity/src/Resources/views/shop/customers/account/wishlist/shared-wishlist.blade.php create mode 100644 packages/Webkul/Velocity/src/Resources/views/shop/customers/account/wishlist/wishlist-products.blade.php create mode 100644 packages/Webkul/Velocity/src/Resources/views/shop/customers/account/wishlist/wishlist-shared.blade.php diff --git a/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php b/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php index 9a0b339fb..49bfe055c 100755 --- a/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php +++ b/packages/Webkul/Customer/src/Http/Controllers/WishlistController.php @@ -3,6 +3,7 @@ namespace Webkul\Customer\Http\Controllers; use Cart; +use Webkul\Customer\Repositories\CustomerRepository; use Webkul\Customer\Repositories\WishlistRepository; use Webkul\Product\Repositories\ProductRepository; @@ -70,7 +71,7 @@ class WishlistController extends Controller } return view($this->_config['view'], [ - 'items' => $wishlistItems, + 'wishlistItems' => $wishlistItems, 'isWishlistShared' => $this->currentCustomer->isWishlistShared(), 'wishlistSharedLink' => $this->currentCustomer->getWishlistSharedLink() ]); @@ -137,18 +138,11 @@ class WishlistController extends Controller */ public function share() { - $sharedToken = \Illuminate\Support\Str::random(16); - $data = $this->validate(request(), [ 'shared' => 'required|boolean' ]); - $updateCounts = $this->currentCustomer->wishlist_items()->update([ - 'shared' => $data['shared'], - 'additional' => [ - 'token' => $sharedToken - ] - ]); + $updateCounts = $this->currentCustomer->wishlist_items()->update(['shared' => $data['shared']]); if ($updateCounts && $updateCounts > 0) { session()->flash('success', 'Shared wishlist settings updated successfully'); @@ -164,13 +158,20 @@ class WishlistController extends Controller * * @return \Illuminate\Http\Response */ - public function shared() + public function shared(CustomerRepository $customerRepository) { - if (! core()->getConfigData('general.content.shop.wishlist_option')) { + if ( + ! request()->hasValidSignature() + || ! core()->getConfigData('general.content.shop.wishlist_option') + ) { abort(404); } - return view($this->_config['view']); + $customer = $customerRepository->find(request()->get('id')); + + $wishlistItems = $customer->wishlist_items()->where('shared', 1)->get(); + + return view($this->_config['view'], compact('customer', 'wishlistItems')); } /** diff --git a/packages/Webkul/Customer/src/Models/Customer.php b/packages/Webkul/Customer/src/Models/Customer.php index af5b52e22..92d273b3d 100755 --- a/packages/Webkul/Customer/src/Models/Customer.php +++ b/packages/Webkul/Customer/src/Models/Customer.php @@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Facades\URL; use Tymon\JWTAuth\Contracts\JWTSubject; use Webkul\Checkout\Models\CartProxy; use Webkul\Core\Models\SubscribersListProxy; @@ -199,9 +200,9 @@ class Customer extends Authenticatable implements CustomerContract, JWTSubject */ public function isWishlistShared(): bool { - $sharedWishlists = $this->wishlist_items()->where('shared', 1)->get(); - - return $sharedWishlists->count() > 0 ? true : false; + return $this->wishlist_items()->where('shared', 1)->first() + ? true + : false; } /** @@ -211,22 +212,9 @@ class Customer extends Authenticatable implements CustomerContract, JWTSubject */ public function getWishlistSharedLink() { - $firstSharedWishlist = $this->wishlist_items()->where('shared', 1)->first(); - - if ( - $firstSharedWishlist - && $firstSharedWishlist->additional - && isset($firstSharedWishlist->additional['token']) - ) { - $sharedToken = $firstSharedWishlist->additional['token']; - - return route('customer.wishlist.shared', [ - 'id' => $this->id, - 'token' => $sharedToken - ]); - } - - return; + return $this->isWishlistShared() + ? URL::signedRoute('customer.wishlist.shared', ['id' => $this->id]) + : null; } /** diff --git a/packages/Webkul/Customer/src/Repositories/WishlistRepository.php b/packages/Webkul/Customer/src/Repositories/WishlistRepository.php index 5a356ac56..c8e918b68 100755 --- a/packages/Webkul/Customer/src/Repositories/WishlistRepository.php +++ b/packages/Webkul/Customer/src/Repositories/WishlistRepository.php @@ -57,6 +57,20 @@ class WishlistRepository extends Repository return $this->model->find($id)->item_wishlist; } + /** + * Get shared wishlist by customer's id. + * + * @param int $id + * @return Illuminate\Database\Eloquent\Collection + */ + public function getSharedWishlistByCustomerId($id) + { + return $this + ->where('customer_id', $id) + ->where('shared', 1) + ->get(); + } + /** * Get customer wishlist items. * diff --git a/packages/Webkul/Shop/src/Routes/customer-routes.php b/packages/Webkul/Shop/src/Routes/customer-routes.php index df3956bbd..3029f7a3b 100644 --- a/packages/Webkul/Shop/src/Routes/customer-routes.php +++ b/packages/Webkul/Shop/src/Routes/customer-routes.php @@ -91,7 +91,7 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function Route::get('wishlist/shared', [WishlistController::class, 'shared']) ->defaults('_config', [ - 'view' => 'shop::customers.account.wishlist.shared-wishlist' + 'view' => 'shop::customers.account.wishlist.wishlist-shared' ]) ->withoutMiddleware('customer') ->name('customer.wishlist.shared'); diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/customers/account/wishlist/shared-wishlist.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/customers/account/wishlist/shared-wishlist.blade.php deleted file mode 100644 index 94704b20b..000000000 --- a/packages/Webkul/Velocity/src/Resources/views/shop/customers/account/wishlist/shared-wishlist.blade.php +++ /dev/null @@ -1,9 +0,0 @@ -@extends('shop::layouts.master') - -@section('page_title') - {{ __('shop::app.customer.account.wishlist.page-title') }} -@endsection - -@section('content-wrapper') - Lorem ipsum dolor, sit amet consectetur adipisicing elit. Tempora, officia ab consequatur cum velit aliquid dicta harum dolorum? At accusantium possimus doloribus eum aut excepturi consequuntur blanditiis suscipit maxime dicta. -@endsection \ No newline at end of file diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/customers/account/wishlist/wishlist-products.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/customers/account/wishlist/wishlist-products.blade.php new file mode 100644 index 000000000..08d3d5289 --- /dev/null +++ b/packages/Webkul/Velocity/src/Resources/views/shop/customers/account/wishlist/wishlist-products.blade.php @@ -0,0 +1,62 @@ +@php + /** + * Product model. + * + * @var \Webkul\Product\Models\Product + */ + $product = $wishlistItem->product; +@endphp + +
+ + +
+
+ + +
+ @include ('shop::products.price', ['product' => $product]) +
+ +
+
+ + Visibility: + + + {{ $wishlistItem->shared ? 'Public' : 'Private' }} + + +
+ +
+ @include ('shop::products.add-to-cart', [ + 'addWishlistClass' => 'pl10', + 'product' => $product, + 'addToCartBtnClass' => 'medium-padding', + 'showCompare' => core()->getConfigData('general.content.shop.compare_option') == "1" ? true : false, + ]) +
+
+
+
+
\ No newline at end of file diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/customers/account/wishlist/wishlist-shared.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/customers/account/wishlist/wishlist-shared.blade.php new file mode 100644 index 000000000..15b82148f --- /dev/null +++ b/packages/Webkul/Velocity/src/Resources/views/shop/customers/account/wishlist/wishlist-shared.blade.php @@ -0,0 +1,37 @@ +@extends('shop::layouts.master') + +@section('page_title') + {{ __('shop::app.customer.account.wishlist.page-title') }} +@endsection + +@section('content-wrapper') +
+
+
+
+ +
+
+
+ +
+
+
+ @if ($wishlistItems->count()) +

+ {{ $customer->name }}'s Wishlist +

+ + @foreach ($wishlistItems as $wishlistItem) + @include ('shop::customers.account.wishlist.wishlist-products', ['wishlistItem' => $wishlistItem]) + @endforeach + @else +
+ {{ __('customer::app.wishlist.empty') }} +
+ @endif +
+
+
+
+@endsection \ No newline at end of file diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/customers/account/wishlist/wishlist.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/customers/account/wishlist/wishlist.blade.php index 5f245aee1..66495ca6c 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/customers/account/wishlist/wishlist.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/customers/account/wishlist/wishlist.blade.php @@ -10,7 +10,7 @@
- @if (count($items)) + @if (count($wishlistItems)) - {!! view_render_event('bagisto.shop.customers.account.wishlist.list.before', ['wishlist' => $items]) !!} + {!! view_render_event('bagisto.shop.customers.account.wishlist.list.before', ['wishlist' => $wishlistItems]) !!}
- @if ($items->count()) - @foreach ($items as $item) - @php - $currentMode = $toolbarHelper->getCurrentMode(); - $moveToCartText = __('shop::app.customer.account.wishlist.move-to-cart'); - @endphp - - @include ('shop::products.list.card', [ - 'list' => true, - 'checkmode' => true, - 'moveToCart' => true, - 'wishlistMoveRoute' => route('customer.wishlist.move', $item->id), - 'addToCartForm' => true, - 'removeWishlist' => true, - 'reloadPage' => true, - 'itemId' => $item->id, - 'item' => $item, - 'product' => $item->product, - 'additionalAttributes' => true, - 'btnText' => $moveToCartText, - 'addToCartBtnClass' => 'small-padding', - ]) + @if ($wishlistItems->count()) + @foreach ($wishlistItems as $wishlistItem) + @include ('shop::customers.account.wishlist.wishlist-products', ['wishlistItem' => $wishlistItem]) @endforeach
- {{ $items->links() }} + {{ $wishlistItems->links() }}
@else
@@ -104,7 +85,25 @@
- + + +
+ @if ($isWishlistShared) + Public + @else + Private + @endif +
+
+
+ +
+
+
@if ($isWishlistShared) @@ -128,7 +127,7 @@
- {!! view_render_event('bagisto.shop.customers.account.wishlist.list.after', ['wishlist' => $items]) !!} + {!! view_render_event('bagisto.shop.customers.account.wishlist.list.after', ['wishlist' => $wishlistItems]) !!} @endsection @push('scripts') diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/products/list/card.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/products/list/card.blade.php index dd73e4608..af4ac3c57 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/products/list/card.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/products/list/card.blade.php @@ -44,9 +44,9 @@ 'showCompare' => core()->getConfigData('general.content.shop.compare_option') == "1" ? true : false, - 'btnText' => null, - 'moveToCart' => null, - 'addToCartBtnClass' => '', + 'btnText' => $btnText ?? null, + 'moveToCart' => $moveToCart ?? null, + 'addToCartBtnClass' => $addToCartBtnClass ?? '', ])->render()); @endphp @@ -102,10 +102,22 @@ @endif
+ @if (isset($wishlistItem) && $wishlistItem) +
+ + Visibility: + + + {{ $wishlistItem->shared ? 'Public' : 'Private' }} + + +
+ @endif + @include ('shop::products.add-to-cart', [ 'addWishlistClass' => 'pl10', 'product' => $product, - 'addToCartBtnClass' => 'medium-padding', + 'addToCartBtnClass' => $addToCartBtnClass ?? 'medium-padding', 'showCompare' => core()->getConfigData('general.content.shop.compare_option') == "1" ? true : false, ])