From 5437e5f44baa584440357f8dc5ff61f06a10da98 Mon Sep 17 00:00:00 2001 From: A1Gard Date: Wed, 14 Aug 2024 13:27:29 +0330 Subject: [PATCH] added address control to customer profile added comment list added product favorites control --- app/Http/Controllers/CustomerController.php | 74 +++ app/Models/Customer.php | 5 + resources/js/client-custom/assetsNode.js | 3 + resources/js/client-vue/AddressInput.vue | 427 ++++++++++++++++++ resources/lang/fa.json | 2 + .../AvisaCustomer/AvisaCustomer.blade.php | 89 +++- .../customer/AvisaCustomer/AvisaCustomer.scss | 103 ++++- .../GridPostList/GridPostList.blade.php | 2 +- .../GridPostListSidebar.blade.php | 2 +- routes/web.php | 4 + 10 files changed, 690 insertions(+), 21 deletions(-) create mode 100644 resources/js/client-vue/AddressInput.vue diff --git a/app/Http/Controllers/CustomerController.php b/app/Http/Controllers/CustomerController.php index 0948b8f..2c1b406 100644 --- a/app/Http/Controllers/CustomerController.php +++ b/app/Http/Controllers/CustomerController.php @@ -2,6 +2,8 @@ namespace App\Http\Controllers; +use App\Models\Address; +use App\Models\Customer; use App\Models\Invoice; use App\Models\Product; use Illuminate\Http\Request; @@ -9,6 +11,18 @@ use Illuminate\Validation\Rules\In; class CustomerController extends Controller { + + public function addressSave(Address $address, Request $request) + { + $address->address = $request->input('address'); + $address->lat = $request->input('lat'); + $address->lng = $request->input('lng'); + $address->state_id = $request->input('state_id')??null; + $address->city_id = $request->input('city_id')??null; + $address->zip = $request->input('zip'); + $address->save(); + return $address; + } // public function __construct() { @@ -93,5 +107,65 @@ class CustomerController extends Controller } + public function addresses(){ + return auth('customer')->user()->addresses; + } + + + public function addressUpdate(Request $request, $item) + { + + $item = Address::where('id', $item)->firstOrFail(); + if ($item->customer_id != auth('customer')->user()->id) { + return abort(403); + } + // + $request->validate([ + 'address' => ['required', 'string', 'min:10'], + 'zip' => ['required', 'string', 'min:5'], + 'state_id' => ['required', 'exists:states,id'], + 'city_id' => ['required', 'exists:cities,id'], + 'lat' => ['nullable'], + 'lng' => ['nullable'], + ]); + $this->addressSave($item, $request); + return ['OK' => true, "message" => __("address updated")]; + } + + /** + * Remove the specified resource from storage. + */ + public function addressDestroy(Address $item) + { + // + if ($item->customer_id != auth('customer')->id()) { + return abort(403); + } + $add = $item->address ; + + $item->delete(); + return ['OK' => true, "message" => __(":ADDRESS removed",['ADDRESS' => $add])]; + } + + public function addressStore(Request $request) + { + // + + $request->validate([ + 'address' => ['required', 'string', 'min:10'], + 'zip' => ['required', 'string', 'min:5'], + 'state_id' => ['required', 'exists:states,id'], + 'city_id' => ['required', 'exists:cities,id'], + 'lat' => ['nullable'], + 'lng' => ['nullable'], + ]); + + $address = new Address(); + $address->customer_id = auth('customer')->user()->id; + $address = $this->addressSave($address, $request); + return ['OK' => true,'message' => __("Address added successfully"), 'list'=> auth('customer')->user()->addresses]; + + } + } diff --git a/app/Models/Customer.php b/app/Models/Customer.php index f4fe45f..1fed8c2 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -49,4 +49,9 @@ class Customer extends Authenticatable return $this->belongsToMany(Product::class,'customer_product'); } + public function comments(){ + return $this->morphMany(Comment::class, 'commentator'); + } + + } diff --git a/resources/js/client-custom/assetsNode.js b/resources/js/client-custom/assetsNode.js index 727f883..f136bf3 100644 --- a/resources/js/client-custom/assetsNode.js +++ b/resources/js/client-custom/assetsNode.js @@ -22,6 +22,9 @@ app.component('mp4player', videoPlayer); import mp3player from "../client-vue/mp3player.vue"; app.component('mp3player', mp3player); +import addressInput from "../client-vue/AddressInput.vue"; +app.component('address-input', addressInput); + import NsCard from "../client-vue/NsCard.vue"; app.component('ns-card', NsCard); diff --git a/resources/js/client-vue/AddressInput.vue b/resources/js/client-vue/AddressInput.vue new file mode 100644 index 0000000..6b8aba1 --- /dev/null +++ b/resources/js/client-vue/AddressInput.vue @@ -0,0 +1,427 @@ + + + + + diff --git a/resources/lang/fa.json b/resources/lang/fa.json index d4bce5c..6fc80b4 100644 --- a/resources/lang/fa.json +++ b/resources/lang/fa.json @@ -291,7 +291,9 @@ "Previous": "قبلی", "Price": "مبلغ", "Product": "محصول", + "Product added to compare": "محصول به فهرست مقایسه افزوده شد", "Product added to favorites": "محصول به علاقه‌مندی شما افزوده شد", + "Product removed from compare": "محصول از فهرست مقایسه حذف شد", "Product removed from favorites": "محصول از علاقه مندی های شما حذف شد", "Product table": "جدول محصول", "Products": "محصولات", diff --git a/resources/views/segments/customer/AvisaCustomer/AvisaCustomer.blade.php b/resources/views/segments/customer/AvisaCustomer/AvisaCustomer.blade.php index 0b56675..171fee9 100644 --- a/resources/views/segments/customer/AvisaCustomer/AvisaCustomer.blade.php +++ b/resources/views/segments/customer/AvisaCustomer/AvisaCustomer.blade.php @@ -43,7 +43,7 @@
  • - + {{__("Tickets")}}
  • @@ -105,7 +105,7 @@
    - +

    {{number_format(auth('customer')->user()->tickets()->count())}}

    @@ -125,6 +125,28 @@
    +
    +
    + +

    + {{number_format(auth('customer')->user()->comments()->count())}} +

    +

    + {{__("Comments")}} +

    +
    +
    +
    +
    + +

    + {{number_format(auth('customer')->user()->favorites()->count())}} +

    +

    + {{__("Favorites")}} +

    +
    +
    @if(cardCount() > 0)
    @@ -332,16 +354,73 @@
    - {{-- WIP comments--}} + @if(auth('customer')->user()->comments()->count() == 0) +
    + {{__("You don't have any comments, We are so pleased to hear your look-out")}} +
    + @else + @foreach(auth('customer')->user()->comments as $comment) +
    +

    + {{$comment->commentable->title}} + {{$comment->commentable->name}} +

    + + {{$comment->created_at->ldate('Y-m-d')}} + +

    + {{$comment->body}} +

    +
    + @endforeach + @endif
    {{-- WIP submit new ticket --}}
    - {{-- WIP submit new ticket --}} + __('Address editor'), + 'state' => __('State'), + 'city' => __('City'), + 'address' => __('Address'), + 'post-code' => __('Post code'), + ])}}' + >
    - {{-- WIP submit new ticket --}} + @foreach(auth('customer')->user()->favorites as $fav) + +
    +
    +
    + {{$fav->name}} +
    +
    +

    + {{$fav->name}} +

    +

    + {{$fav->excerpt}} +

    + + + + +
    +
    +
    + @endforeach
    diff --git a/resources/views/segments/customer/AvisaCustomer/AvisaCustomer.scss b/resources/views/segments/customer/AvisaCustomer/AvisaCustomer.scss index 595c877..76c6147 100644 --- a/resources/views/segments/customer/AvisaCustomer/AvisaCustomer.scss +++ b/resources/views/segments/customer/AvisaCustomer/AvisaCustomer.scss @@ -35,15 +35,15 @@ } } - i{ + i { margin: 0 1rem; } } } - .avisa-grid{ - .grid-item{ + .avisa-grid { + .grid-item { overflow: hidden; height: 200px; border-radius: var(--xshop-border-radius); @@ -51,8 +51,9 @@ display: flex; align-items: center; justify-content: center; + margin-bottom: 1rem; - i{ + i { position: absolute; transform: rotateZ(-17deg); inset-inline-start: 7%; @@ -61,7 +62,7 @@ opacity: .3; } - h3{ + h3 { position: absolute; left: 0; right: 0; @@ -71,27 +72,101 @@ } } - &:nth-child(1){ - .grid-item{ - background: rgba(248, 170, 0, 0.63); + &:nth-child(1) { + .grid-item { + background: rgba(248, 124, 0, 0.63); } } - &:nth-child(2){ - .grid-item{ + + &:nth-child(2) { + .grid-item { background: rgba(184, 11, 109, 0.63); } } - &:nth-child(3){ - .grid-item{ + + &:nth-child(3) { + .grid-item { background: rgba(11, 184, 123, 0.63); } } - &:nth-child(4){ - .grid-item{ + + &:nth-child(4) { + .grid-item { background: rgba(11, 112, 184, 0.63); } } + + &:nth-child(5) { + .grid-item { + background: rgba(253, 237, 63, 0.83); + } + } + + &:nth-child(6) { + .grid-item { + background: rgba(139, 32, 253, 0.58); + } + } } + .avisa-comment { + border: 1px solid var(--xshop-primary); + padding: 1rem; + border-radius: var(--xshop-border-radius); + margin-bottom: 1rem; + + h3 { + font-size: 17px; + } + + .comment-date { + background: var(--xshop-secondary); + color: var(--xshop-diff2); + padding: 7px; + border-radius: var(--xshop-border-radius); + } + } + .product-item{ + margin-bottom: 1rem; + border-radius: var(--xshop-border-radius); + border: 1px solid var(--xshop-primary); + overflow: hidden; + + .fav-btn, .compare-btn { + border-radius: var(--xshop-border-radius); + background: #ffffff55; + font-size: 25px; + display: inline-block; + align-items: center; + justify-content: center; + cursor: pointer; + transition: .4s; + min-width: 100px; + text-align: center; + margin-top: -7px; + &:hover { + background: var(--xshop-primary); + color: var(--xshop-diff); + } + } + + .fav-btn { + top: calc(3% + 50px); + + &[data-is-fav="-1"]{ + display: none; + } + &[data-is-fav="1"]{ + .ri-heart-line{ + display: none; + } + } + &[data-is-fav="0"]{ + .ri-heart-fill{ + display: none; + } + } + } + } } diff --git a/resources/views/segments/posts_page/GridPostList/GridPostList.blade.php b/resources/views/segments/posts_page/GridPostList/GridPostList.blade.php index cd519f1..71bba0d 100644 --- a/resources/views/segments/posts_page/GridPostList/GridPostList.blade.php +++ b/resources/views/segments/posts_page/GridPostList/GridPostList.blade.php @@ -16,7 +16,7 @@ {{$post->title}} - {{$post->created_at->ldate('Y/m/d l')}} + {{$post->created_at->ldate('Y-m-d l')}} diff --git a/resources/views/segments/posts_page/GridPostListSidebar/GridPostListSidebar.blade.php b/resources/views/segments/posts_page/GridPostListSidebar/GridPostListSidebar.blade.php index 90e605b..75b5861 100644 --- a/resources/views/segments/posts_page/GridPostListSidebar/GridPostListSidebar.blade.php +++ b/resources/views/segments/posts_page/GridPostListSidebar/GridPostListSidebar.blade.php @@ -16,7 +16,7 @@ {{$post->title}} - {{$post->created_at->ldate('Y/m/d l')}} + {{$post->created_at->ldate('Y-m-d l')}} diff --git a/routes/web.php b/routes/web.php index eb204a0..5328857 100644 --- a/routes/web.php +++ b/routes/web.php @@ -375,6 +375,10 @@ Route::middleware([\App\Http\Middleware\VisitorCounter::class]) Route::get('/card', [\App\Http\Controllers\CardController::class, 'index'])->name('card'); Route::get('/cardClear', [\App\Http\Controllers\CardController::class, 'clearing'])->name('card.clear'); Route::get('/profile', [\App\Http\Controllers\CustomerController::class, 'profile'])->name('profile'); + Route::get('/addresses', [\App\Http\Controllers\CustomerController::class, 'addresses'])->name('addresses'); + Route::post('/address/store', [\App\Http\Controllers\CustomerController::class, 'addressStore'])->name('address.store'); + Route::post('/address/update/{address}', [\App\Http\Controllers\CustomerController::class, 'addressUpdate'])->name('address.update'); + Route::get('/address/destroy/{address}', [\App\Http\Controllers\CustomerController::class, 'addressDestroy'])->name('address.destroy'); Route::post('/profile/save', [\App\Http\Controllers\CustomerController::class, 'save'])->name('profile.save'); Route::get('/invoice/{invoice}', [\App\Http\Controllers\CustomerController::class, 'invoice'])->name('invoice'); Route::get('/products', [ClientController::class, 'products'])->name('products');