2019-06-17 03:26:30 +00:00
|
|
|
<?php
|
|
|
|
|
|
2019-07-19 13:56:33 +00:00
|
|
|
namespace Webkul\Discount\Actions\Cart;
|
2019-06-17 03:26:30 +00:00
|
|
|
|
2019-06-17 06:54:19 +00:00
|
|
|
use Webkul\Discount\Actions\Action;
|
2019-06-17 03:26:30 +00:00
|
|
|
|
2019-07-23 07:37:22 +00:00
|
|
|
class WholeCartToFixed extends Action
|
2019-06-17 06:54:19 +00:00
|
|
|
{
|
2019-07-19 13:56:33 +00:00
|
|
|
public function calculate($rule, $items, $cart)
|
2019-06-17 03:26:30 +00:00
|
|
|
{
|
2019-07-22 06:48:59 +00:00
|
|
|
$report = collect();
|
2019-07-23 12:53:49 +00:00
|
|
|
|
2019-07-22 06:48:59 +00:00
|
|
|
$totalDiscount = 0;
|
2019-06-17 03:26:30 +00:00
|
|
|
|
2019-07-22 06:48:59 +00:00
|
|
|
foreach ($items as $item) {
|
2019-07-23 12:53:49 +00:00
|
|
|
$itemReport = array();
|
|
|
|
|
|
2019-07-22 06:48:59 +00:00
|
|
|
$itemReport['item_id'] = $item->id;
|
2019-07-24 14:02:37 +00:00
|
|
|
$itemReport['product_id'] = $item->product_id;
|
|
|
|
|
$itemReport['discount'] = 0;
|
|
|
|
|
$itemReport['formatted_discount'] = core()->currency(0);
|
2019-07-23 12:53:49 +00:00
|
|
|
|
|
|
|
|
$report->push($itemReport);
|
2019-07-24 14:02:37 +00:00
|
|
|
|
|
|
|
|
unset($itemReport);
|
2019-07-22 06:48:59 +00:00
|
|
|
}
|
2019-06-17 03:26:30 +00:00
|
|
|
|
2019-07-24 14:02:37 +00:00
|
|
|
$report->discount = $cart->base_grand_total - $rule->discount_amount;
|
|
|
|
|
$report->formatted_discount = core()->currency($report->discount);
|
|
|
|
|
|
2019-06-17 03:26:30 +00:00
|
|
|
return $report;
|
|
|
|
|
}
|
2019-06-26 23:05:26 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Calculates the impact on the shipping amount if the rule is apply_to_shipping enabled
|
|
|
|
|
*/
|
|
|
|
|
public function calculateOnShipping($cart)
|
|
|
|
|
{
|
|
|
|
|
$percentOfDiscount = ($cart->base_discount_amount * 100) / $cart->base_grand_total;
|
|
|
|
|
|
|
|
|
|
$discountOnShipping = ($percentOfDiscount / 100) * $cart->selected_shipping_rate->base_price;
|
|
|
|
|
|
|
|
|
|
return $discountOnShipping;
|
|
|
|
|
}
|
2019-06-17 03:26:30 +00:00
|
|
|
}
|