2019-01-19 10:05:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Webkul\Product\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2019-02-18 07:30:40 +00:00
|
|
|
use Webkul\Product\Contracts\ProductFlat as ProductFlatContract;
|
2019-01-19 10:05:12 +00:00
|
|
|
|
2019-02-18 07:30:40 +00:00
|
|
|
class ProductFlat extends Model implements ProductFlatContract
|
2019-01-19 10:05:12 +00:00
|
|
|
{
|
|
|
|
|
protected $table = 'product_flat';
|
|
|
|
|
|
|
|
|
|
protected $guarded = ['id', 'created_at', 'updated_at'];
|
2019-01-23 11:05:34 +00:00
|
|
|
|
|
|
|
|
public $timestamps = false;
|
2019-01-25 11:54:48 +00:00
|
|
|
|
2019-07-08 09:39:42 +00:00
|
|
|
/**
|
|
|
|
|
* Get the product attribute family that owns the product.
|
|
|
|
|
*/
|
|
|
|
|
public function getAttributeFamilyAttribute()
|
|
|
|
|
{
|
|
|
|
|
return $this->product->attribute_family;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-25 11:54:48 +00:00
|
|
|
/**
|
|
|
|
|
* Get the product that owns the attribute value.
|
|
|
|
|
*/
|
|
|
|
|
public function product()
|
|
|
|
|
{
|
2019-02-18 07:30:40 +00:00
|
|
|
return $this->belongsTo(ProductProxy::modelClass());
|
2019-01-25 11:54:48 +00:00
|
|
|
}
|
2019-03-12 12:53:11 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the product variants that owns the product.
|
|
|
|
|
*/
|
|
|
|
|
public function variants()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(self::class, 'parent_id');
|
|
|
|
|
}
|
2019-04-16 10:10:58 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get product type value from base product
|
|
|
|
|
*/
|
|
|
|
|
public function getTypeAttribute()
|
|
|
|
|
{
|
|
|
|
|
return $this->product->type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $key
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function isSaleable()
|
|
|
|
|
{
|
|
|
|
|
if (! $this->status)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if ($this->haveSufficientQuantity(1))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-06 11:13:36 +00:00
|
|
|
/**
|
|
|
|
|
* @return integer
|
|
|
|
|
*/
|
|
|
|
|
public function totalQuantity()
|
|
|
|
|
{
|
|
|
|
|
return $this->product->totalQuantity();
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-16 10:10:58 +00:00
|
|
|
/**
|
|
|
|
|
* @param integer $qty
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function haveSufficientQuantity($qty)
|
|
|
|
|
{
|
|
|
|
|
return $this->product->haveSufficientQuantity($qty);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The images that belong to the product.
|
|
|
|
|
*/
|
|
|
|
|
public function images()
|
|
|
|
|
{
|
|
|
|
|
return (ProductImageProxy::modelClass())
|
|
|
|
|
::where('product_images.product_id', $this->product_id)
|
|
|
|
|
->select('product_images.*');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all of the attributes for the attribute groups.
|
|
|
|
|
*/
|
|
|
|
|
public function getImagesAttribute()
|
|
|
|
|
{
|
|
|
|
|
return $this->images()->get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The reviews that belong to the product.
|
|
|
|
|
*/
|
|
|
|
|
public function reviews()
|
|
|
|
|
{
|
|
|
|
|
return (ProductReviewProxy::modelClass())
|
|
|
|
|
::where('product_reviews.product_id', $this->product_id)
|
|
|
|
|
->select('product_reviews.*');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get all of the reviews for the attribute groups.
|
|
|
|
|
*/
|
|
|
|
|
public function getReviewsAttribute()
|
|
|
|
|
{
|
2019-07-08 09:39:42 +00:00
|
|
|
return $this->reviews()->get();
|
2019-04-16 10:10:58 +00:00
|
|
|
}
|
2019-04-16 10:27:38 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The related products that belong to the product.
|
|
|
|
|
*/
|
|
|
|
|
public function related_products()
|
|
|
|
|
{
|
|
|
|
|
return $this->product->related_products();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The up sells that belong to the product.
|
|
|
|
|
*/
|
|
|
|
|
public function up_sells()
|
|
|
|
|
{
|
|
|
|
|
return $this->product->up_sells();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The cross sells that belong to the product.
|
|
|
|
|
*/
|
|
|
|
|
public function cross_sells()
|
|
|
|
|
{
|
|
|
|
|
return $this->product->cross_sells();
|
|
|
|
|
}
|
2019-01-19 10:05:12 +00:00
|
|
|
}
|