From 54002459f399fdaaa6e9e08c36475bdb56ff1554 Mon Sep 17 00:00:00 2001 From: rahul shukla Date: Wed, 20 Jan 2021 20:55:12 +0530 Subject: [PATCH 01/11] Issue #3572 done --- .../Webkul/Product/src/Type/AbstractType.php | 28 +++++++++++++++++++ .../Resources/views/products/view.blade.php | 8 ++++++ .../views/shop/products/view.blade.php | 8 ++++++ 3 files changed, 44 insertions(+) diff --git a/packages/Webkul/Product/src/Type/AbstractType.php b/packages/Webkul/Product/src/Type/AbstractType.php index 5ac820274..f5c30cad4 100644 --- a/packages/Webkul/Product/src/Type/AbstractType.php +++ b/packages/Webkul/Product/src/Type/AbstractType.php @@ -924,4 +924,32 @@ abstract class AbstractType return false; } + /** + * Get more offers for customer group pricing. + * + * @return array + */ + public function getCustomerGroupPricingOffers() { + $offerLines = []; + + if ($this->haveSpecialPrice()) { + $customerGroupPrices = $this->product->customer_group_prices()->get()->sortBy('qty')->values()->all(); + + $rulePrice = app('Webkul\CatalogRule\Helpers\CatalogRuleProductPrice')->getRulePrice($this->product); + + if ($rulePrice && $rulePrice->price > $this->product->special_price) { + foreach ($customerGroupPrices as $key => $customerGroupPrice) { + if ($key > 0) { + $price = $this->getCustomerGroupPrice($this->product, $customerGroupPrice->qty); + + $save = (($this->product->price - $price)*100)/($this->product->price); + + $offerLines[] = 'Buy' .' '. $customerGroupPrice->qty .' '.'for'.' '. core()->currency($price).' '. 'each and save'.' '.$save.'%'; + } + } + } + } + + return $offerLines; + } } \ No newline at end of file diff --git a/packages/Webkul/Shop/src/Resources/views/products/view.blade.php b/packages/Webkul/Shop/src/Resources/views/products/view.blade.php index 0f378be6d..f37336ac4 100755 --- a/packages/Webkul/Shop/src/Resources/views/products/view.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/view.blade.php @@ -63,6 +63,14 @@ @include ('shop::products.price', ['product' => $product]) + @if (count($product->getTypeInstance()->getCustomerGroupPricingOffers()) > 0) +
+ @foreach ($product->getTypeInstance()->getCustomerGroupPricingOffers() as $offers) +

{{ $offers }}

