misc. updates

This commit is contained in:
shubhammehrotra.symfony@webkul.com 2020-03-03 20:31:43 +05:30
parent 253131668b
commit d09c4b0ea7
22 changed files with 458 additions and 134 deletions

View File

@ -0,0 +1,3 @@
<script>
window.location.href = window.location.href.replace('/guest-wishlist', '');
</script>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
{
"/js/velocity.js": "/js/velocity.js?id=edb24f7ab80594df62df",
"/js/velocity.js": "/js/velocity.js?id=7c7ad485b3dcad7fa046",
"/css/velocity-admin.css": "/css/velocity-admin.css?id=612d35e452446366eef7",
"/css/velocity.css": "/css/velocity.css?id=0c3bbabfcb61f4640459"
"/css/velocity.css": "/css/velocity.css?id=aa28d71b10dc92e59c50"
}

View File

@ -253,5 +253,37 @@ class Helper extends Review
])->render(),
];
}
}
/**
* Returns the count rating of the product
*
* @param $items - & seperated product slugs
*
* @return array
*/
public function fetchProductCollection($items)
{
$productCollection = [];
$productSlugs = explode('&', $items);
foreach ($productSlugs as $slug) {
$product = $this->productRepository->findBySlug($slug);
if ($product) {
$formattedProduct = $this->formatProduct($product);
$productMetaDetails = [];
$productMetaDetails['image'] = $formattedProduct['image'];
$productMetaDetails['priceHTML'] = $formattedProduct['priceHTML'];
$productMetaDetails['addToCartHtml'] = $formattedProduct['addToCartHtml'];
$productMetaDetails['galleryImages'] = $formattedProduct['galleryImages'];
$product = array_merge($product->toArray(), $productMetaDetails);
array_push($productCollection, $product);
}
}
return $productCollection;
}
}

View File

@ -88,22 +88,7 @@ class ComparisonController extends Controller
} else {
// for product details
if ($items = request()->get('items')) {
$productSlugs = explode('&', $items);
foreach ($productSlugs as $slug) {
$product = $this->productRepository->findBySlug($slug);
$formattedProduct = $this->velocityHelper->formatProduct($product);
$productMetaDetails = [];
$productMetaDetails['image'] = $formattedProduct['image'];
$productMetaDetails['priceHTML'] = $formattedProduct['priceHTML'];
$productMetaDetails['addToCartHtml'] = $formattedProduct['addToCartHtml'];
$product = array_merge($product->toArray(), $productMetaDetails);
array_push($productCollection, $product);
}
$productCollection = $this->velocityHelper->fetchProductCollection($items);
}
}

View File

@ -267,4 +267,9 @@ class ShopController extends Controller
])->render(),
];
}
public function getWishlistList()
{
return view($this->_config['view']);
}
}

View File

@ -24,11 +24,17 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function
Route::get('/comparison', 'ComparisonController@getComparisonList')
->name('velocity.product.compare')
->defaults('_config', [
'view' => 'shop::compare.index'
'view' => 'shop::guest.compare.index'
]);
Route::put('/comparison', 'ComparisonController@addCompareProduct')->name('customer.product.add.compare');
Route::delete('/comparison', 'ComparisonController@deleteComparisonProduct')->name('customer.product.delete.compare');
Route::get('/guest-wishlist', 'ShopController@getWishlistList')
->name('velocity.product.guest-wishlist')
->defaults('_config', [
'view' => 'shop::guest.wishlist.index'
]);
});
});

View File

@ -67,7 +67,7 @@
<span class="fs14" v-text="product.firstReviewText"></span>
</div>
<vnode-injector :nodes="$root.getDynamicHTML(product.addToCartHtml)"></vnode-injector>
<vnode-injector :nodes="getDynamicHTML(product.addToCartHtml)"></vnode-injector>
</div>
</div>
</template>

View File

@ -57,6 +57,8 @@
`${this.__('customer.compare.added')}`
);
}
this.$root.headerItemsCount++;
}
}
}

View File

@ -43,7 +43,7 @@
<p class="pt14 fs14 description-text" v-html="product.shortDescription"></p>
<vnode-injector :nodes="$root.getDynamicHTML(product.addToCartHtml)"></vnode-injector>
<vnode-injector :nodes="getDynamicHTML(product.addToCartHtml)"></vnode-injector>
</div>
<div

View File

@ -10,31 +10,84 @@
<a
v-else
@click="addProductWishlist(productId)"
:href="`${$root.baseUrl}/customer/login`"
@click="toggleProductWishlist(productSlug)"
:class="`unset wishlist-icon ${addClass ? addClass : ''} text-right`">
<i
:class="`material-icons ${addClass ? addClass : ''}`"
@mouseover="isActive ? isActive = !isActive : ''"
@mouseout="active !== '' && !isActive ? isActive = !isActive : ''">
{{ isActive ? 'favorite_border' : 'favorite' }}
<i
@mouseout="! isStateChanged ? isActive = !isActive : isStateChanged = false"
@mouseover="! isStateChanged ? isActive = !isActive : isStateChanged = false"
:class="`material-icons ${addClass ? addClass : ''}`">
{{ isActive ? 'favorite' : 'favorite_border' }}
</i>
</a>
</template>
<script type="text/javascript">
export default {
props: ['active', 'addClass', 'isCustomer', 'productId'],
props: [
'active',
'addClass',
'addedText',
'removeText',
'isCustomer',
'productSlug',
],
data: function () {
return {
isStateChanged: false,
isActive: this.active,
}
},
created: function () {
if (this.isCustomer == 'false') {
this.isActive = this.isWishlisted(this.productSlug);
}
},
methods: {
addProductWishlist: function () {
toggleProductWishlist: function (productSlug) {
var updatedValue = [productSlug];
let existingValue = this.getStorageValue('wishlist_product');
if (existingValue) {
let valueIndex = existingValue.indexOf(productSlug);
if (valueIndex == -1) {
this.isActive = true;
existingValue.push(productSlug);
} else {
this.isActive = false;
existingValue.splice(valueIndex, 1);
}
updatedValue = existingValue;
}
this.$root.headerItemsCount++;
this.isStateChanged = true;
this.setStorageValue('wishlist_product', updatedValue);
window.showAlert(
'alert-success',
this.__('shop.general.alert.success'),
this.isActive ? this.addedText : this.removeText
);
return true;
},
isWishlisted: function (productSlug) {
let existingValue = this.getStorageValue('wishlist_product');
if (existingValue) {
return ! (existingValue.indexOf(productSlug) == -1);
} else {
return false;
}
}
}
}

View File

@ -59,6 +59,7 @@ $(document).ready(function () {
return {
'baseUrl': document.querySelector("script[src$='velocity.js']").getAttribute('baseUrl'),
'navContainer': false,
'headerItemsCount': 0,
'responsiveSidebarTemplate': '',
'responsiveSidebarKey': Math.random(),
'sharedRootCategories': [],
@ -184,7 +185,23 @@ $(document).ready(function () {
this.$options.staticRenderFns = _staticRenderFns;
return output;
}
},
getStorageValue: function (key) {
let value = window.localStorage.getItem(key);
if (value) {
value = JSON.parse(value);
}
return value;
},
setStorageValue: function (key, value) {
window.localStorage.setItem(key, JSON.stringify(value));
return true;
},
}
});

View File

@ -514,7 +514,8 @@ header {
// transition: transform .15s,opacity .15s;
}
~ .compare-btn {
~ .compare-btn,
~ .wishlist-btn {
height: 50px;
float: right;
font-size: 18px;
@ -522,8 +523,30 @@ header {
padding: 10px 16px 6px 16px;
i {
margin-right: 5px;
vertical-align: middle;
}
.badge-container {
position: relative;
display: inline-block;
.badge {
@include border-radius(50%);
top: -23px;
left: -15px;
padding: 4px;
min-width: 20px;
position: absolute;
background: $button-primary-bg;
}
}
span {
top: 2px;
position: relative;
}
}
}

View File

@ -276,36 +276,29 @@
}
}
.add-to-cart-btn {
width: 100%;
position: relative;
padding-right: 35px;
.btn-add-to-cart {
max-width: 140px;
&.small-padding {
max-width: 130px;
}
.card-body {
.compare-icon,
.wishlist-icon {
margin-left: 10px;
}
~ a {
.compare-icon {
right: 0;
margin: 0;
padding: 0;
height: 38px;
display: table;
cursor: pointer;
text-align: right;
position: absolute;
}
&.compare-icon {
right: 27px;
}
.add-to-cart-btn {
width: 100%;
position: relative;
> i {
display: table-cell;
vertical-align: middle;
.btn-add-to-cart {
width: 100%;
max-width: 140px;
max-width: 100% !important;
&.small-padding {
max-width: 130px;
}
}
}
}
@ -1524,6 +1517,18 @@
font-weight: 600;
}
.price-from {
span:nth-child(2) {
margin-left: 6px;
text-transform: lowercase;
display: inline-block !important;
}
span:nth-child(3) {
display: block !important;
}
}
.price-label {
margin-right: 6px;
}
@ -2180,6 +2185,9 @@
}
.bottom-toolbar {
width: 100%;
display: block;
.pagination {
.page-item {
padding: 0 10px;
@ -2226,14 +2234,6 @@
.VueCarousel-slide {
cursor: default;
}
#new-products-carousel {
.add-to-cart-btn {
~ a {
position: static;
}
}
}
}
.vue-slider {

View File

@ -672,22 +672,22 @@ a {
text-decoration: none !important;
}
&.remove-decoration {
text-decoration: none;
}
&.remove-decoration:hover,
&.remove-decoration:active,
&.remove-decoration:focus {
text-decoration: none;
}
&.active-hover {
&:hover {
color: $link-color !important;
text-decoration: underline !important;
}
}
&.remove-decoration {
text-decoration: none !important;
&:hover,
&:active,
&:focus {
text-decoration: none !important;
}
}
}
.dropdown-icon::after {

View File

@ -56,7 +56,7 @@
<script type="text/x-template" id="searchbar-template">
<div class="row no-margin right searchbar">
<div class="col-lg-8 col-md-12 no-padding input-group">
<div class="col-lg-6 col-md-12 no-padding input-group">
<form
method="GET"
role="search"
@ -114,7 +114,7 @@
</form>
</div>
<div class="col-4">
<div class="col-6">
{!! view_render_event('bagisto.shop.layout.header.cart-item.before') !!}
@include('shop::checkout.cart.mini-cart')
{!! view_render_event('bagisto.shop.layout.header.cart-item.after') !!}
@ -122,9 +122,24 @@
{!! view_render_event('bagisto.shop.layout.header.compare.before') !!}
<a class="compare-btn unset" href="{{ route('velocity.product.compare') }}">
<i class="material-icons">compare_arrows</i>
<span>Compare</span>
<div class="badge-container" v-if="compareCount > 0">
<span class="badge" v-text="compareCount"></span>
</div>
<span>{{ __('velocity::app.customer.compare.text') }}</span>
</a>
{!! view_render_event('bagisto.shop.layout.header.compare.after') !!}
@guest('customer')
{!! view_render_event('bagisto.shop.layout.header.wishlist.before') !!}
<a class="wishlist-btn unset" href="{{ route('velocity.product.guest-wishlist') }}">
<i class="material-icons">favorite_border</i>
<div class="badge-container" v-if="wishlistCount > 0">
<span class="badge" v-text="wishlistCount"></span>
</div>
<span>{{ __('shop::app.layouts.wishlist') }}</span>
</a>
{!! view_render_event('bagisto.shop.layout.header.wishlist.after') !!}
@endguest
</div>
</div>
</script>
@ -600,10 +615,18 @@
template: '#searchbar-template',
data: function () {
return {
compareCount: 0,
wishlistCount: 0,
searchedQuery: []
}
},
watch: {
'$root.headerItemsCount': function () {
this.updateHeaderItemsCount();
}
},
created: function () {
let searchedItem = window.location.search.replace("?", "");
searchedItem = searchedItem.split('&');
@ -616,11 +639,26 @@
});
this.searchedQuery = updatedSearchedCollection;
this.updateHeaderItemsCount();
},
methods: {
'focusInput': function (event) {
$(event.target.parentElement.parentElement).find('input').focus();
},
'updateHeaderItemsCount': function () {
let comparedItems = this.getStorageValue('compared_product');
let wishlistedItems = this.getStorageValue('wishlist_product');
if (wishlistedItems) {
this.wishlistCount = wishlistedItems.length;
}
if (comparedItems) {
this.compareCount = comparedItems.length;
}
}
}
})

