From 8b8803672772fa70df4e457aa51f5e24eff154e7 Mon Sep 17 00:00:00 2001 From: merdan Date: Thu, 22 Sep 2022 13:16:32 +0500 Subject: [PATCH] menu Controller --- .../API/Http/Resources/Catalog/Product.php | 44 ++--- .../views/catalog/menus/edit.blade.php | 3 +- .../views/catalog/menus/menu-links.blade.php | 153 ++++++++++++++++++ .../Webkul/Product/src/Type/Configurable.php | 12 ++ 4 files changed, 182 insertions(+), 30 deletions(-) create mode 100644 packages/Sarga/Admin/src/Resources/views/catalog/menus/menu-links.blade.php diff --git a/packages/Sarga/API/Http/Resources/Catalog/Product.php b/packages/Sarga/API/Http/Resources/Catalog/Product.php index 0b0eba602..e86b7772a 100644 --- a/packages/Sarga/API/Http/Resources/Catalog/Product.php +++ b/packages/Sarga/API/Http/Resources/Catalog/Product.php @@ -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()) ), ]; } diff --git a/packages/Sarga/Admin/src/Resources/views/catalog/menus/edit.blade.php b/packages/Sarga/Admin/src/Resources/views/catalog/menus/edit.blade.php index 260e74fdb..978c81f78 100644 --- a/packages/Sarga/Admin/src/Resources/views/catalog/menus/edit.blade.php +++ b/packages/Sarga/Admin/src/Resources/views/catalog/menus/edit.blade.php @@ -99,7 +99,8 @@
- +
diff --git a/packages/Sarga/Admin/src/Resources/views/catalog/menus/menu-links.blade.php b/packages/Sarga/Admin/src/Resources/views/catalog/menus/menu-links.blade.php new file mode 100644 index 000000000..e9539c6b2 --- /dev/null +++ b/packages/Sarga/Admin/src/Resources/views/catalog/menus/menu-links.blade.php @@ -0,0 +1,153 @@ + + +
+ + + +
+
+ +@push('scripts') + + + + + +@endpush \ No newline at end of file diff --git a/packages/Webkul/Product/src/Type/Configurable.php b/packages/Webkul/Product/src/Type/Configurable.php index 87c8ec88d..e64a8fd44 100644 --- a/packages/Webkul/Product/src/Type/Configurable.php +++ b/packages/Webkul/Product/src/Type/Configurable.php @@ -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. *