update
This commit is contained in:
@@ -45,7 +45,8 @@
|
||||
<hr>
|
||||
<? endif; ?>
|
||||
<?= \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'] ):?>
|
||||
<div class="basket-product-message">
|
||||
@@ -112,4 +113,4 @@
|
||||
<div class="alert alert-danger">Brak produktów w koszyku</div>
|
||||
<? endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -537,4 +537,62 @@
|
||||
console.warn('#orlen_point_id nie został znaleziony.');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
// 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>
|
||||
|
||||
Reference in New Issue
Block a user