feat: ✨ Allow to buy a product for free
This commit is contained in:
parent
ff2d0b794e
commit
a077092631
|
@ -39,10 +39,14 @@ class PaymentController extends Controller
|
||||||
*/
|
*/
|
||||||
public function checkOut(ShopProduct $shopProduct)
|
public function checkOut(ShopProduct $shopProduct)
|
||||||
{
|
{
|
||||||
|
$discount = PartnerDiscount::getDiscount();
|
||||||
|
$price = $shopProduct->price - ($shopProduct->price * $discount / 100);
|
||||||
|
|
||||||
|
$paymentGateways = [];
|
||||||
|
if ($price > 0) {
|
||||||
$extensions = ExtensionHelper::getAllExtensionsByNamespace('PaymentGateways');
|
$extensions = ExtensionHelper::getAllExtensionsByNamespace('PaymentGateways');
|
||||||
|
|
||||||
// build a paymentgateways array that contains the routes for the payment gateways and the image path for the payment gateway which lays in public/images/Extensions/PaymentGateways with the extensionname in lowercase
|
// build a paymentgateways array that contains the routes for the payment gateways and the image path for the payment gateway which lays in public/images/Extensions/PaymentGateways with the extensionname in lowercase
|
||||||
$paymentGateways = [];
|
|
||||||
foreach ($extensions as $extension) {
|
foreach ($extensions as $extension) {
|
||||||
$extensionName = basename($extension);
|
$extensionName = basename($extension);
|
||||||
if (!ExtensionHelper::getExtensionConfig($extensionName, 'enabled')) continue; // skip if not enabled
|
if (!ExtensionHelper::getExtensionConfig($extensionName, 'enabled')) continue; // skip if not enabled
|
||||||
|
@ -52,8 +56,12 @@ class PaymentController extends Controller
|
||||||
$payment->image = asset('images/Extensions/PaymentGateways/' . strtolower($extensionName) . '_logo.png');
|
$payment->image = asset('images/Extensions/PaymentGateways/' . strtolower($extensionName) . '_logo.png');
|
||||||
$paymentGateways[] = $payment;
|
$paymentGateways[] = $payment;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$discount = PartnerDiscount::getDiscount();
|
|
||||||
|
|
||||||
return view('store.checkout')->with([
|
return view('store.checkout')->with([
|
||||||
'product' => $shopProduct,
|
'product' => $shopProduct,
|
||||||
|
@ -64,6 +72,7 @@ class PaymentController extends Controller
|
||||||
'taxpercent' => $shopProduct->getTaxPercent(),
|
'taxpercent' => $shopProduct->getTaxPercent(),
|
||||||
'total' => $shopProduct->getTotalPrice(),
|
'total' => $shopProduct->getTotalPrice(),
|
||||||
'paymentGateways' => $paymentGateways,
|
'paymentGateways' => $paymentGateways,
|
||||||
|
'productIsFree' => $price <= 0,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -130,11 +130,15 @@
|
||||||
<!-- this row will not appear when printing -->
|
<!-- this row will not appear when printing -->
|
||||||
<div class="row no-print">
|
<div class="row no-print">
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<button :disabled="!payment_method || clicked"
|
<button :disabled="(!payment_method || clicked) && {{ !$productIsFree }}"
|
||||||
:class="!payment_method || clicked ? 'disabled' : ''"
|
:class="(!payment_method || clicked) && {{ !$productIsFree }} ? 'disabled' : ''"
|
||||||
class="btn btn-success float-right"><i class="far fa-credit-card mr-2"
|
class="btn btn-success float-right"><i class="far fa-credit-card mr-2"
|
||||||
@click="clicked = true"></i>
|
@click="clicked = true"></i>
|
||||||
|
@if ($productIsFree)
|
||||||
|
{{ __('Get for free') }}
|
||||||
|
@else
|
||||||
{{ __('Submit Payment') }}
|
{{ __('Submit Payment') }}
|
||||||
|
@endif
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue