Refactor code structure for improved readability and maintainability

This commit is contained in:
2026-02-21 21:48:03 +01:00
parent 29970ba4ee
commit 846bad0085
21 changed files with 172 additions and 150 deletions

BIN
templates/.DS_Store vendored

Binary file not shown.

View File

@@ -8,7 +8,7 @@
$basket = \Shared\Helpers\Helpers::get_session( 'basket' );
$coupon = \Shared\Helpers\Helpers::get_session( 'coupon' );
$transport_cost = ( new \Domain\Transport\TransportRepository( $GLOBALS['mdb'] ) )->transportCostCached( \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' ) );
$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;
?>
@@ -41,4 +41,4 @@
</div>
</div>
<? endif;?>
<? endforeach; endif;?>
<? endforeach; endif;?>

View File

@@ -1,9 +1,22 @@
<div id="category-subcategory-tiles">
<ul class="category-subcategory-tiles">
<?php foreach ( $this -> categories as $category ): ?>
<?php
global $lang_id;
$categoryRepo = new \Domain\Category\CategoryRepository( $GLOBALS['mdb'] );
foreach ( $this -> categories as $category ):
$title = $category['language']['title'] ?? ( $category['title'] ?? '' );
$url = '#';
if ( !empty( $category['id'] ) ) {
$url = $categoryRepo->categoryUrl( (int)$category['id'], (string)$lang_id );
} elseif ( !empty( $category['language']['seo_link'] ) ) {
$url = '/' . ltrim( (string)$category['language']['seo_link'], '/' );
} elseif ( !empty( $category['seo_link'] ) ) {
$url = '/' . ltrim( (string)$category['seo_link'], '/' );
}
?>
<li class="category-subcategory-tile">
<a href="/<?= $category['seo_link']; ?>"><?= $category['title']; ?></a>
<a href="<?= $url; ?>"><?= $title; ?></a>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>

View File

@@ -16,7 +16,7 @@ endif;
if ( $this -> category['view_subcategories'] ):
echo \Shared\Tpl\Tpl::view( 'shop-category/_partials/category-subcategory-tiles', [
'categories' => ( new \Domain\Category\CategoryRepository( $GLOBALS['mdb'] ) )->subcategoriesLangCached( (int)$this -> category['id'] ),
'categories' => ( new \Domain\Category\CategoryRepository( $GLOBALS['mdb'] ) )->categoriesTree( $lang_id, (int)$this -> category['id'] ),
] );
endif;
@@ -36,4 +36,4 @@ if ( $this -> category_description ):
'category' => $this -> category
] );
endif;
?>
?>

View File

@@ -106,23 +106,26 @@ echo $this -> settings['newsletter_header'];
</td>
<td style="text-align: right; white-space: nowrap; padding: 0 5px;">
<?
echo \Shared\Helpers\Helpers::decimal( $position['price_brutto_promo'] ) . ' zł';
if ( $position['price_brutto_promo'] and $position['price_brutto_promo'] < $position['price_brutto'])
echo '<u style="font-size: 15px; font-weight: 400; color: #c3c3c3; margin-left: 5px; text-decoration: line-through;">' . \Shared\Helpers\Helpers::decimal( $position['price_brutto'] ) . ' zł</u>';
if ( $position['price_brutto_promo'] and $position['price_brutto_promo'] < $position['price_brutto'] )
$discount += \Shared\Helpers\Helpers::normalize_decimal( ( $position['price_brutto'] - $position['price_brutto_promo'] ) * $position['quantity'] );
$_promo = round( (float)$position['price_brutto_promo'], 2 );
$_base = round( (float)$position['price_brutto'], 2 );
if ( $_promo > 0 and $_promo < $_base ) {
echo \Shared\Helpers\Helpers::decimal( $_promo ) . ' zł';
echo '<u style="font-size: 15px; font-weight: 400; color: #c3c3c3; margin-left: 5px; text-decoration: line-through;">' . \Shared\Helpers\Helpers::decimal( $_base ) . ' zł</u>';
$discount += \Shared\Helpers\Helpers::normalize_decimal( ( $_base - $_promo ) * $position['quantity'] );
} else {
echo \Shared\Helpers\Helpers::decimal( $_base ) . ' zł';
}
$_effective = ( $_promo > 0 and $_promo < $_base ) ? $_promo : $_base;
?>
</td>
<td style="text-align: right; white-space: nowrap; padding: 0 5px;">
<?= $position['quantity'];?>
</td>
<td style="text-align: right; white-space: nowrap; padding: 0 5px;">
<?= \Shared\Helpers\Helpers::decimal( \Shared\Helpers\Helpers::normalize_decimal( $position['price_brutto_promo'] * $position['quantity'] ) );?> zł
<?= \Shared\Helpers\Helpers::decimal( \Shared\Helpers\Helpers::normalize_decimal( $_effective * $position['quantity'] ) );?> zł
</td>
</tr>
<? $summary += \Shared\Helpers\Helpers::normalize_decimal( $position['price_brutto'] * $position['quantity'] );?>
<? $summary += \Shared\Helpers\Helpers::normalize_decimal( $_base * $position['quantity'] );?>
<? $quantity += $position['quantity'];?>
<? endforeach; endif;?>
<tr>

