Fixed shipping create issue and refactored models

This commit is contained in:
jitendra 2022-08-09 17:49:38 +05:30
parent 057c873342
commit 8c61634698
23 changed files with 62 additions and 78 deletions

View File

@ -88,13 +88,15 @@ class ShipmentController extends Controller
'shipment.items.*.*' => 'required|numeric|min:0',
]);
if (! $this->isInventoryValidate(request()->all())) {
$data = request()->all();
if (! $this->isInventoryValidate($data)) {
session()->flash('error', trans('admin::app.sales.shipments.quantity-invalid'));
return redirect()->back();
}
$this->shipmentRepository->create(array_merge(request()->all(), [
$this->shipmentRepository->create(array_merge($data, [
'order_id' => $orderId,
]));

View File

@ -56,8 +56,8 @@ class Attribute extends TranslatableModel implements AttributeContract
public function scopeFilterableAttributes(Builder $query): Builder
{
return $query->where('is_filterable', 1)
->where('swatch_type', '<>', 'image')
->orderBy('position');
->where('swatch_type', '<>', 'image')
->orderBy('position');
}
/**

View File

@ -27,10 +27,10 @@ class AttributeFamily extends Model implements AttributeFamilyContract
public function custom_attributes()
{
return (AttributeProxy::modelClass())::join('attribute_group_mappings', 'attributes.id', '=', 'attribute_group_mappings.attribute_id')
->join('attribute_groups', 'attribute_group_mappings.attribute_group_id', '=', 'attribute_groups.id')
->join('attribute_families', 'attribute_groups.attribute_family_id', '=', 'attribute_families.id')
->where('attribute_families.id', $this->id)
->select('attributes.*');
->join('attribute_groups', 'attribute_group_mappings.attribute_group_id', '=', 'attribute_groups.id')
->join('attribute_families', 'attribute_groups.attribute_family_id', '=', 'attribute_families.id')
->where('attribute_families.id', $this->id)
->select('attributes.*');
}

View File

@ -17,7 +17,7 @@ class AttributeGroup extends Model implements AttributeGroupContract
public function custom_attributes()
{
return $this->belongsToMany(AttributeProxy::modelClass(), 'attribute_group_mappings')
->withPivot('position')
->orderBy('pivot_position', 'asc');
->withPivot('position')
->orderBy('pivot_position', 'asc');
}
}

View File

@ -111,7 +111,7 @@ class CartRule extends Model implements CartRuleContract
public function coupon_code(): \Illuminate\Database\Eloquent\Relations\HasOne
{
return $this->cart_rule_coupon()
->where('is_primary', 1);
->where('is_primary', 1);
}
/**
@ -121,8 +121,7 @@ class CartRule extends Model implements CartRuleContract
*/
public function getCouponCodeAttribute()
{
$coupon = $this->coupon_code()
->first();
$coupon = $this->coupon_code()->first();
if (! $coupon) {
return;

View File

@ -135,13 +135,11 @@ class Category extends TranslatableModel implements CategoryContract
'parent_id',
'=',
null,
],
[
], [
'_lft',
'<=',
$this->_lft,
],
[
], [
'_rgt',
'>=',
$this->_rgt,
@ -163,6 +161,7 @@ class Category extends TranslatableModel implements CategoryContract
while (isset($category->parent)) {
$category = $category->parent;
$categories[] = $category;
}

View File

@ -20,18 +20,13 @@ class Cart extends Model implements CartContract
'updated_at',
];
// protected $with = [
// 'items',
// 'items.children',
// ];
/**
* To get relevant associated items with the cart instance
*/
public function items(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(CartItemProxy::modelClass())
->whereNull('parent_id');
->whereNull('parent_id');
}
/**
@ -56,7 +51,7 @@ class Cart extends Model implements CartContract
public function billing_address(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->addresses()
->where('address_type', CartAddress::ADDRESS_TYPE_BILLING);
->where('address_type', CartAddress::ADDRESS_TYPE_BILLING);
}
/**
@ -64,8 +59,7 @@ class Cart extends Model implements CartContract
*/
public function getBillingAddressAttribute()
{
return $this->billing_address()
->first();
return $this->billing_address()->first();
}
/**
@ -74,7 +68,7 @@ class Cart extends Model implements CartContract
public function shipping_address(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->addresses()
->where('address_type', CartAddress::ADDRESS_TYPE_SHIPPING);
->where('address_type', CartAddress::ADDRESS_TYPE_SHIPPING);
}
/**
@ -82,8 +76,7 @@ class Cart extends Model implements CartContract
*/
public function getShippingAddressAttribute()
{
return $this->shipping_address()
->first();
return $this->shipping_address()->first();
}
/**
@ -100,7 +93,7 @@ class Cart extends Model implements CartContract
public function selected_shipping_rate(): \Illuminate\Database\Eloquent\Relations\HasManyThrough
{
return $this->shipping_rates()
->where('method', $this->shipping_method);
->where('method', $this->shipping_method);
}
/**
@ -109,8 +102,8 @@ class Cart extends Model implements CartContract
public function getSelectedShippingRateAttribute()
{
return $this->selected_shipping_rate()
->where('method', $this->shipping_method)
->first();
->where('method', $this->shipping_method)
->first();
}
/**
@ -162,7 +155,7 @@ class Cart extends Model implements CartContract
public function hasProductsWithQuantityBox(): bool
{
foreach ($this->items as $item) {
if ($item->product->getTypeInstance()->showQuantityBox() === true) {
if ($item->product->getTypeInstance()->showQuantityBox()) {
return true;
}
}

View File

@ -41,9 +41,9 @@ class CartItem extends Model implements CartItemContract
public function product_flat()
{
return (ProductFlatProxy::modelClass())::where('product_flat.product_id', $this->product_id)
->where('product_flat.locale', app()->getLocale())
->where('product_flat.channel', core()->getCurrentChannelCode())
->select('product_flat.*');
->where('product_flat.locale', app()->getLocale())
->where('product_flat.channel', core()->getCurrentChannelCode())
->select('product_flat.*');
}
/**
@ -51,8 +51,7 @@ class CartItem extends Model implements CartItemContract
*/
public function getProductFlatAttribute()
{
return $this->product_flat()
->first();
return $this->product_flat()->first();
}
public function cart(): HasOne

View File

@ -202,9 +202,7 @@ class Customer extends Authenticatable implements CustomerContract, JWTSubject
*/
public function isWishlistShared(): bool
{
return $this->wishlist_items()->where('shared', 1)->first()
? true
: false;
return (bool) $this->wishlist_items()->where('shared', 1)->first();
}
/**

View File

@ -491,8 +491,10 @@ class Product extends Model implements ProductContract
$locale = core()->checkRequestedLocaleCodeInRequestedChannel();
$channel = core()->getRequestedChannelCode();
if (array_key_exists($this->id, self::$loadedAttributeValues)
&& array_key_exists($attribute->id, self::$loadedAttributeValues[$this->id])) {
if (
array_key_exists($this->id, self::$loadedAttributeValues)
&& array_key_exists($attribute->id, self::$loadedAttributeValues[$this->id])
) {
return self::$loadedAttributeValues[$this->id][$attribute->id];
}

View File

@ -27,17 +27,17 @@ class ProductAttributeValue extends Model implements ProductAttributeValueContra
* @var array
*/
public static $attributeTypeFields = [
'text' => 'text_value',
'textarea' => 'text_value',
'price' => 'float_value',
'boolean' => 'boolean_value',
'select' => 'integer_value',
'text' => 'text_value',
'textarea' => 'text_value',
'price' => 'float_value',
'boolean' => 'boolean_value',
'select' => 'integer_value',
'multiselect' => 'text_value',
'datetime' => 'datetime_value',
'date' => 'date_value',
'file' => 'text_value',
'image' => 'text_value',
'checkbox' => 'text_value',
'datetime' => 'datetime_value',
'date' => 'date_value',
'file' => 'text_value',
'image' => 'text_value',
'checkbox' => 'text_value',
];
/**

View File

@ -40,13 +40,6 @@ class ProductFlat extends Model implements ProductFlatContract
'attribute_family_id',
];
/**
* Indicates if the model should be timestamped.
*
* @var boolean
*/
// public $timestamps = false;
/**
* Get the index name for the model.
*

View File

@ -34,8 +34,8 @@ class Invoice extends Model implements InvoiceContract
* @var array
*/
protected $statusLabel = [
'pending' => 'Pending',
'paid' => 'Paid',
'pending' => 'Pending',
'paid' => 'Paid',
'refunded' => 'Refunded',
];
@ -61,7 +61,7 @@ class Invoice extends Model implements InvoiceContract
public function items(): HasMany
{
return $this->hasMany(InvoiceItemProxy::modelClass())
->whereNull('parent_id');
->whereNull('parent_id');
}
/**
@ -86,7 +86,7 @@ class Invoice extends Model implements InvoiceContract
public function address(): BelongsTo
{
return $this->belongsTo(OrderAddressProxy::modelClass(), 'order_address_id')
->where('address_type', OrderAddress::ADDRESS_TYPE_BILLING);
->where('address_type', OrderAddress::ADDRESS_TYPE_BILLING);
}
/**

View File

@ -234,8 +234,7 @@ class Order extends Model implements OrderContract
public function haveStockableItems(): bool
{
foreach ($this->items as $item) {
if ($item->getTypeInstance()
->isStockable()) {
if ($item->getTypeInstance()->isStockable()) {
return true;
}
}
@ -378,8 +377,7 @@ class Order extends Model implements OrderContract
}
}
if ($this->base_grand_total_invoiced - $this->base_grand_total_refunded - $this->refunds()
->sum('base_adjustment_fee') > 0) {
if ($this->base_grand_total_invoiced - $this->base_grand_total_refunded - $this->refunds()->sum('base_adjustment_fee') > 0) {
return true;
}

View File

@ -53,9 +53,12 @@ class OrderAddress extends Address implements OrderAddressContract
switch ($address->address_type) {
case CartAddress::ADDRESS_TYPE_BILLING:
$address->address_type = self::ADDRESS_TYPE_BILLING;
break;
case CartAddress::ADDRESS_TYPE_SHIPPING:
$address->address_type = self::ADDRESS_TYPE_SHIPPING;
break;
}
});

View File

@ -56,8 +56,7 @@ class OrderItem extends Model implements OrderItemContract
*/
public function isStockable(): bool
{
return $this->getTypeInstance()
->isStockable();
return $this->getTypeInstance()->isStockable();
}
/**

View File

@ -45,7 +45,7 @@ class Refund extends Model implements RefundContract
public function items(): HasMany
{
return $this->hasMany(RefundItemProxy::modelClass())
->whereNull('parent_id');
->whereNull('parent_id');
}
/**

View File

@ -60,7 +60,7 @@ class Shipment extends Model implements ShipmentContract
public function address(): BelongsTo
{
return $this->belongsTo(OrderAddressProxy::modelClass(), 'order_address_id')
->where('address_type', OrderAddress::ADDRESS_TYPE_SHIPPING);
->where('address_type', OrderAddress::ADDRESS_TYPE_SHIPPING);
}
/**

View File

@ -13,7 +13,8 @@ class Category extends BaseCategory implements Sitemapable
*/
public function toSitemapTag(): Url | string | array
{
if (! $this->slug
if (
! $this->slug
|| ! $this->status
) {
return [];

View File

@ -13,7 +13,8 @@ class Product extends BaseProduct implements Sitemapable
*/
public function toSitemapTag(): Url | string | array
{
if (! $this->url_key
if (
! $this->url_key
|| ! $this->status
|| ! $this->visible_individually
) {

View File

@ -31,7 +31,7 @@ class TaxCategory extends Model implements TaxCategoryContract
public function tax_rates(): BelongsToMany
{
return $this->belongsToMany(TaxRateProxy::modelClass(), 'tax_categories_tax_rates', 'tax_category_id')
->withPivot('id');
->withPivot('id');
}
/**

View File

@ -7,7 +7,6 @@ use Webkul\Velocity\Contracts\Content as ContentContract;
class Content extends TranslatableModel implements ContentContract
{
protected $table = 'velocity_contents';
public $translatedAttributes = [

View File

@ -9,6 +9,4 @@ class VelocityMetadata extends Model implements VelocityMetadataContract
{
protected $table = 'velocity_meta_data';
protected $guarded = [];
}