menu Controller

This commit is contained in:
merdan 2022-09-22 13:16:32 +05:00
parent cd5052d7b4
commit 8b88036727
4 changed files with 182 additions and 30 deletions

View File

@ -36,32 +36,13 @@ class Product extends JsonResource
return [
/* product's information */
'id' => $product->id,
// 'sku' => $product->sku,
'type' => $product->type,
'name' => $product->name,
// 'url_key' => $product->url_key,
'price' => (double) core()->convertPrice($productTypeInstance->getMinimalPrice()),
'formatted_price' => core()->currency($productTypeInstance->getMinimalPrice()),
// 'short_description' => $product->short_description,
'description' => $product->description,
'images' => ProductImage::collection($productTypeInstance->getImages()),
/* product's checks */
// 'in_stock' => $product->haveSufficientQuantity(1),
'is_wishlisted' => $this->isWishlisted($product) ,
'is_item_in_cart' => \Cart::hasProduct($product),
'shop_title' => $this->shop_title,
// 'new' => $this->new,
// 'featured' => $this->featured,
'brand' => $product->brand->name ?? '',
// 'show_quantity_changer' => $this->when(
// $product->type !== 'grouped',
// $product->getTypeInstance()->showQuantityBox()
// ),
/*
* attributes
*/
// 'specifications' => app('Webkul\Product\Helpers\View')->getAdditionalData($product),
/* product's extra information */
$this->merge($this->allProductExtraInfo()),
@ -102,26 +83,31 @@ class Product extends JsonResource
*/
private function specialPriceInfo()
{
$product = $this->product ? $this->product : $this;
$product = $this->type == 'configurable' ? $product->getTypeInstance()->getMinPriceVariant()->product : $this->product;
$productTypeInstance = $product->getTypeInstance();
$typeInstance = $product->getTypeInstance();
return [
'images' => ProductImage::collection($product->images)),
'price' => (double) core()->convertPrice($typeInstance->getMinimalPrice()),
'formatted_price' => core()->currency($typeInstance->getMinimalPrice()),
'special_price' => $this->when(
$productTypeInstance->haveSpecialPrice(),
(double) core()->convertPrice($productTypeInstance->getSpecialPrice())
$typeInstance->haveSpecialPrice(),
(double) core()->convertPrice($typeInstance->getSpecialPrice())
),
'formatted_special_price' => $this->when(
$productTypeInstance->haveSpecialPrice(),
core()->currency($productTypeInstance->getSpecialPrice())
$typeInstance->haveSpecialPrice(),
core()->currency($typeInstance->getSpecialPrice())
),
'regular_price' => $this->when(
$productTypeInstance->haveSpecialPrice(),
(double) core()->convertPrice($productTypeInstance->getMaximumPrice())
$typeInstance->haveSpecialPrice(),
(double) core()->convertPrice($typeInstance->getMaximumPrice())
),
'formatted_regular_price' => $this->when(
$productTypeInstance->haveSpecialPrice(),
core()->currency($productTypeInstance->getMaximumPrice())
$typeInstance->haveSpecialPrice(),
core()->currency($typeInstance->getMaximumPrice())
),
];
}

View File

@ -99,7 +99,8 @@
<accordian title="{{ __('admin::app.catalog.categories.parent-category') }}" :active="true">
<div slot="body">
<tree-view value-field="id" name-field="parent_id" input-type="radio" items='@json($categories)' value='@json($category->parent_id)' fallback-locale="{{ config('app.fallback_locale') }}"></tree-view>
<tree-view behavior="normal" value-field="id" name-field="categories" input-type="checkbox" value='@json($menu->categories->pluck("id"))'
items='@json($categories)' fallback-locale="{{ config('app.fallback_locale') }}"></tree-view>
</div>
</accordian>

View File

