update
This commit is contained in:
@@ -1,4 +1,46 @@
|
||||
<? global $settings; ?>
|
||||
<?
|
||||
if ( $settings['google_tag_manager_id'] && is_array( $this -> basket ) && count( $this -> basket ) ):
|
||||
$view_cart_items = '';
|
||||
$view_cart_value = 0;
|
||||
|
||||
foreach ( $this -> basket as $position ):
|
||||
$vc_product = (new \Domain\Product\ProductRepository($GLOBALS['mdb']))->findCached( (int)$position['product-id'], (new \Domain\Languages\LanguagesRepository($GLOBALS['mdb']))->defaultLanguage() );
|
||||
|
||||
if ( !$vc_product )
|
||||
continue;
|
||||
|
||||
$vc_price = (float)$vc_product['price_brutto_promo'] > 0 && (float)$vc_product['price_brutto_promo'] < (float)$vc_product['price_brutto']
|
||||
? (float)$vc_product['price_brutto_promo']
|
||||
: (float)$vc_product['price_brutto'];
|
||||
|
||||
$vc_qty = (int)$position['quantity'];
|
||||
$view_cart_value += $vc_price * $vc_qty;
|
||||
|
||||
if ( $view_cart_items )
|
||||
$view_cart_items .= ',';
|
||||
|
||||
$view_cart_items .= '{';
|
||||
$view_cart_items .= 'item_id: "' . $vc_product['id'] . '",';
|
||||
$view_cart_items .= 'item_name: "' . str_replace( '"', '', $vc_product['language']['name'] ) . '",';
|
||||
$view_cart_items .= 'price: ' . \Shared\Helpers\Helpers::normalize_decimal( $vc_price ) . ',';
|
||||
$view_cart_items .= 'quantity: ' . $vc_qty . ',';
|
||||
$view_cart_items .= 'google_business_vertical: "retail"';
|
||||
$view_cart_items .= '}';
|
||||
endforeach;
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
dataLayer.push({ ecommerce: null });
|
||||
dataLayer.push({
|
||||
event: "view_cart",
|
||||
ecommerce: {
|
||||
currency: "PLN",
|
||||
value: <?= \Shared\Helpers\Helpers::normalize_decimal( $view_cart_value );?>,
|
||||
items: [<?= $view_cart_items;?>]
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<? endif; ?>
|
||||
<div id="basket-container">
|
||||
<div id="content">
|
||||
<?= $this->basket_details; ?>
|
||||
@@ -508,4 +550,62 @@
|
||||
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>
|
||||
Reference in New Issue
Block a user