ver. 0.269: ShopPaymentMethod refactor + Apilo keepalive

This commit is contained in:
2026-02-14 15:22:02 +01:00
parent 5e5d3d068a
commit 818cd7f2c0
31 changed files with 1832 additions and 269 deletions

View File

@@ -3,72 +3,64 @@ namespace front\factory;
class ShopPaymentMethod
{
private static function repo(): \Domain\PaymentMethod\PaymentMethodRepository
{
global $mdb;
return new \Domain\PaymentMethod\PaymentMethodRepository( $mdb );
}
// get_apilo_payment_method_id
static public function get_apilo_payment_method_id( $payment_method_id ) {
global $mdb;
return $mdb -> get( 'pp_shop_payment_methods', 'apilo_payment_type_id', [ 'id' => $payment_method_id ] );
return self::repo()->getApiloPaymentTypeId( (int)$payment_method_id );
}
public static function payment_methods_by_transport( $transport_method_id )
{
global $mdb, $settings;
$transport_method_id = (int)$transport_method_id;
$cacheKey = 'payment_methods_by_transport' . $transport_method_id;
$payments = \Cache::fetch( $cacheKey );
if ( !$payments = \Cache::fetch( 'payment_methods_by_transport' . $transport_method_id ) )
{
$results = $mdb -> query( 'SELECT '
. 'pspm.id, name, description '
. 'FROM '
. 'pp_shop_payment_methods AS pspm '
. 'INNER JOIN pp_shop_transport_payment_methods AS pstpm ON pstpm.id_payment_method = pspm.id '
. 'WHERE '
. 'status = 1 '
. 'AND '
. 'id_transport = ' . $transport_method_id ) -> fetchAll();
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
$payments[] = $row;
\Cache::store( 'payment_methods_by_transport' . $transport_method_id, $payments );
if ( $payments !== false && is_array( $payments ) ) {
return $payments;
}
$payments = self::repo()->forTransport( $transport_method_id );
\Cache::store( $cacheKey, $payments );
return $payments;
}
public static function is_payment_active( $payment_method_id )
{
global $mdb;
return $mdb -> get( 'pp_shop_payment_methods', 'status', [ 'id' => $payment_method_id ] );
return self::repo()->isActive( (int)$payment_method_id );
}
public static function payment_method( $payment_method_id )
{
global $mdb;
$payment_method_id = (int)$payment_method_id;
$cacheKey = 'payment_method' . $payment_method_id;
$payment_method = \Cache::fetch( $cacheKey );
if ( !$payment_method = \Cache::fetch( 'payment_method' . $payment_method_id ) )
{
$payment_method = $mdb -> get( 'pp_shop_payment_methods', '*', [
'AND' => [
'id' => $payment_method_id,
'status' => 1
] ] );
\Cache::store( 'payment_method' . $payment_method_id, $payment_method );
if ( $payment_method === false ) {
$payment_method = self::repo()->findActiveById( $payment_method_id );
\Cache::store( $cacheKey, $payment_method );
}
return $payment_method;
}
public static function payment_methods()
{
global $mdb;
$cacheKey = 'payment_methods';
$payment_methods = \Cache::fetch( $cacheKey );
if ( !$payment_methods = \Cache::fetch( 'payment_methods' ) )
{
$results = $mdb -> select( 'pp_shop_payment_methods', '*', [ 'status' => 1 ] );
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
$payment_methods[] = $row;
\Cache::store( 'payment_methods', $payment_methods );
if ( $payment_methods !== false && is_array( $payment_methods ) ) {
return $payment_methods;
}
$payment_methods = self::repo()->allActive();
\Cache::store( $cacheKey, $payment_methods );
return $payment_methods;
}
}