@ -0,0 +1,153 @@
<accordian title="{{ __('admin::app.catalog.products.product-link') }}" :active="false">
<div slot="body">
<linked-products></linked-products>
</div>
</accordian>
@push('scripts')
<script type="text/x-template" id="linked-products-template">
<div>
<div class="control-group" v-for='(key) in linkedProducts'>
<label for="up-selling" v-if="(key == 'up_sells')">
{{ __('admin::app.catalog.products.up-selling') }}
</label>
<input type="text" class="control" autocomplete="off" v-model="search_term[key]" placeholder="{{ __('admin::app.catalog.products.product-search-hint') }}" v-on:keyup="search(key)">
<div class="linked-product-search-result">
<ul>
<li v-for='(product, index) in products[key]' v-if='products[key].length' @click="addProduct(product, key)">
@{{ product.name }}
</li>
<li v-if='! products[key].length && search_term[key].length && ! is_searching[key]'>
{{ __('admin::app.catalog.products.no-result-found') }}
</li>
<li v-if="is_searching[key] && search_term[key].length">
{{ __('admin::app.catalog.products.searching') }}
</li>
</ul>
</div>
<input type="hidden" name="up_sell[]" v-for='(product, index) in addedProducts.up_sells' v-if="(key == 'up_sells') && addedProducts.up_sells.length" :value="product.id"/>
<span class="filter-tag linked-product-filter-tag" v-if="addedProducts[key].length">
<span class="wrapper linked-product-wrapper " v-for='(product, index) in addedProducts[key]'>
<span class="do-not-cross-linked-product-arrow">
@{{ product.name }}
</span>
<span class="icon cross-icon" @click="removeProduct(product, key)"></span>
</span>
</span>
</div>
</div>
</script>
<script>
Vue.component('linked-products', {
template: '#linked-products-template',
data: function() {
return {
products: {
'up_sells': [],
},
search_term: {
'up_sells': '',
},
addedProducts: {
'up_sells': [],
},
is_searching: {
'up_sells': false,
},
productId: {{ $product->id }},
linkedProducts: ['up_sells'],
upSellingProducts: @json($product->up_sells()->get()),
}
},
created: function () {
if (this.upSellingProducts.length >= 1) {
for (var index in this.upSellingProducts) {
this.addedProducts.up_sells.push(this.upSellingProducts[index]);
}
}
},
methods: {
addProduct: function (product, key) {
this.addedProducts[key].push(product);
this.search_term[key] = '';
this.products[key] = []
},
removeProduct: function (product, key) {
for (var index in this.addedProducts[key]) {
if (this.addedProducts[key][index].id == product.id ) {
this.addedProducts[key].splice(index, 1);
}
}
},
search: function (key) {
this_this = this;
this.is_searching[key] = true;
if (this.search_term[key].length >= 1) {
this.$http.get ("{{ route('admin.catalog.products.productlinksearch') }}", {params: {query: this.search_term[key]}})
.then (function(response) {
for (var index in response.data) {
if (response.data[index].id == this_this.productId) {
response.data.splice(index, 1);
}
}
if (this_this.addedProducts[key].length) {
for (var product in this_this.addedProducts[key]) {
for (var productId in response.data) {
if (response.data[productId].id == this_this.addedProducts[key][product].id) {
response.data.splice(productId, 1);
}
}
}
}
this_this.products[key] = response.data;
this_this.is_searching[key] = false;
})
.catch (function (error) {
this_this.is_searching[key] = false;
})
} else {
this_this.products[key] = [];
this_this.is_searching[key] = false;
}
}
}
});
</script>
@endpush

View File

@ -498,6 +498,18 @@ class Configurable extends AbstractType
return false;
}
public function getMinPriceVariant(){
return ProductFlat::join('products', 'product_flat.product_id', '=', 'products.id')
->distinct()
->where('products.parent_id', $this->product->id)
->selectRaw("IF( {$tablePrefix}product_flat.special_price_from IS NOT NULL
AND {$tablePrefix}product_flat.special_price_to IS NOT NULL , IF( NOW( ) >= {$tablePrefix}product_flat.special_price_from
AND NOW( ) <= {$tablePrefix}product_flat.special_price_to, IF( {$tablePrefix}product_flat.special_price IS NULL OR {$tablePrefix}product_flat.special_price = 0 , {$tablePrefix}product_flat.price, LEAST( {$tablePrefix}product_flat.special_price, {$tablePrefix}product_flat.price ) ) , {$tablePrefix}product_flat.price ) , IF( {$tablePrefix}product_flat.special_price_from IS NULL , IF( {$tablePrefix}product_flat.special_price_to IS NULL , IF( {$tablePrefix}product_flat.special_price IS NULL OR {$tablePrefix}product_flat.special_price = 0 , {$tablePrefix}product_flat.price, LEAST( {$tablePrefix}product_flat.special_price, {$tablePrefix}product_flat.price ) ) , IF( NOW( ) <= {$tablePrefix}product_flat.special_price_to, IF( {$tablePrefix}product_flat.special_price IS NULL OR {$tablePrefix}product_flat.special_price = 0 , {$tablePrefix}product_flat.price, LEAST( {$tablePrefix}product_flat.special_price, {$tablePrefix}product_flat.price ) ) , {$tablePrefix}product_flat.price ) ) , IF( {$tablePrefix}product_flat.special_price_to IS NULL , IF( NOW( ) >= {$tablePrefix}product_flat.special_price_from, IF( {$tablePrefix}product_flat.special_price IS NULL OR {$tablePrefix}product_flat.special_price = 0 , {$tablePrefix}product_flat.price, LEAST( {$tablePrefix}product_flat.special_price, {$tablePrefix}product_flat.price ) ) , {$tablePrefix}product_flat.price ) , {$tablePrefix}product_flat.price ) ) ) AS min_price")
->where('product_flat.channel', core()->getCurrentChannelCode())
->orderBy('product_flat.min_price', 'ASC')
->first()
}
/**
* Get product minimal price.
*