feat: Add Transport module with repository, controller, and views

- Implemented TransportRepository for managing transport data with methods for listing, finding, saving, and retrieving transport costs.
- Created ShopTransportController to handle transport-related actions, including listing, editing, and saving transports.
- Added views for transport management: transports list and transport edit forms.
- Introduced JavaScript for responsive tabs in transport edit view.
- Updated testing suite with comprehensive unit tests for TransportRepository and ShopTransportController.
- Increased test coverage with new assertions and scenarios for transport functionalities.
This commit is contained in:
2026-02-14 20:16:18 +01:00
parent 9c23e7f16b
commit 6543f8dc31
20 changed files with 1215 additions and 377 deletions

View File

@@ -4,103 +4,7 @@ class ShopTransport
{
public static function lowest_transport_price( $wp ) {
global $mdb;
return $mdb -> get( 'pp_shop_transports', 'cost', [ 'AND' => [ 'status' => 1, 'id' => [ 2, 4, 6, 8, 9 ], 'max_wp[>=]' => $wp ], 'ORDER' => [ 'cost' => 'ASC' ] ] );
}
public static function transport_save( $transport_id, $name, $name_visible, $description, $status, $cost, $payment_methods, $max_wp, $default, $apilo_carrier_account_id, $delivery_free )
{
global $mdb;
if ( !$transport_id )
{
if ( $default == 'on' )
$mdb -> update( 'pp_shop_transports', [ 'default' => '0' ] );
$mdb -> insert( 'pp_shop_transports', [
'name' => $name,
'name_visible' => $name_visible,
'description' => $description,
'status' => $status == 'on' ? 1 : 0,
'default' => $default == 'on' ? 1 : 0,
'cost' => $cost,
'max_wp' => $max_wp ? $max_wp : null,
'apilo_carrier_account_id' => $apilo_carrier_account_id ? $apilo_carrier_account_id : null,
'delivery_free' => $delivery_free == 'on' ? 1 : 0
] );
$id = $mdb -> id();
if ( $id )
{
if ( is_array( $payment_methods ) ) foreach ( $payment_methods as $payment_method )
{
$mdb -> insert( 'pp_shop_transport_payment_methods', [
'id_payment_method' => (int)$payment_method,
'id_transport' => (int)$id
] );
}
else if ( $payment_methods )
{
$mdb -> insert( 'pp_shop_transport_payment_methods', [
'id_payment_method' => (int)$payment_methods,
'id_transport' => (int)$id
] );
}
\S::delete_dir( '../temp/' );
return $id;
}
}
else
{
if ( $default == 'on' )
$mdb -> update( 'pp_shop_transports', [ 'default' => '0' ] );
$mdb -> update( 'pp_shop_transports', [
'name' => $name,
'name_visible' => $name_visible,
'description' => $description,
'status' => $status == 'on' ? 1 : 0,
'default' => $default == 'on' ? 1 : 0,
'cost' => $cost,
'max_wp' => $max_wp ? $max_wp : null,
'apilo_carrier_account_id' => $apilo_carrier_account_id ? $apilo_carrier_account_id : null,
'delivery_free' => $delivery_free == 'on' ? 1 : 0
], [
'id' => $transport_id
] );
$mdb -> delete( 'pp_shop_transport_payment_methods', [ 'id_transport' => (int)$transport_id ] );
if ( is_array( $payment_methods ) ) foreach ( $payment_methods as $payment_method )
{
$mdb -> insert( 'pp_shop_transport_payment_methods', [
'id_payment_method' => (int)$payment_method,
'id_transport' => (int)$transport_id
] );
}
else if ( $payment_methods )
{
$mdb -> insert( 'pp_shop_transport_payment_methods', [
'id_payment_method' => (int)$payment_methods,
'id_transport' => (int)$transport_id
] );
}
\S::delete_dir( '../temp/' );
return true;
}
}
public static function transport_details( $transport_id )
{
global $mdb;
$transport = $mdb -> get( 'pp_shop_transports', '*', [ 'id' => $transport_id ] );
$transport['payment_methods'] = $mdb -> select( 'pp_shop_transport_payment_methods', 'id_payment_method', [ 'id_transport' => $transport_id ] );
return $transport;
$repo = new \Domain\Transport\TransportRepository($mdb);
return $repo->lowestTransportPrice($wp);
}
}