Fixed discount code standard
This commit is contained in:
parent
2446f56413
commit
77d35fc1e6
|
|
@ -9,8 +9,6 @@ abstract class Action
|
|||
*/
|
||||
protected $rule;
|
||||
|
||||
abstract public function calculate($rule);
|
||||
|
||||
/**
|
||||
* Empty collection instance for keeping final list of items
|
||||
*/
|
||||
|
|
@ -18,17 +16,15 @@ abstract class Action
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
/**
|
||||
* Making $matchedItems property empty collection instance.
|
||||
*/
|
||||
$this->matchedItems = collect();
|
||||
}
|
||||
|
||||
abstract public function calculate($rule);
|
||||
|
||||
/**
|
||||
* To find the eligble items for the current rule,
|
||||
*
|
||||
* @param CartRule $rule
|
||||
*
|
||||
* @return Collection $matchedItems
|
||||
*/
|
||||
public function getEligibleItems()
|
||||
|
|
@ -39,9 +35,8 @@ abstract class Action
|
|||
|
||||
$items = $cart->items()->get();
|
||||
|
||||
if ($this->rule->action_type == 'whole_cart_to_percent' || $this->rule->action_type == 'whole_cart_to_fixed_amount') {
|
||||
if ($this->rule->action_type == 'whole_cart_to_percent' || $this->rule->action_type == 'whole_cart_to_fixed_amount')
|
||||
$this->matchedItems = $items;
|
||||
}
|
||||
|
||||
if (! $rule->uses_attribute_conditions) {
|
||||
$this->matchedItems = $items;
|
||||
|
|
@ -52,18 +47,15 @@ abstract class Action
|
|||
|
||||
foreach ($items as $item) {
|
||||
foreach ($productIDs as $productID) {
|
||||
$childrens = collect();
|
||||
$childrens = $item->children;
|
||||
|
||||
foreach ($childrens as $children) {
|
||||
if ($children->product_id == $productID) {
|
||||
if ($children->product_id == $productID)
|
||||
$this->matchedItems->push($children);
|
||||
}
|
||||
}
|
||||
|
||||
if ($item->product_id == $productID) {
|
||||
if ($item->product_id == $productID)
|
||||
$this->matchedItems->push($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -85,13 +77,12 @@ abstract class Action
|
|||
return true;
|
||||
} else {
|
||||
if ($rule->action_type == 'whole_cart_to_percent' && $rule->uses_attribute_condition) {
|
||||
$matchingIDs = explode(',', $rule->product_ids);
|
||||
$matchingIds = explode(',', $rule->product_ids);
|
||||
|
||||
foreach ($matchingIDs as $matchingID) {
|
||||
foreach ($matchingIds as $matchingId) {
|
||||
foreach ($eligibleItems as $item) {
|
||||
if (($item->child ? $item->child->product_id : $item->product_id) == $matchingID) {
|
||||
if (($item->child ? $item->child->product_id : $item->product_id) == $matchingId)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,6 @@ class FixedAmount extends Action
|
|||
{
|
||||
parent::__construct();
|
||||
|
||||
/**
|
||||
* Setting the rule getting applied
|
||||
*/
|
||||
$this->rule = $rule;
|
||||
}
|
||||
|
||||
|
|
@ -41,9 +38,8 @@ class FixedAmount extends Action
|
|||
$isQtyZero = true;
|
||||
|
||||
foreach ($item->children as $children) {
|
||||
if ($children->quantity > 0) {
|
||||
if ($children->quantity > 0)
|
||||
$isQtyZero = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($isQtyZero) {
|
||||
|
|
|
|||
|
|
@ -46,18 +46,17 @@ class PercentOfProduct extends Action
|
|||
$discQuantity = $this->rule->disc_quantity;
|
||||
$discQuantity = $itemQuantity <= $discQuantity ? $itemQuantity : $discQuantity;
|
||||
|
||||
$discount_amount = ($this->rule->disc_amount > 100) ? 100 : $this->rule->disc_amount;
|
||||
$discountAmount = ($this->rule->disc_amount > 100) ? 100 : $this->rule->disc_amount;
|
||||
|
||||
$discount = $itemPrice * ($discount_amount / 100) * $discQuantity;
|
||||
$discount = $itemPrice * ($discountAmount / 100) * $discQuantity;
|
||||
$discount = $discount <= $itemPrice * $discQuantity ? $discount : $itemPrice * $discQuantity;
|
||||
|
||||
if ($item->product->getTypeInstance()->isComposite()) {
|
||||
$isQtyZero = true;
|
||||
|
||||
foreach ($item->children as $children) {
|
||||
if ($children->quantity > 0) {
|
||||
if ($children->quantity > 0)
|
||||
$isQtyZero = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($isQtyZero) {
|
||||
|
|
|
|||
|
|
@ -85,33 +85,24 @@ class ConvertXToProductId
|
|||
|
||||
$attributeValues = $attributeConditions->attributes ?? null;
|
||||
|
||||
if (!isset($categoryValues) && ! isset($attributeValues)) {
|
||||
if (! isset($categoryValues) && ! isset($attributeValues))
|
||||
return false;
|
||||
}
|
||||
|
||||
$categoryResult = collect();
|
||||
|
||||
if (isset($categoryValues) && count($categoryValues)) {
|
||||
if (isset($categoryValues) && count($categoryValues))
|
||||
$categoryResult = $this->convertFromCategories($categoryValues);
|
||||
}
|
||||
|
||||
$attributeResult = collect();
|
||||
|
||||
if (isset($attributeValues) && count($attributeValues)) {
|
||||
if (isset($attributeValues) && count($attributeValues))
|
||||
$attributeResult = $this->convertFromAttributes($attributeValues);
|
||||
}
|
||||
|
||||
// now call the function that will find all the unique product ids
|
||||
$productIDs = $this->findAllUniqueIds($attributeResult, $categoryResult);
|
||||
|
||||
// save the product ids against the cart rules
|
||||
$result = $this->saveIDs($ruleId, $productIDs);
|
||||
|
||||
if ($result) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return $this->saveIDs($ruleId, $productIDs) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -127,9 +118,7 @@ class ConvertXToProductId
|
|||
$selectedOptions = $attributeOption->value;
|
||||
|
||||
if ($attributeOption->type == 'select' || $attributeOption->type == 'multiselect') {
|
||||
$attribute = $this->attribute->findWhere([
|
||||
'code' => $attributeOption->attribute
|
||||
]);
|
||||
$attribute = $this->attribute->findWhere(['code' => $attributeOption->attribute]);
|
||||
|
||||
$attributeOptions = $attribute->first()->options;
|
||||
|
||||
|
|
@ -137,9 +126,8 @@ class ConvertXToProductId
|
|||
|
||||
foreach ($attributeOptions as $attributeOption) {
|
||||
foreach ($selectedOptions as $key => $value) {
|
||||
if ($attributeOption->id == $value) {
|
||||
if ($attributeOption->id == $value)
|
||||
$selectedAttributeOptions->push($attributeOption);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -207,6 +195,7 @@ class ConvertXToProductId
|
|||
|
||||
foreach ($categories as $category) {
|
||||
$data = $this->getAll($category->id);
|
||||
|
||||
if ($data->count()) {
|
||||
$products->push($data);
|
||||
|
||||
|
|
@ -233,14 +222,13 @@ class ConvertXToProductId
|
|||
$mergedCollection = $attributeResult->merge($categoryResult);
|
||||
|
||||
$productIDs = collect();
|
||||
|
||||
foreach ($mergedCollection as $merged) {
|
||||
$productIDs->push($merged->id);
|
||||
}
|
||||
|
||||
// find all the unique product ids
|
||||
$productIDs = $productIDs->unique();
|
||||
|
||||
return $productIDs->flatten()->all();
|
||||
return $productIDs->unique()->flatten()->all();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -258,9 +246,7 @@ class ConvertXToProductId
|
|||
|
||||
$productIDs = implode(',', $productIDs);
|
||||
|
||||
return $cartRule->update([
|
||||
'product_ids' => $productIDs
|
||||
]);
|
||||
return $cartRule->update(['product_ids' => $productIDs]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -272,7 +258,7 @@ class ConvertXToProductId
|
|||
*/
|
||||
public function getAll($categoryId = null)
|
||||
{
|
||||
$results = app('Webkul\Product\Repositories\ProductFlatRepository')->scopeQuery(function($query) use($categoryId) {
|
||||
return app('Webkul\Product\Repositories\ProductFlatRepository')->scopeQuery(function($query) use($categoryId) {
|
||||
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
|
||||
|
||||
$locale = request()->get('locale') ?: app()->getLocale();
|
||||
|
|
@ -302,7 +288,5 @@ class ConvertXToProductId
|
|||
|
||||
return $qb->groupBy('product_flat.id');
|
||||
})->get();
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
|
@ -48,9 +48,7 @@ class CouponAbleRule extends Discount
|
|||
{
|
||||
$cart = Cart::getCart();
|
||||
|
||||
$existingRule = $this->cartRuleCart->findWhere([
|
||||
'cart_id' => $cart->id
|
||||
]);
|
||||
$existingRule = $this->cartRuleCart->findWhere(['cart_id' => $cart->id]);
|
||||
|
||||
$this->clearDiscount();
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,11 @@ abstract class Discount
|
|||
*/
|
||||
protected $setPercentages;
|
||||
|
||||
public function __construct(CartRule $cartRule, CartRuleCart $cartRuleCart, CartItem $cartItem)
|
||||
public function __construct(
|
||||
CartRule $cartRule,
|
||||
CartRuleCart $cartRuleCart,
|
||||
CartItem $cartItem
|
||||
)
|
||||
{
|
||||
$this->cartRule = $cartRule;
|
||||
|
||||
|
|
@ -66,10 +70,7 @@ abstract class Discount
|
|||
$rules = collect();
|
||||
|
||||
if ($code != null) {
|
||||
$eligibleRules = $this->cartRule->findWhere([
|
||||
'use_coupon' => 1,
|
||||
'status' => 1
|
||||
]);
|
||||
$eligibleRules = $this->cartRule->findWhere(['use_coupon' => 1, 'status' => 1]);
|
||||
|
||||
foreach($eligibleRules as $rule) {
|
||||
if ($rule->coupons->code == $code) {
|
||||
|
|
@ -79,10 +80,7 @@ abstract class Discount
|
|||
}
|
||||
}
|
||||
} else {
|
||||
$rules = $this->cartRule->findWhere([
|
||||
'use_coupon' => 0,
|
||||
'status' => 1
|
||||
]);
|
||||
$rules = $this->cartRule->findWhere(['use_coupon' => 0, 'status' => 1]);
|
||||
}
|
||||
|
||||
$filteredRules = collect();
|
||||
|
|
@ -193,9 +191,8 @@ abstract class Discount
|
|||
$minPriority = $rules->min('priority');
|
||||
|
||||
foreach ($rules as $rule) {
|
||||
if ($rule->priority == $minPriority) {
|
||||
if ($rule->priority == $minPriority)
|
||||
$sortedRules->push($rule);
|
||||
}
|
||||
}
|
||||
|
||||
return $sortedRules;
|
||||
|
|
@ -228,9 +225,7 @@ abstract class Discount
|
|||
{
|
||||
$cart = \Cart::getCart();
|
||||
|
||||
$alreadyApplied = $this->cartRuleCart->findWhere([
|
||||
'cart_id' => $cart->id
|
||||
]);
|
||||
$alreadyApplied = $this->cartRuleCart->findWhere(['cart_id' => $cart->id]);
|
||||
|
||||
if ($alreadyApplied->count() && $alreadyApplied->first()->cart_rule->id == $rule->id) {
|
||||
if ($this->validateRule($alreadyApplied->first()->cart_rule)) {
|
||||
|
|
@ -324,9 +319,8 @@ abstract class Discount
|
|||
$maxDiscount = $rules->max('impact.discount');
|
||||
|
||||
foreach ($rules as $rule) {
|
||||
if ($rule->impact->discount == $maxDiscount) {
|
||||
if ($rule->impact->discount == $maxDiscount)
|
||||
$maxImpact = $maxImpact->push($rule);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return collect();
|
||||
|
|
@ -382,26 +376,22 @@ abstract class Discount
|
|||
|
||||
// time based constraints
|
||||
if ($rule->starts_from != null && $rule->ends_till == null) {
|
||||
if (Carbon::parse($rule->starts_from) < now()) {
|
||||
if (Carbon::parse($rule->starts_from) < now())
|
||||
$timeBased = true;
|
||||
}
|
||||
} else if ($rule->starts_from == null && $rule->ends_till != null) {
|
||||
if (Carbon::parse($rule->ends_till) > now()) {
|
||||
if (Carbon::parse($rule->ends_till) > now())
|
||||
$timeBased = true;
|
||||
}
|
||||
} else if ($rule->starts_from != null && $rule->ends_till != null) {
|
||||
if (Carbon::parse($rule->starts_from) < now() && now() < Carbon::parse($rule->ends_till)) {
|
||||
if (Carbon::parse($rule->starts_from) < now() && now() < Carbon::parse($rule->ends_till))
|
||||
$timeBased = true;
|
||||
}
|
||||
} else {
|
||||
$timeBased = true;
|
||||
}
|
||||
|
||||
// channel based constraints
|
||||
foreach ($rule->channels as $channel) {
|
||||
if ($channel->channel_id == core()->getCurrentChannel()->id) {
|
||||
if ($channel->channel_id == core()->getCurrentChannel()->id)
|
||||
$channelBased = true;
|
||||
}
|
||||
}
|
||||
|
||||
$customerGroupBased = false;
|
||||
|
|
@ -410,16 +400,14 @@ abstract class Discount
|
|||
if (auth()->guard('customer')->check()) {
|
||||
foreach ($rule->customer_groups as $customer_group) {
|
||||
if (auth()->guard('customer')->user()->group->exists()) {
|
||||
if ($customer_group->customer_group_id == auth()->guard('customer')->user()->group->id) {
|
||||
if ($customer_group->customer_group_id == auth()->guard('customer')->user()->group->id)
|
||||
$customerGroupBased = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($rule->customer_groups as $customer_group) {
|
||||
if ($customer_group->customer_group->code == 'guest') {
|
||||
if ($customer_group->customer_group->code == 'guest')
|
||||
$customerGroupBased = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -431,13 +419,11 @@ abstract class Discount
|
|||
|
||||
$test_mode = array_last($conditions);
|
||||
|
||||
if ($test_mode->criteria == 'any_is_true') {
|
||||
if ($test_mode->criteria == 'any_is_true')
|
||||
$conditionsBased = $this->testIfAnyConditionIsTrue($conditions, $cart);
|
||||
}
|
||||
|
||||
if ($test_mode->criteria == 'all_are_true') {
|
||||
if ($test_mode->criteria == 'all_are_true')
|
||||
$conditionsBased = $this->testIfAllConditionAreTrue($conditions, $cart);
|
||||
}
|
||||
}
|
||||
|
||||
$partialMatch = 0;
|
||||
|
|
@ -447,9 +433,8 @@ abstract class Discount
|
|||
|
||||
foreach ($productIDs as $productID) {
|
||||
foreach ($cart->items as $item) {
|
||||
if ($item->product_id == $productID) {
|
||||
if ($item->product_id == $productID)
|
||||
$partialMatch = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -478,26 +463,15 @@ abstract class Discount
|
|||
{
|
||||
$cart = \Cart::getCart();
|
||||
|
||||
$alreadyApplied = $this->cartRuleCart->findWhere([
|
||||
'cart_id' => $cart->id
|
||||
]);
|
||||
$alreadyApplied = $this->cartRuleCart->findWhere(['cart_id' => $cart->id]);
|
||||
|
||||
if ($alreadyApplied->count()) {
|
||||
$result = $alreadyApplied->first()->update([
|
||||
'cart_rule_id' => $rule->id
|
||||
]);
|
||||
$result = $alreadyApplied->first()->update(['cart_rule_id' => $rule->id]);
|
||||
} else {
|
||||
$result = $this->cartRuleCart->create([
|
||||
'cart_id' => $cart->id,
|
||||
'cart_rule_id' => $rule->id
|
||||
]);
|
||||
$result = $this->cartRuleCart->create(['cart_id' => $cart->id, 'cart_rule_id' => $rule->id]);
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return $result ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -515,10 +489,7 @@ abstract class Discount
|
|||
|
||||
if (isset($cart->selected_shipping_rate)) {
|
||||
if ($appliedRule->free_shipping && $cart->selected_shipping_rate->base_price > 0) {
|
||||
$cart->selected_shipping_rate->update([
|
||||
'price' => 0,
|
||||
'base_price' => 0
|
||||
]);
|
||||
$cart->selected_shipping_rate->update(['price' => 0, 'base_price' => 0]);
|
||||
} else if ($appliedRule->free_shipping == 0 && $appliedRule->apply_to_shipping && $cart->selected_shipping_rate->base_price > 0) {
|
||||
$actionType = config('discount-rules')[$appliedRule->action_type];
|
||||
|
||||
|
|
@ -569,10 +540,7 @@ abstract class Discount
|
|||
$actualShippingBasePrice = $actualShippingRate->base_price;
|
||||
$cartShippingRate = $cart->selected_shipping_rate;
|
||||
|
||||
$cartShippingRate->update([
|
||||
'price' => $actualShippingPrice,
|
||||
'base_price' => $actualShippingBasePrice
|
||||
]);
|
||||
$cartShippingRate->update(['price' => $actualShippingPrice, 'base_price' => $actualShippingBasePrice]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -608,17 +576,13 @@ abstract class Discount
|
|||
]);
|
||||
|
||||
if ($rule->action_type == 'percent_of_product') {
|
||||
$child->update([
|
||||
'discount_percent' => $rule->discount_amount
|
||||
]);
|
||||
$child->update(['discount_percent' => $rule->discount_amount]);
|
||||
}
|
||||
|
||||
if ($rule->use_coupon) {
|
||||
$coupon = $rule->coupons->code;
|
||||
|
||||
$child->update([
|
||||
'coupon_code' => $coupon
|
||||
]);
|
||||
$child->update(['coupon_code' => $coupon]);
|
||||
}
|
||||
|
||||
$this->updateParent($child, $totalItemDiscount, $cartCurrencyCode = $cart->cart_currency_code);
|
||||
|
|
@ -630,25 +594,19 @@ abstract class Discount
|
|||
]);
|
||||
|
||||
if ($rule->action_type == 'percent_of_product') {
|
||||
$item->update([
|
||||
'discount_percent' => $rule->discount_amount
|
||||
]);
|
||||
$item->update(['discount_percent' => $rule->discount_amount]);
|
||||
}
|
||||
|
||||
if ($rule->use_coupon) {
|
||||
$coupon = $rule->coupons->code;
|
||||
|
||||
$item->update([
|
||||
'coupon_code' => $coupon
|
||||
]);
|
||||
$item->update(['coupon_code' => $coupon]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($rule->use_coupon) {
|
||||
$cart->update([
|
||||
'coupon_code' => $rule->coupons->code
|
||||
]);
|
||||
$cart->update(['coupon_code' => $rule->coupons->code]);
|
||||
}
|
||||
|
||||
// if ($rule->free_shipping || $rule->apply_on_shipping) {
|
||||
|
|
@ -702,9 +660,7 @@ abstract class Discount
|
|||
]);
|
||||
|
||||
// find & remove cart rule from cart rule cart resource
|
||||
$cartRuleCart = $this->cartRuleCart->findWhere([
|
||||
'cart_id' => $cart->id
|
||||
]);
|
||||
$cartRuleCart = $this->cartRuleCart->findWhere(['cart_id' => $cart->id]);
|
||||
|
||||
$cartRuleCart->first()->delete();
|
||||
|
||||
|
|
@ -738,9 +694,7 @@ abstract class Discount
|
|||
{
|
||||
$cart = \Cart::getCart();
|
||||
|
||||
$alreadyAppliedRule = $this->cartRuleCart->findWhere([
|
||||
'cart_id' => $cart->id
|
||||
]);
|
||||
$alreadyAppliedRule = $this->cartRuleCart->findWhere(['cart_id' => $cart->id]);
|
||||
|
||||
if ($alreadyAppliedRule->count()) {
|
||||
$alreadyAppliedCartRule = $alreadyAppliedRule->first()->cart_rule;
|
||||
|
|
@ -811,11 +765,7 @@ abstract class Discount
|
|||
|
||||
$shipping_city = $shipping_address->city ?? null;
|
||||
|
||||
if (isset($cart->payment)) {
|
||||
$payment_method = $paymentMethods[$cart->payment->method]['title'];
|
||||
} else {
|
||||
$payment_method = null;
|
||||
}
|
||||
$payment_method = isset($cart->payment) ? $paymentMethods[$cart->payment->method]['title'] : null;
|
||||
|
||||
$sub_total = $cart->base_sub_total;
|
||||
|
||||
|
|
@ -840,7 +790,6 @@ abstract class Discount
|
|||
|
||||
if (isset($condition->attribute)) {
|
||||
$actual_value = ${$condition->attribute};
|
||||
|
||||
} else {
|
||||
$result = false;
|
||||
}
|
||||
|
|
@ -945,11 +894,7 @@ abstract class Discount
|
|||
|
||||
$shipping_city = $shipping_address->city ?? null;
|
||||
|
||||
if (isset($cart->payment)) {
|
||||
$payment_method = $paymentMethods[$cart->payment->method]['title'];
|
||||
} else {
|
||||
$payment_method = null;
|
||||
}
|
||||
$payment_method = isset($cart->payment) ? $paymentMethods[$cart->payment->method]['title'] : null;
|
||||
|
||||
$sub_total = $cart->base_sub_total;
|
||||
|
||||
|
|
@ -974,15 +919,13 @@ abstract class Discount
|
|||
|
||||
if (isset($condition->value)) {
|
||||
$test_value = $condition->value;
|
||||
|
||||
} else {
|
||||
$result = false;
|
||||
}
|
||||
|
||||
if (isset($condition->condition)) {
|
||||
$test_condition = $condition->condition;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$result = false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -102,8 +102,6 @@ class Apply extends Sale
|
|||
$this->activeRules->push($rule);
|
||||
} else {
|
||||
$this->deceased->push($rule->id);
|
||||
|
||||
// Job execution for deceased rules
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -521,13 +519,9 @@ class Apply extends Sale
|
|||
$count = 0;
|
||||
|
||||
foreach ($this->deceased as $deceased) {
|
||||
$cartRuleProducts = $this->catalogRuleProduct->findWhere([
|
||||
'catalog_rule_id' => $deceased
|
||||
]);
|
||||
$cartRuleProducts = $this->catalogRuleProduct->findWhere(['catalog_rule_id' => $deceased]);
|
||||
|
||||
$cartRuleProductsPrice = $this->catalogRuleProductPrice->findWhere([
|
||||
'catalog_rule_id' => $deceased
|
||||
]);
|
||||
$cartRuleProductsPrice = $this->catalogRuleProductPrice->findWhere(['catalog_rule_id' => $deceased]);
|
||||
|
||||
// obvious logic for removing entries as entries in both storage needs to be exactly equal for a product
|
||||
foreach ($cartRuleProducts as $cartRuleProduct) {
|
||||
|
|
|
|||
|
|
@ -81,21 +81,18 @@ class ConvertXToProductId
|
|||
|
||||
$attributeValues = $attributeConditions->attributes;
|
||||
|
||||
if (! isset($categoryValues) && ! isset($attributeValues)) {
|
||||
if (! isset($categoryValues) && ! isset($attributeValues))
|
||||
return false;
|
||||
}
|
||||
|
||||
$categoryResult = collect();
|
||||
|
||||
if (isset($categoryValues) && count($categoryValues)) {
|
||||
if (isset($categoryValues) && count($categoryValues))
|
||||
$categoryResult = $this->convertFromCategories($categoryValues);
|
||||
}
|
||||
|
||||
$attributeResult = collect();
|
||||
|
||||
if (isset($attributeValues) && count($attributeValues)) {
|
||||
if (isset($attributeValues) && count($attributeValues))
|
||||
$attributeResult = $this->convertFromAttributes($attributeValues);
|
||||
}
|
||||
|
||||
// now call the function that will find all the unique product ids
|
||||
$productIDs = $this->findAllUniqueIds($attributeResult, $categoryResult);
|
||||
|
|
@ -117,9 +114,7 @@ class ConvertXToProductId
|
|||
$selectedOptions = $attributeOption->value;
|
||||
|
||||
if ($attributeOption->type == 'select' || $attributeOption->type == 'multiselect') {
|
||||
$attribute = $this->attribute->findWhere([
|
||||
'code' => $attributeOption->attribute
|
||||
]);
|
||||
$attribute = $this->attribute->findWhere(['code' => $attributeOption->attribute]);
|
||||
|
||||
$attributeOptions = $attribute->first()->options;
|
||||
|
||||
|
|
@ -127,9 +122,8 @@ class ConvertXToProductId
|
|||
|
||||
foreach ($attributeOptions as $attributeOption) {
|
||||
foreach ($selectedOptions as $key => $value) {
|
||||
if ($attributeOption->id == $value) {
|
||||
if ($attributeOption->id == $value)
|
||||
$selectedAttributeOptions->push($attributeOption);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -147,9 +141,7 @@ class ConvertXToProductId
|
|||
}
|
||||
}
|
||||
} else {
|
||||
$attribute = $this->attribute->findWhere([
|
||||
'code' => $attributeOption->attribute
|
||||
]);
|
||||
$attribute = $this->attribute->findWhere(['code' => $attributeOption->attribute]);
|
||||
|
||||
$pavValues = $attribute->first();
|
||||
|
||||
|
|
@ -227,6 +219,7 @@ class ConvertXToProductId
|
|||
$mergedCollection = $attributeResult->merge($categoryResult);
|
||||
|
||||
$productIDs = collect();
|
||||
|
||||
foreach ($mergedCollection as $merged) {
|
||||
$productIDs->push($merged->id);
|
||||
}
|
||||
|
|
@ -246,7 +239,6 @@ class ConvertXToProductId
|
|||
*/
|
||||
public function getAll($categoryId = null)
|
||||
{
|
||||
|
||||
$results = app('Webkul\Product\Repositories\ProductFlatRepository')->scopeQuery(function ($query) use ($categoryId) {
|
||||
|
||||
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());
|
||||
|
|
|
|||
|
|
@ -32,24 +32,20 @@ abstract class Sale
|
|||
|
||||
// time based constraints
|
||||
if ($rule->starts_from != null && $rule->ends_till == null) {
|
||||
if (Carbon::parse($rule->starts_from) < now()) {
|
||||
if (Carbon::parse($rule->starts_from) < now())
|
||||
$timeBased = true;
|
||||
}
|
||||
} else if ($rule->starts_from == null && $rule->ends_till != null) {
|
||||
if (Carbon::parse($rule->ends_till) > now()) {
|
||||
if (Carbon::parse($rule->ends_till) > now())
|
||||
$timeBased = true;
|
||||
}
|
||||
} else if ($rule->starts_from != null && $rule->ends_till != null) {
|
||||
if (Carbon::parse($rule->starts_from) < now() && now() < Carbon::parse($rule->ends_till)) {
|
||||
if (Carbon::parse($rule->starts_from) < now() && now() < Carbon::parse($rule->ends_till))
|
||||
$timeBased = true;
|
||||
}
|
||||
} else {
|
||||
$timeBased = true;
|
||||
}
|
||||
|
||||
if ($rule->status) {
|
||||
if ($rule->status)
|
||||
$status = true;
|
||||
}
|
||||
|
||||
if ($timeBased && $status) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -81,9 +81,8 @@ class CartRuleRepository extends Repository
|
|||
foreach ($oldCustomerGroups as $key => $oldCustomerGroup) {
|
||||
$found = 0;
|
||||
foreach ($newCustomerGroups as $newCustomerGroup) {
|
||||
if ($oldCustomerGroup['customer_group_id'] == $newCustomerGroup) {
|
||||
if ($oldCustomerGroup['customer_group_id'] == $newCustomerGroup)
|
||||
$found = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($found == 0) {
|
||||
|
|
@ -98,9 +97,8 @@ class CartRuleRepository extends Repository
|
|||
foreach ($oldCustomerGroups as $oldCustomerGroup) {
|
||||
$found = 0;
|
||||
foreach ($newCustomerGroups as $key => $newCustomerGroup) {
|
||||
if ($oldCustomerGroup['customer_group_id'] == $newCustomerGroup) {
|
||||
if ($oldCustomerGroup['customer_group_id'] == $newCustomerGroup)
|
||||
unset($newCustomerGroups[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -122,6 +120,7 @@ class CartRuleRepository extends Repository
|
|||
public function ChannelSync($newChannels, $cartRule)
|
||||
{
|
||||
$oldChannels = array();
|
||||
|
||||
foreach ($cartRule->channels as $oldChannel) {
|
||||
array_push($oldChannels, ['id' => $oldChannel->id, 'channel_id' => $oldChannel->channel_id]);
|
||||
}
|
||||
|
|
@ -129,9 +128,8 @@ class CartRuleRepository extends Repository
|
|||
foreach ($oldChannels as $key => $oldChannel) {
|
||||
$found = 0;
|
||||
foreach ($newChannels as $newChannel) {
|
||||
if ($oldChannel['channel_id'] == $newChannel) {
|
||||
if ($oldChannel['channel_id'] == $newChannel)
|
||||
$found = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($found == 0) {
|
||||
|
|
@ -145,10 +143,10 @@ class CartRuleRepository extends Repository
|
|||
if (count($newChannels) && count($oldChannels)) {
|
||||
foreach ($oldChannels as $oldChannel) {
|
||||
$found = 0;
|
||||
|
||||
foreach ($newChannels as $key => $newChannel) {
|
||||
if ($oldChannel['channel_id'] == $newChannel) {
|
||||
if ($oldChannel['channel_id'] == $newChannel)
|
||||
unset($newChannels[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -157,6 +155,7 @@ class CartRuleRepository extends Repository
|
|||
foreach ($newChannels as $newChannel) {
|
||||
$data['channel_id'] = $newChannel;
|
||||
$data['cart_rule_id'] = $cartRule->id;
|
||||
|
||||
$this->cartRuleChannels->create($data);
|
||||
}
|
||||
|
||||
|
|
@ -175,9 +174,7 @@ class CartRuleRepository extends Repository
|
|||
$updated = 0;
|
||||
foreach ($cartRule->labels as $label) {
|
||||
if ($label->channel->code == $channelCode && $label->locale->code == $localeCode) {
|
||||
$label->update([
|
||||
'label' => $localeValue
|
||||
]);
|
||||
$label->update(['label' => $localeValue]);
|
||||
|
||||
$updated = 1;
|
||||
}
|
||||
|
|
@ -185,9 +182,8 @@ class CartRuleRepository extends Repository
|
|||
|
||||
if ($updated == 0) {
|
||||
foreach (core()->getAllChannels() as $channel) {
|
||||
if ($channel->code == $channelCode) {
|
||||
if ($channel->code == $channelCode)
|
||||
$newLabel['channel_id'] = $channel->id;
|
||||
}
|
||||
|
||||
foreach($channel->locales as $locale) {
|
||||
if ($localeCode == $locale->code) {
|
||||
|
|
|
|||
|
|
@ -66,10 +66,10 @@ class CatalogRuleRepository extends Repository
|
|||
|
||||
foreach ($oldCustomerGroups as $key => $oldCustomerGroup) {
|
||||
$found = 0;
|
||||
|
||||
foreach($newCustomerGroups as $newCustomerGroup) {
|
||||
if ($oldCustomerGroup['customer_group_id'] == $newCustomerGroup) {
|
||||
if ($oldCustomerGroup['customer_group_id'] == $newCustomerGroup)
|
||||
$found = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($found == 0) {
|
||||
|
|
@ -83,10 +83,10 @@ class CatalogRuleRepository extends Repository
|
|||
if (count($newCustomerGroups) && count($oldCustomerGroups)) {
|
||||
foreach ($oldCustomerGroups as $oldCustomerGroup) {
|
||||
$found = 0;
|
||||
|
||||
foreach ($newCustomerGroups as $key => $newCustomerGroup) {
|
||||
if ($oldCustomerGroup['customer_group_id'] == $newCustomerGroup) {
|
||||
if ($oldCustomerGroup['customer_group_id'] == $newCustomerGroup)
|
||||
unset($newCustomerGroups[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -120,9 +120,8 @@ class CatalogRuleRepository extends Repository
|
|||
foreach ($oldChannels as $key => $oldChannel) {
|
||||
$found = 0;
|
||||
foreach($newChannels as $newChannel) {
|
||||
if ($oldChannel['channel_id'] == $newChannel) {
|
||||
if ($oldChannel['channel_id'] == $newChannel)
|
||||
$found = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ($found == 0) {
|
||||
|
|
@ -136,10 +135,10 @@ class CatalogRuleRepository extends Repository
|
|||
if (count($newChannels) && count($oldChannels)) {
|
||||
foreach ($oldChannels as $oldChannel) {
|
||||
$found = 0;
|
||||
|
||||
foreach ($newChannels as $key => $newChannel) {
|
||||
if ($oldChannel['channel_id'] == $newChannel) {
|
||||
if ($oldChannel['channel_id'] == $newChannel)
|
||||
unset($newChannels[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue