Merge pull request #4507 from rahulshukla-webkul/development

Issue #3572 done
This commit is contained in:
Glenn Hermans 2021-01-29 09:59:36 +01:00 committed by GitHub
commit e1a32a2f83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 178 additions and 35 deletions

View File

@ -30,10 +30,17 @@ class SliderDataGrid extends DataGrid
{
parent::__construct();
$this->locale = request()->get('locale') ?? 'all';
$this->channel = request()->get('channel')
? Channel::find(request()->get('channel'))->code
: 'all';
/* locale */
$this->locale = request()->get('locale') ?? app()->getLocale();
/* channel */
$this->channel = request()->get('channel') ?? (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
/* finding channel code */
if ($this->channel !== 'all') {
$this->channel = Channel::query()->find($this->channel);
$this->channel = $this->channel ? $this->channel->code : 'all';
}
}
public function prepareQueryBuilder()

View File

@ -38,7 +38,7 @@
<div class="control-group">
<select class="control" id="locale-switcher" name="locale">
@foreach (core()->getAllLocales() as $localeModel)
@foreach (app('Webkul\Core\Repositories\ChannelRepository')->findOneByField('code', $channel)->locales as $localeModel)
<option
value="{{ $localeModel->code }}" {{ ($localeModel->code) == $locale ? 'selected' : '' }}>
@ -199,6 +199,13 @@
$(document).ready(function () {
$('#channel-switcher, #locale-switcher').on('change', function (e) {
$('#channel-switcher').val()
if (event.target.id == 'channel-switcher') {
let locale = "{{ app('Webkul\Core\Repositories\ChannelRepository')->findOneByField('code', $channel)->locales->first()->code }}";
$('#locale-switcher').val(locale);
}
var query = '?channel=' + $('#channel-switcher').val() + '&locale=' + $('#locale-switcher').val();
window.location.href = "{{ route('admin.catalog.products.edit', $product->id) }}" + query;

View File

@ -924,4 +924,72 @@ abstract class AbstractType
return false;
}
/**
* Get more offers for customer group pricing.
*
* @return array
*/
public function getCustomerGroupPricingOffers() {
$offerLines = [];
$haveOffers = true;
$customerGroupId = null;
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);
if ($rulePrice && $rulePrice->price < $this->product->special_price) {
$haveOffers = false;
}
if ($haveOffers) {
foreach ($customerGroupPrices as $key => $customerGroupPrice) {
if ($key > 0) {
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;
}
}

View File

@ -96,7 +96,7 @@ class Configurable extends AbstractType
{
$product = parent::update($data, $id, $attribute);
$route = request()->route() ? request()->route()->getName() : '';
if ($route != 'admin.catalog.products.massupdate') {
$previousVariantIds = $product->variants->pluck('id');
@ -355,7 +355,7 @@ class Configurable extends AbstractType
*/
public function getMinimalPrice($qty = null)
{
$minPrices = [];
$minPrices = $rulePrices = $customerGroupPrices = [];
/* method is calling many time so using variable */
$tablePrefix = DB::getTablePrefix();
@ -373,11 +373,21 @@ class Configurable extends AbstractType
$minPrices[] = $price->min_price;
}
foreach ($this->product->variants as $variant) {
$rulePrice = app('Webkul\CatalogRule\Helpers\CatalogRuleProductPrice')->getRulePrice($variant);
if ($rulePrice) {
$rulePrices[] = $rulePrice->price;
}
$customerGroupPrices[] = $this->getCustomerGroupPrice($variant, 1);
}
if (empty($minPrices)) {
return 0;
}
return min($minPrices);
return min(array_merge(array_merge($minPrices, $rulePrices), $customerGroupPrices));
}
/**
@ -540,7 +550,7 @@ class Configurable extends AbstractType
$product = $item->child->product;
} else {
$product = $item->product;
}
}
}
}

View File

@ -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' => [

View File

@ -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' => [

View File

@ -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' => [

View File

@ -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' => [

View File

@ -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' => [

View File

@ -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' => [

View File

@ -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' => [

View File

@ -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' => [

View File

@ -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' => [

View File

@ -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' => [

View File

@ -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' => [

View File

@ -63,6 +63,14 @@
@include ('shop::products.price', ['product' => $product])
@if (count($product->getTypeInstance()->getCustomerGroupPricingOffers()) > 0)
<div class="regular-price">
@foreach ($product->getTypeInstance()->getCustomerGroupPricingOffers() as $offers)
<p> {{ $offers }} </p>
@endforeach
</div>
@endif
@include ('shop::products.view.stock', ['product' => $product])
{!! view_render_event('bagisto.shop.products.view.short_description.before', ['product' => $product]) !!}

View File

@ -2,6 +2,12 @@
$locale = request()->get('locale') ?: app()->getLocale();
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
$customer_group = request()->get('customer_group');
if ($channel == 'all') {
$locales = core()->getAllLocales();
} else {
$locales = app('Webkul\Core\Repositories\ChannelRepository')->findOneByField('code', $channel)->locales;
}
@endphp
<div class="table">
@ -27,8 +33,8 @@
</option>
@foreach ($results['extraFilters']['channels'] as $channelModel)
<option
value="{{ $channelModel->id }}"
{{ (isset($channel) && ($channelModel->id) == $channel) ? 'selected' : '' }}>
value="{{ $channelModel->code }}"
{{ (isset($channel) && ($channelModel->code) == $channel) ? 'selected' : '' }}>
{{ $channelModel->name }}
</option>
@endforeach
@ -45,7 +51,7 @@
<option value="all" {{ ! isset($locale) ? 'selected' : '' }}>
{{ __('admin::app.admin.system.all-locales') }}
</option>
@foreach ($results['extraFilters']['locales'] as $localeModel)
@foreach ($locales as $localeModel)
<option
value="{{ $localeModel->code }}" {{ (isset($locale) && ($localeModel->code) == $locale) ? 'selected' : '' }}>
{{ $localeModel->name }}
@ -715,7 +721,7 @@
case "channel":
obj.label = "Channel";
if ('channels' in this.extraFilters) {
obj.prettyValue = this.extraFilters['channels'].find(channel => channel.id == obj.val).name
obj.prettyValue = this.extraFilters['channels'].find(channel => channel.code == obj.val).name
}
break;
case "locale":

View File

@ -33,11 +33,12 @@
<input type="hidden" name="channel" value="{{ $channel }}" />
<div class="control-group">
<select class="control" id="channel-switcher" onChange="window.location.href = this.value">
@foreach (core()->getAllChannels() as $ch)
<select class="control" id="channel-switcher" name="channel">
@foreach (core()->getAllChannels() as $channelModel)
<option value="{{ route('velocity.admin.meta-data') . '?channel=' . $ch->code . '&locale=' . $locale }}" {{ ($ch->code) == $channel ? 'selected' : '' }}>
{{ $ch->name }}
<option
value="{{ $channelModel->code }}" {{ ($channelModel->code) == $channel ? 'selected' : '' }}>
{{ $channelModel->name }}
</option>
@endforeach
@ -45,10 +46,11 @@
</div>
<div class="control-group">
<select class="control" id="locale-switcher" onChange="window.location.href = this.value">
@foreach (core()->getAllLocales() as $localeModel)
<select class="control" id="locale-switcher" name="locale">
@foreach (app('Webkul\Core\Repositories\ChannelRepository')->findOneByField('code', $channel)->locales as $localeModel)
<option value="{{ route('velocity.admin.meta-data') . '?locale=' . $localeModel->code . '&channel=' . $channel }}" {{ ($localeModel->code) == $locale ? 'selected' : '' }}>
<option
value="{{ $localeModel->code }}" {{ ($localeModel->code) == $locale ? 'selected' : '' }}>
{{ $localeModel->name }}
</option>
@ -105,9 +107,9 @@
value="{{ $metaData ? $metaData->header_content_count : '5' }}" />
</div>
<div class="control-group">
<label style="width:100%;">
{{ __('velocity::app.admin.meta-data.home-page-content') }}
@ -181,7 +183,7 @@
'url' => asset('/themes/velocity/assets/images/kids.webp'),
];
@endphp
<image-wrapper
:multiple="true"
input-name="images[4]"
@ -351,6 +353,20 @@
plugins: 'image imagetools media wordcount save fullscreen code',
toolbar1: 'formatselect | bold italic strikethrough forecolor backcolor | link | alignleft aligncenter alignright alignjustify | numlist bullist outdent indent | removeformat | code',
});
$('#channel-switcher, #locale-switcher').on('change', function (e) {
$('#channel-switcher').val()
if (event.target.id == 'channel-switcher') {
let locale = "{{ app('Webkul\Core\Repositories\ChannelRepository')->findOneByField('code', $channel)->locales->first()->code }}";
$('#locale-switcher').val(locale);
}
var query = '?channel=' + $('#channel-switcher').val() + '&locale=' + $('#locale-switcher').val();
window.location.href = "{{ route('velocity.admin.meta-data') }}" + query;
})
});
</script>
@endpush

View File

@ -113,7 +113,9 @@
@endif
<div class="row col-12 no-padding no-margin">
@include ('shop::products.price', ['product' => $product])
<div class="product-price">
<span>{{ core()->currency($item->base_price) }}</span>
</div>
</div>
@php

View File

@ -123,6 +123,14 @@
@include ('shop::products.price', ['product' => $product])
</div>
@if (count($product->getTypeInstance()->getCustomerGroupPricingOffers()) > 0)
<div class="col-12">
@foreach ($product->getTypeInstance()->getCustomerGroupPricingOffers() as $offers)
{{ $offers }} </br>
@endforeach
</div>
@endif
<div class="product-actions">
@if (core()->getConfigData('catalog.products.storefront.buy_now_button_display'))
@include ('shop::products.buy-now', [