+ @endforeach +
+ @endif + @include ('shop::products.view.stock', ['product' => $product]) {!! view_render_event('bagisto.shop.products.view.short_description.before', ['product' => $product]) !!} diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/products/view.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/products/view.blade.php index b9fe70ce5..89af6057a 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/products/view.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/products/view.blade.php @@ -123,6 +123,14 @@ @include ('shop::products.price', ['product' => $product]) + @if (count($product->getTypeInstance()->getCustomerGroupPricingOffers()) > 0) +
+ @foreach ($product->getTypeInstance()->getCustomerGroupPricingOffers() as $offers) + {{ $offers }}
+ @endforeach +
+ @endif +
@if (core()->getConfigData('catalog.products.storefront.buy_now_button_display')) @include ('shop::products.buy-now', [ From b6639ab0ebaa4127c76a1547374850a920d3c474 Mon Sep 17 00:00:00 2001 From: rahul shukla Date: Thu, 21 Jan 2021 13:56:32 +0530 Subject: [PATCH 02/11] did the required changes --- packages/Webkul/Product/src/Type/AbstractType.php | 5 +++-- packages/Webkul/Shop/src/Resources/lang/ar/app.php | 3 ++- packages/Webkul/Shop/src/Resources/lang/de/app.php | 3 ++- packages/Webkul/Shop/src/Resources/lang/en/app.php | 3 ++- packages/Webkul/Shop/src/Resources/lang/es/app.php | 3 ++- packages/Webkul/Shop/src/Resources/lang/fa/app.php | 3 ++- packages/Webkul/Shop/src/Resources/lang/it/app.php | 3 ++- packages/Webkul/Shop/src/Resources/lang/ja/app.php | 3 ++- packages/Webkul/Shop/src/Resources/lang/nl/app.php | 3 ++- packages/Webkul/Shop/src/Resources/lang/pl/app.php | 3 ++- packages/Webkul/Shop/src/Resources/lang/pt_BR/app.php | 3 ++- packages/Webkul/Shop/src/Resources/lang/tr/app.php | 3 ++- 12 files changed, 25 insertions(+), 13 deletions(-) diff --git a/packages/Webkul/Product/src/Type/AbstractType.php b/packages/Webkul/Product/src/Type/AbstractType.php index f5c30cad4..3e9e71f3f 100644 --- a/packages/Webkul/Product/src/Type/AbstractType.php +++ b/packages/Webkul/Product/src/Type/AbstractType.php @@ -942,9 +942,10 @@ abstract class AbstractType if ($key > 0) { $price = $this->getCustomerGroupPrice($this->product, $customerGroupPrice->qty); - $save = (($this->product->price - $price)*100)/($this->product->price); + $discount = (($this->product->price - $price) * 100) / ($this->product->price); - $offerLines[] = 'Buy' .' '. $customerGroupPrice->qty .' '.'for'.' '. core()->currency($price).' '. 'each and save'.' '.$save.'%'; + $offerLines[] = trans('shop::app.products.offers', ['qty' => $customerGroupPrice->qty, + 'price' => core()->currency($price), 'discount' => $discount]); } } } diff --git a/packages/Webkul/Shop/src/Resources/lang/ar/app.php b/packages/Webkul/Shop/src/Resources/lang/ar/app.php index 445db41a9..25ed9e625 100644 --- a/packages/Webkul/Shop/src/Resources/lang/ar/app.php +++ b/packages/Webkul/Shop/src/Resources/lang/ar/app.php @@ -442,7 +442,8 @@ return [ 'available-for-order' => 'متوفر لطلب الشراء', 'settings' => 'Settings', 'compare_options' => 'قارن الخيارات', - 'wishlist-options' => 'Wishlist Options' + 'wishlist-options' => 'Wishlist Options', + 'offers' => 'Buy :qty for :price each and save :discount%', ], // 'reviews' => [ diff --git a/packages/Webkul/Shop/src/Resources/lang/de/app.php b/packages/Webkul/Shop/src/Resources/lang/de/app.php index 0066a2122..6fdc32ea8 100755 --- a/packages/Webkul/Shop/src/Resources/lang/de/app.php +++ b/packages/Webkul/Shop/src/Resources/lang/de/app.php @@ -439,7 +439,8 @@ return [ 'available' => 'Verfügbar', 'settings' => 'Settings', 'compare_options' => 'Compare Options', - 'wishlist-options' => 'Wishlist Options' + 'wishlist-options' => 'Wishlist Options', + 'offers' => 'Buy :qty for :price each and save :discount%', ], // 'reviews' => [ diff --git a/packages/Webkul/Shop/src/Resources/lang/en/app.php b/packages/Webkul/Shop/src/Resources/lang/en/app.php index 798e652a5..59200cdc4 100755 --- a/packages/Webkul/Shop/src/Resources/lang/en/app.php +++ b/packages/Webkul/Shop/src/Resources/lang/en/app.php @@ -443,7 +443,8 @@ return [ 'available-for-order' => 'Available for Order', 'settings' => 'Settings', 'compare_options' => 'Compare Options', - 'wishlist-options' => 'Wishlist Options' + 'wishlist-options' => 'Wishlist Options', + 'offers' => 'Buy :qty for :price each and save :discount%', ], // 'reviews' => [ diff --git a/packages/Webkul/Shop/src/Resources/lang/es/app.php b/packages/Webkul/Shop/src/Resources/lang/es/app.php index d257a8285..186b25d0b 100644 --- a/packages/Webkul/Shop/src/Resources/lang/es/app.php +++ b/packages/Webkul/Shop/src/Resources/lang/es/app.php @@ -412,7 +412,8 @@ return [ 'available-for-order' => 'Disponible para ordenar', 'settings' => 'Settings', 'compare_options' => 'Compare Options', - 'wishlist-options' => 'Wishlist Options' + 'wishlist-options' => 'Wishlist Options', + 'offers' => 'Buy :qty for :price each and save :discount%', ], // 'reviews' => [ diff --git a/packages/Webkul/Shop/src/Resources/lang/fa/app.php b/packages/Webkul/Shop/src/Resources/lang/fa/app.php index 4d35980c9..eab862143 100644 --- a/packages/Webkul/Shop/src/Resources/lang/fa/app.php +++ b/packages/Webkul/Shop/src/Resources/lang/fa/app.php @@ -441,7 +441,8 @@ return [ 'available-for-order' => 'Available for Order', 'settings' => 'Settings', 'compare_options' => 'Compare Options', - 'wishlist-options' => 'Wishlist Options' + 'wishlist-options' => 'Wishlist Options', + 'offers' => 'Buy :qty for :price each and save :discount%', ], // 'reviews' => [ diff --git a/packages/Webkul/Shop/src/Resources/lang/it/app.php b/packages/Webkul/Shop/src/Resources/lang/it/app.php index df2e7126b..844909a64 100644 --- a/packages/Webkul/Shop/src/Resources/lang/it/app.php +++ b/packages/Webkul/Shop/src/Resources/lang/it/app.php @@ -439,7 +439,8 @@ return [ 'available-for-order' => 'Disponibile per lordine', 'settings' => 'Settings', 'compare_options' => 'Compare Options', - 'wishlist-options' => 'Wishlist Options' + 'wishlist-options' => 'Wishlist Options', + 'offers' => 'Buy :qty for :price each and save :discount%', ], // 'reviews' => [ diff --git a/packages/Webkul/Shop/src/Resources/lang/ja/app.php b/packages/Webkul/Shop/src/Resources/lang/ja/app.php index c33d606e9..fea315087 100644 --- a/packages/Webkul/Shop/src/Resources/lang/ja/app.php +++ b/packages/Webkul/Shop/src/Resources/lang/ja/app.php @@ -408,7 +408,8 @@ return [ 'available-for-order' => '注文可能', 'settings' => 'Settings', 'compare_options' => 'Compare Options', - 'wishlist-options' => 'Wishlist Options' + 'wishlist-options' => 'Wishlist Options', + 'offers' => 'Buy :qty for :price each and save :discount%', ], 'buynow' => [ diff --git a/packages/Webkul/Shop/src/Resources/lang/nl/app.php b/packages/Webkul/Shop/src/Resources/lang/nl/app.php index 1213ff27c..4979cff60 100644 --- a/packages/Webkul/Shop/src/Resources/lang/nl/app.php +++ b/packages/Webkul/Shop/src/Resources/lang/nl/app.php @@ -446,7 +446,8 @@ return [ 'available-for-order' => 'Beschikbaar voor bestelling', 'settings' => 'Settings', 'compare_options' => 'Compare Options', - 'wishlist-options' => 'Wishlist Options' + 'wishlist-options' => 'Wishlist Options', + 'offers' => 'Buy :qty for :price each and save :discount%', ], // 'reviews' => [ diff --git a/packages/Webkul/Shop/src/Resources/lang/pl/app.php b/packages/Webkul/Shop/src/Resources/lang/pl/app.php index 5161c9bde..fcff349b7 100644 --- a/packages/Webkul/Shop/src/Resources/lang/pl/app.php +++ b/packages/Webkul/Shop/src/Resources/lang/pl/app.php @@ -439,7 +439,8 @@ return [ 'available-for-order' => 'Dostępne na zamówienie', 'settings' => 'Settings', 'compare_options' => 'Compare Options', - 'wishlist-options' => 'Wishlist Options' + 'wishlist-options' => 'Wishlist Options', + 'offers' => 'Buy :qty for :price each and save :discount%', ], // 'reviews' => [ diff --git a/packages/Webkul/Shop/src/Resources/lang/pt_BR/app.php b/packages/Webkul/Shop/src/Resources/lang/pt_BR/app.php index 05deed015..735bd0b60 100755 --- a/packages/Webkul/Shop/src/Resources/lang/pt_BR/app.php +++ b/packages/Webkul/Shop/src/Resources/lang/pt_BR/app.php @@ -429,7 +429,8 @@ return [ 'available-for-order' => 'Disponível para encomenda', 'settings' => 'Settings', 'compare_options' => 'Compare Options', - 'wishlist-options' => 'Wishlist Options' + 'wishlist-options' => 'Wishlist Options', + 'offers' => 'Buy :qty for :price each and save :discount%', ], // 'reviews' => [ diff --git a/packages/Webkul/Shop/src/Resources/lang/tr/app.php b/packages/Webkul/Shop/src/Resources/lang/tr/app.php index bd8527cdf..de0b092aa 100644 --- a/packages/Webkul/Shop/src/Resources/lang/tr/app.php +++ b/packages/Webkul/Shop/src/Resources/lang/tr/app.php @@ -439,7 +439,8 @@ return [ 'available-for-order' => 'Sipariş İçin Uygun', 'settings' => 'Settings', 'compare_options' => 'Compare Options', - 'wishlist-options' => 'Wishlist Options' + 'wishlist-options' => 'Wishlist Options', + 'offers' => 'Buy :qty for :price each and save :discount%', ], // 'reviews' => [ From b3b1dadca97b939c4a1821eaa4c47f5d3275af1f Mon Sep 17 00:00:00 2001 From: rahul shukla Date: Fri, 22 Jan 2021 17:38:00 +0530 Subject: [PATCH 03/11] Issue #fixes as per comment --- .../Webkul/Product/src/Type/AbstractType.php | 42 +++++++++++++++---- .../views/shop/checkout/cart/index.blade.php | 4 +- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/packages/Webkul/Product/src/Type/AbstractType.php b/packages/Webkul/Product/src/Type/AbstractType.php index 3e9e71f3f..5caf7c2aa 100644 --- a/packages/Webkul/Product/src/Type/AbstractType.php +++ b/packages/Webkul/Product/src/Type/AbstractType.php @@ -931,26 +931,50 @@ abstract class AbstractType */ public function getCustomerGroupPricingOffers() { $offerLines = []; + $haveOffers = true; + + $customerGroupPrices = $this->product->customer_group_prices()->get()->sortBy('qty')->values()->all(); if ($this->haveSpecialPrice()) { - $customerGroupPrices = $this->product->customer_group_prices()->get()->sortBy('qty')->values()->all(); - $rulePrice = app('Webkul\CatalogRule\Helpers\CatalogRuleProductPrice')->getRulePrice($this->product); - if ($rulePrice && $rulePrice->price > $this->product->special_price) { + if ($rulePrice && $rulePrice->price < $this->product->special_price) { + $haveOffers = false; + } + + if ($haveOffers) { foreach ($customerGroupPrices as $key => $customerGroupPrice) { if ($key > 0) { - $price = $this->getCustomerGroupPrice($this->product, $customerGroupPrice->qty); - - $discount = (($this->product->price - $price) * 100) / ($this->product->price); - - $offerLines[] = trans('shop::app.products.offers', ['qty' => $customerGroupPrice->qty, - 'price' => core()->currency($price), 'discount' => $discount]); + array_push($offerLines, $this->getOfferLines($customerGroupPrice)); } } } + } else { + if (count($customerGroupPrices) > 0) { + foreach ($customerGroupPrices as $key => $customerGroupPrice) { + array_push($offerLines, $this->getOfferLines($customerGroupPrice)); + } + } } return $offerLines; } + + /** + * Get offers lines. + * + * @param array $customerGroupPrice + * + * @return array + */ + public function getOfferLines($customerGroupPrice) { + $price = $this->getCustomerGroupPrice($this->product, $customerGroupPrice->qty); + + $discount = (($this->product->price - $price) * 100) / ($this->product->price); + + $offerLines = trans('shop::app.products.offers', ['qty' => $customerGroupPrice->qty, + 'price' => core()->currency($price), 'discount' => $discount]); + + return $offerLines; + } } \ No newline at end of file diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/checkout/cart/index.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/checkout/cart/index.blade.php index a5dabc8cc..fc85aa0b2 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/checkout/cart/index.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/checkout/cart/index.blade.php @@ -113,7 +113,9 @@ @endif
- @include ('shop::products.price', ['product' => $product]) +
+ {{ core()->currency($item->base_price) }} +
@php From 5b05cf75f446771c2f1d0fa34b3546c4df52646d Mon Sep 17 00:00:00 2001 From: rahul shukla Date: Wed, 27 Jan 2021 14:58:54 +0530 Subject: [PATCH 04/11] Issue #3572 fixes according to comment --- .../Webkul/Product/src/Type/AbstractType.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/Webkul/Product/src/Type/AbstractType.php b/packages/Webkul/Product/src/Type/AbstractType.php index 5caf7c2aa..083c38c57 100644 --- a/packages/Webkul/Product/src/Type/AbstractType.php +++ b/packages/Webkul/Product/src/Type/AbstractType.php @@ -932,8 +932,23 @@ abstract class AbstractType public function getCustomerGroupPricingOffers() { $offerLines = []; $haveOffers = true; + $customerGroupId = null; - $customerGroupPrices = $this->product->customer_group_prices()->get()->sortBy('qty')->values()->all(); + if (Cart::getCurrentCustomer()->check()) { + $customerGroupId = Cart::getCurrentCustomer()->user()->customer_group_id; + } else { + $customerGroupRepository = app('Webkul\Customer\Repositories\CustomerGroupRepository'); + + if ($customerGuestGroup = $customerGroupRepository->findOneByField('code', 'guest')) { + $customerGroupId = $customerGuestGroup->id; + } + } + + $customerGroupPrices = $this->product->customer_group_prices()->where(function ($query) use ($customerGroupId) { + $query->where('customer_group_id', $customerGroupId) + ->orWhereNull('customer_group_id'); + } + )->groupBy('qty')->get()->sortBy('qty')->values()->all(); if ($this->haveSpecialPrice()) { $rulePrice = app('Webkul\CatalogRule\Helpers\CatalogRuleProductPrice')->getRulePrice($this->product); From dab3393e381b2b621e3c6573f73f3f0540876df9 Mon Sep 17 00:00:00 2001 From: devansh bawari Date: Wed, 27 Jan 2021 15:11:20 +0530 Subject: [PATCH 05/11] Fixed Extra Question Mark --- .../Webkul/Product/src/Helpers/Toolbar.php | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/Webkul/Product/src/Helpers/Toolbar.php b/packages/Webkul/Product/src/Helpers/Toolbar.php index 8d06a1f88..8ea2ee097 100755 --- a/packages/Webkul/Product/src/Helpers/Toolbar.php +++ b/packages/Webkul/Product/src/Helpers/Toolbar.php @@ -46,7 +46,7 @@ class Toolbar extends AbstractProduct { $keys = explode('-', $key); - return request()->fullUrlWithQuery([ + return $this->fullUrlWithQuery([ 'sort' => current($keys), 'order' => end($keys), ]); @@ -60,7 +60,7 @@ class Toolbar extends AbstractProduct */ public function getLimitUrl($limit) { - return request()->fullUrlWithQuery([ + return $this->fullUrlWithQuery([ 'limit' => $limit, ]); } @@ -73,7 +73,7 @@ class Toolbar extends AbstractProduct */ public function getModeUrl($mode) { - return request()->fullUrlWithQuery([ + return $this->fullUrlWithQuery([ 'mode' => $mode, ]); } @@ -185,4 +185,22 @@ class Toolbar extends AbstractProduct /* if still default config is not set from the admin then in last needed hardcoded value */ return $viewOption ?? 'grid'; } + + /** + * Returns the query string. As request built in method does not able to handle the + * multiple question marks, this method will check the query string and append the query string. + * + * @param array $additionalQuery + * @return string + */ + public function fullUrlWithQuery($additionalQuery) + { + $queryString = request()->getQueryString(); + + $additionalQueryString = http_build_query($additionalQuery); + + return $queryString + ? url()->current() . '?' . $queryString . '&' . $additionalQueryString + : url()->current() . '?' . $additionalQueryString; + } } \ No newline at end of file From ec467a2a0f67d9278db8a57040fdba72f3368c22 Mon Sep 17 00:00:00 2001 From: rahul shukla Date: Wed, 27 Jan 2021 17:24:03 +0530 Subject: [PATCH 06/11] Issue #4495 fixed --- .../src/Resources/views/catalog/products/edit.blade.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php b/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php index 82850d4d7..df4959da4 100755 --- a/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php @@ -38,7 +38,7 @@
- + @foreach (core()->getAllChannels() as $channelModel) - @endforeach @@ -45,10 +46,11 @@
- + @foreach (app('Webkul\Core\Repositories\ChannelRepository')->findOneByField('code', $channel)->locales as $localeModel) - @@ -105,9 +107,9 @@ value="{{ $metaData ? $metaData->header_content_count : '5' }}" />
- - + +