From 695494a2d980d627b98201f1c41b17b92f059a24 Mon Sep 17 00:00:00 2001 From: Bayu Lukman Yusuf Date: Mon, 5 Jan 2026 10:52:01 +0700 Subject: [PATCH] price variant --- .env.example | 14 +++--- app/Http/Controllers/ProductController.php | 2 + app/Models/ItemVariant.php | 43 ------------------- app/Repositories/Catalog/BrandRepository.php | 40 ++++++++--------- app/View/Components/LocationSelector.php | 2 +- .../Components/LocationSelectorSidebar.php | 2 +- config/database.php | 2 +- .../components/home/product-card.blade.php | 4 +- resources/views/home/fashion-v1.blade.php | 1 + .../views/shop/product-fashion.blade.php | 24 ++++++----- 10 files changed, 48 insertions(+), 86 deletions(-) diff --git a/.env.example b/.env.example index 9a855bf..5a6e60e 100644 --- a/.env.example +++ b/.env.example @@ -20,12 +20,12 @@ LOG_STACK=single LOG_DEPRECATIONS_CHANNEL=null LOG_LEVEL=debug -DB_CONNECTION=sqlite -# DB_HOST=127.0.0.1 -# DB_PORT=3306 -# DB_DATABASE=laravel -# DB_USERNAME=root -# DB_PASSWORD= +DB_CONNECTION=pgsql +DB_HOST=127.0.0.1 +DB_PORT=5432 +DB_DATABASE=asiagolf +DB_USERNAME=postgres +DB_PASSWORD=12345678 SESSION_DRIVER=file SESSION_LIFETIME=120 @@ -37,7 +37,7 @@ BROADCAST_CONNECTION=log FILESYSTEM_DISK=local QUEUE_CONNECTION=database -CACHE_STORE=database +CACHE_STORE=file # CACHE_PREFIX= MEMCACHED_HOST=127.0.0.1 diff --git a/app/Http/Controllers/ProductController.php b/app/Http/Controllers/ProductController.php index c5fdcfc..a2e3e57 100644 --- a/app/Http/Controllers/ProductController.php +++ b/app/Http/Controllers/ProductController.php @@ -13,11 +13,13 @@ class ProductController extends Controller $product = Items::where('slug', $slug)->first(); + if ($product == null) { abort(404); } + $complete_look_products_data = $productRepository->getList([ 'category_id' => $product->category1_id, 'limit' => 4, diff --git a/app/Models/ItemVariant.php b/app/Models/ItemVariant.php index ba64851..6ec93e7 100644 --- a/app/Models/ItemVariant.php +++ b/app/Models/ItemVariant.php @@ -72,50 +72,7 @@ class ItemVariant extends Model 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/app/Repositories/Catalog/BrandRepository.php b/app/Repositories/Catalog/BrandRepository.php index afc7316..7e8f0fc 100644 --- a/app/Repositories/Catalog/BrandRepository.php +++ b/app/Repositories/Catalog/BrandRepository.php @@ -3,20 +3,18 @@ namespace App\Repositories\Catalog; use App\Models\Brand; -use Illuminate\Support\Facades\DB; -use Carbon\Carbon; use Illuminate\Support\Facades\Cache; -use Image; -use Storage; +use Illuminate\Support\Facades\DB; + class BrandRepository { + public function getList($params) + { + return Cache::remember('catalog_brand_'.json_encode($params), 60, function () use ($params) { - public function getList($params){ - return Cache::remember("catalog_brand_".json_encode($params),60, function() use ($params) { - - $category_id = @$params["category_id"]; - if ($category_id){ - $ids = DB::select("select distinct brand from store_category_map a + $category_id = @$params['category_id']; + if ($category_id) { + $ids = DB::select('select distinct brand from store_category_map a left join item_dimension b left join items on b.no = items.number on a.category1 = b.category1 @@ -24,17 +22,19 @@ class BrandRepository and (a.category3 = b.category3 or a.category3 is null) and (a.category4 = b.category4 or a.category4 is null) where store_category_id = ? - and items.is_publish = true ",[$category_id]); - $ids = collect($ids)->pluck("brand"); - return Brand::whereIn("name",$ids)->orderBy('priority', 'desc') - ->where("priority",">",0) - ->orderBy('name', 'asc')->get(); - } - return Brand::orderBy('priority', 'desc')->orderBy('name', 'asc') - ->where("priority",">",0) - ->get(); + and items.is_publish = true ', [$category_id]); + $ids = collect($ids)->pluck('brand'); -}); + return Brand::whereIn('name', $ids)->orderBy('priority', 'desc') + ->where('priority', '>', 0) + ->orderBy('name', 'asc')->get(); + } + + return Brand::orderBy('priority', 'desc')->orderBy('name', 'asc') + ->where('priority', '>', 0) + ->get(); + + }); } } diff --git a/app/View/Components/LocationSelector.php b/app/View/Components/LocationSelector.php index 2b00686..e7e415c 100644 --- a/app/View/Components/LocationSelector.php +++ b/app/View/Components/LocationSelector.php @@ -8,7 +8,7 @@ use Illuminate\View\View; class LocationSelector extends Component { - public Location $selected; + public ?Location $selected; public $locations; diff --git a/app/View/Components/LocationSelectorSidebar.php b/app/View/Components/LocationSelectorSidebar.php index 9d04cd2..19e60e5 100644 --- a/app/View/Components/LocationSelectorSidebar.php +++ b/app/View/Components/LocationSelectorSidebar.php @@ -8,7 +8,7 @@ use Illuminate\View\View; class LocationSelectorSidebar extends Component { - public Location $selected; + public ?Location $selected; public $locations; diff --git a/config/database.php b/config/database.php index 5b318f5..42b3e25 100644 --- a/config/database.php +++ b/config/database.php @@ -94,7 +94,7 @@ return [ 'prefix' => '', 'prefix_indexes' => true, 'search_path' => 'public', - 'sslmode' => 'prefer', + 'sslmode' => 'disable', ], 'sqlsrv' => [ diff --git a/resources/views/components/home/product-card.blade.php b/resources/views/components/home/product-card.blade.php index b7d51b8..9bf2f6c 100644 --- a/resources/views/components/home/product-card.blade.php +++ b/resources/views/components/home/product-card.blade.php @@ -11,7 +11,7 @@ aria-label="Add to Wishlist"> - +
@@ -33,7 +33,7 @@
diff --git a/resources/views/home/fashion-v1.blade.php b/resources/views/home/fashion-v1.blade.php index 32262d4..50c3950 100644 --- a/resources/views/home/fashion-v1.blade.php +++ b/resources/views/home/fashion-v1.blade.php @@ -203,6 +203,7 @@ + diff --git a/resources/views/shop/product-fashion.blade.php b/resources/views/shop/product-fashion.blade.php index 820c27d..529871b 100644 --- a/resources/views/shop/product-fashion.blade.php +++ b/resources/views/shop/product-fashion.blade.php @@ -1809,21 +1809,23 @@ @endif
Rp {{ number_format($product->display_price, 0, ',', '.') }} + + - {{ $product->discount_display_price ? ' Rp ' . number_format($product->discount_display_price, 0, ',', '.') : '' }} + {{ $product->display_discount_price ? ' Rp ' . number_format($product->display_discount_price, 0, ',', '.') : '' }}
-
+ id="variantOption">{{ $product->variants->first()->description ?? '' }} +
@foreach ($product->variants as $key => $variant)