Customer query on VAT and discounts #1263
Unanswered
tidygraphic
asked this question in
Help
Replies: 2 comments
-
|
The easiest approach would probably be to override SC's I haven't tested these steps, but you should be able to do this:
<?php
namespace App\SimpleCommerce;
use Closure;
use DuncanMcClean\SimpleCommerce\Contracts\Order;
use DuncanMcClean\SimpleCommerce\Coupons\CouponType;
class CouponCalculator
{
public function handle(Order $order, Closure $next)
{
if ($coupon = $order->coupon()) {
$value = (int) $coupon->value();
// Double check coupon is still valid
if (! $coupon->isValid($order)) {
$order->coupon(null);
$order->couponTotal(0);
return $next($order);
}
$baseAmount = $order->itemsTotal() + $order->taxTotal(); // TODO: probably remove taxTotal() from the calculation here
// Otherwise do all the other stuff...
if ($coupon->type() === CouponType::Percentage) {
$order->couponTotal(
(int) ($value * $baseAmount) / 100
);
}
if ($coupon->type() === CouponType::Fixed) {
$order->couponTotal(
(int) $baseAmount - ($baseAmount - $value)
);
}
$order->couponTotal(
(int) round($order->couponTotal())
);
}
return $next($order);
}
}
<?php
namespace App\SimpleCommerce;
use DuncanMcClean\SimpleCommerce\Contracts\Calculator as Contract;
use DuncanMcClean\SimpleCommerce\Contracts\Order;
use Illuminate\Support\Facades\Pipeline;
class Calculator implements Contract
{
public static function calculate(Order $order): Order
{
return Pipeline::send($order)
->through([
\DuncanMcClean\SimpleCommerce\Orders\Calculator\ResetTotals::class,
\DuncanMcClean\SimpleCommerce\Orders\Calculator\LineItemCalculator::class,
L\DuncanMcClean\SimpleCommerce\Orders\Calculator\ineItemTaxCalculator::class,
\DuncanMcClean\SimpleCommerce\Orders\Calculator\CalculateItemsTotal::class,
CouponCalculator::class, // this is your class
\DuncanMcClean\SimpleCommerce\Orders\Calculator\ShippingCalculator::class,
\DuncanMcClean\SimpleCommerce\Orders\Calculator\ShippingTaxCalculator::class,
\DuncanMcClean\SimpleCommerce\Orders\Calculator\CalculateGrandTotal::class,
])
->thenReturn();
}
}// app/Providers/AppServiceProvider.php
public function boot(): void
{
// ...
$this->app->bind(
\DuncanMcClean\SimpleCommerce\Contracts\Calculator::class,
\App\SimpleCommerce\Calculator::class
);
}Hopefully that'll work! 😅 |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Thanks so much - we'll give this a whirl and report back. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We have a customer query which we've been looking at in our private repo around how discounts are made at the checkout; they aren't made on prices excluding VAT and so can cause invoicing discrepancies. Is there anything simple we can do to address this or does this involve breaking/updating core functionality?
Overall we'd like to move them to Cargo but that's a big upgrade and so I wondered if we have anything we can do within Simple Commerce first?
Beta Was this translation helpful? Give feedback.
All reactions