Fixed all actions of Cart rules
This commit is contained in:
parent
852a6b91af
commit
ee4c4c43cb
|
|
@ -60,7 +60,7 @@ class AttributeTableSeeder extends Seeder
|
|||
'use_in_flat' => '1','created_at' => $now,'updated_at' => $now],
|
||||
['id' => '24','code' => 'size','admin_name' => 'Size','type' => 'select','validation' => NULL,'position' => '24','is_required' => '0','is_unique' => '0','value_per_locale' => '0','value_per_channel' => '0','is_filterable' => '1','is_configurable' => '1','is_user_defined' => '1','is_visible_on_front' => '0',
|
||||
'use_in_flat' => '1','created_at' => $now,'updated_at' => $now],
|
||||
['id' => '25','code' => 'brand','admin_name' => 'Brand','type' => 'text','validation' => NULL,'position' => '25','is_required' => '0','is_unique' => '0','value_per_locale' => '0','value_per_channel' => '0','is_filterable' => '1','is_configurable' => '0','is_user_defined' => '0','is_visible_on_front' => '1',
|
||||
['id' => '25','code' => 'brand','admin_name' => 'Brand','type' => 'select','validation' => NULL,'position' => '25','is_required' => '0','is_unique' => '0','value_per_locale' => '0','value_per_channel' => '0','is_filterable' => '1','is_configurable' => '0','is_user_defined' => '0','is_visible_on_front' => '1',
|
||||
'use_in_flat' => '1','created_at' => $now,'updated_at' => $now]
|
||||
]);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,12 +15,6 @@ class FixedAmount extends Action
|
|||
|
||||
$totalDiscount = 0;
|
||||
|
||||
if ($rule->discount_amount >= 100) {
|
||||
$impact->discount = $cart->base_sub_total;
|
||||
|
||||
$impact->formatted_discount = core()->currency($impact->discount);
|
||||
}
|
||||
|
||||
if ($rule->uses_attribute_conditions) {
|
||||
$productIDs = $rule->product_ids;
|
||||
|
||||
|
|
|
|||
|
|
@ -23,13 +23,7 @@ class WholeCartToPercent extends Action
|
|||
|
||||
$impact = collect();
|
||||
|
||||
if ($rule->discount_amount >= 100) {
|
||||
$impact->discount = $cart->base_sub_total;
|
||||
} else {
|
||||
$impact->discount = ($rule->disc_amount / 100) * $cart->base_sub_total;
|
||||
}
|
||||
|
||||
$impact->formatted_discount = core()->currency($impact->discount);
|
||||
$totalDiscount = 0;
|
||||
|
||||
if ($rule->uses_attribute_conditions) {
|
||||
$productIDs = $rule->product_ids;
|
||||
|
|
@ -47,42 +41,56 @@ class WholeCartToPercent extends Action
|
|||
}
|
||||
|
||||
if ($matchCount > 0) {
|
||||
$discountPerItem = $impact->discount / $matchCount;
|
||||
}
|
||||
foreach ($productIDs as $productID) {
|
||||
foreach ($items as $item) {
|
||||
$itemPrice = $item->base_price;
|
||||
|
||||
foreach ($productIDs as $productID) {
|
||||
foreach ($items as $item) {
|
||||
if ($item->product_id == $productID) {
|
||||
$report = array();
|
||||
$discount = round(($itemPrice * $rule->disc_amount) / 100, 4);
|
||||
|
||||
$report['item_id'] = $item->id;
|
||||
$report['product_id'] = $item->product_id;
|
||||
$report['discount'] = round($discountPerItem, 4);
|
||||
$report['formatted_discount'] = core()->currency(round($discountPerItem, 4));
|
||||
$totalDiscount = $totalDiscount + $discount;
|
||||
|
||||
$impact->push($report);
|
||||
if ($item->product_id == $productID) {
|
||||
$report = array();
|
||||
|
||||
unset($report);
|
||||
$report['item_id'] = $item->id;
|
||||
$report['product_id'] = $item->child ? $item->child->product_id : $item->product_id;
|
||||
$report['discount'] = $discount;
|
||||
$report['formatted_discount'] = core()->currency(round($discount, 4));
|
||||
|
||||
$impact->push($report);
|
||||
|
||||
unset($report);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$discountPerItem = $impact->discount / $cart->items_qty;
|
||||
|
||||
foreach ($items as $item) {
|
||||
$report = array();
|
||||
$itemPrice = $item->base_price;
|
||||
|
||||
$report['item_id'] = $item->id;
|
||||
$report['product_id'] = $item->product_id;
|
||||
$report['discount'] = round($discountPerItem, 4);
|
||||
$report['formatted_discount'] = core()->currency(round($discountPerItem, 4));
|
||||
$discount = round(($itemPrice * $rule->disc_amount) / 100, 4);
|
||||
|
||||
$impact->push($report);
|
||||
$totalDiscount = $totalDiscount + $discount;
|
||||
|
||||
unset($report);
|
||||
if ($item->product_id == $productID) {
|
||||
$report = array();
|
||||
|
||||
$report['item_id'] = $item->id;
|
||||
$report['product_id'] = $item->child ? $item->child->product_id : $item->product_id;
|
||||
$report['discount'] = $discount;
|
||||
$report['formatted_discount'] = core()->currency(round($discount, 4));
|
||||
|
||||
$impact->push($report);
|
||||
|
||||
unset($report);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$impact->discount = $totalDiscount;
|
||||
|
||||
$impact->fomatted_discount = core()->currency($impact->discount);
|
||||
|
||||
return $impact;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue