- 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.
84 lines
2.2 KiB
PHP
84 lines
2.2 KiB
PHP
<?php
|
|
namespace front\factory;
|
|
class ShopTransport
|
|
{
|
|
static public function get_apilo_carrier_account_id( $transport_method_id )
|
|
{
|
|
global $mdb;
|
|
$repo = new \Domain\Transport\TransportRepository($mdb);
|
|
return $repo->getApiloCarrierAccountId($transport_method_id);
|
|
}
|
|
|
|
public static function transport_methods( $basket, $coupon )
|
|
{
|
|
global $mdb, $settings;
|
|
|
|
$cacheHandler = new \CacheHandler();
|
|
$cacheKey = "\front\factory\ShopTransport::transport_methods";
|
|
|
|
$objectData = $cacheHandler -> get( $cacheKey );
|
|
|
|
if ( !$objectData )
|
|
{
|
|
$repo = new \Domain\Transport\TransportRepository($mdb);
|
|
$transports_tmp = $repo->allActive();
|
|
|
|
$cacheHandler -> set( $cacheKey, $transports_tmp );
|
|
}
|
|
else
|
|
{
|
|
$transports_tmp = unserialize( $objectData );
|
|
}
|
|
|
|
$wp_summary = \front\factory\ShopBasket::summary_wp( $basket );
|
|
|
|
foreach ( $transports_tmp as $tr )
|
|
{
|
|
if ( $tr['max_wp'] == null )
|
|
$transports[] = $tr;
|
|
elseif ( $tr['max_wp'] != null and $wp_summary <= $tr['max_wp'] )
|
|
$transports[] = $tr;
|
|
}
|
|
|
|
|
|
if ( \S::normalize_decimal( \front\factory\ShopBasket::summary_price( $basket, $coupon ) ) >= \S::normalize_decimal( $settings['free_delivery'] ) )
|
|
{
|
|
for ( $i = 0; $i < count( $transports ); $i++ ){
|
|
if($transports[ $i ]['delivery_free'] == 1) {
|
|
$transports[ $i ]['cost'] = 0.00;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $transports;
|
|
}
|
|
|
|
public static function transport_cost( $transport_id )
|
|
{
|
|
global $mdb;
|
|
|
|
if ( !$cost = \Cache::fetch( 'transport_cost_' . $transport_id ) )
|
|
{
|
|
$repo = new \Domain\Transport\TransportRepository($mdb);
|
|
$cost = $repo->getTransportCost($transport_id);
|
|
|
|
\Cache::store( 'transport_cost_' . $transport_id, $cost );
|
|
}
|
|
return $cost;
|
|
}
|
|
|
|
public static function transport( $transport_id )
|
|
{
|
|
global $mdb;
|
|
|
|
if ( !$transport = \Cache::fetch( 'transport' . $transport_id ) )
|
|
{
|
|
$repo = new \Domain\Transport\TransportRepository($mdb);
|
|
$transport = $repo->findActiveById($transport_id);
|
|
|
|
\Cache::store( 'transport' . $transport_id, $transport );
|
|
}
|
|
return $transport;
|
|
}
|
|
}
|