From 2e24c2e2e58e328ccb1b03c3c4bcf02d450041ae Mon Sep 17 00:00:00 2001 From: Jitendra Singh Date: Fri, 21 Feb 2020 19:13:15 +0530 Subject: [PATCH] Updated event booking system --- .../accordians/grouped-products.blade.php | 4 +- .../views/catalog/products/edit.blade.php | 24 ++++---- ...Slot.php => BookingProductEventTicket.php} | 2 +- .../BookingProductEventTicketTranslation.php | 7 +++ ...2_180307_create_booking_products_table.php | 3 + ...te_booking_product_default_slots_table.php | 2 - ...ooking_product_appointment_slots_table.php | 3 - ...e_booking_product_event_tickets_table.php} | 11 ++-- ...ate_booking_product_rental_slots_table.php | 7 +-- ...eate_booking_product_table_slots_table.php | 3 - ...roduct_event_ticket_translations_table.php | 36 +++++++++++ .../BookingProduct/src/Helpers/Booking.php | 40 +++++++------ .../src/Helpers/DefaultSlot.php | 20 +++++-- .../{EventSlot.php => EventTicket.php} | 16 ++--- .../BookingProduct/src/Helpers/RentalSlot.php | 12 ++-- .../Shop/BookingProductController.php | 8 +-- .../BookingProduct/src/Listeners/Product.php | 54 ----------------- .../src/Models/BookingProduct.php | 8 +-- .../src/Models/BookingProductDefaultSlot.php | 2 +- .../src/Models/BookingProductEventSlot.php | 15 ----- .../src/Models/BookingProductEventTicket.php | 15 +++++ ...php => BookingProductEventTicketProxy.php} | 2 +- .../BookingProductEventTicketTranslation.php | 13 ++++ ...kingProductEventTicketTranslationProxy.php | 10 ++++ .../src/Models/BookingProductTableSlot.php | 2 +- .../src/Providers/EventServiceProvider.php | 2 - .../src/Providers/ModuleServiceProvider.php | 3 +- .../BookingProductEventSlotRepository.php | 24 -------- .../BookingProductEventTicketRepository.php | 55 +++++++++++++++++ .../Repositories/BookingProductRepository.php | 36 ++++++----- .../products/accordians/booking.blade.php | 43 +++++++++++++- .../accordians/booking/appointment.blade.php | 39 ------------ .../accordians/booking/default.blade.php | 24 -------- .../accordians/booking/event.blade.php | 59 +++++++------------ .../accordians/booking/rental.blade.php | 39 ------------ .../accordians/booking/table.blade.php | 39 ------------ .../products/view/booking/event.blade.php | 2 +- .../BookingProduct/src/Type/Booking.php | 27 ++++++++- 38 files changed, 338 insertions(+), 373 deletions(-) rename packages/Webkul/BookingProduct/src/Contracts/{BookingProductEventSlot.php => BookingProductEventTicket.php} (58%) create mode 100644 packages/Webkul/BookingProduct/src/Contracts/BookingProductEventTicketTranslation.php rename packages/Webkul/BookingProduct/src/Database/Migrations/{2019_07_05_154440_create_booking_product_event_slots_table.php => 2019_07_05_154440_create_booking_product_event_tickets_table.php} (61%) create mode 100644 packages/Webkul/BookingProduct/src/Database/Migrations/2020_02_21_121201_create_booking_product_event_ticket_translations_table.php rename packages/Webkul/BookingProduct/src/Helpers/{EventSlot.php => EventTicket.php} (71%) delete mode 100644 packages/Webkul/BookingProduct/src/Listeners/Product.php delete mode 100644 packages/Webkul/BookingProduct/src/Models/BookingProductEventSlot.php create mode 100644 packages/Webkul/BookingProduct/src/Models/BookingProductEventTicket.php rename packages/Webkul/BookingProduct/src/Models/{BookingProductEventSlotProxy.php => BookingProductEventTicketProxy.php} (61%) create mode 100644 packages/Webkul/BookingProduct/src/Models/BookingProductEventTicketTranslation.php create mode 100644 packages/Webkul/BookingProduct/src/Models/BookingProductEventTicketTranslationProxy.php delete mode 100644 packages/Webkul/BookingProduct/src/Repositories/BookingProductEventSlotRepository.php create mode 100644 packages/Webkul/BookingProduct/src/Repositories/BookingProductEventTicketRepository.php diff --git a/packages/Webkul/Admin/src/Resources/views/catalog/products/accordians/grouped-products.blade.php b/packages/Webkul/Admin/src/Resources/views/catalog/products/accordians/grouped-products.blade.php index 8a3908f3b..20fef053c 100644 --- a/packages/Webkul/Admin/src/Resources/views/catalog/products/accordians/grouped-products.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/catalog/products/accordians/grouped-products.blade.php @@ -203,9 +203,9 @@ computed: { inputName: function () { if (this.groupedProduct.id) - return "links[" + this.groupedProduct.id + "]"; + return 'links[' + this.groupedProduct.id + ']'; - return "links[link_" + this.index + "]"; + return 'links[link_' + this.index + ']'; } }, diff --git a/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php b/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php index 6adba4afc..c1cfcf2e1 100755 --- a/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php @@ -77,23 +77,23 @@ @foreach ($customAttributes as $attribute) code == 'guest_checkout' && ! core()->getConfigData('catalog.products.guest-checkout.allow-guest-checkout')) { - continue; - } + if ($attribute->code == 'guest_checkout' && ! core()->getConfigData('catalog.products.guest-checkout.allow-guest-checkout')) { + continue; + } - $validations = []; + $validations = []; - if ($attribute->is_required) { - array_push($validations, 'required'); - } + if ($attribute->is_required) { + array_push($validations, 'required'); + } - if ($attribute->type == 'price') { - array_push($validations, 'decimal'); - } + if ($attribute->type == 'price') { + array_push($validations, 'decimal'); + } - array_push($validations, $attribute->validation); + array_push($validations, $attribute->validation); - $validations = implode('|', array_filter($validations)); + $validations = implode('|', array_filter($validations)); ?> @if (view()->exists($typeView = 'admin::catalog.products.field-types.' . $attribute->type)) diff --git a/packages/Webkul/BookingProduct/src/Contracts/BookingProductEventSlot.php b/packages/Webkul/BookingProduct/src/Contracts/BookingProductEventTicket.php similarity index 58% rename from packages/Webkul/BookingProduct/src/Contracts/BookingProductEventSlot.php rename to packages/Webkul/BookingProduct/src/Contracts/BookingProductEventTicket.php index 8feb903e9..cbecbd396 100644 --- a/packages/Webkul/BookingProduct/src/Contracts/BookingProductEventSlot.php +++ b/packages/Webkul/BookingProduct/src/Contracts/BookingProductEventTicket.php @@ -2,6 +2,6 @@ namespace Webkul\BookingProduct\Contracts; -interface BookingProductEventSlot +interface BookingProductEventTicket { } \ No newline at end of file diff --git a/packages/Webkul/BookingProduct/src/Contracts/BookingProductEventTicketTranslation.php b/packages/Webkul/BookingProduct/src/Contracts/BookingProductEventTicketTranslation.php new file mode 100644 index 000000000..3f9f535e3 --- /dev/null +++ b/packages/Webkul/BookingProduct/src/Contracts/BookingProductEventTicketTranslation.php @@ -0,0 +1,7 @@ +string('type'); $table->string('location')->nullable(); $table->boolean('show_location')->default(0); + $table->boolean('available_every_week')->nullable(); + $table->date('available_from')->nullable(); + $table->date('available_to')->nullable(); $table->integer('product_id')->unsigned(); $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade'); diff --git a/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154415_create_booking_product_default_slots_table.php b/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154415_create_booking_product_default_slots_table.php index 77ac24993..5705d6773 100644 --- a/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154415_create_booking_product_default_slots_table.php +++ b/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154415_create_booking_product_default_slots_table.php @@ -16,8 +16,6 @@ class CreateBookingProductDefaultSlotsTable extends Migration Schema::create('booking_product_default_slots', function (Blueprint $table) { $table->increments('id'); $table->string('booking_type'); - $table->date('available_from')->nullable(); - $table->date('available_to')->nullable(); $table->integer('duration')->nullable(); $table->integer('break_time')->nullable(); $table->json('slots')->nullable(); diff --git a/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154429_create_booking_product_appointment_slots_table.php b/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154429_create_booking_product_appointment_slots_table.php index 3a3190f8a..d3a8db3ba 100644 --- a/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154429_create_booking_product_appointment_slots_table.php +++ b/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154429_create_booking_product_appointment_slots_table.php @@ -17,9 +17,6 @@ class CreateBookingProductAppointmentSlotsTable extends Migration $table->increments('id'); $table->integer('duration')->nullable(); $table->integer('break_time')->nullable(); - $table->boolean('available_every_week')->nullable(); - $table->date('available_from')->nullable(); - $table->date('available_to')->nullable(); $table->boolean('slot_has_quantity')->nullable(); $table->boolean('same_slot_all_days')->nullable(); $table->json('slots')->nullable(); diff --git a/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154440_create_booking_product_event_slots_table.php b/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154440_create_booking_product_event_tickets_table.php similarity index 61% rename from packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154440_create_booking_product_event_slots_table.php rename to packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154440_create_booking_product_event_tickets_table.php index 5857c5a89..88298d4bd 100644 --- a/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154440_create_booking_product_event_slots_table.php +++ b/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154440_create_booking_product_event_tickets_table.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; -class CreateBookingProductEventSlotsTable extends Migration +class CreateBookingProductEventTicketsTable extends Migration { /** * Run the migrations. @@ -13,11 +13,10 @@ class CreateBookingProductEventSlotsTable extends Migration */ public function up() { - Schema::create('booking_product_event_slots', function (Blueprint $table) { + Schema::create('booking_product_event_tickets', function (Blueprint $table) { $table->increments('id'); - $table->datetime('available_from')->nullable(); - $table->datetime('available_to')->nullable(); - $table->json('slots')->nullable(); + $table->decimal('price', 12, 4)->default(0)->nullable(); + $table->integer('qty')->default(0)->nullable(); $table->integer('booking_product_id')->unsigned(); $table->foreign('booking_product_id')->references('id')->on('booking_products')->onDelete('cascade'); @@ -31,6 +30,6 @@ class CreateBookingProductEventSlotsTable extends Migration */ public function down() { - Schema::dropIfExists('booking_product_event_slots'); + Schema::dropIfExists('booking_product_event_tickets'); } } diff --git a/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154451_create_booking_product_rental_slots_table.php b/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154451_create_booking_product_rental_slots_table.php index c48a332f4..b9e4b4be1 100644 --- a/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154451_create_booking_product_rental_slots_table.php +++ b/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154451_create_booking_product_rental_slots_table.php @@ -16,11 +16,8 @@ class CreateBookingProductRentalSlotsTable extends Migration Schema::create('booking_product_rental_slots', function (Blueprint $table) { $table->increments('id'); $table->string('renting_type'); - $table->decimal('daily_price', 12, 4)->default(0)->nullable();; - $table->decimal('hourly_price', 12, 4)->default(0)->nullable();; - $table->boolean('available_every_week')->nullable(); - $table->date('available_from')->nullable(); - $table->date('available_to')->nullable(); + $table->decimal('daily_price', 12, 4)->default(0)->nullable(); + $table->decimal('hourly_price', 12, 4)->default(0)->nullable(); $table->boolean('slot_has_quantity')->nullable(); $table->boolean('same_slot_all_days')->nullable(); $table->json('slots')->nullable(); diff --git a/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154502_create_booking_product_table_slots_table.php b/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154502_create_booking_product_table_slots_table.php index 72258199d..696688547 100644 --- a/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154502_create_booking_product_table_slots_table.php +++ b/packages/Webkul/BookingProduct/src/Database/Migrations/2019_07_05_154502_create_booking_product_table_slots_table.php @@ -21,9 +21,6 @@ class CreateBookingProductTableSlotsTable extends Migration $table->integer('duration'); $table->integer('break_time'); $table->integer('prevent_scheduling_before'); - $table->boolean('available_every_week')->nullable(); - $table->date('available_from')->nullable(); - $table->date('available_to')->nullable(); $table->boolean('same_slot_all_days')->nullable(); $table->json('slots')->nullable(); diff --git a/packages/Webkul/BookingProduct/src/Database/Migrations/2020_02_21_121201_create_booking_product_event_ticket_translations_table.php b/packages/Webkul/BookingProduct/src/Database/Migrations/2020_02_21_121201_create_booking_product_event_ticket_translations_table.php new file mode 100644 index 000000000..e5089e05b --- /dev/null +++ b/packages/Webkul/BookingProduct/src/Database/Migrations/2020_02_21_121201_create_booking_product_event_ticket_translations_table.php @@ -0,0 +1,36 @@ +bigIncrements('id'); + $table->string('locale'); + $table->text('name')->nullable(); + $table->text('description')->nullable(); + $table->integer('booking_product_event_ticket_id')->unsigned(); + $table->unique(['booking_product_event_ticket_id', 'locale'], 'booking_product_event_ticket_translations_locale_unique'); + $table->foreign('booking_product_event_ticket_id', 'booking_product_event_ticket_translations_locale_foreign')->references('id')->on('booking_product_event_tickets')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('booking_product_event_ticket_translations'); + } +} diff --git a/packages/Webkul/BookingProduct/src/Helpers/Booking.php b/packages/Webkul/BookingProduct/src/Helpers/Booking.php index 36756c6a9..b97d0ab6a 100644 --- a/packages/Webkul/BookingProduct/src/Helpers/Booking.php +++ b/packages/Webkul/BookingProduct/src/Helpers/Booking.php @@ -6,7 +6,7 @@ use Carbon\Carbon; use Webkul\BookingProduct\Repositories\BookingProductRepository; use Webkul\BookingProduct\Repositories\BookingProductDefaultSlotRepository; use Webkul\BookingProduct\Repositories\BookingProductAppointmentSlotRepository; -use Webkul\BookingProduct\Repositories\BookingProductEventSlotRepository; +use Webkul\BookingProduct\Repositories\BookingProductEventTicketRepository; use Webkul\BookingProduct\Repositories\BookingProductRentalSlotRepository; use Webkul\BookingProduct\Repositories\BookingProductTableSlotRepository; @@ -36,7 +36,7 @@ class Booking protected $typeHelpers = [ 'default' => DefaultSlot::class, 'appointment' => AppointmentSlot::class, - 'event' => EventSlot::class, + 'event' => EventTicket::class, 'rental' => RentalSlot::class, 'table' => TableSlot::class, ]; @@ -52,7 +52,7 @@ class Booking * @param Webkul\BookingProduct\Repositories\BookingProductRepository $bookingProductRepository * @param Webkul\BookingProduct\Repositories\BookingProductDefaultSlotRepository $bookingProductDefaultSlotRepository * @param Webkul\BookingProduct\Repositories\BookingProductAppointmentSlotRepository $bookingProductAppointmentSlotRepository - * @param Webkul\BookingProduct\Repositories\BookingProductEventSlotRepository $bookingProductEventSlotRepository + * @param Webkul\BookingProduct\Repositories\BookingProductEventTicketRepository $bookingProductEventTicketRepository * @param Webkul\BookingProduct\Repositories\BookingProductRentalSlotRepository $bookingProductRentalSlotRepository * @param Webkul\BookingProduct\Repositories\BookingProductTableSlotRepository $bookingProductTableSlotRepository * @return void @@ -61,7 +61,7 @@ class Booking BookingProductRepository $bookingProductRepository, BookingProductDefaultSlotRepository $bookingProductDefaultSlotRepository, BookingProductAppointmentSlotRepository $bookingProductAppointmentSlotRepository, - BookingProductEventSlotRepository $bookingProductEventSlotRepository, + BookingProductEventTicketRepository $bookingProductEventTicketRepository, BookingProductRentalSlotRepository $bookingProductRentalSlotRepository, BookingProductTableSlotRepository $bookingProductTableSlotRepository ) @@ -72,7 +72,7 @@ class Booking $this->typeRepositories['appointment'] = $bookingProductAppointmentSlotRepository; - $this->typeRepositories['event'] = $bookingProductEventSlotRepository; + $this->typeRepositories['event'] = $bookingProductEventTicketRepository; $this->typeRepositories['rental'] = $bookingProductRentalSlotRepository; @@ -102,7 +102,7 @@ class Booking $bookingProductSlot = $this->typeRepositories[$bookingProduct->type]->findOneByField('booking_product_id', $bookingProduct->id); - $availabileDays = $this->getAvailableWeekDays($bookingProductSlot); + $availabileDays = $this->getAvailableWeekDays($bookingProduct); foreach ($this->daysOfWeek as $index => $isOpen) { $slots = []; @@ -155,12 +155,12 @@ class Booking /** * Returns the available week days * - * @param Object $bookingProductSlot + * @param Object $bookingProduct * @return array */ - public function getAvailableWeekDays($bookingProductSlot) + public function getAvailableWeekDays($bookingProduct) { - if ($bookingProductSlot->available_every_week) { + if ($bookingProduct->available_every_week) { return $this->daysOfWeek; } @@ -168,9 +168,9 @@ class Booking $currentTime = Carbon::now(); - $availableFrom = Carbon::createFromTimeString($bookingProductSlot->available_from . " 00:00:01"); + $availableFrom = Carbon::createFromTimeString($bookingProduct->available_from . " 00:00:01"); - $availableTo = Carbon::createFromTimeString($bookingProductSlot->available_to . " 23:59:59"); + $availableTo = Carbon::createFromTimeString($bookingProduct->available_to . " 23:59:59"); for ($i = 0; $i < 7; $i++) { $date = clone $currentTime; @@ -246,13 +246,13 @@ class Booking $currentTime = Carbon::now(); - $availableFrom = ! $bookingProductSlot->available_every_week - ? Carbon::createFromTimeString($bookingProductSlot->available_from . " 00:00:00") - : Carbon::createFromTimeString($currentTime->format('Y-m-d') . ' 00:00:00'); + $availableFrom = ! $bookingProduct->available_every_week && $bookingProduct->available_from + ? Carbon::createFromTimeString($bookingProduct->available_from . " 00:00:00") + : Carbon::createFromTimeString($currentTime->format('Y-m-d') . ' 00:00:00'); - $availableTo = ! $bookingProductSlot->available_every_week - ? Carbon::createFromTimeString($bookingProductSlot->available_to . ' 23:59:59') - : Carbon::createFromTimeString('2080-01-01 00:00:00'); + $availableTo = ! $bookingProduct->available_every_week && $bookingProduct->available_from + ? Carbon::createFromTimeString($bookingProduct->available_to . ' 23:59:59') + : Carbon::createFromTimeString('2080-01-01 00:00:00'); $timeDurations = $bookingProductSlot->same_slot_all_days ? $bookingProductSlot->slots @@ -328,6 +328,12 @@ class Booking } switch ($bookingProduct->type) { + case 'event': + + dd($data, $bookingProduct->event_tickets); + + break; + case 'rental': $rentingType = $data['booking']['renting_type'] ?? $bookingProduct->rental_slot->renting_type; diff --git a/packages/Webkul/BookingProduct/src/Helpers/DefaultSlot.php b/packages/Webkul/BookingProduct/src/Helpers/DefaultSlot.php index 827dcbbbe..7531cc096 100644 --- a/packages/Webkul/BookingProduct/src/Helpers/DefaultSlot.php +++ b/packages/Webkul/BookingProduct/src/Helpers/DefaultSlot.php @@ -32,13 +32,17 @@ class DefaultSlot extends Booking return []; } - $requestedDate = Carbon::createFromTimeString($date . " 00:00:00"); + $requestedDate = Carbon::createFromTimeString($date . ' 00:00:00'); $currentTime = Carbon::now(); - $availableFrom = Carbon::createFromTimeString($bookingProductSlot->available_from . " 00:00:00"); + $availableFrom = ! $bookingProduct->available_from && $bookingProduct->available_from + ? Carbon::createFromTimeString($bookingProduct->available_from . ' 00:00:00') + : clone $currentTime; - $availableTo = Carbon::createFromTimeString($bookingProductSlot->available_to . ' 23:59:59'); + $availableTo = ! $bookingProduct->available_from && $bookingProduct->available_to + ? Carbon::createFromTimeString($bookingProduct->available_to . ' 23:59:59') + : Carbon::createFromTimeString('2080-01-01 00:00:00'); if ($requestedDate < $currentTime || $requestedDate < $availableFrom @@ -91,11 +95,17 @@ class DefaultSlot extends Booking */ public function getManyBookingsforOneDaySlots($bookingProductSlot, $requestedDate) { + $bookingProduct = $bookingProductSlot->booking_product; + $currentTime = Carbon::now(); - $availableFrom = Carbon::createFromTimeString($bookingProductSlot->available_from . ' 00:00:00'); + $availableFrom = ! $bookingProduct->available_from && $bookingProduct->available_from + ? Carbon::createFromTimeString($bookingProduct->available_from . ' 00:00:00') + : clone $currentTime; - $availableTo = Carbon::createFromTimeString($bookingProductSlot->available_to . ' 23:59:59'); + $availableTo = ! $bookingProduct->available_from && $bookingProduct->available_to + ? Carbon::createFromTimeString($bookingProduct->available_to . ' 23:59:59') + : Carbon::createFromTimeString('2080-01-01 00:00:00'); $timeDuration = $bookingProductSlot->slots[$requestedDate->format('w')] ?? []; diff --git a/packages/Webkul/BookingProduct/src/Helpers/EventSlot.php b/packages/Webkul/BookingProduct/src/Helpers/EventTicket.php similarity index 71% rename from packages/Webkul/BookingProduct/src/Helpers/EventSlot.php rename to packages/Webkul/BookingProduct/src/Helpers/EventTicket.php index 56971e667..9218aa485 100644 --- a/packages/Webkul/BookingProduct/src/Helpers/EventSlot.php +++ b/packages/Webkul/BookingProduct/src/Helpers/EventTicket.php @@ -5,12 +5,12 @@ namespace Webkul\BookingProduct\Helpers; use Carbon\Carbon; /** - * EventSlot Helper + * EventTicket Helper * * @author Jitendra Singh * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class EventSlot extends Booking +class EventTicket extends Booking { /** * Returns event date @@ -20,9 +20,9 @@ class EventSlot extends Booking */ public function getEventDate($bookingProduct) { - $from = Carbon::createFromTimeString($bookingProduct->event_slot->available_from)->format('d F, Y h:i A'); + $from = Carbon::createFromTimeString($bookingProduct->available_from)->format('d F, Y h:i A'); - $to = Carbon::createFromTimeString($bookingProduct->event_slot->available_to)->format('d F, Y h:i A'); + $to = Carbon::createFromTimeString($bookingProduct->available_to)->format('d F, Y h:i A'); return $from . ' - ' . $to; } @@ -35,11 +35,11 @@ class EventSlot extends Booking */ public function getTickets($bookingProduct) { - if (! $bookingProduct->event_slot) { + if (! $bookingProduct->event_tickets()->count()) { return; } - return $this->formatPrice($bookingProduct->event_slot->slots); + return $this->formatPrice($bookingProduct->event_tickets); } /** @@ -51,8 +51,8 @@ class EventSlot extends Booking public function formatPrice($tickets) { foreach ($tickets as $index => $ticket) { - $tickets[$index]['converted_price'] = core()->convertPrice($ticket['price']); - $tickets[$index]['formated_price'] = $formatedPrice = core()->currency($ticket['price']); + $tickets[$index]['converted_price'] = core()->convertPrice($ticket->price); + $tickets[$index]['formated_price'] = $formatedPrice = core()->currency($ticket->price); $tickets[$index]['formated_price_text'] = trans('bookingproduct::app.shop.products.per-ticket-price', ['price' => $formatedPrice]); } diff --git a/packages/Webkul/BookingProduct/src/Helpers/RentalSlot.php b/packages/Webkul/BookingProduct/src/Helpers/RentalSlot.php index e0dc4f298..3c5322d1a 100644 --- a/packages/Webkul/BookingProduct/src/Helpers/RentalSlot.php +++ b/packages/Webkul/BookingProduct/src/Helpers/RentalSlot.php @@ -31,13 +31,13 @@ class RentalSlot extends Booking $currentTime = Carbon::now(); - $availableFrom = ! $bookingProductSlot->available_every_week - ? Carbon::createFromTimeString($bookingProductSlot->available_from . ' 00:00:00') - : Carbon::createFromTimeString($currentTime->format('Y-m-d') . ' 00:00:00'); + $availableFrom = ! $bookingProduct->available_every_week && $bookingProduct->available_from + ? Carbon::createFromTimeString($bookingProduct->available_from . ' 00:00:00') + : Carbon::createFromTimeString($currentTime->format('Y-m-d') . ' 00:00:00'); - $availableTo = ! $bookingProductSlot->available_every_week - ? Carbon::createFromTimeString($bookingProductSlot->available_to . ' 23:59:59') - : Carbon::createFromTimeString('2080-01-01 00:00:00'); + $availableTo = ! $bookingProduct->available_every_week && $bookingProduct->available_from + ? Carbon::createFromTimeString($bookingProduct->available_to . ' 23:59:59') + : Carbon::createFromTimeString('2080-01-01 00:00:00'); $timeDurations = $bookingProductSlot->same_slot_all_days ? $bookingProductSlot->slots diff --git a/packages/Webkul/BookingProduct/src/Http/Controllers/Shop/BookingProductController.php b/packages/Webkul/BookingProduct/src/Http/Controllers/Shop/BookingProductController.php index f0b3f4cf2..ee5b0ff54 100644 --- a/packages/Webkul/BookingProduct/src/Http/Controllers/Shop/BookingProductController.php +++ b/packages/Webkul/BookingProduct/src/Http/Controllers/Shop/BookingProductController.php @@ -6,7 +6,7 @@ use Webkul\BookingProduct\Repositories\BookingProductRepository; use Webkul\BookingProduct\Helpers\DefaultSlot as DefaultSlotHelper; use Webkul\BookingProduct\Helpers\AppointmentSlot as AppointmentSlotHelper; use Webkul\BookingProduct\Helpers\RentalSlot as RentalSlotHelper; -use Webkul\BookingProduct\Helpers\EventSlot as EventSlotHelper; +use Webkul\BookingProduct\Helpers\EventTicket as EventTicketHelper; use Webkul\BookingProduct\Helpers\TableSlot as TableSlotHelper; /** @@ -36,7 +36,7 @@ class BookingProductController extends Controller * @param Webkul\BookingProduct\Helpers\DefaultSlot $defaultSlotHelper * @param Webkul\BookingProduct\Helpers\AppointmentSlot $appointmentSlotHelper * @param Webkul\BookingProduct\Helpers\RentalSlot $rentalSlotHelper - * @param Webkul\BookingProduct\Helpers\EventSlot $eventSlotHelper + * @param Webkul\BookingProduct\Helpers\EventTicket $EventTicketHelper * @param Webkul\BookingProduct\Helpers\TableSlot $tableSlotHelper * @return void */ @@ -45,7 +45,7 @@ class BookingProductController extends Controller DefaultSlotHelper $defaultSlotHelper, AppointmentSlotHelper $appointmentSlotHelper, RentalSlotHelper $rentalSlotHelper, - EventSlotHelper $eventSlotHelper, + EventTicketHelper $eventTicketHelper, TableSlotHelper $tableSlotHelper ) { @@ -57,7 +57,7 @@ class BookingProductController extends Controller $this->bookingHelpers['rental'] = $rentalSlotHelper; - $this->bookingHelpers['event'] = $eventSlotHelper; + $this->bookingHelpers['event'] = $eventTicketHelper; $this->bookingHelpers['table'] = $tableSlotHelper; } diff --git a/packages/Webkul/BookingProduct/src/Listeners/Product.php b/packages/Webkul/BookingProduct/src/Listeners/Product.php deleted file mode 100644 index 1d27f5286..000000000 --- a/packages/Webkul/BookingProduct/src/Listeners/Product.php +++ /dev/null @@ -1,54 +0,0 @@ - - * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) - */ -class Product -{ - /** - * BookingProductRepository Object - * - * @var Object - */ - protected $bookingProductRepository; - - /** - * Create a new listener instance. - * - * @param Webkul\BookingProduct\Repositories\BookingProductRepository $bookingProductRepository - * @return void - */ - public function __construct(BookingProductRepository $bookingProductRepository) - { - $this->bookingProductRepository = $bookingProductRepository; - } - - /** - * After the product is updated - * - * @return void - */ - public function afterProductUpdated($product) - { - if ($product->type != 'booking' || ! request('booking')) { - return; - } - - $bookingProduct = $this->bookingProductRepository->findOneByField('product_id', $product->id); - - if ($bookingProduct) { - $this->bookingProductRepository->update(request('booking'), $bookingProduct->id); - } else { - $this->bookingProductRepository->create(array_merge(request('booking'), [ - 'product_id' => $product->id - ])); - } - } -} \ No newline at end of file diff --git a/packages/Webkul/BookingProduct/src/Models/BookingProduct.php b/packages/Webkul/BookingProduct/src/Models/BookingProduct.php index 6c54592c3..0f20d30c0 100644 --- a/packages/Webkul/BookingProduct/src/Models/BookingProduct.php +++ b/packages/Webkul/BookingProduct/src/Models/BookingProduct.php @@ -8,9 +8,9 @@ use Webkul\BookingProduct\Contracts\BookingProduct as BookingProductContract; class BookingProduct extends Model implements BookingProductContract { - protected $fillable = ['location', 'show_location', 'type', 'product_id']; + protected $fillable = ['location', 'show_location', 'type', 'available_every_week', 'available_from', 'available_to', 'product_id']; - protected $with = ['default_slot', 'appointment_slot', 'event_slot', 'rental_slot', 'table_slot']; + protected $with = ['default_slot', 'appointment_slot', 'event_tickets', 'rental_slot', 'table_slot']; /** * The Product Default Booking that belong to the product booking. @@ -31,9 +31,9 @@ class BookingProduct extends Model implements BookingProductContract /** * The Product Event Booking that belong to the product booking. */ - public function event_slot() + public function event_tickets() { - return $this->hasOne(BookingProductEventSlotProxy::modelClass()); + return $this->hasMany(BookingProductEventTicketProxy::modelClass()); } /** diff --git a/packages/Webkul/BookingProduct/src/Models/BookingProductDefaultSlot.php b/packages/Webkul/BookingProduct/src/Models/BookingProductDefaultSlot.php index d143d324b..873ff2f8a 100644 --- a/packages/Webkul/BookingProduct/src/Models/BookingProductDefaultSlot.php +++ b/packages/Webkul/BookingProduct/src/Models/BookingProductDefaultSlot.php @@ -13,7 +13,7 @@ class BookingProductDefaultSlot extends Model implements BookingProductDefaultSl protected $casts = ['slots' => 'array']; - protected $fillable = ['booking_type', 'duration', 'break_time', 'available_from', 'available_to', 'slots', 'booking_product_id']; + protected $fillable = ['booking_type', 'duration', 'break_time', 'slots', 'booking_product_id']; /** * Get the product that owns the attribute value. diff --git a/packages/Webkul/BookingProduct/src/Models/BookingProductEventSlot.php b/packages/Webkul/BookingProduct/src/Models/BookingProductEventSlot.php deleted file mode 100644 index bca8d5eaa..000000000 --- a/packages/Webkul/BookingProduct/src/Models/BookingProductEventSlot.php +++ /dev/null @@ -1,15 +0,0 @@ - 'array']; - - protected $fillable = ['available_from', 'available_to', 'slots', 'booking_product_id']; -} \ No newline at end of file diff --git a/packages/Webkul/BookingProduct/src/Models/BookingProductEventTicket.php b/packages/Webkul/BookingProduct/src/Models/BookingProductEventTicket.php new file mode 100644 index 000000000..f9d5feac2 --- /dev/null +++ b/packages/Webkul/BookingProduct/src/Models/BookingProductEventTicket.php @@ -0,0 +1,15 @@ + 'array']; - protected $fillable = ['price_type', 'guest_limit', 'guest_capacity', 'duration', 'break_time', 'prevent_scheduling_before', 'available_every_week', 'available_from', 'available_to', 'same_slot_all_days', 'slots', 'booking_product_id']; + protected $fillable = ['price_type', 'guest_limit', 'guest_capacity', 'duration', 'break_time', 'prevent_scheduling_before', 'available_every_week', 'same_slot_all_days', 'slots', 'booking_product_id']; } \ No newline at end of file diff --git a/packages/Webkul/BookingProduct/src/Providers/EventServiceProvider.php b/packages/Webkul/BookingProduct/src/Providers/EventServiceProvider.php index 98d66d424..98d14f49c 100644 --- a/packages/Webkul/BookingProduct/src/Providers/EventServiceProvider.php +++ b/packages/Webkul/BookingProduct/src/Providers/EventServiceProvider.php @@ -17,7 +17,5 @@ class EventServiceProvider extends ServiceProvider Event::listen('bagisto.shop.products.view.short_description.after', function($viewRenderEventManager) { $viewRenderEventManager->addTemplate('bookingproduct::shop.products.view.booking'); }); - - Event::listen('catalog.product.update.after', 'Webkul\BookingProduct\Listeners\Product@afterProductUpdated'); } } \ No newline at end of file diff --git a/packages/Webkul/BookingProduct/src/Providers/ModuleServiceProvider.php b/packages/Webkul/BookingProduct/src/Providers/ModuleServiceProvider.php index d01915a8e..8da297a24 100644 --- a/packages/Webkul/BookingProduct/src/Providers/ModuleServiceProvider.php +++ b/packages/Webkul/BookingProduct/src/Providers/ModuleServiceProvider.php @@ -10,7 +10,8 @@ class ModuleServiceProvider extends BaseModuleServiceProvider \Webkul\BookingProduct\Models\BookingProduct::class, \Webkul\BookingProduct\Models\BookingProductDefaultSlot::class, \Webkul\BookingProduct\Models\BookingProductAppointmentSlot::class, - \Webkul\BookingProduct\Models\BookingProductEventSlot::class, + \Webkul\BookingProduct\Models\BookingProductEventTicket::class, + \Webkul\BookingProduct\Models\BookingProductEventTicketTranslation::class, \Webkul\BookingProduct\Models\BookingProductRentalSlot::class, \Webkul\BookingProduct\Models\BookingProductTableSlot::class, \Webkul\BookingProduct\Models\Booking::class diff --git a/packages/Webkul/BookingProduct/src/Repositories/BookingProductEventSlotRepository.php b/packages/Webkul/BookingProduct/src/Repositories/BookingProductEventSlotRepository.php deleted file mode 100644 index b2e44336c..000000000 --- a/packages/Webkul/BookingProduct/src/Repositories/BookingProductEventSlotRepository.php +++ /dev/null @@ -1,24 +0,0 @@ - - * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) - */ -class BookingProductEventSlotRepository extends Repository -{ - /** - * Specify Model class name - * - * @return mixed - */ - function model() - { - return 'Webkul\BookingProduct\Contracts\BookingProductEventSlot'; - } -} \ No newline at end of file diff --git a/packages/Webkul/BookingProduct/src/Repositories/BookingProductEventTicketRepository.php b/packages/Webkul/BookingProduct/src/Repositories/BookingProductEventTicketRepository.php new file mode 100644 index 000000000..7250d5895 --- /dev/null +++ b/packages/Webkul/BookingProduct/src/Repositories/BookingProductEventTicketRepository.php @@ -0,0 +1,55 @@ + + * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) + */ +class BookingProductEventTicketRepository extends Repository +{ + /** + * Specify Model class name + * + * @return mixed + */ + function model() + { + return 'Webkul\BookingProduct\Contracts\BookingProductEventTicket'; + } + + /** + * @param array $data + * @param BookingProduct $bookingProduct + * @return void + */ + public function saveEventTickets($data, $bookingProduct) + { + $previousTicketIds = $bookingProduct->event_tickets()->pluck('id'); + + if (isset($data['tickets'])) { + foreach ($data['tickets'] as $ticketId => $ticketInputs) { + if (Str::contains($ticketId, 'ticket_')) { + $this->create(array_merge([ + 'booking_product_id' => $bookingProduct->id, + ], $ticketInputs)); + } else { + if (is_numeric($index = $previousTicketIds->search($ticketId))) { + $previousTicketIds->forget($index); + } + + $this->update($ticketInputs, $ticketId); + } + } + } + + foreach ($previousTicketIds as $previousTicketId) { + $this->delete($previousTicketId); + } + } +} \ No newline at end of file diff --git a/packages/Webkul/BookingProduct/src/Repositories/BookingProductRepository.php b/packages/Webkul/BookingProduct/src/Repositories/BookingProductRepository.php index d75ff0e08..90198f3c1 100644 --- a/packages/Webkul/BookingProduct/src/Repositories/BookingProductRepository.php +++ b/packages/Webkul/BookingProduct/src/Repositories/BookingProductRepository.php @@ -23,7 +23,7 @@ class BookingProductRepository extends Repository * * @param Webkul\BookingProduct\Repositories\BookingProductDefaultSlotRepository $bookingProductDefaultSlotRepository * @param Webkul\BookingProduct\Repositories\BookingProductAppointmentSlotRepository $bookingProductAppointmentSlotRepository - * @param Webkul\BookingProduct\Repositories\BookingProductEventSlotRepository $bookingProductEventSlotRepository + * @param Webkul\BookingProduct\Repositories\BookingProductEventTicketRepository $bookingProductEventTicketRepository * @param Webkul\BookingProduct\Repositories\BookingProductRentalSlotRepository $bookingProductRentalSlotRepository * @param Webkul\BookingProduct\Repositories\BookingProductTableSlotRepository $bookingProductTableSlotRepository * @return void @@ -31,7 +31,7 @@ class BookingProductRepository extends Repository public function __construct( BookingProductDefaultSlotRepository $bookingProductDefaultSlotRepository, BookingProductAppointmentSlotRepository $bookingProductAppointmentSlotRepository, - BookingProductEventSlotRepository $bookingProductEventSlotRepository, + BookingProductEventTicketRepository $bookingProductEventTicketRepository, BookingProductRentalSlotRepository $bookingProductRentalSlotRepository, BookingProductTableSlotRepository $bookingProductTableSlotRepository, App $app @@ -43,7 +43,7 @@ class BookingProductRepository extends Repository $this->typeRepositories['appointment'] = $bookingProductAppointmentSlotRepository; - $this->typeRepositories['event'] = $bookingProductEventSlotRepository; + $this->typeRepositories['event'] = $bookingProductEventTicketRepository; $this->typeRepositories['rental'] = $bookingProductRentalSlotRepository; @@ -68,7 +68,11 @@ class BookingProductRepository extends Repository { $bookingProduct = parent::create($data); - $this->typeRepositories[$data['type']]->create(array_merge($data, ['booking_product_id' => $bookingProduct->id])); + if ($bookingProduct->type == 'event') { + $this->typeRepositories[$data['type']]->saveEventTickets($data, $bookingProduct); + } else { + $this->typeRepositories[$data['type']]->create(array_merge($data, ['booking_product_id' => $bookingProduct->id])); + } return $bookingProduct; } @@ -81,7 +85,7 @@ class BookingProductRepository extends Repository */ public function update(array $data, $id, $attribute = "id") { - parent::update($data, $id, $attribute); + $bookingProduct = parent::update($data, $id, $attribute); foreach ($this->typeRepositories as $type => $repository) { if ($type == $data['type']) { @@ -91,16 +95,20 @@ class BookingProductRepository extends Repository $repository->deleteWhere(['booking_product_id' => $id]); } - $bookingProductTypeSlot = $this->typeRepositories[$data['type']]->findOneByField('booking_product_id', $id); - - if (isset($data['slots'])) { - $data['slots'] = $this->formatSlots($data); - } - - if (! $bookingProductTypeSlot) { - $this->typeRepositories[$data['type']]->create(array_merge($data, ['booking_product_id' => $id])); + if ($bookingProduct->type == 'event') { + $this->typeRepositories[$data['type']]->saveEventTickets($data, $bookingProduct); } else { - $this->typeRepositories[$data['type']]->update($data, $bookingProductTypeSlot->id); + $bookingProductTypeSlot = $this->typeRepositories[$data['type']]->findOneByField('booking_product_id', $id); + + if (isset($data['slots'])) { + $data['slots'] = $this->formatSlots($data); + } + + if (! $bookingProductTypeSlot) { + $this->typeRepositories[$data['type']]->create(array_merge($data, ['booking_product_id' => $id])); + } else { + $this->typeRepositories[$data['type']]->update($data, $bookingProductTypeSlot->id); + } } } diff --git a/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking.blade.php b/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking.blade.php index d667982b3..709ecc6dc 100644 --- a/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking.blade.php +++ b/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking.blade.php @@ -37,6 +37,41 @@ +
+
+ + + + + @{{ errors.first('booking[available_every_week]') }} +
+ +
+
+ + + + + + + @{{ errors.first('booking[available_from]') }} +
+ +
+ + + + + + + @{{ errors.first('booking[available_to]') }} +
+
+
+
@include ('bookingproduct::admin.catalog.products.accordians.booking.default', ['bookingProduct' => $bookingProduct])
@@ -73,7 +108,13 @@ return { booking_type: bookingProduct ? bookingProduct.type : 'default', - location: '' + location: '', + + available_every_week: bookingProduct.available_every_week, + + available_from: bookingProduct.available_from, + + available_to: bookingProduct.available_to } } }); diff --git a/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking/appointment.blade.php b/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking/appointment.blade.php index 5d885c644..cd28365e9 100644 --- a/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking/appointment.blade.php +++ b/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking/appointment.blade.php @@ -25,39 +25,6 @@ @{{ errors.first('booking[break_time]') }} -
- - - - - @{{ errors.first('booking[available_every_week]') }} -
- -
-
- - - - - - - @{{ errors.first('booking[available_from]') }} -
- -
- - - - - - - @{{ errors.first('booking[available_to]') }} -
-
-
@@ -112,12 +79,6 @@ break_time: 15, - available_every_week: 1, - - available_from: '', - - available_to: '', - same_slot_all_days: 1, slot_has_quantity: 1, diff --git a/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking/default.blade.php b/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking/default.blade.php index 07e0610a9..996603c31 100644 --- a/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking/default.blade.php +++ b/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking/default.blade.php @@ -37,26 +37,6 @@ @{{ errors.first('booking[booking_type]') }}
- -
- - - - - - - @{{ errors.first('booking[available_from]') }} -
- -
- - - - - - - @{{ errors.first('booking[available_to]') }} -
@@ -238,10 +218,6 @@ break_time: 15, - available_from: '', - - available_to: '', - slots: [] }, diff --git a/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking/event.blade.php b/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking/event.blade.php index 99d9cc579..061c8e92d 100644 --- a/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking/event.blade.php +++ b/packages/Webkul/BookingProduct/src/Resources/views/admin/catalog/products/accordians/booking/event.blade.php @@ -9,26 +9,6 @@