Fix: personalizacja produktu w koszyku

This commit is contained in:
Roman Pyrih
2026-05-12 14:10:26 +02:00
parent 56c982f99e
commit d8c793b84c
6 changed files with 3800 additions and 3645 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -11,10 +11,8 @@ $cGrayLight: #eceff1;
$cComment: #c3c3c3; $cComment: #c3c3c3;
$cWhite: #fff; $cWhite: #fff;
$fJosefin: 'Josefin Sans', $fJosefin: 'Josefin Sans', sans-serif;
sans-serif; $font_nunito: 'Nunito Sans', sans-serif;
$font_nunito: 'Nunito Sans',
sans-serif;
@import '_mixins'; @import '_mixins';
@keyframes fade_in_show { @keyframes fade_in_show {
@@ -753,7 +751,6 @@ input:-webkit-autofill:active {
@include respond-above(xxl) { @include respond-above(xxl) {
.product-mini { .product-mini {
&:nth-child(11), &:nth-child(11),
&:nth-child(12) { &:nth-child(12) {
display: none; display: none;
@@ -2224,10 +2221,12 @@ ul.pager {
opacity: 1; opacity: 1;
-webkit-background-clip: text; -webkit-background-clip: text;
-webkit-text-fill-color: transparent; -webkit-text-fill-color: transparent;
background-image: linear-gradient(to right, background-image: linear-gradient(
to right,
#000, #000,
#000 50%, #000 50%,
rgba(0, 0, 0, 0.3) 50%); rgba(0, 0, 0, 0.3) 50%
);
background-size: 200% 100%; background-size: 200% 100%;
background-position: 100%; background-position: 100%;
transition: all 1.2s cubic-bezier(0.19, 1, 0.22, 1); transition: all 1.2s cubic-bezier(0.19, 1, 0.22, 1);
@@ -2303,7 +2302,6 @@ ul.pager {
.swiper { .swiper {
&:hover { &:hover {
.swiper-button-next, .swiper-button-next,
.swiper-button-prev { .swiper-button-prev {
opacity: 1; opacity: 1;
@@ -2719,6 +2717,60 @@ ul.pager {
} }
#transport-methods { #transport-methods {
.free-delivery-bar {
background: #3a3a3a;
border-radius: 8px;
padding: 15px 20px;
margin-top: 15px;
display: flex;
align-items: center;
gap: 15px;
color: #fff;
&.success {
background: #28a745;
}
&__icon {
font-size: 28px;
flex-shrink: 0;
}
&__content {
flex: 1;
}
&__text {
font-size: 14px;
font-weight: 600;
margin-bottom: 8px;
}
&__progress {
height: 8px;
background: #555;
border-radius: 4px;
overflow: hidden;
}
&__progress-fill {
height: 100%;
background: linear-gradient(90deg, #28a745, #5cb85c);
border-radius: 4px;
transition: width 0.3s ease;
}
&__remaining {
font-size: 12px;
margin-top: 5px;
color: #ccc;
strong {
color: #ff9800;
}
}
}
@include respond-below(sm) { @include respond-below(sm) {
width: 100%; width: 100%;
margin-bottom: 15px; margin-bottom: 15px;
@@ -3773,7 +3825,6 @@ ul.pager {
} }
.pager { .pager {
.first, .first,
.last { .last {
display: none; display: none;
@@ -4458,3 +4509,8 @@ div[class^='products-box-'] {
display: none !important; display: none !important;
} }
} }
.btn-save-custom-fields {
color: #fff !important;
margin-top: 20px;
}

View File

@@ -1,15 +1,55 @@
<? if ( $this -> custom_fields ): foreach ( $this -> custom_fields as $key => $val ):?> <? if ( $this -> custom_fields ) : ?>
<? if ( $key ):?> <pre style="display: none;">
<?php print_r($this); ?>
</pre>
<div class="custom-fields-display" data-product-code="<?= htmlspecialchars( $this->product_code ); ?>">
<? foreach ( $this -> custom_fields as $key => $val ) : ?>
<? $custom_field = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->findCustomFieldCached( $key ); ?>
<? $field_type = !empty( $custom_field['type'] ) ? $custom_field['type'] : 'text'; ?>
<? if ( $field_type == 'text' ) : ?>
<div class="custom-field"> <div class="custom-field">
<div class="_name"> <div class="_name">
<? <?= htmlspecialchars( $custom_field['name'] ) . ':'; ?>
$custom_field = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->findCustomFieldCached( $key );
echo $custom_field['name'] . ':';
?>
</div> </div>
<div class="_text"> <div class="_text">
<?= $val;?> <?= nl2br( htmlspecialchars( $val ) );?>
</div>
</div>
<? elseif ( $field_type == 'image' && !empty( $val ) ) : ?>
<div class="custom-field">
<div class="_name">
<?= htmlspecialchars( $custom_field['name'] ) . ':'; ?>
</div>
<div class="_image">
<img src="<?= htmlspecialchars( $val );?>" alt="<?= htmlspecialchars( $custom_field['name'] );?>">
</div>
</div>
<? endif; ?>
<? endforeach; ?>
<a href="#" class="btn btn-sm btn-default btn-edit-custom-fields">Edytuj personalizację</a>
</div>
<div class="custom-fields-edit" data-product-code="<?= htmlspecialchars( $this->product_code ); ?>" style="display: none;">
<? foreach ( $this -> custom_fields as $key => $val ) : ?>
<? $custom_field = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->findCustomFieldCached( $key ); ?>
<? $field_type = !empty( $custom_field['type'] ) ? $custom_field['type'] : 'text'; ?>
<? $is_required = !empty( $custom_field['is_required'] ) ? (int)$custom_field['is_required'] : 0; ?>
<div class="custom-field-edit-row" style="margin-bottom: 5px;">
<label>
<?= htmlspecialchars( $custom_field['name'] ); ?><?= $is_required ? ' <span style="color:red;">*</span>' : ''; ?>
</label>
<? if ( $field_type == 'text' ) : ?>
<input type="text" class="form-control form-control-sm" name="custom_field[<?= (int)$key; ?>]" value="<?= htmlspecialchars( $val ); ?>" <?= $is_required ? 'required' : ''; ?>>
<? elseif ( $field_type == 'image' ) : ?>
<input type="text" class="form-control form-control-sm" name="custom_field[<?= (int)$key; ?>]" value="<?= htmlspecialchars( $val ); ?>" placeholder="URL obrazka" <?= $is_required ? 'required' : ''; ?>>
<? endif; ?>
</div>
<? endforeach; ?>
<div style="margin-top: 5px;">
<a href="#" class="btn btn-sm btn-success btn-save-custom-fields">Zapisz</a>
<a href="#" class="btn btn-sm btn-default btn-cancel-custom-fields">Anuluj</a>
</div> </div>
</div> </div>
<? endif; ?> <? endif; ?>
<? endforeach; endif;?>

View File

@@ -57,7 +57,8 @@
<hr> <hr>
<? endif; ?> <? endif; ?>
<?= \Shared\Tpl\Tpl::view( 'shop-basket/_partials/product-custom-fields', [ <?= \Shared\Tpl\Tpl::view( 'shop-basket/_partials/product-custom-fields', [
'custom_fields' => $position['custom_fields'] 'custom_fields' => $position['custom_fields'],
'product_code' => $position_hash
] ); ?> ] ); ?>
<? if ( $product['additional_message'] ):?> <? if ( $product['additional_message'] ):?>
<div class="basket-product-message"> <div class="basket-product-message">

View File

@@ -511,4 +511,62 @@
console.warn('#orlen_point_id nie został znaleziony.'); console.warn('#orlen_point_id nie został znaleziony.');
} }
}); });
// edycja personalizacji produktu w koszyku
$(document).on('click', '.btn-edit-custom-fields', function(e) {
e.preventDefault();
var $display = $(this).closest('.custom-fields-display');
var productCode = $display.data('product-code');
$display.hide();
$display.siblings('.custom-fields-edit[data-product-code="' + productCode + '"]').show();
});
$(document).on('click', '.btn-cancel-custom-fields', function(e) {
e.preventDefault();
var $edit = $(this).closest('.custom-fields-edit');
var productCode = $edit.data('product-code');
$edit.hide();
$edit.siblings('.custom-fields-display[data-product-code="' + productCode + '"]').show();
});
$(document).on('click', '.btn-save-custom-fields', function(e) {
e.preventDefault();
var $edit = $(this).closest('.custom-fields-edit');
var productCode = $edit.data('product-code');
var valid = true;
$edit.find('input[required]').each(function() {
if ($.trim($(this).val()) === '') {
$(this).css('border-color', 'red');
valid = false;
} else {
$(this).css('border-color', '');
}
});
if (!valid) {
alert('Wypełnij wszystkie wymagane pola');
return;
}
var formData = { product_code: productCode };
$edit.find('input[name^="custom_field"]').each(function() {
formData[$(this).attr('name')] = $(this).val();
});
$.ajax({
type: 'POST',
cache: false,
url: '/shopBasket/basket_update_custom_fields',
data: formData,
success: function(response) {
var data = jQuery.parseJSON(response);
if (data.result === 'ok') {
location.reload();
} else {
alert(data.message || 'Wystąpił błąd');
}
}
});
});
</script> </script>