fix issue in validateCartItem, refactoring of CartRule helper
This commit is contained in:
parent
f64a62dc29
commit
be931439aa
|
|
@ -144,7 +144,7 @@ class CartRule
|
|||
if ($staticCartRules::$cartID === cart()->getCart()->id && $staticCartRules::$cartRules) {
|
||||
return $staticCartRules::$cartRules;
|
||||
}
|
||||
|
||||
|
||||
$staticCartRules::$cartID = cart()->getCart()->id;
|
||||
|
||||
$customerGroupId = null;
|
||||
|
|
@ -157,21 +157,7 @@ class CartRule
|
|||
}
|
||||
}
|
||||
|
||||
$cartRules = $this->cartRuleRepository->scopeQuery(function ($query) use ($customerGroupId) {
|
||||
return $query->leftJoin('cart_rule_customer_groups', 'cart_rules.id', '=', 'cart_rule_customer_groups.cart_rule_id')
|
||||
->leftJoin('cart_rule_channels', 'cart_rules.id', '=', 'cart_rule_channels.cart_rule_id')
|
||||
->where('cart_rule_customer_groups.customer_group_id', $customerGroupId)
|
||||
->where('cart_rule_channels.channel_id', core()->getCurrentChannel()->id)
|
||||
->where(function ($query1) {
|
||||
$query1->where('cart_rules.starts_from', '<=', Carbon::now()->format('Y-m-d'))
|
||||
->orWhereNull('cart_rules.starts_from');
|
||||
})
|
||||
->where(function ($query2) {
|
||||
$query2->where('cart_rules.ends_till', '>=', Carbon::now()->format('Y-m-d'))
|
||||
->orWhereNull('cart_rules.ends_till');
|
||||
})
|
||||
->orderBy('sort_order', 'asc');
|
||||
})->findWhere(['status' => 1]);
|
||||
$cartRules = $this->getCartRuleQuery($customerGroupId, core()->getCurrentChannel()->id);
|
||||
|
||||
$staticCartRules::$cartRules = $cartRules;
|
||||
return $cartRules;
|
||||
|
|
@ -564,4 +550,32 @@ class CartRule
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $customerGroupId
|
||||
* @param $channelId
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Collection
|
||||
*/
|
||||
public function getCartRuleQuery($customerGroupId, $channelId): \Illuminate\Database\Eloquent\Collection
|
||||
{
|
||||
$cartRules = $this->cartRuleRepository->scopeQuery(function ($query) use ($customerGroupId, $channelId) {
|
||||
return $query->leftJoin('cart_rule_customer_groups', 'cart_rules.id', '=',
|
||||
'cart_rule_customer_groups.cart_rule_id')
|
||||
->leftJoin('cart_rule_channels', 'cart_rules.id', '=', 'cart_rule_channels.cart_rule_id')
|
||||
->where('cart_rule_customer_groups.customer_group_id', $customerGroupId)
|
||||
->where('cart_rule_channels.channel_id', $channelId)
|
||||
->where(function ($query1) {
|
||||
$query1->where('cart_rules.starts_from', '<=', Carbon::now()->format('Y-m-d'))
|
||||
->orWhereNull('cart_rules.starts_from');
|
||||
})
|
||||
->where(function ($query2) {
|
||||
$query2->where('cart_rules.ends_till', '>=', Carbon::now()->format('Y-m-d'))
|
||||
->orWhereNull('cart_rules.ends_till');
|
||||
})
|
||||
->orderBy('sort_order', 'asc');
|
||||
})->findWhere(['status' => 1]);
|
||||
return $cartRules;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -816,7 +816,7 @@ class Cart
|
|||
}
|
||||
|
||||
foreach ($cart->items as $item) {
|
||||
if ($item->product && $item->product->status === 0) {
|
||||
if ($this->isCartItemInactive($item)) {
|
||||
|
||||
$this->cartItemRepository->delete($item->id);
|
||||
|
||||
|
|
@ -1123,6 +1123,25 @@ class Cart
|
|||
return $cart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true, if cart item is inactive
|
||||
*
|
||||
* @param \Webkul\Checkout\Contracts\CartItem $item
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function isCartItemInactive(\Webkul\Checkout\Contracts\CartItem $item): bool {
|
||||
if ($item->product->status === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($item->product->type === 'configurable' && $item->child && $item->child->product->status === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $user
|
||||
*
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Webkul\Product\Type;
|
||||
|
||||
use Webkul\Customer\Contracts\CartItem;
|
||||
use Webkul\Product\Models\ProductAttributeValue;
|
||||
use Webkul\Product\Models\ProductFlat;
|
||||
use Illuminate\Support\Str;
|
||||
|
|
@ -539,10 +540,13 @@ class Configurable extends AbstractType
|
|||
* Validate cart item product price
|
||||
*
|
||||
* @param \Webkul\Checkout\Contracts\CartItem $item
|
||||
* @return float
|
||||
*/
|
||||
public function validateCartItem($item)
|
||||
{
|
||||
if (! $item || ! $item->child) {
|
||||
return;
|
||||
}
|
||||
|
||||
$price = $item->child->product->getTypeInstance()->getFinalPrice($item->quantity);
|
||||
|
||||
if ($price == $item->base_price) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue