Files
shopPRO/templates/shop-basket/basket-payments-methods.php
Jacek Pyziak 9de4afec9a ver. 0.304: Configurable payment method order amount limits
Replace hardcoded PayPo condition (id=6, 40-1000 PLN) with generic
min/max order amount columns on pp_shop_payment_methods. Admin form
fields added, frontend basket checkout filters dynamically. Cache
invalidation on save. 4 new tests (734 total, 2080 assertions).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 15:26:51 +01:00

52 lines
2.4 KiB
PHP

<?
$pm_found = false;
if ( is_array( $this -> payment_methods ) ): foreach ( $this -> payment_methods as $payment_method ):
if ( $payment_method['id'] == \Shared\Helpers\Helpers::get_session( 'basket-payment-method-id' ) )
$pm_found = true;
endforeach; endif;
$basket = \Shared\Helpers\Helpers::get_session( 'basket' );
$coupon = \Shared\Helpers\Helpers::get_session( 'coupon' );
$transport_cost = ( new \Domain\Transport\TransportRepository( $GLOBALS['mdb'] ) )->transportCostCached( (int)\Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' ) ) ?? 0.0;
$basket_summary = \Domain\Basket\BasketCalculator::summaryPrice( $basket, $coupon ) + $transport_cost;
?>
<? if ( is_array( $this -> payment_methods ) ): foreach ( $this -> payment_methods as $payment_method ):?>
<?
$min = isset($payment_method['min_order_amount']) ? (float)$payment_method['min_order_amount'] : null;
$max = isset($payment_method['max_order_amount']) ? (float)$payment_method['max_order_amount'] : null;
$show = true;
if ($min !== null && $min > 0 && $basket_summary < $min) $show = false;
if ($max !== null && $max > 0 && $basket_summary > $max) $show = false;
?>
<? if ( $show ):?>
<div class="options">
<div class="check">
<input type="radio" class="icheck" name="payment_method" value="<?= $payment_method['id'];?>"
<?
if (
$payment_method['id'] == \Shared\Helpers\Helpers::get_session( 'basket-payment-method-id' )
or
count( $this -> payment_methods ) === 1
or
!\Shared\Helpers\Helpers::get_session( 'basket-payment-method-id' ) and $payment_method == end( $this -> payment_methods )
or
\Shared\Helpers\Helpers::get_session( 'basket-payment-method-id' ) and !$pm_found and $payment_method == end( $this -> payment_methods )
):
\Shared\Helpers\Helpers::set_session( 'basket-payment-method-id', $payment_method['id'] );
echo 'checked="checked"';
endif;
?>
>
</div>
<div class="description">
<div><?= $payment_method['name'];?> <? if ( $payment_method['id'] == 6 ):?><img src="/layout/images/paypo-logo.svg"><? endif;?></div>
<div class="small"><?= $payment_method['description'];?></div>
</div>
</div>
<? endif;?>
<? endforeach; endif;?>