Files
shopPRO/templates/shop-product/product.php
Jacek 589f9d9a38 feat: DataLayer GA4 analytics fix — poprawka eventów ecommerce
Naprawione eventy purchase, begin_checkout, view_item, add_to_cart
do formatu GA4 (item_id/item_name zamiast id/name, currency PLN,
google_business_vertical, poprawne typy danych).
Dodany nowy event view_cart na stronie koszyka.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 19:01:22 +01:00

715 lines
30 KiB
PHP

<? global $lang_id, $mdb;?>
<?
$attributes = (new \Domain\Product\ProductRepository($GLOBALS['mdb']))->getProductAttributes( $this -> product['product_combinations'] );
$dictionariesRepository = new \Domain\Dictionaries\DictionariesRepository( $mdb );
?>
<script class="footer" type="text/javascript">
function fradio_label_click( element, refresh )
{
element.parents( '.fradio' ).siblings().children( 'label' ).removeClass( 'active' );
element.parents( '.fradio' ).siblings().children( 'input' ).removeAttr( 'checked' );
element.parents( '.fradio' ).children( 'label' ).addClass( 'active' );
element.parents( '.fradio' ).children( 'input' ).prop( "checked", true );
if ( refresh )
refresh_product_attributes( element.attr( 'for' ), element.attr( 'order' ) );
}
</script>
<div id="product">
<div class="row">
<div class="col-12 col-md-6">
<div id="image-big">
<? if ( $this -> product['new_to_date'] and $this -> product['new_to_date'] >= date( 'Y-m-d' ) ):?>
<div class="new"><?= \Shared\Helpers\Helpers::lang( 'nowosc' );?></div>
<? endif;?>
<? if ( file_exists( substr( $this -> product['images'][0]['src'], 1 ) ) ):?>
<a image-id="0">
<img src="/thumb/625/0<?= $this -> product['images'][0]['src'];?>" alt="">
</a>
<? else:?>
<? endif;?>
</div>
<div class="gallery">
<? for ( $i = 0; $i < count( $this -> product['images'] ); $i++ ): if ( file_exists( substr( $this -> product['images'][$i]['src'], 1 ) ) ):?>
<a href="<?= $this -> product['images'][$i]['src'];?>" class="item" data-fancybox="product" id="image-<?= $i;?>" i="<?= $i;?>">
<img src="/thumb/180/0<?= $this -> product['images'][$i]['src'];?>" src="" alt="<?= $this -> product['images'][$i]['alt'];?>">
</a>
<? endif; endfor;?>
</div>
</div>
<div class="col-12 col-md-6">
<div class="product-options" id="product-options">
<?= \Shared\Tpl\Tpl::view( 'shop-product/_partial/product-warehouse-message', [
'product' => $this -> product,
'lang_id' => $this -> lang_id,
'settings' => $this -> settings
] );?>
<h1><?= $this -> product['language']['name'];?></h1>
<div class="prices">
<? if ( $this -> product['price_brutto_promo'] ):?>
<div class="price">
<?= \Shared\Helpers\Helpers::shortPrice( $this -> product['price_brutto_promo'] );?> <span class="small">zł</span>
</div>
<div class="price-old">
<?= \Shared\Helpers\Helpers::shortPrice( $this -> product['price_brutto'] );?> <span class="small">zł</span>
</div>
<div class="price-minimal">
Najniższa cena w ciągu ostatnich 30 dni: <strong><?= \Shared\Helpers\Helpers::shortPrice( ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->getMinimalPriceCached( (int)$this -> product['id'], $this -> product['price_brutto_promo'] ) );?> zł</strong>
</div>
<? if ( $this -> product['weight'] > 0 && $this -> product['product_unit_id'] ):?>
<div class="price_weight">
<?= \Shared\Helpers\Helpers::shortPrice( $this -> product['price_brutto_promo'] / $this -> product['wegiht'] * 1 );?> <?= $this -> product['product_unit'];?>
</div>
<? endif;?>
<? else:?>
<div class="price">
<?= \Shared\Helpers\Helpers::shortPrice( $this -> product['price_brutto'] );?> <span class="small">zł</span>
</div>
<? if ( $this -> product['weight'] > 0 && $this -> product['product_unit_id'] ):?>
<div class="price_weight">
<?= \Shared\Helpers\Helpers::shortPrice( $this -> product['price_brutto'] / $this -> product['weight'] );?> <span class="small">zł</span> / <?= $dictionariesRepository -> getUnitNameById( (int)$this -> product['product_unit_id'], $this -> lang_id );?>
</div>
<? endif;?>
<? endif;?>
</div>
<form class="product-options" id="product-<?= $this -> product['id'];?>">
<input type="hidden" name="product-id" value="<?= $this -> product['id'];?>">
<? if ( \Shared\Helpers\Helpers::is_array_fix( $attributes ) ):?>
<div id="attributes">
<div class="title">Opcje produktu</div>
<? foreach ( $attributes as $key => $val )
echo \Shared\Tpl\Tpl::view( 'shop-product/_partial/product-attribute', [
'attribute' => $val,
'order' => $key,
'level' => ++$level,
'max_level' => count( $attributes )
] );?>
</div>
<? endif;?>
<? if ( $this -> product['additional_message'] ):?>
<div class="product-message">
<textarea class="form-control" name="product-message" <? if ( $this -> product['additional_message_required'] ):?>required="required"<? endif;?> placeholder="<?= $this -> product['additional_message_text'] ? $this -> product['additional_message_text'] : 'Miejsce na dodatkową wiadomość';?>"></textarea>
</div>
<? endif;?>
<?= \Shared\Tpl\Tpl::view( 'shop-product/_partial/product-custom-fields', [
'custom_fields' => $this -> product['custom_fields']
] );?>
<div class="add-to-basket">
<div class="quantity-container">
<a href="#" class="btn-minus">
<i class="fa fa-minus"></i>
</a>
<input type="text" name="quantity" id="quantity" value="1" class="int-format" min="1" max="<?= ( !$this -> product['quantity'] and $this -> product['stock_0_buy'] ) ? 999 : $this -> product['quantity'];?>">
<a href="#" class="btn-plus">
<i class="fa fa-plus"></i>
</a>
</div>
<button id="add-to-basket" class="btn btn-success"><?= \Shared\Helpers\Helpers::lang( 'do-koszyka' );?></span>
</button>
<div class="alert hidden">Produkt chwilowo niedostępny.</div>
<?
if ( !$this -> product['product_combinations'] and !( $this -> product['quantity'] > 0 or $this -> product['stock_0_buy'] ) ):
?>
<script class="footer" type="text/javascript">
$(function ()
{
$('#product-<?= $this -> product['id'];?> .add-to-basket .quantity-container, #product-<?= $this -> product['id'];?> .add-to-basket #add-to-basket').addClass('hidden');
$('#product-<?= $this -> product['id'];?> .add-to-basket .alert').removeClass('hidden');
});
</script>
<? endif;?>
</div>
</form>
<? if ( $this -> product['producer'] and $this -> product['producer']['status'] ):?>
<div class="product-producer">
Producent: <a href="/producent/<?= \Shared\Helpers\Helpers::seo( $this -> product['producer']['name'] );?>" title="Produkty marki <?= htmlspecialchars( $this -> product['producer']['name'] );?>"><?= $this -> product['producer']['name'];?></a>
</div>
<? endif;?>
<?= \Shared\Tpl\Tpl::view( 'shop-product/_partial/product-meta', [
'product_id' => $this->product['id']
]);?>
<div class="short-description">
<?= $this -> product['language']['short_description'];?>
</div>
</div>
</div>
</div>
<div id="description">
<div class="row">
<div class="col-12 col-lg-8">
<ul class="tabs" id="tabs-menu">
<li class="tab-link current" id="tab-link-0" tab="0"><?= ucfirst( \Shared\Helpers\Helpers::lang( 'opis' ) );?></li>
<? if ( $this -> product['language']['tab_name_1'] ):?>
<li class="tab-link" id="tab-link-1" tab="1"><?= $this -> product['language']['tab_name_1'];?></li>
<? endif;?>
<li class="tab-link" id="tab-link-2" tab="2"><?= ucfirst( \Shared\Helpers\Helpers::lang( 'opinie' ) );?></li>
<li class="tab-link" id="tab-link-3" tab="3">Bezpieczeństwo</li>
</ul>
<div id="tab-0" class="tab-content">
<div class="tab-title"><?= \Shared\Helpers\Helpers::lang( 'opis-produktu' );?></div>
<?= $this -> product['language']['description'];?>
</div>
<? if ( $this -> product['language']['tab_description_1'] ):?>
<div id="tab-1" class="tab-content">
<div class="tab-title"><?= $this -> product['language']['tab_name_1'];?></div>
<?= $this -> product['language']['tab_description_1'];?>
</div>
<? endif;?>
<div id="tab-2" class="tab-content reviews">
<div class="tab-title"><?= ucfirst( \Shared\Helpers\Helpers::lang( 'opinie' ) );?></div>
<div id="widget-container" class="data-ekomi-emp ekomi-widget-container ekomi-widget-sf14835961656364de9f9" ></div>
<div id="ekomi-product-widget-identifier" class="prod-data-emp" style="visibility: hidden"><?= $this -> product['id'];?></div>
<a href="https://www.ekomi-pl.com/opinie-marianek.html" target="_blank"><img alt="marianek.pl Reviews with ekomi-pl.com" src="https://smart-widget-assets.ekomiapps.de/resources/ekomi_logo.png" style="display: none;"/></a>
<script type="text/javascript">
function registerWidget (w, token) {
w['_ekomiWidgetsServerUrl'] = 'https://widgets.ekomi.com';
w['_customerId'] = 148359;
w['_language'] = new Array();
w['_language'][token] = 'auto';
if(typeof(w['_ekomiWidgetTokens']) !== 'undefined'){
w['_ekomiWidgetTokens'][w['_ekomiWidgetTokens'].length] = token;
} else {
w['_ekomiWidgetTokens'] = new Array(token);
}
if(typeof(ekomiWidgetJs) == 'undefined') {
ekomiWidgetJs = true;
var scr = document.createElement('script');scr.src = 'https://sw-assets.ekomiapps.de/static_resources/widget.js';
var head = document.getElementsByTagName('head')[0];head.appendChild(scr);
}
return true;
}
(function (w) {
var token = 'sf14835961656364de9f9';
var k = document.getElementsByClassName("ekomi-widget-" + token);
for(var x=0;x<k.length;x++){ registerWidget(w,token); }
})(window);
</script>
</div>
<div id="tab-3" class="tab-content">
<? if ( $this -> product['producer']['data'] ):?>
<div class="tab-title">Producent</div>
<?= $this -> product['producer']['data'];?>
<? endif;?>
<? if ( $this -> product['language']['security_information'] ):?>
<div class="tab-title">Informacje o bezpieczeństwie</div>
<?= $this -> product['language']['security_information'];?>
<? endif;?>
</div>
</div>
<div class="col-12 col-lg-4">
<? if ( $this -> product['language']['tab_name_2'] ):?>
<div class="description-right">
<div class="title"><?= $this -> product['language']['tab_name_2'];?></div>
<div class="content">
<?= $this -> product['language']['tab_description_2'];?>
</div>
</div>
<? endif;?>
</div>
</div>
</div>
<? if ( \Shared\Helpers\Helpers::is_array_fix( $this -> product['products_sets'] ) ):?>
<div class="products-sets box">
<div class="row">
<div class="col-12">
<div class="box-title"><?= ucfirst( \Shared\Helpers\Helpers::lang( 'dobierz-do-kompletu' ) );?></div>
<div class="owl-carousel owl-theme">
<?
foreach ( $this -> product['products_sets'] as $product_sets_id ):
$product = (new \Domain\Product\ProductRepository($GLOBALS['mdb']))->findCached( $product_sets_id, $lang_id );
if ( $product and $product['status'] ):
echo \Shared\Tpl\Tpl::view( 'shop-product/product-mini', [
'product' => $product,
'class' => 'item'
] );
endif;
endforeach;
?>
</div>
</div>
</div>
</div>
<? endif;?>
<? if ( \Shared\Helpers\Helpers::is_array_fix( $this -> product['products_related'] ) ):?>
<div class="products-related box">
<div class="row">
<div class="col-12">
<div class="box-title">Inne wzory i kolory</div>
<div class="owl-carousel owl-theme">
<?
foreach ( $this -> product['products_related'] as $product_related_id ):
$product = (new \Domain\Product\ProductRepository($GLOBALS['mdb']))->findCached( $product_related_id, $lang_id );
if ( $product and $product['status'] ):
echo \Shared\Tpl\Tpl::view( 'shop-product/product-mini', [
'product' => $product,
'class' => 'item'
] );
endif;
endforeach;
?>
</div>
</div>
</div>
</div>
<? endif;?>
<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(){
<? if ( $this -> settings['google_tag_manager_id'] ):?>
dataLayer.push({ ecommerce: null });
dataLayer.push({
event: "view_item",
ecommerce: {
currency: "PLN",
value: <? if ( $this -> product['price_brutto_promo'] ): echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto_promo'] ); else: echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto'] ); endif;?>,
items: [
{
item_id: "<?= $this -> product['id'];?>",
item_name: "<?= str_replace( '"', '', $this -> product['language']['name'] );?>",
price: <? if ( $this -> product['price_brutto_promo'] ): echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto_promo'] ); else: echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto'] ); endif;?>,
quantity: 1,
google_business_vertical: "retail"
}
]
}
});
<? endif;?>
});
</script>
<script class="footer" type="text/javascript">
$( function ()
{
var fullUrl = window.location.href;
var hash = fullUrl.split('/')[4];
if ( hash ) {
// Podziel fragment na tablicę za pomocą znaku /
var array = hash.split('/');
// Sprawdź, czy tablica nie jest pusta
if (array.length > 0) {
// Przechodź przez tablicę elementów
array.forEach(function(element, index) {
// Ustaw opóźnienie na podstawie indeksu, aby kliknięcia były w odstępach półsekundowych
setTimeout(function() {
// Znajdź label z atrybutem for odpowiadającym aktualnemu elementowi tablicy i kliknij go
$("label[for='" + element + "']").click();
}, 100 * index); // 500 ms * indeks elementu
});
}
}
if ( windowsize > 767 )
{
$( "#tabs-menu" ).sticky({
topSpacing: 56
});
}
else
{
$( "#tabs-menu" ).sticky({
topSpacing: 0
});
};
if ( $( '#product #tab-0' ).is( ':visible' ) )
$( '#product #tabs-menu #tab-link-0' ).addClass( 'current' );
else
$( '#product #tabs-menu #tab-link-0' ).removeClass( 'current' );
if ( $( '#product #tab-1' ).is( ':visible' ) )
$( '#product #tabs-menu #tab-link-1' ).addClass( 'current' );
else
$( '#product #tabs-menu #tab-link-1' ).removeClass( 'current' );
if ( $( '#product #tab-2' ).is( ':visible' ) )
$( '#product #tabs-menu #tab-link-2' ).addClass( 'current' );
else
$( '#product #tabs-menu #tab-link-2' ).removeClass( 'current' );
$( 'body' ).on( click_event, '.fradio label', function()
{
fradio_label_click( $( this ), true );
});
$( 'body' ).on( click_event, '.tab-link', function()
{
$( 'html, body' ).animate({
scrollTop: $( "#tab-" + $( this ).attr( 'tab' ) ).offset().top - 120
}, 333 );
});
$('.products-sets .owl-carousel, .products-related .owl-carousel').owlCarousel({
loop: false,
responsiveClass: true,
dots: false,
lazyLoad: true,
responsive: {
0: {
items: 1,
nav: true
},
576: {
items: 2,
nav: true
},
768: {
items: 3,
nav: true
},
1280: {
items: 4,
nav: true
}
}
});
// powiększenie zdjęcia
$('body').on( click_event, '#image-big a', function ()
{
var image_id = $(this).attr('image-id');
$('#image-' + image_id).trigger('click');
});
$('body').on('mouseover', '#gallery a', function()
{
var i = $(this).attr('i');
var src = $(this).attr('href');
if (i != $('#image-big a').attr('image-id'))
{
$('#image-big a').attr('image-id', i);
$('#image-big img').attr('src', src);
}
});
$('body').on('change', '#quantity', function(e)
{
e.preventDefault();
var quantity = parseInt($('#quantity').val());
var max_value = parseInt($('input#quantity').attr('max'));
quantity = quantity + 1;
if (quantity > max_value)
{
quantity = max_value;
$.alert(
{
title: '<?= ucfirst( \Shared\Helpers\Helpers::lang( 'uwaga' ) );?>',
content: 'Maksymalna ilość wybranego produktu wynosi: <b>' + max_value + '<\/b>',
type: 'blue',
closeIcon: true,
closeIconClass: 'fas fa-times',
typeAnimated: true,
animation: 'opacity',
useBootstrap: false,
theme: 'modern',
autoClose: 'confirm|5000',
icon: 'fas fa-exclamation',
buttons: {
confirm: {
text: '<?= \Shared\Helpers\Helpers::lang( 'zamknij' );?>',
btnClass: 'btn-blue',
keys: ['enter'],
action: function () {}
}
}
});
}
$('input#quantity').val(quantity);
return false;
});
$( 'body').on( click_event, '.btn-plus', function (e)
{
e.preventDefault();
var quantity = parseInt($('#quantity').val());
var max_value = parseInt($('input#quantity').attr('max'));
quantity = quantity + 1;
if (quantity > max_value)
{
quantity = max_value;
$.alert(
{
title: '<?= ucfirst( \Shared\Helpers\Helpers::lang( 'uwaga' ) );?>',
content: 'Maksymalna ilość wybranego produktu wynosi: <b>' + max_value + '<\/b>',
type: 'blue',
closeIcon: true,
closeIconClass: 'fas fa-times',
typeAnimated: true,
animation: 'opacity',
useBootstrap: false,
theme: 'modern',
autoClose: 'confirm|5000',
icon: 'fas fa-exclamation',
buttons: {
confirm: {
text: '<?= \Shared\Helpers\Helpers::lang( 'zamknij' );?>',
btnClass: 'btn-blue',
keys: ['enter'],
action: function () {}
}
}
});
}
$('input#quantity').val(quantity);
return false;
});
$('body').on(click_event, '.btn-minus', function (e)
{
e.preventDefault();
var quantity = parseInt($('input#quantity').val());
var min_value = parseInt($('input#quantity').attr('min'));
quantity = quantity - 1;
if (quantity < min_value)
quantity = min_value;
$('input#quantity').val(quantity);
return false;
});
$('body').on(click_event, '#add-to-basket', function ()
{
var check = true;
$( '#attributes input[type="hidden"], #attributes select' ).each( function( index, element )
{
if ( $( element ).val() == '' )
{
var name = $( element ).attr( 'description' );
shopAlert(
'<?= ucfirst( \Shared\Helpers\Helpers::lang( 'uwaga' ) );?>',
'<?= ucfirst( \Shared\Helpers\Helpers::lang( 'prosze-wybrac' ) );?>: <b>' + name + '</b>',
[
'<a href="#" onclick="shopAlertClose(); return false;" class="btn btn-success">Zamknij</a>',
] );
check = false;
return false;
}
});
$( '#attributes .fradio-group' ).each( function( index, element )
{
var atrribute = $( element ).attr( 'attribute' );
var value = $( element ).find( 'input[type="radio"]:checked' ).val();
if ( typeof value === "undefined" )
{
var name = $( element ).attr( 'attribute-name' );
shopAlert(
'<?= ucfirst( \Shared\Helpers\Helpers::lang( 'uwaga' ) );?>',
'<?= ucfirst( \Shared\Helpers\Helpers::lang( 'prosze-wybrac' ) );?>: <b>' + name + '</b>',
[
'<a href="#" onclick="shopAlertClose(); return false;" class="btn btn-success">Zamknij</a>',
] );
check = false;
return false;
}
});
if ( $( '.product-message textarea' ).prop( 'required' ) && $.trim( $( '.product-message textarea' ).val() ) == '' )
{
shopAlert(
'<?= ucfirst( \Shared\Helpers\Helpers::lang( 'uwaga' ) );?>',
'Proszę uzupełnić pole na dodatkową wiadomość.',
[
'<a href="#" onclick="shopAlertClose(); return false;" class="btn btn-success">Zamknij</a>',
] );
check = false;
return false;
}
// dodatkowe pola muszą być uzupełnione
$( '.custom-field input[required]' ).each( function( index, element )
{
if ( $.trim( $( element ).val() ) == '' )
{
shopAlert(
'<?= ucfirst( \Shared\Helpers\Helpers::lang( 'uwaga' ) );?>',
'Proszę uzupełnić pole: <b>' + $( element ).attr( 'field_name' ) + '</b>',
[
'<a href="#" onclick="shopAlertClose(); return false;" class="btn btn-success">Zamknij</a>',
] );
check = false;
return false;
}
});
if (!check)
return false;
var values = $( '#product-<?= $this -> product['id'];?>' ).serializeArray();
var quantity = $('#product-<?= $this -> product['id'];?> #quantity').val();
jQuery.ajax(
{
type: 'POST',
cache: false,
url: '/shopBasket/basket_add_product',
data:
{
values: JSON.stringify(values)
},
beforeSend: function()
{
$('#add-to-basket').addClass('disabled');
},
success: function( response )
{
data = jQuery.parseJSON(response);
$('#add-to-basket').removeClass('disabled');
$('#basket-mini #products-count').html(data.basket_mini_count);
$('#basket-mini #basket-value').html(data.basket_mini_value);
$('#product #quantity').val(1);
if (data.result == 'ok')
{
<? if ( $this -> settings['piksel'] ):?>
for (var i = 1; i <= quantity; i++)
{
fbq('track', 'AddToCart', {
content_name: '<?= str_replace( '"', '', $this -> product['language']['name'] );?>',
content_category: 'produkt',
content_ids: ['<?= $this -> product['id'];?>'],
content_type: 'product',
value: '<?
if ( $this -> product['price_brutto_promo'] ):
echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto_promo'] );
else:
echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto'] );
endif;
?>',
currency: 'PLN'
});
}
<? endif;?>
<? if ( $this -> settings['google_tag_manager_id'] ):?>
var add_to_cart_value = <? if ( $this -> product['price_brutto_promo'] ): echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto_promo'] ); else: echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto'] ); endif;?> * quantity;
dataLayer.push({ ecommerce: null });
dataLayer.push({
event: "add_to_cart",
ecommerce: {
currency: "PLN",
value: add_to_cart_value,
items: [
{
item_id: "<?= $this -> product['id'];?>",
item_name: "<?= str_replace( '"', '', $this -> product['language']['name'] );?>",
price: <? if ( $this -> product['price_brutto_promo'] ): echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto_promo'] ); else: echo \Shared\Helpers\Helpers::normalize_decimal( $this -> product['price_brutto'] ); endif;?>,
quantity: parseInt(quantity),
google_business_vertical: "retail"
}
]
}
});
<? endif;?>
shopAlert(
'Produkt dodany do koszyka',
data.product_sets,
[
'<a href="#" onclick="shopAlertClose(); return false;" class="btn btn-default">Wróć do zakupów</a>',
'<a href="/koszyk" class="btn btn-success">Przejdź do koszyka</a>'
] );
observer.observe();
}
}
});
return false;
});
});
// odświeżenie listy atrybutów produktu
function refresh_product_attributes( attribute_with_value, attribute_order )
{
// Wybierz wszystkie etykiety z klasą "active" wewnątrz elementu o ID "attributes"
const activeLabels = document.querySelectorAll('#attributes label.active');
// Utwórz tablicę z wartościami atrybutu "for" tych etykiet
const forValues = Array.from(activeLabels).map(label => label.getAttribute('for'));
$.ajax({
type: 'POST',
cache: false,
url: '/shopProduct/draw_product_attributes',
data: {
selected_values: forValues,
product_id: <?= $this -> product['id'];?>
},
beforeSend: function() {
$( '#add-to-basket' ).addClass('disabled');
},
success: function( response ) {
data = jQuery.parseJSON( response );
$( '#add-to-basket' ).removeClass( 'disabled' );
if ( data.product_data )
{
if ( data.product_data.price_brutto_promo )
{
$( '#product-options .prices .price-old' ).html( data.product_data.price_brutto + ' <span class="small">zł</span>' );
$( '#product-options .prices .price' ).html( data.product_data.price_brutto_promo + ' <span class="small">zł</span>' );
}
else
{
$( '#product-options .prices .price' ).html( data.product_data.price_brutto + ' <span class="small">zł</span>' );
}
// jeżeli stan magazynowy jest większy niż 0
if ( data.product_data.quantity > 0 )
{
$( '.warehouse-message' ).html( data.product_data.messages.warehouse_message_nonzero );
$( '#quantity' ).attr( 'max', data.product_data.quantity );
$( '.add-to-basket #add-to-basket, .add-to-basket .quantity-container' ).show();
$( '.add-to-basket .alert' ).addClass( 'hidden' );
}
// jeżeli stan magazynowy jest równy 0
else
{
// jeżeli można kupić produkt ze stanem magazynowym równym 0
if ( data.product_data.stock_0_buy == 1 )
{
$( '.warehouse-message' ).html( data.product_data.messages.warehouse_message_zero );
$( '#quantity' ).attr( 'max', 99 );
$( '.add-to-basket #add-to-basket, .add-to-basket .quantity-container' ).show();
$( '.add-to-basket .alert' ).addClass( 'hidden' );
}
// jeżeli nie można kupić produktu ze stanem magazynowym równym 0
else
{
$( '.warehouse-message' ).html( '' );
$( '#quantity' ).attr( 'max', 0 );
$( '.add-to-basket #add-to-basket, .add-to-basket .quantity-container' ).hide();
$( '.add-to-basket .alert' ).removeClass( 'hidden' );
}
}
}
}
});
return false;
}
</script>