diff --git a/packages/Webkul/BookingProduct/src/Contracts/Booking.php b/packages/Webkul/BookingProduct/src/Contracts/Booking.php new file mode 100644 index 000000000..1b02e9e3c --- /dev/null +++ b/packages/Webkul/BookingProduct/src/Contracts/Booking.php @@ -0,0 +1,7 @@ +bigIncrements('id'); + $table->json('slot_information')->nullable(); + + $table->integer('order_item_id')->unsigned()->nullable(); + + $table->integer('order_id')->unsigned()->nullable(); + $table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade'); + + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('bookings'); + } +} diff --git a/packages/Webkul/BookingProduct/src/Helpers/DefaultSlot.php b/packages/Webkul/BookingProduct/src/Helpers/DefaultSlot.php index 26f9f1253..6805c5ddf 100644 --- a/packages/Webkul/BookingProduct/src/Helpers/DefaultSlot.php +++ b/packages/Webkul/BookingProduct/src/Helpers/DefaultSlot.php @@ -138,11 +138,11 @@ class DefaultSlot extends Booking if ($qty && $currentTime <= $from) { $slots[] = [ - 'from' => $from->format('h:i A'), - 'to' => $to->format('h:i A'), - 'timestamp' => $from->getTimestamp() . '-' . $to->getTimestamp(), - 'qty' => $qty, - ]; + 'from' => $from->format('h:i A'), + 'to' => $to->format('h:i A'), + 'timestamp' => $from->getTimestamp() . '-' . $to->getTimestamp(), + 'qty' => $qty, + ]; } } else { break; diff --git a/packages/Webkul/BookingProduct/src/Models/Booking.php b/packages/Webkul/BookingProduct/src/Models/Booking.php new file mode 100644 index 000000000..b27552031 --- /dev/null +++ b/packages/Webkul/BookingProduct/src/Models/Booking.php @@ -0,0 +1,31 @@ +belongsTo(OrderProxy::modelClass()); + } + + /** + * Get the child item record associated with the order item. + */ + public function order_item() + { + return $this->hasOne(OrderItemProxy::modelClass()); + } +} \ No newline at end of file diff --git a/packages/Webkul/BookingProduct/src/Models/BookingProxy.php b/packages/Webkul/BookingProduct/src/Models/BookingProxy.php new file mode 100644 index 000000000..196bc852c --- /dev/null +++ b/packages/Webkul/BookingProduct/src/Models/BookingProxy.php @@ -0,0 +1,10 @@ + + * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) + */ +class BookingRepository extends Repository +{ + /** + * Specify Model class name + * + * @return mixed + */ + function model() + { + return 'Webkul\BookingProduct\Contracts\Booking'; + } +} \ No newline at end of file diff --git a/packages/Webkul/BookingProduct/src/Type/Booking.php b/packages/Webkul/BookingProduct/src/Type/Booking.php index 17de2eecb..a3f30ac99 100644 --- a/packages/Webkul/BookingProduct/src/Type/Booking.php +++ b/packages/Webkul/BookingProduct/src/Type/Booking.php @@ -10,7 +10,7 @@ use Webkul\Product\Repositories\ProductImageRepository; use Webkul\Product\Helpers\ProductImage; use Webkul\BookingProduct\Repositories\BookingProductRepository; use Webkul\BookingProduct\Helpers\Booking as BookingHelper; -use Webkul\Product\Type\AbstractType; +use Webkul\Product\Type\Virtual; /** * Class Booking. @@ -18,7 +18,7 @@ use Webkul\Product\Type\AbstractType; * @author Jitendra Singh * @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com) */ -class Booking extends AbstractType +class Booking extends Virtual { /** * BookingProductRepository instance @@ -34,26 +34,14 @@ class Booking extends AbstractType */ protected $bookingHelper; - /** - * Skip attribute for virtual product type - * - * @var array - */ - protected $skipAttributes = ['width', 'height', 'depth', 'weight']; - - /** - * Show quantity box - * - * @var boolean - */ - protected $showQuantityBox = true; - /** * @var array */ protected $additionalViews = [ + 'admin::catalog.products.accordians.inventories', 'admin::catalog.products.accordians.images', 'admin::catalog.products.accordians.categories', + 'admin::catalog.products.accordians.channels', 'bookingproduct::admin.catalog.products.accordians.booking', 'admin::catalog.products.accordians.product-links' ]; @@ -97,37 +85,42 @@ class Booking extends AbstractType } /** - * Return true if this product type is saleable + * Returns additional views * * @return array */ - public function isSaleable() + public function getBookingProduct($productId) + { + static $bookingProduct; + + if ($bookingProduct) + return $bookingProduct; + + return $bookingProduct = $this->bookingProductRepository->findOneByField('product_id', $productId); + } + + /** + * @param integer $qty + * @return bool + */ + public function haveSufficientQuantity($qty) { - if (! $this->product->status) - return false; - return true; } /** - * Return true if this product can have inventory + * Returns additional views * * @return array */ - public function isStockable() + public function getAdditionalViews() { - return false; - } + $bookingProduct = $this->getBookingProduct($this->product->id); - /** - * Return true if item can be moved to cart from wishlist - * - * @param CartItem $item - * @return boolean - */ - public function canBeMovedFromWishlistToCart($item) - { - return true; + if ($bookingProduct->type != 'default') + unset($this->additionalViews[0]); + + return $this->additionalViews; } /** @@ -143,7 +136,7 @@ class Booking extends AbstractType $products = parent::prepareForCart($data); - $bookingProduct = $this->bookingProductRepository->findOneByField('product_id', $data['product_id']); + $bookingProduct = $this->getBookingProduct($data['product_id']); if ($bookingProduct) $products = app($this->bookingHelper->getTypeHepler($bookingProduct->type))->addAdditionalPrices($products); @@ -184,7 +177,7 @@ class Booking extends AbstractType */ public function validateCartItem($item) { - $bookingProduct = $this->bookingProductRepository->findOneByField('product_id', $item->product_id); + $bookingProduct = $this->getBookingProduct($item->product_id); if (! $bookingProduct) return; diff --git a/packages/Webkul/Product/src/Type/Virtual.php b/packages/Webkul/Product/src/Type/Virtual.php index 487be2d9e..d5e6d4ad3 100644 --- a/packages/Webkul/Product/src/Type/Virtual.php +++ b/packages/Webkul/Product/src/Type/Virtual.php @@ -66,6 +66,6 @@ class Virtual extends AbstractType */ public function haveSufficientQuantity($qty) { - return $qty <= $this->totalQuantity() ? true : false; + return true; } } \ No newline at end of file