From 7173d2c1171ee7dbcf59f6447e38ec4e1fe799aa Mon Sep 17 00:00:00 2001 From: Bayu Lukman Yusuf Date: Fri, 2 Jan 2026 15:01:00 +0700 Subject: [PATCH] change price, image if variant click and show description --- app/Http/Controllers/ProductController.php | 14 +- app/Models/ItemVariant.php | 54 +++ .../components/home/product-card.blade.php | 5 +- resources/views/layouts/landing.blade.php | 2 + .../views/shop/product-fashion.blade.php | 388 +++--------------- 5 files changed, 126 insertions(+), 337 deletions(-) diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index d209b07..c5fdcfc 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -3,11 +3,12 @@ namespace App\Http\Controllers; use App\Models\Items; +use App\Repositories\Catalog\ProductRepository; use Illuminate\Http\Request; class ProductController extends Controller { - public function detail($slug, Request $request) + public function detail($slug, Request $request, ProductRepository $productRepository) { $product = Items::where('slug', $slug)->first(); @@ -17,8 +18,19 @@ class ProductController extends Controller } + $complete_look_products_data = $productRepository->getList([ + 'category_id' => $product->category1_id, + 'limit' => 4, + ]); + + + + $complete_look_products = collect($complete_look_products_data->items())->chunk(2); + + return view('shop.product-fashion',[ 'product' => $product, + 'complete_look_products' => $complete_look_products ]); } } diff --git a/app/Models/ItemVariant.php b/app/Models/ItemVariant.php index 865c49d..ba64851 100644 --- a/app/Models/ItemVariant.php +++ b/app/Models/ItemVariant.php @@ -5,6 +5,8 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Awobaz\Compoships\Compoships; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; class ItemVariant extends Model @@ -64,4 +66,56 @@ class ItemVariant extends Model return $image ? Storage::disk('wms')->url($image) : null; } + + public function item() + { + return $this->belongsTo(Items::class, 'item_id'); + } + + public function conversion_value() + { + $item = $this->item; + + $convertion = 1; + if (($item->display_unit != $item->unit) and ($item->display_unit)){ + $convertions = DB::select("select to_qty / from_qty as conv + from item_convertions where from_unit = ? and to_unit = ?", + [$item->display_unit, $item->unit] ); + $convertion = max((float) @$convertions[0]->conv,1); + } + + return $convertion; + } + + + public function getDisplayPriceAttribute() + { + try { + $convertion = $this->conversion_value(); + + $price = $this->reference->price->price ?? null; + $price = $price ? $price : $this->item->net_price; + + + + return (float) $price * $convertion; + } catch (\Exception $e) { + Log::info($e); + return 0; + } + } + + public function getDisplayDiscountPriceAttribute() + { + try { + $convertion = $this->conversion_value(); + + $discountPrice = @$this->discount->price ?? 0; + return (float) $discountPrice * $convertion; + } catch (\Exception $e) { + return 0; + } + } + + } diff --git a/resources/views/components/home/product-card.blade.php b/resources/views/components/home/product-card.blade.php index b698056..b7d51b8 100644 --- a/resources/views/components/home/product-card.blade.php +++ b/resources/views/components/home/product-card.blade.php @@ -1,9 +1,12 @@
+ @if ($product->display_discount_price > 0) Sale - - + - +
- Cartzilla + + + + + +
@@ -757,56 +716,8 @@
@@ -1788,9 +1699,9 @@ @@ -1801,10 +1712,14 @@
+
+ + @if ($product->display_discount_price > 0) Sale -
-
    + {{--
    • @@ -1983,10 +1897,10 @@ On all orders over $100.00
    • -
    +
--}} -
+ {{--
🔥 Hurry up! The sale is coming to an end 6 items in stock! @@ -1994,7 +1908,7 @@
-
+
--}}
@@ -2077,23 +1991,7 @@ aria-labelledby="description-tab">
-
    -
  • Model's height: 176 cm
  • -
  • The model is wearing size: S/36 -
  • -
-

This skirt is designed to fall just below the knee, offering a flattering length that is - suitable for various occasions. It is made from a soft and lightweight fabric that drapes - beautifully, ensuring comfort and ease of movement. The blue color adds a vibrant touch, - making it a standout piece in your wardrobe.

-
    -
  • fitted waistband
  • -
  • fastened with a hidden zipper
  • -
  • midi length
  • -
-

The blue color of the skirt allows for easy pairing with a variety of tops. - You can opt for a crisp white blouse for a classic and polished outfit, or choose a - patterned or contrasting-colored top for a more vibrant and fashion-forward look.

+ {!! nl2br($product->description) !!}
@@ -2496,224 +2394,30 @@ }'>
- -
-
+ @foreach ($complete_look_products as $key => $value) +
+
- - {{--
- -
--}} + @foreach ($value as $key2 => $value2) +
+ + +
+ @endforeach - -
-
-
- - -
- Image -
-
-
-
- 6 - 6.5 - 7 - 7.5 - -
-
-
- -
$160.00
-
-
+1 - color
-
- - - - -
-
-
-
+ + @endforeach - -
-
- - -
-
-
- - -
- Image -
-
-
-
- XS - S - M - L - -
-
-
- -
$38.50
-
-
+1 - color
-
- - - - -
-
-
-
- - -
-
-
- - -
- Image -
-
-
-
- 6.5 - 7 - 7.5 - 8 - -
-
-
- -
$74.00
-
-
+2 - colors
-
- - - - - - -
-
-
-
-
-
+
- Image
@@ -3306,14 +3010,28 @@ document.addEventListener('DOMContentLoaded', function() { radio.addEventListener('change', function() { const label = document.querySelector(`label[for="${this.id}"]`); const price = label.getAttribute('data-price'); + const discountPrice = label.getAttribute('data-discount-price'); const image = label.getAttribute('data-image'); const labelText = label.getAttribute('data-label'); + document.querySelector('.display_price').textContent = price; + const discountSpan = document.querySelector('.display_discount_price'); + if (discountPrice) { + discountSpan.textContent = ' ' + discountPrice; + discountSpan.style.display = 'inline'; + } else { + discountSpan.style.display = 'none'; + } document.querySelector('.product-main-image').src = image; document.querySelector('#colorOption').textContent = labelText; }); }); + // Trigger change for the initially checked radio + const checkedRadio = document.querySelector('input[name="colors"]:checked'); + if (checkedRadio) { + checkedRadio.dispatchEvent(new Event('change')); + } }); @endsection