diff --git a/packages/Webkul/Shop/src/Resources/views/guest/compare/compare-products.blade.php b/packages/Webkul/Shop/src/Resources/views/guest/compare/compare-products.blade.php index cba9eff37..403341771 100644 --- a/packages/Webkul/Shop/src/Resources/views/guest/compare/compare-products.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/guest/compare/compare-products.blade.php @@ -4,7 +4,7 @@ $locale = request()->get('locale') ?: app()->getLocale(); - $attributeOptionTranslations = DB::table(DB::getTablePrefix() . 'attribute_option_translations')->where('locale', $locale)->get()->toJson(); + $attributeOptionTranslations = DB::table('attribute_option_translations')->where('locale', $locale)->get()->toJson(); @endphp @push('scripts') @@ -230,6 +230,8 @@ this.$root.addFlashMessages(); } + + this.updateCompareCount(); }, 'getDynamicHTML': function (input) { @@ -311,6 +313,28 @@ } return attributeOptions; + }, + + 'updateCompareCount': function () { + if (this.isCustomer == "true" || this.isCustomer == true) { + this.$http.get(`${this.baseUrl}/items-count`) + .then(response => { + $('#compare-items-count').html(response.data.compareProductsCount); + }) + .catch(exception => { + window.flashMessages = [{ + 'type': `alert-error`, + 'message': "{{ __('shop::app.common.error') }}" + }]; + + this.$root.addFlashMessages(); + }); + } else { + let comparedItems = JSON.parse(localStorage.getItem('compared_product')); + comparedItemsCount = comparedItems ? comparedItems.length : 0; + + $('#compare-items-count').html(comparedItemsCount); + } } } }); diff --git a/packages/Webkul/Shop/src/Resources/views/layouts/header/index.blade.php b/packages/Webkul/Shop/src/Resources/views/layouts/header/index.blade.php index 9aeea6461..18204a281 100755 --- a/packages/Webkul/Shop/src/Resources/views/layouts/header/index.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/layouts/header/index.blade.php @@ -336,8 +336,22 @@ toggleDropdown(e); }); - let comparedItems = JSON.parse(localStorage.getItem('compared_product')); - $('#compare-items-count').append(comparedItems.length); + @auth('customer') + @php + $compareCount = app('Webkul\Velocity\Repositories\VelocityCustomerCompareProductRepository') + ->count([ + 'customer_id' => auth()->guard('customer')->user()->id, + ]); + @endphp + + let comparedItems = JSON.parse(localStorage.getItem('compared_product')); + $('#compare-items-count').html({{ $compareCount }}); + @endauth + + @guest('customer') + let comparedItems = JSON.parse(localStorage.getItem('compared_product')); + $('#compare-items-count').html(comparedItems ? comparedItems.length : 0); + @endguest function toggleDropdown(e) { var currentElement = $(e.currentTarget); diff --git a/packages/Webkul/Shop/src/Resources/views/products/compare.blade.php b/packages/Webkul/Shop/src/Resources/views/products/compare.blade.php index 447e75661..5a5778858 100755 --- a/packages/Webkul/Shop/src/Resources/views/products/compare.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/compare.blade.php @@ -18,7 +18,7 @@ template: '#compare-component-template', - data: function () { + data: function () { return { 'baseUrl': "{{ url()->to('/') }}", 'customer': '{{ auth()->guard('customer')->user() ? "true" : "false" }}' == "true", @@ -37,7 +37,7 @@ 'type': `alert-${response.data.status}`, 'message': response.data.message }]; - + this.$root.addFlashMessages() }).catch(error => { window.flashMessages = [{ @@ -82,6 +82,8 @@ this.$root.addFlashMessages() } } + + this.updateCompareCount(); }, 'getStorageValue': function (key) { @@ -99,6 +101,28 @@ return true; }, + + 'updateCompareCount': function () { + if (this.customer == "true" || this.customer == true) { + this.$http.get(`${this.baseUrl}/items-count`) + .then(response => { + $('#compare-items-count').html(response.data.compareProductsCount); + }) + .catch(exception => { + window.flashMessages = [{ + 'type': `alert-error`, + 'message': "{{ __('shop::app.common.error') }}" + }]; + + this.$root.addFlashMessages(); + }); + } else { + let comparedItems = JSON.parse(localStorage.getItem('compared_product')); + comparedItemsCount = comparedItems ? comparedItems.length : 0; + + $('#compare-items-count').html(comparedItemsCount); + } + } } }); diff --git a/packages/Webkul/Velocity/src/Http/Controllers/Shop/Controller.php b/packages/Webkul/Velocity/src/Http/Controllers/Shop/Controller.php index cbe3ab1e3..4d5c1a356 100755 --- a/packages/Webkul/Velocity/src/Http/Controllers/Shop/Controller.php +++ b/packages/Webkul/Velocity/src/Http/Controllers/Shop/Controller.php @@ -93,7 +93,6 @@ class Controller extends BaseController * @param \Webkul\Category\Repositories\CategoryRepository $categoryRepository * @param \Webkul\Velocity\Repositories\Product\ProductRepository $velocityProductRepository * @param \Webkul\Velocity\Repositories\VelocityCustomerCompareProductRepository $compareProductsRepository - * @param \Webkul\Velocity\Repositories\VelocityCustomerCompareProductRepository $compareProductsRepository * * @return void */ diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/guest/compare/compare-products.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/guest/compare/compare-products.blade.php index 83266e50f..eaf6c6199 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/guest/compare/compare-products.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/guest/compare/compare-products.blade.php @@ -4,7 +4,7 @@ $locale = request()->get('locale') ?: app()->getLocale(); - $attributeOptionTranslations = DB::table(DB::getTablePrefix() . 'attribute_option_translations')->where('locale', $locale)->get()->toJson(); + $attributeOptionTranslations = DB::table('attribute_option_translations')->where('locale', $locale)->get()->toJson(); @endphp @push('css')