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:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,12 @@
|
|||||||
|
<script type="text/javascript">
|
||||||
|
$(function() {
|
||||||
|
disable_menu();
|
||||||
|
|
||||||
|
$('#settings-tabs').easyResponsiveTabs({
|
||||||
|
width: 'auto',
|
||||||
|
fit: true,
|
||||||
|
tabidentify: 'settings-tabs',
|
||||||
|
type: 'vertical'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -1,139 +1,8 @@
|
|||||||
<script type="text/javascript" src="/libraries/framework/vendor/plugins/ckeditor/ckeditor.js"></script>
|
<?php
|
||||||
<script type="text/javascript" src="/libraries/framework/vendor/plugins/ckeditor/adapters/jquery.js"></script>
|
echo \Tpl::view('components/form-edit', [
|
||||||
<?
|
'form' => $this->form,
|
||||||
global $db;
|
]);
|
||||||
$carrier_accounts[''] = '--- wybierz konto przewoźnika ---';
|
|
||||||
foreach ( $this -> apilo_carrier_account_list as $carrier_account )
|
|
||||||
{
|
|
||||||
$carrier_accounts[ $carrier_account['id'] ] = $carrier_account['name'];
|
|
||||||
}
|
|
||||||
ob_start();
|
|
||||||
?>
|
|
||||||
<div id="settings-tabs">
|
|
||||||
<ul class="resp-tabs-list settings-tabs">
|
|
||||||
<li><i class="fa fa-file"></i>Ogólne</li>
|
|
||||||
<li><i class="fa fa-wrench"></i>Powiązane metody płatności</li>
|
|
||||||
</ul>
|
|
||||||
<div class="resp-tabs-container settings-tabs">
|
|
||||||
<div>
|
|
||||||
<?= \Html::input(
|
|
||||||
array(
|
|
||||||
'label' => 'Nazwa',
|
|
||||||
'class' => 'require',
|
|
||||||
'name' => 'name',
|
|
||||||
'id' => 'name',
|
|
||||||
'readonly' => true,
|
|
||||||
'value' => $this -> transport_details['name']
|
|
||||||
)
|
|
||||||
);?>
|
|
||||||
<?= \Html::input(
|
|
||||||
array(
|
|
||||||
'label' => 'Nazwa widoczna',
|
|
||||||
'name' => 'name_visible',
|
|
||||||
'id' => 'name_visible',
|
|
||||||
'value' => $this -> transport_details['name_visible']
|
|
||||||
)
|
|
||||||
);?>
|
|
||||||
<?= \Html::input(
|
|
||||||
array(
|
|
||||||
'label' => 'Opis',
|
|
||||||
'name' => 'description',
|
|
||||||
'id' => 'description',
|
|
||||||
'value' => $this -> transport_details['description']
|
|
||||||
)
|
|
||||||
);?>
|
|
||||||
<?= \Html::input(
|
|
||||||
array(
|
|
||||||
'label' => 'Koszt (PLN)',
|
|
||||||
'class' => 'number-format require',
|
|
||||||
'name' => 'cost',
|
|
||||||
'id' => 'cost',
|
|
||||||
'value' => $this -> transport_details['cost']
|
|
||||||
)
|
|
||||||
);?>
|
|
||||||
<?= \Html::input(
|
|
||||||
array(
|
|
||||||
'label' => 'Maks. WP',
|
|
||||||
'class' => 'number-format require',
|
|
||||||
'name' => 'max_wp',
|
|
||||||
'id' => 'max_wp',
|
|
||||||
'value' => $this -> transport_details['max_wp']
|
|
||||||
)
|
|
||||||
);?>
|
|
||||||
<?= \Html::input_switch( [
|
|
||||||
'label' => 'Domyślna forma dostawy',
|
|
||||||
'name' => 'default',
|
|
||||||
'checked' => $this -> transport_details['default'] == 1 ? true : false
|
|
||||||
] );?>
|
|
||||||
<?= \Html::input_switch(
|
|
||||||
array(
|
|
||||||
'label' => 'Aktywny',
|
|
||||||
'name' => 'status',
|
|
||||||
'checked' => $this -> transport_details['status'] == 1 ? true : false
|
|
||||||
)
|
|
||||||
);?>
|
|
||||||
<?= \Html::input_switch( [
|
|
||||||
'label' => 'Darmowa dostawa',
|
|
||||||
'name' => 'delivery_free',
|
|
||||||
'checked' => $this -> transport_details['delivery_free'] == 1 ? true : false
|
|
||||||
] );?>
|
|
||||||
<?= \Html::select( [
|
|
||||||
'label' => 'Kurier z Apilo',
|
|
||||||
'name' => 'apilo_carrier_account_id',
|
|
||||||
'id' => 'apilo_carrier_account_id',
|
|
||||||
'values' => $carrier_accounts,
|
|
||||||
'value' => $this -> transport_details['apilo_carrier_account_id']
|
|
||||||
] );?>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<? if ( is_array( $this -> payments_list ) ): foreach ( $this -> payments_list as $payment_method ):?>
|
|
||||||
<div class="form-group">
|
|
||||||
<div class="col-lg-12">
|
|
||||||
<div class="list">
|
|
||||||
<input type="checkbox" class="g-checkbox" name="payment_methods[]" value="<?= $payment_method['id'];?>" <? if ( in_array( $payment_method['id'], $this -> transport_details['payment_methods'] ) ):?>checked="checked"<? endif;?> />
|
|
||||||
<span class="bold <? if ( !$payment_method['status'] ):?>text-muted<? endif;?>"><?= $payment_method['name'];?></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<? endforeach; endif;?>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<?
|
|
||||||
$out = ob_get_clean();
|
|
||||||
|
|
||||||
$grid = new \gridEdit;
|
echo \Tpl::view('shop-transport/transport-edit-custom-script', [
|
||||||
$grid -> id = 'transport-edit';
|
'form' => $this->form,
|
||||||
$grid -> gdb_opt = $gdb;
|
]);
|
||||||
$grid -> include_plugins = true;
|
|
||||||
$grid -> title = 'Edycja rodzaju transportu';
|
|
||||||
$grid -> fields = [
|
|
||||||
[
|
|
||||||
'db' => 'id',
|
|
||||||
'type' => 'hidden',
|
|
||||||
'value' => $this -> transport_details['id']
|
|
||||||
]
|
|
||||||
];
|
|
||||||
$grid -> actions = [
|
|
||||||
'save' => [ 'url' => '/admin/shop_transport/transport_save/', 'back_url' => '/admin/shop_transport/view_list/' ],
|
|
||||||
'cancel' => [ 'url' => '/admin/shop_transport/view_list/' ]
|
|
||||||
];
|
|
||||||
$grid -> external_code = $out;
|
|
||||||
$grid -> persist_edit = true;
|
|
||||||
$grid -> id_param = 'id';
|
|
||||||
|
|
||||||
echo $grid -> draw();
|
|
||||||
?>
|
|
||||||
<script type="text/javascript">
|
|
||||||
$( function()
|
|
||||||
{
|
|
||||||
disable_menu();
|
|
||||||
|
|
||||||
$( '#settings-tabs' ).easyResponsiveTabs({
|
|
||||||
width: 'auto',
|
|
||||||
fit: true,
|
|
||||||
tabidentify: 'settings-tabs',
|
|
||||||
type: 'vertical'
|
|
||||||
});
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|||||||
1
admin/templates/shop-transport/transports-list.php
Normal file
1
admin/templates/shop-transport/transports-list.php
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<?= \Tpl::view('components/table-list', ['list' => $this->viewModel]); ?>
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
<?php
|
|
||||||
global $gdb;
|
|
||||||
|
|
||||||
foreach ( $this -> apilo_carrier_account_list as $carrier_account )
|
|
||||||
{
|
|
||||||
$carrier_accounts[ $carrier_account['id'] ] = $carrier_account['name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$grid = new \grid( 'pp_shop_transports' );
|
|
||||||
$grid -> gdb_opt = $gdb;
|
|
||||||
$grid -> debug = true;
|
|
||||||
$grid -> order = [ 'column' => 'name', 'type' => 'ASC' ];
|
|
||||||
$grid -> search = [
|
|
||||||
[ 'name' => 'Nazwa', 'db' => 'name', 'type' => 'text' ],
|
|
||||||
[ 'name' => 'Aktywny', 'db' => 'status', 'type' => 'select', 'replace' => [ 'array' => [ 0 => 'nie', 1 => 'tak' ] ] ]
|
|
||||||
];
|
|
||||||
$grid -> columns_view = [
|
|
||||||
[
|
|
||||||
'name' => 'Lp.',
|
|
||||||
'th' => [ 'class' => 'g-lp' ],
|
|
||||||
'td' => [ 'class' => 'g-center' ],
|
|
||||||
'autoincrement' => true
|
|
||||||
], [
|
|
||||||
'name' => 'Domyślna FT',
|
|
||||||
'db' => 'default',
|
|
||||||
'replace' => [ 'array' => [ 0 => '<span style="color: #FF0000;">nie</span>', 1 => 'tak' ] ],
|
|
||||||
'td' => [ 'class' => 'g-center' ],
|
|
||||||
'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ],
|
|
||||||
'sort' => true
|
|
||||||
], [
|
|
||||||
'name' => 'Aktywny',
|
|
||||||
'db' => 'status',
|
|
||||||
'replace' => [ 'array' => [ 0 => '<span style="color: #FF0000;">nie</span>', 1 => 'tak' ] ],
|
|
||||||
'td' => [ 'class' => 'g-center' ],
|
|
||||||
'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ],
|
|
||||||
'sort' => true
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'Koszt',
|
|
||||||
'db' => 'cost',
|
|
||||||
'td' => [ 'class' => 'g-center' ],
|
|
||||||
'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ],
|
|
||||||
'php' => 'echo \\S::decimal( [cost] ) . " zł";',
|
|
||||||
'sort' => true
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'Maks. WP',
|
|
||||||
'db' => 'max_wp',
|
|
||||||
'td' => [ 'class' => 'g-center' ],
|
|
||||||
'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ],
|
|
||||||
'sort' => true
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'Nazwa',
|
|
||||||
'db' => 'name',
|
|
||||||
'sort' => true,
|
|
||||||
'php' => 'echo "<a href=\'/admin/shop_transport/transport_edit/id=[id]\'>[name]</a>";'
|
|
||||||
], [
|
|
||||||
'name' => 'Typ kuriera Apilo',
|
|
||||||
'db' => 'apilo_carrier_account_id',
|
|
||||||
'th' => [ 'class' => 'g-center' ],
|
|
||||||
'td' => [ 'class' => 'g-center' ],
|
|
||||||
'replace' => [ 'array' => $carrier_accounts ],
|
|
||||||
], [
|
|
||||||
'name' => 'Edytuj',
|
|
||||||
'action' => [ 'type' => 'edit', 'url' => '/admin/shop_transport/transport_edit/id=[id]' ],
|
|
||||||
'th' => [ 'class' => 'g-center', 'style' => 'width: 70px;' ],
|
|
||||||
'td' => [ 'class' => 'g-center' ]
|
|
||||||
]
|
|
||||||
];
|
|
||||||
echo $grid -> draw();
|
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li><a href="/admin/shop_attribute/view_list/"><img src="/admin/layout/icon/icon-menu/star-filled.svg">Cechy produktów</a></li>
|
<li><a href="/admin/shop_attribute/view_list/"><img src="/admin/layout/icon/icon-menu/star-filled.svg">Cechy produktów</a></li>
|
||||||
<li><a href="/admin/shop_transport/view_list/"><img src="/admin/layout/icon/icon-menu/bus.svg">Rodzaje transportu</a></li>
|
<li><a href="/admin/shop_transport/list/"><img src="/admin/layout/icon/icon-menu/bus.svg">Rodzaje transportu</a></li>
|
||||||
<li><a href="/admin/shop_payment_method/list/"><img src="/admin/layout/icon/icon-menu/coins-fill.svg">Metody płatności</a></li>
|
<li><a href="/admin/shop_payment_method/list/"><img src="/admin/layout/icon/icon-menu/coins-fill.svg">Metody płatności</a></li>
|
||||||
<li>
|
<li>
|
||||||
<a href="/admin/shop_statuses/list/"><i class="fa fa-bars"></i>Statusy zamówień</a>
|
<a href="/admin/shop_statuses/list/"><i class="fa fa-bars"></i>Statusy zamówień</a>
|
||||||
|
|||||||
342
autoload/Domain/Transport/TransportRepository.php
Normal file
342
autoload/Domain/Transport/TransportRepository.php
Normal file
@@ -0,0 +1,342 @@
|
|||||||
|
<?php
|
||||||
|
namespace Domain\Transport;
|
||||||
|
|
||||||
|
class TransportRepository
|
||||||
|
{
|
||||||
|
private const MAX_PER_PAGE = 100;
|
||||||
|
|
||||||
|
private $db;
|
||||||
|
|
||||||
|
public function __construct($db)
|
||||||
|
{
|
||||||
|
$this->db = $db;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listForAdmin(
|
||||||
|
array $filters = [],
|
||||||
|
string $sortColumn = 'name',
|
||||||
|
string $sortDir = 'ASC',
|
||||||
|
int $page = 1,
|
||||||
|
int $perPage = 15
|
||||||
|
): array {
|
||||||
|
$allowedSortColumns = [
|
||||||
|
'id' => 'st.id',
|
||||||
|
'name' => 'st.name',
|
||||||
|
'status' => 'st.status',
|
||||||
|
'cost' => 'st.cost',
|
||||||
|
'max_wp' => 'st.max_wp',
|
||||||
|
'default' => 'st.default',
|
||||||
|
'o' => 'st.o',
|
||||||
|
];
|
||||||
|
|
||||||
|
$sortSql = $allowedSortColumns[$sortColumn] ?? 'st.name';
|
||||||
|
$sortDir = strtoupper(trim($sortDir)) === 'DESC' ? 'DESC' : 'ASC';
|
||||||
|
$page = max(1, $page);
|
||||||
|
$perPage = min(self::MAX_PER_PAGE, max(1, $perPage));
|
||||||
|
$offset = ($page - 1) * $perPage;
|
||||||
|
|
||||||
|
$where = ['1 = 1'];
|
||||||
|
$params = [];
|
||||||
|
|
||||||
|
$name = trim((string)($filters['name'] ?? ''));
|
||||||
|
if ($name !== '') {
|
||||||
|
if (strlen($name) > 255) {
|
||||||
|
$name = substr($name, 0, 255);
|
||||||
|
}
|
||||||
|
$where[] = 'st.name LIKE :name';
|
||||||
|
$params[':name'] = '%' . $name . '%';
|
||||||
|
}
|
||||||
|
|
||||||
|
$status = trim((string)($filters['status'] ?? ''));
|
||||||
|
if ($status === '0' || $status === '1') {
|
||||||
|
$where[] = 'st.status = :status';
|
||||||
|
$params[':status'] = (int)$status;
|
||||||
|
}
|
||||||
|
|
||||||
|
$whereSql = implode(' AND ', $where);
|
||||||
|
|
||||||
|
$sqlCount = "
|
||||||
|
SELECT COUNT(0)
|
||||||
|
FROM pp_shop_transports AS st
|
||||||
|
WHERE {$whereSql}
|
||||||
|
";
|
||||||
|
|
||||||
|
$stmtCount = $this->db->query($sqlCount, $params);
|
||||||
|
$countRows = $stmtCount ? $stmtCount->fetchAll() : [];
|
||||||
|
$total = isset($countRows[0][0]) ? (int)$countRows[0][0] : 0;
|
||||||
|
|
||||||
|
$sql = "
|
||||||
|
SELECT
|
||||||
|
st.id,
|
||||||
|
st.name,
|
||||||
|
st.name_visible,
|
||||||
|
st.description,
|
||||||
|
st.status,
|
||||||
|
st.cost,
|
||||||
|
st.max_wp,
|
||||||
|
st.default,
|
||||||
|
st.apilo_carrier_account_id,
|
||||||
|
st.delivery_free,
|
||||||
|
st.o
|
||||||
|
FROM pp_shop_transports AS st
|
||||||
|
WHERE {$whereSql}
|
||||||
|
ORDER BY {$sortSql} {$sortDir}, st.id ASC
|
||||||
|
LIMIT {$perPage} OFFSET {$offset}
|
||||||
|
";
|
||||||
|
|
||||||
|
$stmt = $this->db->query($sql, $params);
|
||||||
|
$items = $stmt ? $stmt->fetchAll() : [];
|
||||||
|
|
||||||
|
if (!is_array($items)) {
|
||||||
|
$items = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($items as &$item) {
|
||||||
|
$item = $this->normalizeTransport($item);
|
||||||
|
}
|
||||||
|
unset($item);
|
||||||
|
|
||||||
|
return [
|
||||||
|
'items' => $items,
|
||||||
|
'total' => $total,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function find(int $transportId): ?array
|
||||||
|
{
|
||||||
|
if ($transportId <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$transport = $this->db->get('pp_shop_transports', '*', ['id' => $transportId]);
|
||||||
|
|
||||||
|
if (!is_array($transport)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$transport = $this->normalizeTransport($transport);
|
||||||
|
|
||||||
|
$paymentMethods = $this->db->select(
|
||||||
|
'pp_shop_transport_payment_methods',
|
||||||
|
'id_payment_method',
|
||||||
|
['id_transport' => $transportId]
|
||||||
|
);
|
||||||
|
|
||||||
|
$transport['payment_methods'] = is_array($paymentMethods) ? $paymentMethods : [];
|
||||||
|
|
||||||
|
return $transport;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(array $data): ?int
|
||||||
|
{
|
||||||
|
$transportId = isset($data['id']) ? (int)$data['id'] : 0;
|
||||||
|
$name = trim((string)($data['name'] ?? ''));
|
||||||
|
$nameVisible = trim((string)($data['name_visible'] ?? ''));
|
||||||
|
$description = trim((string)($data['description'] ?? ''));
|
||||||
|
$status = $this->toSwitchValue($data['status'] ?? 0);
|
||||||
|
$cost = isset($data['cost']) ? (float)$data['cost'] : 0.0;
|
||||||
|
$maxWp = isset($data['max_wp']) && $data['max_wp'] !== '' ? (int)$data['max_wp'] : null;
|
||||||
|
$default = $this->toSwitchValue($data['default'] ?? 0);
|
||||||
|
$apiloCarrierAccountId = isset($data['apilo_carrier_account_id']) && $data['apilo_carrier_account_id'] !== ''
|
||||||
|
? (int)$data['apilo_carrier_account_id']
|
||||||
|
: null;
|
||||||
|
$deliveryFree = $this->toSwitchValue($data['delivery_free'] ?? 0);
|
||||||
|
$paymentMethods = $data['payment_methods'] ?? [];
|
||||||
|
|
||||||
|
if ($default === 1) {
|
||||||
|
$this->db->update('pp_shop_transports', ['default' => 0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$transportData = [
|
||||||
|
'name' => $name,
|
||||||
|
'name_visible' => $nameVisible,
|
||||||
|
'description' => $description,
|
||||||
|
'status' => $status,
|
||||||
|
'default' => $default,
|
||||||
|
'cost' => $cost,
|
||||||
|
'max_wp' => $maxWp,
|
||||||
|
'apilo_carrier_account_id' => $apiloCarrierAccountId,
|
||||||
|
'delivery_free' => $deliveryFree,
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!$transportId) {
|
||||||
|
$this->db->insert('pp_shop_transports', $transportData);
|
||||||
|
$id = $this->db->id();
|
||||||
|
|
||||||
|
if ($id) {
|
||||||
|
$this->savePaymentMethodLinks((int)$id, $paymentMethods);
|
||||||
|
return (int)$id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
$this->db->update('pp_shop_transports', $transportData, ['id' => $transportId]);
|
||||||
|
$this->db->delete('pp_shop_transport_payment_methods', ['id_transport' => $transportId]);
|
||||||
|
$this->savePaymentMethodLinks($transportId, $paymentMethods);
|
||||||
|
return $transportId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function allActive(): array
|
||||||
|
{
|
||||||
|
$transports = $this->db->select(
|
||||||
|
'pp_shop_transports',
|
||||||
|
'*',
|
||||||
|
[
|
||||||
|
'status' => 1,
|
||||||
|
'ORDER' => ['o' => 'ASC'],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!is_array($transports)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($transports as &$transport) {
|
||||||
|
$transport = $this->normalizeTransport($transport);
|
||||||
|
}
|
||||||
|
unset($transport);
|
||||||
|
|
||||||
|
return $transports;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findActiveById(int $transportId): ?array
|
||||||
|
{
|
||||||
|
if ($transportId <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$transport = $this->db->get(
|
||||||
|
'pp_shop_transports',
|
||||||
|
'*',
|
||||||
|
['AND' => ['id' => $transportId, 'status' => 1]]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!$transport) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->normalizeTransport($transport);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getApiloCarrierAccountId(int $transportId): ?int
|
||||||
|
{
|
||||||
|
if ($transportId <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->db->get(
|
||||||
|
'pp_shop_transports',
|
||||||
|
'apilo_carrier_account_id',
|
||||||
|
['id' => $transportId]
|
||||||
|
);
|
||||||
|
|
||||||
|
return $result !== null ? (int)$result : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTransportCost(int $transportId): ?float
|
||||||
|
{
|
||||||
|
if ($transportId <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->db->get(
|
||||||
|
'pp_shop_transports',
|
||||||
|
'cost',
|
||||||
|
['AND' => ['id' => $transportId, 'status' => 1]]
|
||||||
|
);
|
||||||
|
|
||||||
|
return $result !== null ? (float)$result : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function lowestTransportPrice(int $wp): ?float
|
||||||
|
{
|
||||||
|
$result = $this->db->get(
|
||||||
|
'pp_shop_transports',
|
||||||
|
'cost',
|
||||||
|
[
|
||||||
|
'AND' => [
|
||||||
|
'status' => 1,
|
||||||
|
'id' => [2, 4, 6, 8, 9],
|
||||||
|
'max_wp[>=]' => $wp
|
||||||
|
],
|
||||||
|
'ORDER' => ['cost' => 'ASC']
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
return $result !== null ? (float)$result : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function allForAdmin(): array
|
||||||
|
{
|
||||||
|
$transports = $this->db->select(
|
||||||
|
'pp_shop_transports',
|
||||||
|
'*',
|
||||||
|
['ORDER' => ['o' => 'ASC']]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!is_array($transports)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($transports as &$transport) {
|
||||||
|
$transport = $this->normalizeTransport($transport);
|
||||||
|
}
|
||||||
|
unset($transport);
|
||||||
|
|
||||||
|
return $transports;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function savePaymentMethodLinks(int $transportId, $paymentMethods): void
|
||||||
|
{
|
||||||
|
if (is_array($paymentMethods)) {
|
||||||
|
foreach ($paymentMethods as $paymentMethodId) {
|
||||||
|
$this->db->insert('pp_shop_transport_payment_methods', [
|
||||||
|
'id_payment_method' => (int)$paymentMethodId,
|
||||||
|
'id_transport' => $transportId,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} elseif ($paymentMethods) {
|
||||||
|
$this->db->insert('pp_shop_transport_payment_methods', [
|
||||||
|
'id_payment_method' => (int)$paymentMethods,
|
||||||
|
'id_transport' => $transportId,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function normalizeTransport(array $transport): array
|
||||||
|
{
|
||||||
|
$transport['id'] = isset($transport['id']) ? (int)$transport['id'] : 0;
|
||||||
|
$transport['status'] = $this->toSwitchValue($transport['status'] ?? 0);
|
||||||
|
$transport['default'] = $this->toSwitchValue($transport['default'] ?? 0);
|
||||||
|
$transport['delivery_free'] = $this->toSwitchValue($transport['delivery_free'] ?? 0);
|
||||||
|
$transport['cost'] = isset($transport['cost']) ? (float)$transport['cost'] : 0.0;
|
||||||
|
$transport['max_wp'] = isset($transport['max_wp']) && $transport['max_wp'] !== null
|
||||||
|
? (int)$transport['max_wp']
|
||||||
|
: null;
|
||||||
|
$transport['apilo_carrier_account_id'] = isset($transport['apilo_carrier_account_id']) && $transport['apilo_carrier_account_id'] !== null
|
||||||
|
? (int)$transport['apilo_carrier_account_id']
|
||||||
|
: null;
|
||||||
|
$transport['o'] = isset($transport['o']) ? (int)$transport['o'] : 0;
|
||||||
|
|
||||||
|
return $transport;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function toSwitchValue($value): int
|
||||||
|
{
|
||||||
|
if (is_bool($value)) {
|
||||||
|
return $value ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_numeric($value)) {
|
||||||
|
return ((int)$value) === 1 ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_string($value)) {
|
||||||
|
$normalized = strtolower(trim($value));
|
||||||
|
return in_array($normalized, ['1', 'on', 'true', 'yes'], true) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
342
autoload/admin/Controllers/ShopTransportController.php
Normal file
342
autoload/admin/Controllers/ShopTransportController.php
Normal file
@@ -0,0 +1,342 @@
|
|||||||
|
<?php
|
||||||
|
namespace admin\Controllers;
|
||||||
|
|
||||||
|
use Domain\Transport\TransportRepository;
|
||||||
|
use Domain\PaymentMethod\PaymentMethodRepository;
|
||||||
|
use admin\ViewModels\Common\PaginatedTableViewModel;
|
||||||
|
use admin\ViewModels\Forms\FormAction;
|
||||||
|
use admin\ViewModels\Forms\FormEditViewModel;
|
||||||
|
use admin\ViewModels\Forms\FormField;
|
||||||
|
use admin\ViewModels\Forms\FormTab;
|
||||||
|
|
||||||
|
class ShopTransportController
|
||||||
|
{
|
||||||
|
private TransportRepository $transportRepository;
|
||||||
|
private PaymentMethodRepository $paymentMethodRepository;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
TransportRepository $transportRepository,
|
||||||
|
PaymentMethodRepository $paymentMethodRepository
|
||||||
|
) {
|
||||||
|
$this->transportRepository = $transportRepository;
|
||||||
|
$this->paymentMethodRepository = $paymentMethodRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function list(): string
|
||||||
|
{
|
||||||
|
$sortableColumns = ['id', 'name', 'status', 'cost', 'max_wp', 'default', 'o'];
|
||||||
|
$filterDefinitions = [
|
||||||
|
[
|
||||||
|
'key' => 'name',
|
||||||
|
'label' => 'Nazwa',
|
||||||
|
'type' => 'text',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'key' => 'status',
|
||||||
|
'label' => 'Aktywny',
|
||||||
|
'type' => 'select',
|
||||||
|
'options' => [
|
||||||
|
'' => '- aktywny -',
|
||||||
|
'1' => 'tak',
|
||||||
|
'0' => 'nie',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$listRequest = \admin\Support\TableListRequestFactory::fromRequest(
|
||||||
|
$filterDefinitions,
|
||||||
|
$sortableColumns,
|
||||||
|
'name'
|
||||||
|
);
|
||||||
|
|
||||||
|
$sortDir = $listRequest['sortDir'];
|
||||||
|
if (trim((string)\S::get('sort')) === '') {
|
||||||
|
$sortDir = 'ASC';
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->transportRepository->listForAdmin(
|
||||||
|
$listRequest['filters'],
|
||||||
|
$listRequest['sortColumn'],
|
||||||
|
$sortDir,
|
||||||
|
$listRequest['page'],
|
||||||
|
$listRequest['perPage']
|
||||||
|
);
|
||||||
|
|
||||||
|
$apiloCarrierAccounts = $this->getApiloCarrierAccounts();
|
||||||
|
|
||||||
|
$rows = [];
|
||||||
|
$lp = ($listRequest['page'] - 1) * $listRequest['perPage'] + 1;
|
||||||
|
foreach ($result['items'] as $item) {
|
||||||
|
$id = (int)($item['id'] ?? 0);
|
||||||
|
$name = trim((string)($item['name'] ?? ''));
|
||||||
|
$status = (int)($item['status'] ?? 0);
|
||||||
|
$cost = (float)($item['cost'] ?? 0.0);
|
||||||
|
$maxWp = $item['max_wp'] ?? null;
|
||||||
|
$default = (int)($item['default'] ?? 0);
|
||||||
|
$apiloCarrierAccountId = $item['apilo_carrier_account_id'] ?? null;
|
||||||
|
|
||||||
|
$apiloLabel = '-';
|
||||||
|
if ($apiloCarrierAccountId !== null) {
|
||||||
|
$apiloKey = (string)$apiloCarrierAccountId;
|
||||||
|
if (isset($apiloCarrierAccounts[$apiloKey])) {
|
||||||
|
$apiloLabel = $apiloCarrierAccounts[$apiloKey];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$rows[] = [
|
||||||
|
'lp' => $lp++ . '.',
|
||||||
|
'default' => $default === 1 ? 'tak' : '<span style="color: #FF0000;">nie</span>',
|
||||||
|
'status' => $status === 1 ? 'tak' : '<span style="color: #FF0000;">nie</span>',
|
||||||
|
'cost' => \S::decimal($cost) . ' zł',
|
||||||
|
'max_wp' => $maxWp !== null ? (int)$maxWp : '-',
|
||||||
|
'name' => '<a href="/admin/shop_transport/edit/id=' . $id . '">' . htmlspecialchars($name, ENT_QUOTES, 'UTF-8') . '</a>',
|
||||||
|
'apilo_carrier' => htmlspecialchars((string)$apiloLabel, ENT_QUOTES, 'UTF-8'),
|
||||||
|
'_actions' => [
|
||||||
|
[
|
||||||
|
'label' => 'Edytuj',
|
||||||
|
'url' => '/admin/shop_transport/edit/id=' . $id,
|
||||||
|
'class' => 'btn btn-xs btn-primary',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$total = (int)$result['total'];
|
||||||
|
$totalPages = max(1, (int)ceil($total / $listRequest['perPage']));
|
||||||
|
|
||||||
|
$viewModel = new PaginatedTableViewModel(
|
||||||
|
[
|
||||||
|
['key' => 'lp', 'label' => 'Lp.', 'class' => 'text-center', 'sortable' => false],
|
||||||
|
['key' => 'default', 'sort_key' => 'default', 'label' => 'Domyślna FT', 'class' => 'text-center', 'sortable' => true, 'raw' => true],
|
||||||
|
['key' => 'status', 'sort_key' => 'status', 'label' => 'Aktywny', 'class' => 'text-center', 'sortable' => true, 'raw' => true],
|
||||||
|
['key' => 'cost', 'sort_key' => 'cost', 'label' => 'Koszt', 'class' => 'text-center', 'sortable' => true, 'raw' => true],
|
||||||
|
['key' => 'max_wp', 'sort_key' => 'max_wp', 'label' => 'Maks. WP', 'class' => 'text-center', 'sortable' => true, 'raw' => true],
|
||||||
|
['key' => 'name', 'sort_key' => 'name', 'label' => 'Nazwa', 'sortable' => true, 'raw' => true],
|
||||||
|
['key' => 'apilo_carrier', 'label' => 'Typ kuriera Apilo', 'class' => 'text-center', 'sortable' => false],
|
||||||
|
],
|
||||||
|
$rows,
|
||||||
|
$listRequest['viewFilters'],
|
||||||
|
[
|
||||||
|
'column' => $listRequest['sortColumn'],
|
||||||
|
'dir' => $sortDir,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'page' => $listRequest['page'],
|
||||||
|
'per_page' => $listRequest['perPage'],
|
||||||
|
'total' => $total,
|
||||||
|
'total_pages' => $totalPages,
|
||||||
|
],
|
||||||
|
array_merge($listRequest['queryFilters'], [
|
||||||
|
'sort' => $listRequest['sortColumn'],
|
||||||
|
'dir' => $sortDir,
|
||||||
|
'per_page' => $listRequest['perPage'],
|
||||||
|
]),
|
||||||
|
$listRequest['perPageOptions'],
|
||||||
|
$sortableColumns,
|
||||||
|
'/admin/shop_transport/list/',
|
||||||
|
'Brak danych w tabeli.'
|
||||||
|
);
|
||||||
|
|
||||||
|
return \Tpl::view('shop-transport/transports-list', [
|
||||||
|
'viewModel' => $viewModel,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function edit(): string
|
||||||
|
{
|
||||||
|
$transport = $this->transportRepository->find((int)\S::get('id'));
|
||||||
|
if ($transport === null) {
|
||||||
|
\S::alert('Rodzaj transportu nie został znaleziony.');
|
||||||
|
header('Location: /admin/shop_transport/list/');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$paymentMethods = $this->paymentMethodRepository->allForAdmin();
|
||||||
|
$apiloCarrierAccounts = $this->getApiloCarrierAccounts();
|
||||||
|
|
||||||
|
return \Tpl::view('shop-transport/transport-edit', [
|
||||||
|
'form' => $this->buildFormViewModel($transport, $paymentMethods, $apiloCarrierAccounts),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(): void
|
||||||
|
{
|
||||||
|
$payload = $_POST;
|
||||||
|
$transportId = isset($payload['id']) && $payload['id'] !== ''
|
||||||
|
? (int)$payload['id']
|
||||||
|
: (int)\S::get('id');
|
||||||
|
|
||||||
|
$payload['id'] = $transportId;
|
||||||
|
|
||||||
|
$id = $this->transportRepository->save($payload);
|
||||||
|
if ($id !== null) {
|
||||||
|
\S::delete_dir('../temp/');
|
||||||
|
echo json_encode([
|
||||||
|
'success' => true,
|
||||||
|
'id' => (int)$id,
|
||||||
|
'message' => 'Rodzaj transportu został zapisany.',
|
||||||
|
]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'success' => false,
|
||||||
|
'errors' => ['general' => 'Podczas zapisywania rodzaju transportu wystąpił błąd.'],
|
||||||
|
]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildFormViewModel(
|
||||||
|
array $transport,
|
||||||
|
array $paymentMethods,
|
||||||
|
array $apiloCarrierAccounts
|
||||||
|
): FormEditViewModel {
|
||||||
|
$id = (int)($transport['id'] ?? 0);
|
||||||
|
$name = (string)($transport['name'] ?? '');
|
||||||
|
|
||||||
|
$apiloOptions = ['' => '--- wybierz konto przewoźnika ---'];
|
||||||
|
foreach ($apiloCarrierAccounts as $carrierId => $carrierName) {
|
||||||
|
$apiloOptions[(string)$carrierId] = $carrierName;
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'id' => $id,
|
||||||
|
'name' => $name,
|
||||||
|
'name_visible' => (string)($transport['name_visible'] ?? ''),
|
||||||
|
'description' => (string)($transport['description'] ?? ''),
|
||||||
|
'cost' => (float)($transport['cost'] ?? 0.0),
|
||||||
|
'max_wp' => $transport['max_wp'] ?? '',
|
||||||
|
'default' => (int)($transport['default'] ?? 0),
|
||||||
|
'status' => (int)($transport['status'] ?? 0),
|
||||||
|
'delivery_free' => (int)($transport['delivery_free'] ?? 0),
|
||||||
|
'apilo_carrier_account_id' => $transport['apilo_carrier_account_id'] ?? '',
|
||||||
|
];
|
||||||
|
|
||||||
|
$fields = [
|
||||||
|
FormField::hidden('id', $id),
|
||||||
|
FormField::text('name', [
|
||||||
|
'label' => 'Nazwa',
|
||||||
|
'tab' => 'general',
|
||||||
|
'readonly' => true,
|
||||||
|
'required' => true,
|
||||||
|
]),
|
||||||
|
FormField::text('name_visible', [
|
||||||
|
'label' => 'Nazwa widoczna',
|
||||||
|
'tab' => 'general',
|
||||||
|
]),
|
||||||
|
FormField::text('description', [
|
||||||
|
'label' => 'Opis',
|
||||||
|
'tab' => 'general',
|
||||||
|
]),
|
||||||
|
FormField::number('cost', [
|
||||||
|
'label' => 'Koszt (PLN)',
|
||||||
|
'tab' => 'general',
|
||||||
|
'step' => 0.01,
|
||||||
|
'required' => true,
|
||||||
|
]),
|
||||||
|
FormField::number('max_wp', [
|
||||||
|
'label' => 'Maks. WP',
|
||||||
|
'tab' => 'general',
|
||||||
|
'required' => true,
|
||||||
|
]),
|
||||||
|
FormField::switch('default', [
|
||||||
|
'label' => 'Domyślna forma dostawy',
|
||||||
|
'tab' => 'general',
|
||||||
|
]),
|
||||||
|
FormField::switch('status', [
|
||||||
|
'label' => 'Aktywny',
|
||||||
|
'tab' => 'general',
|
||||||
|
]),
|
||||||
|
FormField::switch('delivery_free', [
|
||||||
|
'label' => 'Darmowa dostawa',
|
||||||
|
'tab' => 'general',
|
||||||
|
]),
|
||||||
|
FormField::select('apilo_carrier_account_id', [
|
||||||
|
'label' => 'Kurier z Apilo',
|
||||||
|
'tab' => 'general',
|
||||||
|
'options' => $apiloOptions,
|
||||||
|
]),
|
||||||
|
];
|
||||||
|
|
||||||
|
$transportPaymentMethods = $transport['payment_methods'] ?? [];
|
||||||
|
|
||||||
|
$paymentMethodsHtml = '';
|
||||||
|
if (is_array($paymentMethods) && !empty($paymentMethods)) {
|
||||||
|
foreach ($paymentMethods as $paymentMethod) {
|
||||||
|
$pmId = (int)($paymentMethod['id'] ?? 0);
|
||||||
|
$pmName = htmlspecialchars((string)($paymentMethod['name'] ?? ''), ENT_QUOTES, 'UTF-8');
|
||||||
|
$pmStatus = (int)($paymentMethod['status'] ?? 0);
|
||||||
|
$checked = in_array($pmId, $transportPaymentMethods) ? 'checked="checked"' : '';
|
||||||
|
$statusClass = $pmStatus === 0 ? 'text-muted' : '';
|
||||||
|
|
||||||
|
$paymentMethodsHtml .= '<div class="form-group">';
|
||||||
|
$paymentMethodsHtml .= '<div class="col-lg-12">';
|
||||||
|
$paymentMethodsHtml .= '<div class="list">';
|
||||||
|
$paymentMethodsHtml .= '<input type="checkbox" class="g-checkbox" name="payment_methods[]" value="' . $pmId . '" ' . $checked . ' />';
|
||||||
|
$paymentMethodsHtml .= '<span class="bold ' . $statusClass . '">' . $pmName . '</span>';
|
||||||
|
$paymentMethodsHtml .= '</div>';
|
||||||
|
$paymentMethodsHtml .= '</div>';
|
||||||
|
$paymentMethodsHtml .= '</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$fields[] = FormField::custom(
|
||||||
|
'payment_methods_section',
|
||||||
|
$paymentMethodsHtml,
|
||||||
|
['tab' => 'payment_methods']
|
||||||
|
);
|
||||||
|
|
||||||
|
$tabs = [
|
||||||
|
new FormTab('general', 'Ogólne', 'fa-file'),
|
||||||
|
new FormTab('payment_methods', 'Powiązane metody płatności', 'fa-wrench'),
|
||||||
|
];
|
||||||
|
|
||||||
|
$actionUrl = '/admin/shop_transport/save/id=' . $id;
|
||||||
|
$actions = [
|
||||||
|
FormAction::save($actionUrl, '/admin/shop_transport/list/'),
|
||||||
|
FormAction::cancel('/admin/shop_transport/list/'),
|
||||||
|
];
|
||||||
|
|
||||||
|
return new FormEditViewModel(
|
||||||
|
'shop-transport-edit',
|
||||||
|
'Edycja rodzaju transportu: ' . $name,
|
||||||
|
$data,
|
||||||
|
$fields,
|
||||||
|
$tabs,
|
||||||
|
$actions,
|
||||||
|
'POST',
|
||||||
|
$actionUrl,
|
||||||
|
'/admin/shop_transport/list/',
|
||||||
|
true,
|
||||||
|
['id' => $id]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getApiloCarrierAccounts(): array
|
||||||
|
{
|
||||||
|
$rawSetting = \admin\factory\Integrations::apilo_settings('carrier-account-list');
|
||||||
|
$raw = null;
|
||||||
|
|
||||||
|
if (is_array($rawSetting)) {
|
||||||
|
$raw = $rawSetting;
|
||||||
|
} elseif (is_string($rawSetting)) {
|
||||||
|
$decoded = @unserialize($rawSetting);
|
||||||
|
if (is_array($decoded)) {
|
||||||
|
$raw = $decoded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_array($raw)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$list = [];
|
||||||
|
foreach ($raw as $carrier) {
|
||||||
|
if (is_array($carrier) && isset($carrier['id'], $carrier['name'])) {
|
||||||
|
$list[(string)$carrier['id']] = (string)$carrier['name'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -323,6 +323,14 @@ class Site
|
|||||||
new \Domain\PaymentMethod\PaymentMethodRepository( $mdb )
|
new \Domain\PaymentMethod\PaymentMethodRepository( $mdb )
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
'ShopTransport' => function() {
|
||||||
|
global $mdb;
|
||||||
|
|
||||||
|
return new \admin\Controllers\ShopTransportController(
|
||||||
|
new \Domain\Transport\TransportRepository( $mdb ),
|
||||||
|
new \Domain\PaymentMethod\PaymentMethodRepository( $mdb )
|
||||||
|
);
|
||||||
|
},
|
||||||
'Pages' => function() {
|
'Pages' => function() {
|
||||||
global $mdb;
|
global $mdb;
|
||||||
|
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace admin\controls;
|
|
||||||
class ShopTransport
|
|
||||||
{
|
|
||||||
public static function transport_save()
|
|
||||||
{
|
|
||||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania rodzaju transportu wystąpił błąd. Proszę spróbować ponownie.' ];
|
|
||||||
$values = json_decode( \S::get( 'values' ), true );
|
|
||||||
|
|
||||||
if ( $id = \admin\factory\ShopTransport::transport_save(
|
|
||||||
$values['id'], $values['name'], $values['name_visible'], $values['description'], $values['status'], $values['cost'], $values['payment_methods'], $values['max_wp'], $values['default'], $values['apilo_carrier_account_id'], $values['delivery_free']
|
|
||||||
) )
|
|
||||||
$response = [ 'status' => 'ok', 'msg' => 'Rodzaj transportu został zapisany.', 'id' => $id ];
|
|
||||||
|
|
||||||
echo json_encode( $response );
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function transport_edit()
|
|
||||||
{
|
|
||||||
global $mdb;
|
|
||||||
$paymentMethodRepository = new \Domain\PaymentMethod\PaymentMethodRepository( $mdb );
|
|
||||||
|
|
||||||
return \Tpl::view( 'shop-transport/transport-edit', [
|
|
||||||
'transport_details' => \admin\factory\ShopTransport::transport_details( \S::get( 'id' ) ),
|
|
||||||
'payments_list' => $paymentMethodRepository -> allForAdmin(),
|
|
||||||
'apilo_carrier_account_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'carrier-account-list' ) ),
|
|
||||||
] );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function view_list()
|
|
||||||
{
|
|
||||||
return \Tpl::view( 'shop-transport/view-list', [
|
|
||||||
'apilo_carrier_account_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'carrier-account-list' ) ),
|
|
||||||
] );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,103 +4,7 @@ class ShopTransport
|
|||||||
{
|
{
|
||||||
public static function lowest_transport_price( $wp ) {
|
public static function lowest_transport_price( $wp ) {
|
||||||
global $mdb;
|
global $mdb;
|
||||||
return $mdb -> get( 'pp_shop_transports', 'cost', [ 'AND' => [ 'status' => 1, 'id' => [ 2, 4, 6, 8, 9 ], 'max_wp[>=]' => $wp ], 'ORDER' => [ 'cost' => 'ASC' ] ] );
|
$repo = new \Domain\Transport\TransportRepository($mdb);
|
||||||
}
|
return $repo->lowestTransportPrice($wp);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace admin\view;
|
|
||||||
class ShopTransport
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -2,11 +2,11 @@
|
|||||||
namespace front\factory;
|
namespace front\factory;
|
||||||
class ShopTransport
|
class ShopTransport
|
||||||
{
|
{
|
||||||
// get_apilo_carrier_account_id
|
|
||||||
static public function get_apilo_carrier_account_id( $transport_method_id )
|
static public function get_apilo_carrier_account_id( $transport_method_id )
|
||||||
{
|
{
|
||||||
global $mdb;
|
global $mdb;
|
||||||
return $mdb -> get( 'pp_shop_transports', 'apilo_carrier_account_id', [ 'id' => $transport_method_id ] );
|
$repo = new \Domain\Transport\TransportRepository($mdb);
|
||||||
|
return $repo->getApiloCarrierAccountId($transport_method_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function transport_methods( $basket, $coupon )
|
public static function transport_methods( $basket, $coupon )
|
||||||
@@ -20,14 +20,8 @@ class ShopTransport
|
|||||||
|
|
||||||
if ( !$objectData )
|
if ( !$objectData )
|
||||||
{
|
{
|
||||||
$results = $mdb -> query( 'SELECT '
|
$repo = new \Domain\Transport\TransportRepository($mdb);
|
||||||
. 'pst.id, name, name_visible, description, cost, max_wp, pst.default, delivery_free '
|
$transports_tmp = $repo->allActive();
|
||||||
. 'FROM '
|
|
||||||
. 'pp_shop_transports AS pst '
|
|
||||||
. 'WHERE '
|
|
||||||
. 'status = 1 ORDER BY o ASC' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
|
||||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
|
||||||
$transports_tmp[] = $row;
|
|
||||||
|
|
||||||
$cacheHandler -> set( $cacheKey, $transports_tmp );
|
$cacheHandler -> set( $cacheKey, $transports_tmp );
|
||||||
}
|
}
|
||||||
@@ -65,11 +59,8 @@ class ShopTransport
|
|||||||
|
|
||||||
if ( !$cost = \Cache::fetch( 'transport_cost_' . $transport_id ) )
|
if ( !$cost = \Cache::fetch( 'transport_cost_' . $transport_id ) )
|
||||||
{
|
{
|
||||||
$cost = $mdb -> get( 'pp_shop_transports', 'cost', [
|
$repo = new \Domain\Transport\TransportRepository($mdb);
|
||||||
'AND' => [
|
$cost = $repo->getTransportCost($transport_id);
|
||||||
'id' => $transport_id,
|
|
||||||
'status' => 1
|
|
||||||
] ] );
|
|
||||||
|
|
||||||
\Cache::store( 'transport_cost_' . $transport_id, $cost );
|
\Cache::store( 'transport_cost_' . $transport_id, $cost );
|
||||||
}
|
}
|
||||||
@@ -82,11 +73,8 @@ class ShopTransport
|
|||||||
|
|
||||||
if ( !$transport = \Cache::fetch( 'transport' . $transport_id ) )
|
if ( !$transport = \Cache::fetch( 'transport' . $transport_id ) )
|
||||||
{
|
{
|
||||||
$transport = $mdb -> get( 'pp_shop_transports', '*', [
|
$repo = new \Domain\Transport\TransportRepository($mdb);
|
||||||
'AND' => [
|
$transport = $repo->findActiveById($transport_id);
|
||||||
'id' => $transport_id,
|
|
||||||
'status' => 1
|
|
||||||
] ] );
|
|
||||||
|
|
||||||
\Cache::store( 'transport' . $transport_id, $transport );
|
\Cache::store( 'transport' . $transport_id, $transport );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,24 @@ Logi zmian z migracji na Domain-Driven Architecture. Najnowsze na gorze.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## ver. 0.269 (2026-02-14) - ShopTransport
|
||||||
|
|
||||||
|
- **ShopTransport** - migracja `/admin/shop_transport` na Domain + DI + nowe widoki
|
||||||
|
- NOWE: `Domain\Transport\TransportRepository` (`listForAdmin`, `find`, `save`, `allActive`, `allForAdmin`, `findActiveById`, `getTransportCost`, `lowestTransportPrice`, `getApiloCarrierAccountId`)
|
||||||
|
- NOWE: `admin\Controllers\ShopTransportController` (DI) z akcjami `list`, `edit`, `save`
|
||||||
|
- NOWE: widoki `shop-transport/transports-list.php` i `shop-transport/transport-edit.php` + `transport-edit-custom-script.php`
|
||||||
|
- UPDATE: routing i menu admin na kanoniczny URL `/admin/shop_transport/list/`
|
||||||
|
- UPDATE: `admin\factory\ShopTransport`, `front\factory\ShopTransport` przepiete na nowe repozytorium
|
||||||
|
- FIX: `save()` return type `?int` zamiast `int|bool` (spojnosc z PaymentMethod)
|
||||||
|
- FIX: `toSwitchValue()` helper zamiast `=== 'on'` (obsluga '1', 'on', 'true', 'yes')
|
||||||
|
- FIX: `\S::delete_dir()` przeniesione z repozytorium do kontrolera (DDD)
|
||||||
|
- FIX: Medoo `select()` syntax - ORDER w WHERE zamiast 4-arg form
|
||||||
|
- CLEANUP: usuniete legacy `autoload/admin/controls/class.ShopTransport.php`, `autoload/admin/view/class.ShopTransport.php`, `admin/templates/shop-transport/view-list.php`
|
||||||
|
- FIX: `transports-list.php` - zmienna `'viewModel'` zmieniona na `'list'` (zgodnie z `table-list.php` komponentem)
|
||||||
|
- Testy: **OK (300 tests, 895 assertions)**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## ver. 0.268 (2026-02-14) - ShopPaymentMethod + Apilo token keepalive
|
## ver. 0.268 (2026-02-14) - ShopPaymentMethod + Apilo token keepalive
|
||||||
|
|
||||||
- **ShopPaymentMethod** - migracja `/admin/shop_payment_method` na Domain + DI + nowe widoki
|
- **ShopPaymentMethod** - migracja `/admin/shop_payment_method` na Domain + DI + nowe widoki
|
||||||
|
|||||||
@@ -384,6 +384,37 @@ Metody platnosci sklepu (modul `/admin/shop_payment_method`).
|
|||||||
|
|
||||||
**Aktualizacja 2026-02-14 (ver. 0.268):** modul `/admin/shop_payment_method` korzysta z `Domain\PaymentMethod\PaymentMethodRepository` przez `admin\Controllers\ShopPaymentMethodController`. Usunieto legacy klasy `admin\controls\ShopPaymentMethod`, `admin\factory\ShopPaymentMethod`, `admin\view\ShopPaymentMethod` oraz widok `admin/templates/shop-payment-method/view-list.php`.
|
**Aktualizacja 2026-02-14 (ver. 0.268):** modul `/admin/shop_payment_method` korzysta z `Domain\PaymentMethod\PaymentMethodRepository` przez `admin\Controllers\ShopPaymentMethodController`. Usunieto legacy klasy `admin\controls\ShopPaymentMethod`, `admin\factory\ShopPaymentMethod`, `admin\view\ShopPaymentMethod` oraz widok `admin/templates/shop-payment-method/view-list.php`.
|
||||||
|
|
||||||
|
## pp_shop_transports
|
||||||
|
Rodzaje transportu sklepu (modul `/admin/shop_transport`).
|
||||||
|
|
||||||
|
| Kolumna | Opis |
|
||||||
|
|---------|------|
|
||||||
|
| id | PK |
|
||||||
|
| name | Nazwa (systemowa, readonly) |
|
||||||
|
| name_visible | Nazwa widoczna dla klienta |
|
||||||
|
| description | Opis metody transportu |
|
||||||
|
| status | Status: 1 = aktywny, 0 = nieaktywny |
|
||||||
|
| cost | Koszt dostawy (PLN) |
|
||||||
|
| max_wp | Maksymalna waga paczki (NULL = bez limitu) |
|
||||||
|
| default | Domyslna forma dostawy (0/1) |
|
||||||
|
| delivery_free | Czy obsluguje darmowa dostawe (0/1) |
|
||||||
|
| apilo_carrier_account_id | ID konta przewoznika w Apilo (NULL gdy brak mapowania) |
|
||||||
|
| o | Kolejnosc wyswietlania |
|
||||||
|
|
||||||
|
**Uzywane w:** `Domain\Transport\TransportRepository`, `admin\Controllers\ShopTransportController`, `front\factory\ShopTransport`, `admin\factory\ShopTransport`
|
||||||
|
|
||||||
|
## pp_shop_transport_payment_methods
|
||||||
|
Powiazanie metod transportu z metodami platnosci (tabela lacznikowa).
|
||||||
|
|
||||||
|
| Kolumna | Opis |
|
||||||
|
|---------|------|
|
||||||
|
| id_transport | FK do pp_shop_transports |
|
||||||
|
| id_payment_method | FK do pp_shop_payment_methods |
|
||||||
|
|
||||||
|
**Uzywane w:** `Domain\Transport\TransportRepository`, `Domain\PaymentMethod\PaymentMethodRepository::forTransport()`
|
||||||
|
|
||||||
|
**Aktualizacja 2026-02-14 (ver. 0.269):** modul `/admin/shop_transport` korzysta z `Domain\Transport\TransportRepository` przez `admin\Controllers\ShopTransportController`. Usunieto legacy klasy `admin\controls\ShopTransport`, `admin\view\ShopTransport` oraz widok `admin/templates/shop-transport/view-list.php`.
|
||||||
|
|
||||||
## pp_shop_apilo_settings
|
## pp_shop_apilo_settings
|
||||||
Ustawienia integracji Apilo (key-value).
|
Ustawienia integracji Apilo (key-value).
|
||||||
|
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ shopPRO/
|
|||||||
|
|
||||||
### Tabele checkout
|
### Tabele checkout
|
||||||
- `pp_shop_payment_methods` - metody platnosci sklepu (mapowanie `apilo_payment_type_id`)
|
- `pp_shop_payment_methods` - metody platnosci sklepu (mapowanie `apilo_payment_type_id`)
|
||||||
|
- `pp_shop_transports` - rodzaje transportu sklepu (mapowanie `apilo_carrier_account_id`)
|
||||||
- `pp_shop_transport_payment_methods` - powiazanie metod transportu i platnosci
|
- `pp_shop_transport_payment_methods` - powiazanie metod transportu i platnosci
|
||||||
|
|
||||||
Pelna dokumentacja tabel: `DATABASE_STRUCTURE.md`
|
Pelna dokumentacja tabel: `DATABASE_STRUCTURE.md`
|
||||||
@@ -215,6 +216,8 @@ autoload/
|
|||||||
│ │ └── CouponRepository.php
|
│ │ └── CouponRepository.php
|
||||||
│ ├── ShopStatus/
|
│ ├── ShopStatus/
|
||||||
│ │ └── ShopStatusRepository.php
|
│ │ └── ShopStatusRepository.php
|
||||||
|
│ ├── Transport/
|
||||||
|
│ │ └── TransportRepository.php
|
||||||
│ └── ...
|
│ └── ...
|
||||||
├── admin/
|
├── admin/
|
||||||
│ ├── Controllers/ # Nowe kontrolery (namespace \admin\Controllers\)
|
│ ├── Controllers/ # Nowe kontrolery (namespace \admin\Controllers\)
|
||||||
@@ -232,6 +235,13 @@ autoload/
|
|||||||
- Modul `/admin/shop_payment_method/*` dziala na nowych widokach (`payment-methods-list`, `payment-method-edit`).
|
- Modul `/admin/shop_payment_method/*` dziala na nowych widokach (`payment-methods-list`, `payment-method-edit`).
|
||||||
- Usunieto legacy: `autoload/admin/controls/class.ShopPaymentMethod.php`, `autoload/admin/factory/class.ShopPaymentMethod.php`, `autoload/admin/view/class.ShopPaymentMethod.php`, `admin/templates/shop-payment-method/view-list.php`.
|
- Usunieto legacy: `autoload/admin/controls/class.ShopPaymentMethod.php`, `autoload/admin/factory/class.ShopPaymentMethod.php`, `autoload/admin/view/class.ShopPaymentMethod.php`, `admin/templates/shop-payment-method/view-list.php`.
|
||||||
|
|
||||||
|
**Aktualizacja 2026-02-14 (ver. 0.269):**
|
||||||
|
- Dodano modul domenowy `Domain/Transport/TransportRepository.php`.
|
||||||
|
- Dodano kontroler DI `admin/Controllers/ShopTransportController.php`.
|
||||||
|
- Modul `/admin/shop_transport/*` dziala na nowych widokach (`transports-list`, `transport-edit`).
|
||||||
|
- Usunieto legacy: `autoload/admin/controls/class.ShopTransport.php`, `autoload/admin/view/class.ShopTransport.php`, `admin/templates/shop-transport/view-list.php`.
|
||||||
|
- `admin\factory\ShopTransport` i `front\factory\ShopTransport` przepiete na repozytorium.
|
||||||
|
|
||||||
### Routing admin (admin\Site::route())
|
### Routing admin (admin\Site::route())
|
||||||
1. Sprawdź mapę `$newControllers` → utwórz instancję z DI → wywołaj
|
1. Sprawdź mapę `$newControllers` → utwórz instancję z DI → wywołaj
|
||||||
2. Jeśli nowy kontroler nie istnieje (`class_exists()` = false) → fallback na `admin\controls\`
|
2. Jeśli nowy kontroler nie istnieje (`class_exists()` = false) → fallback na `admin\controls\`
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ grep -r "Product::getQuantity" .
|
|||||||
| 18 | ShopCoupon | 0.266 | listForAdmin, find, save, delete, categoriesTree |
|
| 18 | ShopCoupon | 0.266 | listForAdmin, find, save, delete, categoriesTree |
|
||||||
| 19 | ShopStatuses | 0.267 | listForAdmin, find, save, color picker |
|
| 19 | ShopStatuses | 0.267 | listForAdmin, find, save, color picker |
|
||||||
| 20 | ShopPaymentMethod | 0.268 | listForAdmin, find, save, allActive, mapowanie Apilo, DI kontroler |
|
| 20 | ShopPaymentMethod | 0.268 | listForAdmin, find, save, allActive, mapowanie Apilo, DI kontroler |
|
||||||
|
| 21 | ShopTransport | 0.269 | listForAdmin, find, save, allActive, allForAdmin, findActiveById, getTransportCost, lowestTransportPrice, getApiloCarrierAccountId, powiazanie z PaymentMethod, DI kontroler |
|
||||||
|
|
||||||
### Product - szczegolowy status
|
### Product - szczegolowy status
|
||||||
- ✅ getQuantity (ver. 0.238)
|
- ✅ getQuantity (ver. 0.238)
|
||||||
@@ -167,12 +168,12 @@ grep -r "Product::getQuantity" .
|
|||||||
|
|
||||||
## Kolejność refaktoryzacji (priorytet)
|
## Kolejność refaktoryzacji (priorytet)
|
||||||
|
|
||||||
1-20: ✅ Cache, Product, Banner, Settings, Dictionaries, ProductArchive, Filemanager, Users, Pages, Integrations, ShopPromotion, ShopCoupon, ShopStatuses, ShopPaymentMethod
|
1-21: ✅ Cache, Product, Banner, Settings, Dictionaries, ProductArchive, Filemanager, Users, Pages, Integrations, ShopPromotion, ShopCoupon, ShopStatuses, ShopPaymentMethod, ShopTransport
|
||||||
|
|
||||||
Nastepne:
|
Nastepne:
|
||||||
21. **Order**
|
22. **Order**
|
||||||
22. **Category**
|
23. **Category**
|
||||||
23. **ShopAttribute**
|
24. **ShopAttribute**
|
||||||
|
|
||||||
## Form Edit System
|
## Form Edit System
|
||||||
|
|
||||||
@@ -269,7 +270,7 @@ tests/
|
|||||||
│ └── UsersControllerTest.php
|
│ └── UsersControllerTest.php
|
||||||
└── Integration/
|
└── Integration/
|
||||||
```
|
```
|
||||||
**Łącznie: 280 testów, 828 asercji**
|
**Łącznie: 300 testów, 895 asercji**
|
||||||
|
|
||||||
Pelna dokumentacja testow: `TESTING.md`
|
Pelna dokumentacja testow: `TESTING.md`
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ Alternatywnie (Git Bash):
|
|||||||
Ostatnio zweryfikowano: 2026-02-14
|
Ostatnio zweryfikowano: 2026-02-14
|
||||||
|
|
||||||
```text
|
```text
|
||||||
OK (280 tests, 828 assertions)
|
OK (300 tests, 895 assertions)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Struktura testow
|
## Struktura testow
|
||||||
@@ -57,6 +57,7 @@ tests/
|
|||||||
| | |-- Promotion/PromotionRepositoryTest.php
|
| | |-- Promotion/PromotionRepositoryTest.php
|
||||||
| | |-- Settings/SettingsRepositoryTest.php
|
| | |-- Settings/SettingsRepositoryTest.php
|
||||||
| | |-- ShopStatus/ShopStatusRepositoryTest.php
|
| | |-- ShopStatus/ShopStatusRepositoryTest.php
|
||||||
|
| | |-- Transport/TransportRepositoryTest.php
|
||||||
| | `-- User/UserRepositoryTest.php
|
| | `-- User/UserRepositoryTest.php
|
||||||
| `-- admin/
|
| `-- admin/
|
||||||
| `-- Controllers/
|
| `-- Controllers/
|
||||||
@@ -69,6 +70,7 @@ tests/
|
|||||||
| |-- ShopPaymentMethodControllerTest.php
|
| |-- ShopPaymentMethodControllerTest.php
|
||||||
| |-- ShopPromotionControllerTest.php
|
| |-- ShopPromotionControllerTest.php
|
||||||
| |-- ShopStatusesControllerTest.php
|
| |-- ShopStatusesControllerTest.php
|
||||||
|
| |-- ShopTransportControllerTest.php
|
||||||
| `-- UsersControllerTest.php
|
| `-- UsersControllerTest.php
|
||||||
`-- Integration/
|
`-- Integration/
|
||||||
```
|
```
|
||||||
@@ -351,3 +353,25 @@ OK (254 tests, 736 assertions)
|
|||||||
Nowe testy dodane 2026-02-14:
|
Nowe testy dodane 2026-02-14:
|
||||||
- `tests/Unit/Domain/ShopStatus/ShopStatusRepositoryTest.php` (9 testow: find z ID=0, find null apilo, save update, save z ID=0, empty apilo sets null, reject negative ID, getApiloStatusId, getByIntegrationStatusId, allStatuses, whitelist sortowania)
|
- `tests/Unit/Domain/ShopStatus/ShopStatusRepositoryTest.php` (9 testow: find z ID=0, find null apilo, save update, save z ID=0, empty apilo sets null, reject negative ID, getApiloStatusId, getByIntegrationStatusId, allStatuses, whitelist sortowania)
|
||||||
- `tests/Unit/admin/Controllers/ShopStatusesControllerTest.php` (5 testow: kontrakty metod, brak aliasow legacy, return types, DI konstruktora)
|
- `tests/Unit/admin/Controllers/ShopStatusesControllerTest.php` (5 testow: kontrakty metod, brak aliasow legacy, return types, DI konstruktora)
|
||||||
|
|
||||||
|
## Aktualizacja suite (ShopPaymentMethod refactor, ver. 0.268)
|
||||||
|
Ostatnio zweryfikowano: 2026-02-14
|
||||||
|
|
||||||
|
```text
|
||||||
|
OK (280 tests, 828 assertions)
|
||||||
|
```
|
||||||
|
|
||||||
|
Nowe testy dodane 2026-02-14:
|
||||||
|
- `tests/Unit/Domain/PaymentMethod/PaymentMethodRepositoryTest.php` (14 testow: find invalid/null/normalize, save update/null/non-numeric apilo, listForAdmin whitelist, allActive, allForAdmin, findActiveById, isActive, getApiloPaymentTypeId, forTransport)
|
||||||
|
- `tests/Unit/admin/Controllers/ShopPaymentMethodControllerTest.php` (5 testow: kontrakty metod, brak aliasow legacy, return types, DI konstruktora)
|
||||||
|
|
||||||
|
## Aktualizacja suite (ShopTransport refactor, ver. 0.269)
|
||||||
|
Ostatnio zweryfikowano: 2026-02-14
|
||||||
|
|
||||||
|
```text
|
||||||
|
OK (300 tests, 895 assertions)
|
||||||
|
```
|
||||||
|
|
||||||
|
Nowe testy dodane 2026-02-14:
|
||||||
|
- `tests/Unit/Domain/Transport/TransportRepositoryTest.php` (14 testow: find invalid/null/normalize/nullables, save insert/update/failure/default reset/switch normalization, listForAdmin whitelist, allActive, getApiloCarrierAccountId, getTransportCost, allForAdmin)
|
||||||
|
- `tests/Unit/admin/Controllers/ShopTransportControllerTest.php` (5 testow: kontrakty metod, brak aliasow legacy, return types, DI konstruktora z 2 repo)
|
||||||
|
|||||||
334
tests/Unit/Domain/Transport/TransportRepositoryTest.php
Normal file
334
tests/Unit/Domain/Transport/TransportRepositoryTest.php
Normal file
@@ -0,0 +1,334 @@
|
|||||||
|
<?php
|
||||||
|
namespace Tests\Unit\Domain\Transport;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Domain\Transport\TransportRepository;
|
||||||
|
|
||||||
|
class TransportRepositoryTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testFindReturnsNullForInvalidId(): void
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
$mockDb->expects($this->never())->method('get');
|
||||||
|
|
||||||
|
$repository = new TransportRepository($mockDb);
|
||||||
|
$this->assertNull($repository->find(0));
|
||||||
|
$this->assertNull($repository->find(-1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFindReturnsNullWhenNotFound(): void
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
$mockDb->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with('pp_shop_transports', '*', ['id' => 5])
|
||||||
|
->willReturn(null);
|
||||||
|
|
||||||
|
$repository = new TransportRepository($mockDb);
|
||||||
|
$this->assertNull($repository->find(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFindNormalizesDataAndIncludesPaymentMethods(): void
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
$mockDb->expects($this->once())
|
||||||
|
->method('get')
|
||||||
|
->with('pp_shop_transports', '*', ['id' => 3])
|
||||||
|
->willReturn([
|
||||||
|
'id' => '3',
|
||||||
|
'name' => 'Kurier DPD',
|
||||||
|
'name_visible' => 'DPD',
|
||||||
|
'description' => 'Opis',
|
||||||
|
'status' => '1',
|
||||||
|
'cost' => '15.99',
|
||||||
|
'max_wp' => '30',
|
||||||
|
'default' => '0',
|
||||||
|
'delivery_free' => '1',
|
||||||
|
'apilo_carrier_account_id' => '42',
|
||||||
|
'o' => '2',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$mockDb->expects($this->once())
|
||||||
|
->method('select')
|
||||||
|
->with('pp_shop_transport_payment_methods', 'id_payment_method', ['id_transport' => 3])
|
||||||
|
->willReturn([1, 3, 5]);
|
||||||
|
|
||||||
|
$repository = new TransportRepository($mockDb);
|
||||||
|
$result = $repository->find(3);
|
||||||
|
|
||||||
|
$this->assertIsArray($result);
|
||||||
|
$this->assertSame(3, $result['id']);
|
||||||
|
$this->assertSame('Kurier DPD', $result['name']);
|
||||||
|
$this->assertSame(1, $result['status']);
|
||||||
|
$this->assertSame(15.99, $result['cost']);
|
||||||
|
$this->assertSame(30, $result['max_wp']);
|
||||||
|
$this->assertSame(0, $result['default']);
|
||||||
|
$this->assertSame(1, $result['delivery_free']);
|
||||||
|
$this->assertSame(42, $result['apilo_carrier_account_id']);
|
||||||
|
$this->assertSame(2, $result['o']);
|
||||||
|
$this->assertSame([1, 3, 5], $result['payment_methods']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFindHandlesNullMaxWpAndApiloId(): void
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
$mockDb->method('get')
|
||||||
|
->willReturn([
|
||||||
|
'id' => '1',
|
||||||
|
'name' => 'Test',
|
||||||
|
'status' => '0',
|
||||||
|
'cost' => '0',
|
||||||
|
'max_wp' => null,
|
||||||
|
'default' => '0',
|
||||||
|
'delivery_free' => '0',
|
||||||
|
'apilo_carrier_account_id' => null,
|
||||||
|
'o' => '0',
|
||||||
|
]);
|
||||||
|
$mockDb->method('select')->willReturn([]);
|
||||||
|
|
||||||
|
$repository = new TransportRepository($mockDb);
|
||||||
|
$result = $repository->find(1);
|
||||||
|
|
||||||
|
$this->assertNull($result['max_wp']);
|
||||||
|
$this->assertNull($result['apilo_carrier_account_id']);
|
||||||
|
$this->assertSame([], $result['payment_methods']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSaveInsertReturnsNewId(): void
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
|
||||||
|
$mockDb->expects($this->once())
|
||||||
|
->method('insert')
|
||||||
|
->with('pp_shop_transports', $this->callback(function ($data) {
|
||||||
|
return $data['name'] === 'Nowy transport'
|
||||||
|
&& $data['status'] === 1
|
||||||
|
&& $data['cost'] === 10.5;
|
||||||
|
}));
|
||||||
|
|
||||||
|
$mockDb->expects($this->once())
|
||||||
|
->method('id')
|
||||||
|
->willReturn('7');
|
||||||
|
|
||||||
|
$repository = new TransportRepository($mockDb);
|
||||||
|
$id = $repository->save([
|
||||||
|
'id' => 0,
|
||||||
|
'name' => 'Nowy transport',
|
||||||
|
'status' => 'on',
|
||||||
|
'cost' => '10.5',
|
||||||
|
'default' => '0',
|
||||||
|
'delivery_free' => 0,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(7, $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSaveUpdateReturnsExistingId(): void
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
|
||||||
|
$mockDb->expects($this->once())
|
||||||
|
->method('update')
|
||||||
|
->with('pp_shop_transports', $this->isType('array'), ['id' => 4]);
|
||||||
|
|
||||||
|
$mockDb->expects($this->once())
|
||||||
|
->method('delete')
|
||||||
|
->with('pp_shop_transport_payment_methods', ['id_transport' => 4]);
|
||||||
|
|
||||||
|
$repository = new TransportRepository($mockDb);
|
||||||
|
$id = $repository->save([
|
||||||
|
'id' => 4,
|
||||||
|
'name' => 'Update',
|
||||||
|
'status' => 1,
|
||||||
|
'cost' => 5.0,
|
||||||
|
'default' => 0,
|
||||||
|
'delivery_free' => 'on',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(4, $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSaveInsertReturnsNullOnFailure(): void
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
$mockDb->method('insert');
|
||||||
|
$mockDb->method('id')->willReturn(null);
|
||||||
|
|
||||||
|
$repository = new TransportRepository($mockDb);
|
||||||
|
$this->assertNull($repository->save([
|
||||||
|
'id' => 0,
|
||||||
|
'name' => 'Fail',
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSaveResetsDefaultWhenSettingNew(): void
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
$updateCalls = [];
|
||||||
|
|
||||||
|
$mockDb->method('update')
|
||||||
|
->willReturnCallback(function ($table, $data, $where = null) use (&$updateCalls) {
|
||||||
|
$updateCalls[] = ['table' => $table, 'data' => $data, 'where' => $where];
|
||||||
|
});
|
||||||
|
|
||||||
|
$mockDb->method('delete');
|
||||||
|
|
||||||
|
$repository = new TransportRepository($mockDb);
|
||||||
|
$repository->save([
|
||||||
|
'id' => 2,
|
||||||
|
'name' => 'X',
|
||||||
|
'default' => 'on',
|
||||||
|
'status' => 0,
|
||||||
|
'delivery_free' => 0,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertCount(2, $updateCalls);
|
||||||
|
$this->assertSame(['default' => 0], $updateCalls[0]['data']);
|
||||||
|
$this->assertNull($updateCalls[0]['where']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSaveSwitchValuesNormalization(): void
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
$savedData = null;
|
||||||
|
|
||||||
|
$mockDb->method('update')
|
||||||
|
->willReturnCallback(function ($table, $data) use (&$savedData) {
|
||||||
|
$savedData = $data;
|
||||||
|
});
|
||||||
|
$mockDb->method('delete');
|
||||||
|
|
||||||
|
$repository = new TransportRepository($mockDb);
|
||||||
|
$repository->save([
|
||||||
|
'id' => 1,
|
||||||
|
'name' => 'T',
|
||||||
|
'status' => 'on',
|
||||||
|
'default' => 'true',
|
||||||
|
'delivery_free' => '1',
|
||||||
|
'cost' => 0,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertSame(1, $savedData['status']);
|
||||||
|
$this->assertSame(1, $savedData['default']);
|
||||||
|
$this->assertSame(1, $savedData['delivery_free']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testListForAdminWhitelistsSortColumn(): void
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
$queries = [];
|
||||||
|
|
||||||
|
$mockDb->method('query')
|
||||||
|
->willReturnCallback(function ($sql, $params = []) use (&$queries) {
|
||||||
|
$queries[] = ['sql' => $sql, 'params' => $params];
|
||||||
|
|
||||||
|
if (strpos($sql, 'COUNT(0)') !== false) {
|
||||||
|
return new class {
|
||||||
|
public function fetchAll() { return [[1]]; }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return new class {
|
||||||
|
public function fetchAll() {
|
||||||
|
return [[
|
||||||
|
'id' => 1, 'name' => 'DPD', 'name_visible' => '',
|
||||||
|
'description' => '', 'status' => 1, 'cost' => 10.0,
|
||||||
|
'max_wp' => null, 'default' => 0,
|
||||||
|
'apilo_carrier_account_id' => null, 'delivery_free' => 0, 'o' => 1,
|
||||||
|
]];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
$repository = new TransportRepository($mockDb);
|
||||||
|
$result = $repository->listForAdmin(
|
||||||
|
[],
|
||||||
|
'name DESC; DROP TABLE pp_shop_transports; --',
|
||||||
|
'DESC; DELETE FROM pp_users; --',
|
||||||
|
1,
|
||||||
|
999
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertCount(2, $queries);
|
||||||
|
$dataSql = $queries[1]['sql'];
|
||||||
|
|
||||||
|
$this->assertMatchesRegularExpression('/ORDER BY\s+st\.name\s+ASC,\s+st\.id\s+ASC/i', $dataSql);
|
||||||
|
$this->assertStringNotContainsString('DROP TABLE', $dataSql);
|
||||||
|
$this->assertMatchesRegularExpression('/LIMIT\s+100\s+OFFSET\s+0/i', $dataSql);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAllActiveReturnsNormalizedRows(): void
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
$mockDb->expects($this->once())
|
||||||
|
->method('select')
|
||||||
|
->willReturn([
|
||||||
|
[
|
||||||
|
'id' => '2', 'name' => 'InPost', 'status' => '1',
|
||||||
|
'cost' => '9.99', 'max_wp' => '25', 'default' => '1',
|
||||||
|
'delivery_free' => '0', 'apilo_carrier_account_id' => null, 'o' => '1',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$repository = new TransportRepository($mockDb);
|
||||||
|
$rows = $repository->allActive();
|
||||||
|
|
||||||
|
$this->assertCount(1, $rows);
|
||||||
|
$this->assertSame(2, $rows[0]['id']);
|
||||||
|
$this->assertSame(9.99, $rows[0]['cost']);
|
||||||
|
$this->assertSame(1, $rows[0]['status']);
|
||||||
|
$this->assertSame(1, $rows[0]['default']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetApiloCarrierAccountIdReturnsNullForInvalidId(): void
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
$mockDb->expects($this->never())->method('get');
|
||||||
|
|
||||||
|
$repository = new TransportRepository($mockDb);
|
||||||
|
$this->assertNull($repository->getApiloCarrierAccountId(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetApiloCarrierAccountIdReturnsIntOrNull(): void
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
$mockDb->expects($this->exactly(2))
|
||||||
|
->method('get')
|
||||||
|
->willReturnOnConsecutiveCalls(null, '55');
|
||||||
|
|
||||||
|
$repository = new TransportRepository($mockDb);
|
||||||
|
$this->assertNull($repository->getApiloCarrierAccountId(1));
|
||||||
|
$this->assertSame(55, $repository->getApiloCarrierAccountId(2));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetTransportCostReturnsFloatOrNull(): void
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
$mockDb->expects($this->exactly(2))
|
||||||
|
->method('get')
|
||||||
|
->willReturnOnConsecutiveCalls(null, '12.50');
|
||||||
|
|
||||||
|
$repository = new TransportRepository($mockDb);
|
||||||
|
$this->assertNull($repository->getTransportCost(99));
|
||||||
|
$this->assertSame(12.5, $repository->getTransportCost(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAllForAdminReturnsAllTransports(): void
|
||||||
|
{
|
||||||
|
$mockDb = $this->createMock(\medoo::class);
|
||||||
|
$mockDb->expects($this->once())
|
||||||
|
->method('select')
|
||||||
|
->willReturn([
|
||||||
|
['id' => '1', 'name' => 'A', 'status' => '1', 'cost' => '5', 'max_wp' => null, 'default' => '0', 'delivery_free' => '0', 'apilo_carrier_account_id' => null, 'o' => '1'],
|
||||||
|
['id' => '2', 'name' => 'B', 'status' => '0', 'cost' => '10', 'max_wp' => '50', 'default' => '1', 'delivery_free' => '1', 'apilo_carrier_account_id' => '3', 'o' => '2'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$repository = new TransportRepository($mockDb);
|
||||||
|
$rows = $repository->allForAdmin();
|
||||||
|
|
||||||
|
$this->assertCount(2, $rows);
|
||||||
|
$this->assertSame(0, $rows[1]['status']);
|
||||||
|
$this->assertSame(1, $rows[1]['default']);
|
||||||
|
$this->assertSame(50, $rows[1]['max_wp']);
|
||||||
|
}
|
||||||
|
}
|
||||||
67
tests/Unit/admin/Controllers/ShopTransportControllerTest.php
Normal file
67
tests/Unit/admin/Controllers/ShopTransportControllerTest.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
namespace Tests\Unit\admin\Controllers;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use admin\Controllers\ShopTransportController;
|
||||||
|
use Domain\Transport\TransportRepository;
|
||||||
|
use Domain\PaymentMethod\PaymentMethodRepository;
|
||||||
|
|
||||||
|
class ShopTransportControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
private $transportRepository;
|
||||||
|
private $paymentMethodRepository;
|
||||||
|
private $controller;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
$this->transportRepository = $this->createMock(TransportRepository::class);
|
||||||
|
$this->paymentMethodRepository = $this->createMock(PaymentMethodRepository::class);
|
||||||
|
$this->controller = new ShopTransportController(
|
||||||
|
$this->transportRepository,
|
||||||
|
$this->paymentMethodRepository
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConstructorAcceptsRepositories(): void
|
||||||
|
{
|
||||||
|
$controller = new ShopTransportController(
|
||||||
|
$this->transportRepository,
|
||||||
|
$this->paymentMethodRepository
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(ShopTransportController::class, $controller);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHasMainActionMethods(): void
|
||||||
|
{
|
||||||
|
$this->assertTrue(method_exists($this->controller, 'list'));
|
||||||
|
$this->assertTrue(method_exists($this->controller, 'edit'));
|
||||||
|
$this->assertTrue(method_exists($this->controller, 'save'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testHasNoLegacyAliasMethods(): void
|
||||||
|
{
|
||||||
|
$this->assertFalse(method_exists($this->controller, 'view_list'));
|
||||||
|
$this->assertFalse(method_exists($this->controller, 'transport_edit'));
|
||||||
|
$this->assertFalse(method_exists($this->controller, 'transport_save'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testActionMethodReturnTypes(): void
|
||||||
|
{
|
||||||
|
$reflection = new \ReflectionClass($this->controller);
|
||||||
|
|
||||||
|
$this->assertEquals('string', (string)$reflection->getMethod('list')->getReturnType());
|
||||||
|
$this->assertEquals('string', (string)$reflection->getMethod('edit')->getReturnType());
|
||||||
|
$this->assertEquals('void', (string)$reflection->getMethod('save')->getReturnType());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testConstructorRequiresBothRepositories(): void
|
||||||
|
{
|
||||||
|
$reflection = new \ReflectionClass(ShopTransportController::class);
|
||||||
|
$constructor = $reflection->getConstructor();
|
||||||
|
$params = $constructor->getParameters();
|
||||||
|
|
||||||
|
$this->assertCount(2, $params);
|
||||||
|
$this->assertEquals('Domain\Transport\TransportRepository', $params[0]->getType()->getName());
|
||||||
|
$this->assertEquals('Domain\PaymentMethod\PaymentMethodRepository', $params[1]->getType()->getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user