View File

@ -21,7 +21,11 @@
</h1>
<div class="col-6" v-if="products.length > 0">
<button class="theme-btn light pull-right" @click="removeProductCompare('all')">Clear All</button>
<button
class="theme-btn light pull-right"
@click="removeProductCompare('all')">
{{ __('shop::app.customer.account.wishlist.deleteall') }}
</button>
</div>
{!! view_render_event('bagisto.shop.customers.account.compare.view.before') !!}
@ -49,36 +53,53 @@
</div>
<div class="col" :key="`title-${index}`" v-for="(product, index) in products">
@if ($attribute['code'] == 'name')
<a :href="`${$root.baseUrl}/${product.url_key}`" class="unset">
<h1 class="fw6 fs18" v-text="product['{{ $attribute['code'] }}']"></h1>
</a>
@elseif ($attribute['code'] == 'image')
<a :href="`${$root.baseUrl}/${product.url_key}`" class="unset">
<img :src="product['{{ $attribute['code'] }}']" class="image-wrapper"></span>
</a>
@elseif ($attribute['code'] == 'price')
<span v-html="product['priceHTML']"></span>
@elseif ($attribute['code'] == 'addToCartHtml')
<div class="action">
<vnode-injector :nodes="$root.getDynamicHTML(product.addToCartHtml)"></vnode-injector>
@switch ($attribute['code'])
@case('name')
<a :href="`${$root.baseUrl}/${product.url_key}`" class="unset remove-decoration active-hover">
<h1 class="fw6 fs18" v-text="product['{{ $attribute['code'] }}']"></h1>
</a>
@break
<i
class="material-icons cross fs16"
@click="removeProductCompare(isCustomer ? product.id : product.slug)">
@case('image')
<a :href="`${$root.baseUrl}/${product.url_key}`" class="unset">
<img :src="product['{{ $attribute['code'] }}']" class="image-wrapper"></span>
</a>
@break
close
</i>
</div>
@elseif ($attribute['code'] == 'color')
<span v-html="product.color_label"></span>
@elseif ($attribute['code'] == 'size')
<span v-html="product.size_label"></span>
@elseif ($attribute['code'] == 'size')
<span v-html="product.size_label"></span>
@else
<span v-html="product['{{ $attribute['code'] }}']"></span>
@endif
@case('price')
<span v-html="product['priceHTML']"></span>
@break
@case('addToCartHtml')
<div class="action">
<vnode-injector :nodes="getDynamicHTML(product.addToCartHtml)"></vnode-injector>
<i
class="material-icons cross fs16"
@click="removeProductCompare(isCustomer ? product.id : product.url_key)">
close
</i>
</div>
@break
@case('color')
<span v-html="product.color_label" class="fs16"></span>
@break
@case('size')
<span v-html="product.size_label" class="fs16"></span>
@break
@case('description')
<span v-html="product.description"></span>
@break
@default
<span v-html="product['{{ $attribute['code'] }}']" class="fs16"></span>
@break
@endswitch
</div>
</div>
@endforeach
@ -163,11 +184,13 @@
this.$set(this, 'products', []);
} else {
updatedItems = existingItems.filter(item => item != productId);
this.$set(this, 'products', this.products.filter(product => product.slug != productId));
this.$set(this, 'products', this.products.filter(product => product.url_key != productId));
}
window.localStorage.setItem('compared_product', JSON.stringify(updatedItems));
this.$root.headerItemsCount++;
window.showAlert(
`alert-success`,
this.__('shop.general.alert.success'),

View File

@ -0,0 +1,135 @@
@extends('shop::layouts.master')
@section('page_title')
{{ __('shop::app.customer.account.wishlist.page-title') }}
@endsection
@section('content-wrapper')
@guest('customer')
<wishlist-product></wishlist-product>
@endguest
@auth('customer')
@push('scripts')
<script>
window.location = '{{ route('customer.wishlist.index') }}';
</script>
@endpush
@endauth
@endsection
@push('scripts')
<script type="text/x-template" id="wishlist-product-template">
<section class="cart-details row no-margin col-12">
<h1 class="fw6 col-6">
{{ __('shop::app.customer.account.wishlist.title') }}
</h1>
<div class="col-6" v-if="products.length > 0">
<button
class="theme-btn light pull-right"
@click="removeProduct('all')">
{{ __('shop::app.customer.account.wishlist.deleteall') }}
</button>
</div>
{!! view_render_event('bagisto.shop.customers.account.guest-customer.view.before') !!}
<div class="row products-collection col-12 ml0">
<carousel-component
slides-per-page="6"
navigation-enabled="hide"
pagination-enabled="hide"
id="wishlist-products-carousel"
:slides-count="products.length">
<slide
:key="index"
:slot="`slide-${index}`"
v-for="(product, index) in products">
<product-card :product="product"></product-card>
</slide>
</carousel-component>
</div>
{!! view_render_event('bagisto.shop.customers.account.guest-customer.view.after') !!}
</section>
</script>
<script>
Vue.component('wishlist-product', {
template: '#wishlist-product-template',
data: function () {
return {
'products': [],
'isProductListLoaded': false,
}
},
mounted: function () {
this.getProducts();
},
methods: {
'getProducts': function () {
let items = JSON.parse(window.localStorage.getItem('wishlist_product'));
items = items ? items.join('&') : '';
var data = {
params: {
items,
data: true,
}
};
this.$http.get(`${this.$root.baseUrl}/comparison`, data)
.then(response => {
this.isProductListLoaded = true;
this.products = response.data.products;
})
.catch(error => {
console.log(this.__('error.something_went_wrong'));
});
},
'removeProduct': function (productId) {
if (this.isCustomer) {
this.$http.delete(`${this.$root.baseUrl}/comparison?productId=${productId}`)
.then(response => {
if (productId == 'all') {
this.$set(this, 'products', this.products.filter(product => false));
} else {
this.$set(this, 'products', this.products.filter(product => product.id != productId));
}
window.showAlert(`alert-${response.data.status}`, response.data.label, response.data.message);
})
.catch(error => {
console.log(this.__('error.something_went_wrong'));
});
} else {
let existingItems = window.localStorage.getItem('compared_product');
existingItems = JSON.parse(existingItems);
if (productId == "all") {
updatedItems = [];
this.$set(this, 'products', []);
} else {
updatedItems = existingItems.filter(item => item != productId);
this.$set(this, 'products', this.products.filter(product => product.slug != productId));
}
window.localStorage.setItem('compared_product', JSON.stringify(updatedItems));
window.showAlert(
`alert-success`,
this.__('shop.general.alert.success'),
`${this.__('customer.compare.removed')}`
);
}
},
}
});
</script>
@endpush

View File

@ -1,6 +1,27 @@
{!! view_render_event('bagisto.shop.products.add_to_cart.before', ['product' => $product]) !!}
<div class="row mx-0 col-12 no-padding">
@if (isset($showCompare) && $showCompare)
<compare-component
@auth('customer')
customer="true"
@endif
@guest('customer')
customer="false"
@endif
slug="{{ $product->url_key }}"
product-id="{{ $product->id }}"
></compare-component>
@endif
@if (! (isset($showWishlist) && !$showWishlist))
@include('shop::products.wishlist', [
'addClass' => $addWishlistClass ?? ''
])
@endif
<div class="add-to-cart-btn pl0">
@if (isset($form) && !$form)
<button
@ -28,27 +49,6 @@
</add-to-cart>
@endif
</div>
@if (isset($showCompare) && $showCompare)
<compare-component
@auth('customer')
customer="true"
@endif
@guest('customer')
customer="false"
@endif
slug="{{ $product->url_key }}"
product-id="{{ $product->id }}"
></compare-component>
@endif
@if (! (isset($showWishlist) && !$showWishlist))
@include('shop::products.wishlist', [
'addClass' => $addWishlistClass ?? ''
])
@endif
</div>
{!! view_render_event('bagisto.shop.products.add_to_cart.after', ['product' => $product]) !!}

View File

@ -24,8 +24,10 @@
<wishlist-component
active="false"
is-customer="false"
product-id="{{ $product->product_id }}"
add-class="{{ $addWishlistClass ?? '' }}">
product-slug="{{ $product->url_key }}"
add-class="{{ $addWishlistClass ?? '' }}"
added-text="{{ __('shop::app.customer.account.wishlist.add') }}"
remove-text="{{ __('shop::app.customer.account.wishlist.remove') }}">
</wishlist-component>
@endauth
{!! view_render_event('bagisto.shop.products.wishlist.after') !!}