Shared Wishlist View Completed

This commit is contained in:
Devansh 2021-11-15 14:05:05 +05:30
parent 2b96b951e3
commit 5191890e1e
9 changed files with 176 additions and 72 deletions

View File

@ -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'));
}
/**

View File

@ -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;
}
/**

View File

@ -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.
*

View File

@ -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');

View File

@ -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

View File

@ -0,0 +1,62 @@
@php
/**
* Product model.
*
* @var \Webkul\Product\Models\Product
*/
$product = $wishlistItem->product;
@endphp
<div class="col-12 lg-card-container list-card product-card row">
<div class="product-image">
<a
title="{{ $product->name }}"
href="{{ route('shop.productOrCategory.index', $product->url_key) }}">
<img
src="{{ productimage()->getProductBaseImage($product)['medium_image_url'] }}"
:onerror="`this.src='${this.$root.baseUrl}/vendor/webkul/ui/assets/images/product/large-product-placeholder.png'`" alt="" />
<div class="quick-view-in-list">
</div>
</a>
</div>
<div class="product-information">
<div class="p-2">
<div class="product-name">
<a
href="{{ route('shop.productOrCategory.index', $product->url_key) }}"
title="{{ $product->name }}" class="unset">
<span class="fs16">{{ $product->name }}</span>
</a>
</div>
<div class="product-price">
@include ('shop::products.price', ['product' => $product])
</div>
<div class="cart-wish-wrap mt5">
<div class="mb-2">
<span class="fs16">
Visibility:
<span class="badge {{ $wishlistItem->shared ? 'badge-success' : 'badge-danger' }}">
{{ $wishlistItem->shared ? 'Public' : 'Private' }}
</span>
</span>
</div>
<div>
@include ('shop::products.add-to-cart', [
'addWishlistClass' => 'pl10',
'product' => $product,
'addToCartBtnClass' => 'medium-padding',
'showCompare' => core()->getConfigData('general.content.shop.compare_option') == "1" ? true : false,
])
</div>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,37 @@
@extends('shop::layouts.master')
@section('page_title')
{{ __('shop::app.customer.account.wishlist.page-title') }}
@endsection
@section('content-wrapper')
<div class="container p-5">
<div class="row">
<div class="col-12">
<div class="wishlist-container">
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="wishlist-container">
@if ($wishlistItems->count())
<h2 class="text-center">
{{ $customer->name }}'s Wishlist
</h2>
@foreach ($wishlistItems as $wishlistItem)
@include ('shop::customers.account.wishlist.wishlist-products', ['wishlistItem' => $wishlistItem])
@endforeach
@else
<div class="empty">
{{ __('customer::app.wishlist.empty') }}
</div>
@endif
</div>
</div>
</div>
</div>
@endsection

View File

@ -10,7 +10,7 @@
<div class="account-head">
<span class="account-heading">{{ __('shop::app.customer.account.wishlist.title') }}</span>
@if (count($items))
@if (count($wishlistItems))
<div class="account-action float-right">
<form id="remove-all-wishlist" class="d-none" action="{{ route('customer.wishlist.removeall') }}" method="POST">
@method('DELETE')
@ -40,35 +40,16 @@
@endif
</div>
{!! view_render_event('bagisto.shop.customers.account.wishlist.list.before', ['wishlist' => $items]) !!}
{!! view_render_event('bagisto.shop.customers.account.wishlist.list.before', ['wishlist' => $wishlistItems]) !!}
<div class="wishlist-container">
@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
<div>
{{ $items->links() }}
{{ $wishlistItems->links() }}
</div>
@else
<div class="empty">
@ -104,7 +85,25 @@
<div class="row mt-2">
<div class="col-12">
<label>Shared Link</label>
<label class="mandatory">
Visibility
</label>
<div>
@if ($isWishlistShared)
<span class="badge badge-success">Public</span>
@else
<span class="badge badge-danger">Private</span>
@endif
</div>
</div>
</div>
<div class="row mt-2">
<div class="col-12">
<label class="mandatory">
Shared Link
</label>
<div>
@if ($isWishlistShared)
@ -128,7 +127,7 @@
</modal>
</div>
{!! 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')

View File

@ -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
<div class="cart-wish-wrap mt5">
@if (isset($wishlistItem) && $wishlistItem)
<div class="mb-2">
<span class="fs16">
Visibility:
<span class="badge {{ $wishlistItem->shared ? 'badge-success' : 'badge-danger' }}">
{{ $wishlistItem->shared ? 'Public' : 'Private' }}
</span>
</span>
</div>
@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,
])
</div>