From 35a9e90780f0d59f75992f7b895d6d93e803de21 Mon Sep 17 00:00:00 2001 From: Herbert Maschke Date: Fri, 7 Feb 2020 11:16:00 +0100 Subject: [PATCH 01/36] add improvements to locale determination on product creation --- packages/Webkul/Core/src/Core.php | 3 + packages/Webkul/Core/src/Models/Channel.php | 14 +++- .../Webkul/Product/src/Models/Product.php | 71 +++++++++++++++---- 3 files changed, 73 insertions(+), 15 deletions(-) diff --git a/packages/Webkul/Core/src/Core.php b/packages/Webkul/Core/src/Core.php index d39459dff..2e4b1d167 100755 --- a/packages/Webkul/Core/src/Core.php +++ b/packages/Webkul/Core/src/Core.php @@ -135,6 +135,9 @@ class Core 'https://' . request()->getHttpHost(), ])->first(); + if (! $channel) + $channel = $this->channelRepository->findOneByField('code', config('app.channel')); + if (! $channel) $channel = $this->channelRepository->first(); diff --git a/packages/Webkul/Core/src/Models/Channel.php b/packages/Webkul/Core/src/Models/Channel.php index 963418413..1908a4872 100755 --- a/packages/Webkul/Core/src/Models/Channel.php +++ b/packages/Webkul/Core/src/Models/Channel.php @@ -10,7 +10,19 @@ use Webkul\Core\Contracts\Channel as ChannelContract; class Channel extends Model implements ChannelContract { - protected $fillable = ['code', 'name', 'description', 'theme', 'home_page_content', 'footer_content', 'hostname', 'default_locale_id', 'base_currency_id', 'root_category_id', 'home_seo']; + protected $fillable = [ + 'code', + 'name', + 'description', + 'theme', + 'home_page_content', + 'footer_content', + 'hostname', + 'default_locale_id', + 'base_currency_id', + 'root_category_id', + 'home_seo', + ]; /** * Get the channel locales. diff --git a/packages/Webkul/Product/src/Models/Product.php b/packages/Webkul/Product/src/Models/Product.php index ce9ab9d08..d73e46527 100755 --- a/packages/Webkul/Product/src/Models/Product.php +++ b/packages/Webkul/Product/src/Models/Product.php @@ -2,6 +2,7 @@ namespace Webkul\Product\Models; +use Webkul\Core\Models\Channel; use Illuminate\Database\Eloquent\Model; use Webkul\Attribute\Models\AttributeFamilyProxy; use Webkul\Category\Models\CategoryProxy; @@ -181,8 +182,8 @@ class Product extends Model implements ProductContract public function inventory_source_qty($inventorySourceId) { return $this->inventories() - ->where('inventory_source_id', $inventorySourceId) - ->sum('qty'); + ->where('inventory_source_id', $inventorySourceId) + ->sum('qty'); } /** @@ -243,6 +244,7 @@ class Product extends Model implements ProductContract * * @param Group $group * @param bool $skipSuperAttribute + * * @return Collection */ public function getEditableAttributes($group = null, $skipSuperAttribute = true) @@ -253,7 +255,8 @@ class Product extends Model implements ProductContract /** * Get an attribute from the model. * - * @param string $key + * @param string $key + * * @return mixed */ public function getAttribute($key) @@ -262,8 +265,9 @@ class Product extends Model implements ProductContract if (isset($this->id)) { $this->attributes[$key] = ''; - $attribute = core()->getSingletonInstance(\Webkul\Attribute\Repositories\AttributeRepository::class) - ->getAttributeByCode($key); + $attribute = core() + ->getSingletonInstance(\Webkul\Attribute\Repositories\AttributeRepository::class) + ->getAttributeByCode($key); $this->attributes[$key] = $this->getCustomAttributeValue($attribute); @@ -284,8 +288,9 @@ class Product extends Model implements ProductContract $hiddenAttributes = $this->getHidden(); if (isset($this->id)) { - $familyAttributes = core()->getSingletonInstance(\Webkul\Attribute\Repositories\AttributeRepository::class) - ->getFamilyAttributes($this->attribute_family); + $familyAttributes = core() + ->getSingletonInstance(\Webkul\Attribute\Repositories\AttributeRepository::class) + ->getFamilyAttributes($this->attribute_family); foreach ($familyAttributes as $attribute) { if (in_array($attribute->code, $hiddenAttributes)) { @@ -306,24 +311,41 @@ class Product extends Model implements ProductContract */ public function getCustomAttributeValue($attribute) { - if (! $attribute) + if (! $attribute) { return; + } $channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode()); - $locale = request()->get('locale') ?: app()->getLocale(); + $locale = $this->determineLocale($channel); if ($attribute->value_per_channel) { if ($attribute->value_per_locale) { - $attributeValue = $this->attribute_values()->where('channel', $channel)->where('locale', $locale)->where('attribute_id', $attribute->id)->first(); + $attributeValue = $this + ->attribute_values() + ->where('channel', $channel) + ->where('locale', $locale) + ->where('attribute_id', $attribute->id) + ->first(); } else { - $attributeValue = $this->attribute_values()->where('channel', $channel)->where('attribute_id', $attribute->id)->first(); + $attributeValue = $this + ->attribute_values() + ->where('channel', $channel) + ->where('attribute_id', $attribute->id) + ->first(); } } else { if ($attribute->value_per_locale) { - $attributeValue = $this->attribute_values()->where('locale', $locale)->where('attribute_id', $attribute->id)->first(); + $attributeValue = $this + ->attribute_values() + ->where('locale', $locale) + ->where('attribute_id', $attribute->id) + ->first(); } else { - $attributeValue = $this->attribute_values()->where('attribute_id', $attribute->id)->first(); + $attributeValue = $this + ->attribute_values() + ->where('attribute_id', $attribute->id) + ->first(); } } @@ -333,7 +355,8 @@ class Product extends Model implements ProductContract /** * Overrides the default Eloquent query builder * - * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $query + * * @return \Illuminate\Database\Eloquent\Builder */ public function newEloquentBuilder($query) @@ -356,4 +379,24 @@ class Product extends Model implements ProductContract { return $this; } + + /** + * Determine if the given channel has a default locale configured. + * If not, return the channel given in the request. + * If none given, return the fallback channel given in the application configuration + * + * @param string $channel + * + * @return string + */ + private function determineLocale(string $channel): string + { + $channelModel = Channel::where(['code' => $channel])->first(); + + if ($channelModel) { + return $channelModel->default_locale->code; + } + + return request()->get('locale') ?: app()->getLocale(); + } } \ No newline at end of file From 38dbb6384d61087e8131506776fe0643947fd331 Mon Sep 17 00:00:00 2001 From: Herbert Maschke Date: Mon, 10 Feb 2020 15:05:03 +0100 Subject: [PATCH 02/36] obey the default channel and configured default locale in product edit form --- .../views/catalog/products/edit.blade.php | 15 ++-- .../Http/Controllers/ProductController.php | 69 ++++++++++++------- 2 files changed, 49 insertions(+), 35 deletions(-) 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 6adba4afc..4b57617fc 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 @@ -6,9 +6,6 @@ @section('content')
- get('locale') ?: app()->getLocale(); ?> - get('channel') ?: core()->getDefaultChannelCode(); ?> - {!! view_render_event('bagisto.admin.catalog.product.edit.before', ['product' => $product]) !!}
@@ -28,7 +25,7 @@ @foreach (core()->getAllChannels() as $channelModel) @@ -41,7 +38,7 @@ @foreach (core()->getAllLocales() as $localeModel) @@ -114,11 +111,11 @@ $channel_locale = []; if ($attribute->value_per_channel) { - array_push($channel_locale, $channel); + array_push($channel_locale, $channelCode); } if ($attribute->value_per_locale) { - array_push($channel_locale, $locale); + array_push($channel_locale, $localeCode); } ?> @@ -181,9 +178,9 @@ \ No newline at end of file diff --git a/packages/Webkul/Velocity/src/Resources/assets/js/UI/components/product-quick-view.vue b/packages/Webkul/Velocity/src/Resources/assets/js/UI/components/product-quick-view.vue new file mode 100644 index 000000000..624c7c18a --- /dev/null +++ b/packages/Webkul/Velocity/src/Resources/assets/js/UI/components/product-quick-view.vue @@ -0,0 +1,93 @@ + + + \ No newline at end of file diff --git a/packages/Webkul/Velocity/src/Resources/assets/js/UI/components/trans.js b/packages/Webkul/Velocity/src/Resources/assets/js/UI/components/trans.js index 7b1347999..56fc2ce05 100644 --- a/packages/Webkul/Velocity/src/Resources/assets/js/UI/components/trans.js +++ b/packages/Webkul/Velocity/src/Resources/assets/js/UI/components/trans.js @@ -3,7 +3,7 @@ module.exports = { /** * Translate the given key. */ - __(key) { + __(key, params) { let splitedKey = key.split('.'); let translation = window._translations; @@ -11,6 +11,13 @@ module.exports = { translation = translation[key]; }); + if (params) { + Object.keys(params).forEach(key => { + let value = params[key]; + translation = translation.replace(`:${key}`, value); + }); + } + return translation } }, diff --git a/packages/Webkul/Velocity/src/Resources/assets/js/app.js b/packages/Webkul/Velocity/src/Resources/assets/js/app.js index 7ff527f30..46585777c 100755 --- a/packages/Webkul/Velocity/src/Resources/assets/js/app.js +++ b/packages/Webkul/Velocity/src/Resources/assets/js/app.js @@ -39,10 +39,11 @@ Vue.component("product-card", require("./UI/components/product-card")); Vue.component("wishlist-component", require("./UI/components/wishlist")); Vue.component('carousel-component', require('./UI/components/carousel')); Vue.component('child-sidebar', require('./UI/components/child-sidebar')); -Vue.component('card-list-content', require('./UI/components/card-list')); Vue.component('card-list-header', require('./UI/components/card-header')); Vue.component('magnify-image', require('./UI/components/image-magnifier')); Vue.component('responsive-sidebar', require('./UI/components/responsive-sidebar')); +Vue.component('product-quick-view', require('./UI/components/product-quick-view')); +Vue.component('product-quick-view-btn', require('./UI/components/product-quick-view-btn')); window.eventBus = new Vue(); @@ -163,6 +164,8 @@ $(document).ready(function () { data: function () { return { modalIds: {}, + quickView: false, + productDetails: [], } }, diff --git a/packages/Webkul/Velocity/src/Resources/assets/sass/components/app.scss b/packages/Webkul/Velocity/src/Resources/assets/sass/components/app.scss index dd2b0e028..44f1e3aa2 100644 --- a/packages/Webkul/Velocity/src/Resources/assets/sass/components/app.scss +++ b/packages/Webkul/Velocity/src/Resources/assets/sass/components/app.scss @@ -338,7 +338,7 @@ .product-card-new:hover { #quick-view-btn-container { - // display: block; + display: block; } } diff --git a/packages/Webkul/Velocity/src/Resources/assets/sass/components/home.scss b/packages/Webkul/Velocity/src/Resources/assets/sass/components/home.scss index 285e23bf4..63c8fbec4 100644 --- a/packages/Webkul/Velocity/src/Resources/assets/sass/components/home.scss +++ b/packages/Webkul/Velocity/src/Resources/assets/sass/components/home.scss @@ -588,15 +588,14 @@ body::after { } .cd-quick-view { - top: 50px; - left: 22%; - width: 734px; - z-index: 11; + top: 100px; + width: 700px; + z-index: 101; padding: 40px; display: block; - position: fixed; - max-width: 900px; - max-height: 1000px; + position: absolute; + margin-bottom: 50px; + left: calc(50% - 350px); background-color: #fff; // transition: box-shadow .3s; // -moz-transition: box-shadow .3s; @@ -609,8 +608,8 @@ body::after { -webkit-backface-visibility: hidden; .cd-slider li.selected img { - width: 317px; - height: 397px; + width: 100%; + height: 100%; display: inline-block !important; } @@ -619,8 +618,9 @@ body::after { } .close-btn { - top: -25px; - right: -15px; + top: 15px; + right: 20px; + font-weight: 600; position: absolute; } @@ -633,6 +633,40 @@ body::after { margin-left: 24px; } } + + .product-price { + span:nth-child(1), + .special-price, + .price-from > span:not(:nth-child(2)) { + font-size: 20px; + font-weight: 600; + } + } + + .wishlist-icon { + height: 38px; + display: table; + margin-left: 10px; + + i { + display: table-cell; + vertical-align: middle; + } + } + + .quick-view-name { + font-size: 24px; + line-height: 25px; + } + + .product-rating { + display: table; + + span { + vertical-align: top; + display: table-cell; + } + } } .container { diff --git a/packages/Webkul/Velocity/src/Resources/assets/sass/components/shared.scss b/packages/Webkul/Velocity/src/Resources/assets/sass/components/shared.scss index ffa3a70cf..34791542d 100644 --- a/packages/Webkul/Velocity/src/Resources/assets/sass/components/shared.scss +++ b/packages/Webkul/Velocity/src/Resources/assets/sass/components/shared.scss @@ -847,18 +847,6 @@ button[disabled] { font-family: 'Webkul Rango' !important; } -.quick-view-name { - font-size: 24px; -} - -.quick-view-price { - font-size: 30px; -} - -.description-text { - font-size: 14px; -} - .max-height-350 { max-height: 350px; } @@ -873,4 +861,12 @@ button[disabled] { textarea { border-color: $border-danger !important; } +} + +.modal-parent { + width: 100%; + height: 100%; + z-index: 5000; + position: fixed; + background: rgba(255, 255, 255, 0.9); } \ No newline at end of file diff --git a/packages/Webkul/Velocity/src/Resources/views/admin/meta-info/meta-data.blade.php b/packages/Webkul/Velocity/src/Resources/views/admin/meta-info/meta-data.blade.php index 5f27c4730..1f849d92f 100644 --- a/packages/Webkul/Velocity/src/Resources/views/admin/meta-info/meta-data.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/admin/meta-info/meta-data.blade.php @@ -30,7 +30,7 @@
- +
diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/UI/product-quick-view.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/UI/product-quick-view.blade.php deleted file mode 100644 index 022e2c0d0..000000000 --- a/packages/Webkul/Velocity/src/Resources/views/shop/UI/product-quick-view.blade.php +++ /dev/null @@ -1,147 +0,0 @@ -@inject ('productImageHelper', 'Webkul\Product\Helpers\ProductImage') -@inject ('reviewHelper', 'Webkul\Product\Helpers\Review') - -@php - $productBaseImage = $productImageHelper->getProductBaseImage($product); - $productPrice = $product->getTypeInstance()->getProductPrices(); - $totalReviews = $product->reviews; - $avgRatings = ceil($reviewHelper->getAverageRating($product)); - - // @TODO - // foreach ($totalReviews as $review) { - // $productReview = $review; - // } -@endphp - - - - - -@push('scripts') - -@endpush \ No newline at end of file diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/layouts/master.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/layouts/master.blade.php index 8a2bb729d..d733051bc 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/layouts/master.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/layouts/master.blade.php @@ -60,6 +60,8 @@
{{-- --}} + +
@section('body-header') diff --git a/packages/Webkul/Velocity/src/Resources/views/shop/products/list/card.blade.php b/packages/Webkul/Velocity/src/Resources/views/shop/products/list/card.blade.php index db0d97ea2..4ac623dce 100644 --- a/packages/Webkul/Velocity/src/Resources/views/shop/products/list/card.blade.php +++ b/packages/Webkul/Velocity/src/Resources/views/shop/products/list/card.blade.php @@ -1,14 +1,14 @@ @inject ('productImageHelper', 'Webkul\Product\Helpers\ProductImage') @inject ('reviewHelper', 'Webkul\Product\Helpers\Review') @inject ('toolbarHelper', 'Webkul\Product\Helpers\Toolbar') -{{-- @include('shop::UI.product-quick-view') --}} +{{-- @include('shop::UI.product-quick-view') --}} @push('css')