View File

@@ -1,4 +1,4 @@
<? global $config; $this -> settings['ssl'] ? $base = 'https' : $base = 'http'; $paymentRepo = new \Domain\PaymentMethod\PaymentMethodRepository( $GLOBALS['mdb'] );?>
<? global $config; $this -> settings['ssl'] ? $base = 'https' : $base = 'http'; $base_secure = 'https'; $paymentRepo = new \Domain\PaymentMethod\PaymentMethodRepository( $GLOBALS['mdb'] );?>
<div class="order-summary">
<div class="box-title">
<?= ucfirst( \Shared\Helpers\Helpers::lang( 'szczegoly-zamowienia' ) );?>: <?= $this -> order['number'];?>
@@ -119,9 +119,9 @@
$url .= '&email=' . urlencode( $this -> order['client_email'] );
$url .= '&nazwisko=' . urlencode( $this -> order['client_name'] . ' ' . $this -> order['client_surname'] );
$url .= '&crc=' . $this -> order['hash'];
$url .= '&result_url=' . urlencode( $base . "://" . $_SERVER['SERVER_NAME'] . '/tpay-status' );
$url .= '&return_url=' . urlencode( $base . "://" . $_SERVER['SERVER_NAME'] . '/potwierdzenie-platnosci/' . $this -> order['hash'] );
$url .= '&return_error_url=' . urlencode( $base . "://" . $_SERVER['SERVER_NAME'] . '/zamowienie/' . $this -> order['hash'] );
$url .= '&result_url=' . urlencode( $base_secure . "://" . $_SERVER['SERVER_NAME'] . '/tpay-status' );
$url .= '&return_url=' . urlencode( $base_secure . "://" . $_SERVER['SERVER_NAME'] . '/potwierdzenie-platnosci/' . $this -> order['hash'] );
$url .= '&return_error_url=' . urlencode( $base_secure . "://" . $_SERVER['SERVER_NAME'] . '/zamowienie/' . $this -> order['hash'] );
$url .= '&md5sum=' . md5( $id . '&' . str_replace( ',', '.', round( $this -> order['summary'], 2 ) ) . '&' . $this -> order['hash'] . '&' . $code );
?>
<button type="button" onclick="document.location.href='<?= $url;?>'" class="btn btn-success"><?= \Shared\Helpers\Helpers::lang( 'zaplac-online' );?> <?= \Shared\Helpers\Helpers::decimal( $this -> order['summary'] );?> zł</b></button>
@@ -189,4 +189,4 @@
<? unset( $_SESSION['google-analytics-purchase'] );?>
<? endif;?>
});
</script>
</script>

View File

