Booking migration added

This commit is contained in:
Jitendra Singh 2020-02-18 19:31:04 +05:30
parent ead65981dc
commit 415eac6766
9 changed files with 145 additions and 42 deletions

View File

@ -0,0 +1,7 @@
<?php
namespace Webkul\BookingProduct\Contracts;
interface Booking
{
}

View File

@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateBookingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('bookings', function (Blueprint $table) {
$table->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');
}
}

View File

@ -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;

View File

@ -0,0 +1,31 @@
<?php
namespace Webkul\BookingProduct\Models;
use Illuminate\Database\Eloquent\Model;
use Webkul\BookingProduct\Contracts\Booking as BookingContract;
use Webkul\Sales\Models\OrderProxy;
use Webkul\Sales\Models\OrderItemProxy;
class Booking extends Model implements BookingContract
{
public $timestamps = false;
protected $fillable = ['slot_information', 'order_item_id', 'order_id'];
/**
* Get the order record associated with the order item.
*/
public function order()
{
return $this->belongsTo(OrderProxy::modelClass());
}
/**
* Get the child item record associated with the order item.
*/
public function order_item()
{
return $this->hasOne(OrderItemProxy::modelClass());
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace Webkul\BookingProduct\Models;
use Konekt\Concord\Proxies\ModelProxy;
class BookingProxy extends ModelProxy
{
}

View File

@ -13,5 +13,6 @@ class ModuleServiceProvider extends BaseModuleServiceProvider
\Webkul\BookingProduct\Models\BookingProductEventSlot::class,
\Webkul\BookingProduct\Models\BookingProductRentalSlot::class,
\Webkul\BookingProduct\Models\BookingProductTableSlot::class,
\Webkul\BookingProduct\Models\Booking::class
];
}

View File

@ -0,0 +1,24 @@
<?php
namespace Webkul\BookingProduct\Repositories;
use Webkul\Core\Eloquent\Repository;
/**
* BookingProduct Repository
*
* @author Jitendra Singh <jitendra@webkul.com>
* @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';
}
}

View File

@ -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 <jitendra@webkul.com>
* @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)
{
if (! $this->product->status)
return false;
static $bookingProduct;
if ($bookingProduct)
return $bookingProduct;
return $bookingProduct = $this->bookingProductRepository->findOneByField('product_id', $productId);
}
/**
* @param integer $qty
* @return bool
*/
public function haveSufficientQuantity($qty)
{
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;

View File

@ -66,6 +66,6 @@ class Virtual extends AbstractType
*/
public function haveSufficientQuantity($qty)
{
return $qty <= $this->totalQuantity() ? true : false;
return true;
}
}