Obsługa nowych zestawów
Z tego artykułu dowiesz się jak dodać w szablonie obsługę nowych zestawów. W pliku product/product-presentation-data.html znajdź frazę {% if product.Sets != null and product.Sets != empty -%}. Powinna występować 3 razy. W każdym z nich zmień Sets na SetsExt. Następnie będąc przy ostatnim wystąpieniu tej frazy (która jest warunkiem) podmień calą zawartość tego warunku poniższym kodem: Następnie w pliku js/init.js znajdź frazę: Jest to jeden z warunków w funkcji post. Podmień calą jego zawartość poniższym kodem: Teraz w tym samym pliku (js/init.js) znajdź frazę List of events i linijkę wyżej wklej poniższy kod: Dalej w tym samym pliku (js/init.js) kilka linijek niżej (w funkcji events) dodaj analogicznie do pozostałych wywołań poniższy kod: Przejdź do pliku js/init-ui2.js i znajdź frazę: Na końcu wyżej wymienionej funkcji oraz następnej, która jest pod nią: wklej poniższy kod: Pozostając w tym samym pliku (js/init-ui2.js) znajdź linijkę: i zamień ją na poniższy kod: Teraz w pliku scss/globals/_globals1.scss na samym końcu dodaj poniższy kod: Następnie w pliku scss/globals/_globals-m.scss znajdź klase .set-product-ui{ i podmień jej zawartość poniższym kodem: Pozostając w tym samym pliku (scss/globals/_globals-m.scss) zaraz pod pierwszą linijką wklej poniższy kod:
Szafir
{{ translations.BuyInSet }}
{% for set in product.SetsExt -%}
{% assign setPrice = '' -%}
{% assign setPreviousPrice = '' -%}
if(form.hasClass('add-set-to-cart-lq')){
var set = {setId:Number($(e.currentTarget).data('set-id')), quantity:1, products:[]};
var setProducts = form.find('.set-product-lq');
var setProductsForDataLayer = [];
var setProductsForFBPixel = [];
var totalValue = 0;
setProducts.each(function () {
var setProduct = {
setElementId: Number($(this).data('set-element-id')),
setProductId: Number($(this).data('set-product-id'))
};
if($(this).find('[name=attributePolyvalent]').length > 0){
var attributesPolyvalent = [];
$(this).find('[name=attributePolyvalent]').each(function(){
var attribute = {
id: Number($(this).data('id')),
valueId: Number($(this).val())
};
attributesPolyvalent.push(attribute);
});
setProduct.attributesPolyvalent = attributesPolyvalent;
}
if($(this).find('[name=attributeEditable]').length > 0){
var attributesEditable = [];
$(this).find('[name=attributeEditable]').each(function(){
var attribute = {
id: Number($(this).data('id')),
value: $(this).val()
};
attributesEditable.push(attribute);
});
setProduct.attributesEditable = attributesEditable;
}
set.products.push(setProduct);
var setProductDL = {
id: $(this).data('id').toString(),
name: $(this).data('name'),
price: $(this).data('price-full'),
quantity: $(this).data('quantity')
};
var setProductFBP = {
id: $(this).data('id').toString(),
content_name: $(this).data('name'),
value: Number($(this).data('price').toString().replace(',','.')),
quantity: $(this).data('quantity')
};
totalValue = totalValue + (Number($(this).data('price').toString().replace(',','.')) * Number($(this).data('quantity').toString().replace(',','.')));
setProductsForDataLayer.push(setProductDL);
setProductsForFBPixel.push(setProductFBP);
});
var data = [
{name: "__csrf", value: __CSRF},
{name: "__action", value: 'Cart/SetExtAdd'},
{name: "set", value: JSON.stringify(set)}
];
if(window.app.getCookie('lastCartId') == undefined || window.app.getCookie('lastCartId') == -1){
data.push({name: "__collection", value: 'customer.Cart.Id'});
}
var dataLayerProds = {
"products": setProductsForDataLayer
};
if(typeof fbq !== 'undefined') {
fbq('track', 'AddToCart',
{
value: totalValue,
currency: __curr,
content_type: 'product',
contents: setProductsForFBPixel
}
);
}
openSetElementProductsPopup: function(setElementId) {
$('[data-set-element-products-popup='+setElementId+']').removeClass('hidden-lq');
app.loadImages();
$('body').addClass('modal-opened-ui');
},
changeSetElementProduct: function(e) {
var setElementId = $(e.currentTarget).parents('[data-set-element-products-popup]').data('set-element-products-popup');
var setProductId = $(e.currentTarget).data('set-product-id');
var form = $(e.currentTarget).parents('.form-lq');
if($(window).width() > 1279) {
form.find('.set-slider-lq').slick('slickUnfilter');
}
form.find('[data-set-element-id='+setElementId+']').addClass('set-product-hidden-lq');
form.find('[data-set-element-id='+setElementId+'][data-set-product-id='+setProductId+']').removeClass('set-product-hidden-lq');
if($(window).width() > 1279) {
form.find('.set-slider-lq').slick('slickFilter',':not(:has(.set-product-hidden-lq))');
}
app.loadImages();
var oldPrice = 0;
var newPrice = 0;
form.find('.set-product-lq:not(.set-product-hidden-lq)').each(function(){
oldPrice = Number((Number(oldPrice) + Number($(this).data('set-product-previous-value').replace(',','.'))).toFixed(__decimalPlacesPrice));
newPrice = Number((Number(newPrice) + Number($(this).data('set-product-value').replace(',','.'))).toFixed(__decimalPlacesPrice));
});
var savedMoney = Number((newPrice - oldPrice).toFixed(__decimalPlacesPrice));
form.find('.old-price-lq .value-lq').html(oldPrice.toPrice());
form.find('.saved-money-lq .value-lq').html(savedMoney.toPrice());
form.find('.brutto-lq .value-lq').html(newPrice.toPrice());
form.find('.netto-lq .value-lq').html(newPrice.toPrice());
$('body').removeClass('modal-opened-ui');
},
$('body').on('click', '.open-set-element-products-popup-lq', function(e) {
app.openSetElementProductsPopup($(e.currentTarget).parents('[data-set-element-id]').data('set-element-id'));
});
$('body').on('click', '.change-set-element-product-lq', function(e) {
app.changeSetElementProduct(e);
});
$('body').on('click', '.hide-lq', function(e) {
($('body').on('click', '.hide-container-lq', function(e) {)
if($(e.currentTarget).parents('.sets-lq').length > 0){
$('body').removeClass('modal-opened-ui');
}
UIFeatures.initSlider('.set-slider-lq', {infinite: false, dots: false, slidesToShow: 4, responsive: [{breakpoint: 1279, settings: "unslick"}]});
if(!$('.set-slider-lq').hasClass('slick-initialized')){
UIFeatures.initSlider('.set-slider-lq', {infinite: false, dots: false, slidesToShow: 4, responsive: [{breakpoint: 1279, settings: "unslick"}]});
if($(window).width() > 1279) {
$('.set-slider-lq').slick('slickFilter',':not(:has(.set-product-hidden-lq))');
}
}
.change-set-element-product-ui{
display: inline-block;
cursor: pointer;
figure{
padding: 0;
width: 200px;
height: 200px;
}
}
&:before{
font-family: 'themify';
content: "\e61a";
color: $labelsColor;
font-size: 20px;
margin: 25px;
display: block;
}
&:first-child:before, &.set-product-hidden-lq:before{
content: none;
}
a{
width: 70px;
display: inline-block;
vertical-align: middle;
}
.name-ui{
display: inline-block;
width: calc(100% - 90px);
margin: 0 0 0 15px;
vertical-align: middle;
text-align: left;
line-height: 1.2;
font-size: 14px;
}
.set-product-hidden-lq{
display: none;
}