@@ -65,20 +65,23 @@
<div class="prices">
<div class="price">
<?
echo \Shared\Helpers\Helpers::decimal( $product['price_brutto_promo'] ) . ' zł';
if ( $product['price_brutto_promo'] and $product['price_brutto_promo'] < $product['price_brutto'] )
echo '<u>' . \Shared\Helpers\Helpers::decimal( $product['price_brutto'] ) . ' zł</u>';
if ( $product['price_brutto_promo'] and $product['price_brutto_promo'] < $product['price_brutto'] )
$discount += \Shared\Helpers\Helpers::normalize_decimal( ( $product['price_brutto'] - $product['price_brutto_promo'] ) * $product['quantity'] );
$_promo = round( (float)$product['price_brutto_promo'], 2 );
$_base = round( (float)$product['price_brutto'], 2 );
if ( $_promo > 0 and $_promo < $_base ) {
echo \Shared\Helpers\Helpers::decimal( $_promo ) . ' zł';
echo '<u>' . \Shared\Helpers\Helpers::decimal( $_base ) . ' zł</u>';
$discount += \Shared\Helpers\Helpers::normalize_decimal( ( $_base - $_promo ) * $product['quantity'] );
} else {
echo \Shared\Helpers\Helpers::decimal( $_base ) . ' zł';
}
$effective_price = ( $_promo > 0 and $_promo < $_base ) ? $_promo : $_base;
?>
<span>x <?= $product['quantity'];?></span>
<?= \Shared\Helpers\Helpers::decimal( \Shared\Helpers\Helpers::normalize_decimal( $product['price_brutto'] * $product['quantity'] ) );?> zł
<?= \Shared\Helpers\Helpers::decimal( \Shared\Helpers\Helpers::normalize_decimal( $effective_price * $product['quantity'] ) );?> zł
</div>
</div>
</div>
<? $summary += \Shared\Helpers\Helpers::normalize_decimal( $product['price_brutto'] * $product['quantity'] );?>
<? $summary += \Shared\Helpers\Helpers::normalize_decimal( $_base * $product['quantity'] );?>
<? endforeach;?>
<div class="basket-summary">
Wartość koszyka <span><?= \Shared\Helpers\Helpers::decimal( $summary );?> zł</span>

View File

@@ -1,23 +1,10 @@
<? if ( is_array( $this -> custom_fields ) ) : ?>
<? foreach ( $this -> custom_fields as $custom_field ): ?>
<? if ( $custom_field['type'] == 'text' ) : ?>
<div class="custom-field">
<div class="_name">
<?= $custom_field['name'];?><? if ( !empty( $custom_field['is_required'] ) ): ?>*<? endif; ?>:
</div>
<div class="_input">
<input type="text" class="form-control" name="custom_field[<?= $custom_field['id_additional_field'];?>]" field_name="<?= $custom_field['name'];?>" value="" <? if ( !empty( $custom_field['is_required'] ) ): ?>required<? endif; ?>>
</div>
</div>
<? elseif ( $custom_field['type'] == 'image' ) : ?>
<div class="custom-field">
<div class="_name">
<?= $custom_field['name'];?><? if ( !empty( $custom_field['is_required'] ) ): ?>*<? endif; ?>:
</div>
<div class="_input">
<input type="file" class="form-control-file" name="custom_field[<?= $custom_field['id_additional_field'];?>]" field_name="<?= $custom_field['name'];?>" src="" alt="" <? if ( !empty( $custom_field['is_required'] ) ): ?>required<? endif; ?>>
</div>
</div>
<? endif; ?>
<? endforeach; ?>
<? endif;?>
<? if ( is_array( $this -> custom_fields ) ): foreach ( $this -> custom_fields as $custom_field ):?>
<div class="custom-field">
<div class="_name">
<?= $custom_field['name'];?><? if ( !empty( $custom_field['is_required'] ) ): ?>*<? endif; ?>:
</div>
<div class="_input">
<input type="text" class="form-control" name="custom_field[<?= $custom_field['id_additional_field'];?>]" field_name="<?= $custom_field['name'];?>" value="" <? if ( !empty( $custom_field['is_required'] ) ): ?>required<? endif; ?>>
</div>
</div>
<? endforeach; endif;?>

View File

@@ -260,11 +260,13 @@
<a href="javascript:history.go(-1)" class="btn btn-success history-back"><?= \Shared\Helpers\Helpers::lang( 'wstecz' );?></a>
</div>
<link class="footer" rel="stylesheet" type="text/css" href="/libraries/fancybox3/css/core.css">
<link class="footer" rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css">
<link class="footer" rel="stylesheet" type="text/css" href="/plugins/OwlCarousel/owl.carousel.css">
<link class="footer" rel="stylesheet" type="text/css" href="/plugins/OwlCarousel/owl.theme.default.css">
<script class="footer" type="text/javascript" src="/libraries/fancybox3/js/core.js"></script>
<script class="footer" type="text/javascript" src="/libraries/fancybox3/js/guestures.js"></script>
<script class="footer" type="text/javascript" src="/libraries/fancybox3/js/wheel.js"></script>
<script class="footer" type="text/javascript" src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script>
<script class="footer" type="text/javascript" src="/plugins/OwlCarousel/owl.carousel.js"></script>
<script type="text/javascript">
$(function(){