2012-09-15 2 views
2

누군가가 나를 도울 수있는 간단한 대답이있을 수 있지만 Javascript에는별로 좋지 않습니다. 기본적으로 Shopify에서 액체 태그 중 하나를 사용하여 가격을 + 20 %로 설정했습니다. 크기가 재고가 없어서 가격이 너무 낮아지면 장바구니에 추가 버튼을 사용할 수 없도록하는 Javascript가 약간 있기 때문에 이는 제품 페이지와 별개로 효과적입니다.Shopify의 Javascript를 통해 제품 가격에 20 % 추가

<script> 
    var selectCallback = function(variant, selector) { 
     if (variant && variant.available) { 
     // valid variant selected 
     $('#add-to-cart').removeClass('disabled').removeAttr('disabled').val('Add to Cart'); // remove unavailable class from add-to-cart button, and re-enable button 
     if (variant.compare_at_price == 0){ 
      $('.product-title .price').html(''+Shopify.formatMoney(variant.price, "{{shop.money_format}}")+' Excluding VAT'); 
     } else { 
      $('.product-title .price').html('<span>'+Shopify.formatMoney(variant.price, "{{shop.money_format}}") + '</span> <del>' + Shopify.formatMoney(variant.compare_at_price, "{{shop.money_format}}") + ' Excluding VAT</del>'); 
     } 
     } else { 
     // variant doesn't exist 
     $('#add-to-cart').addClass('disabled').attr('disabled', 'disabled').val('Sold Out'); // set add-to-cart button to unavailable class and disable button 
     var message = variant ? "Sold Out" : "Unavailable"; 
     $('.product-title .price').text(message); // update price-field message 
     } 
    }; 

페이지를 제품 목록에 내가

{{ product.price_min | times:1.20 | money }}

내가 할 필요가 자바 스크립트를 수정할 수있는 다음과 같은 액체 태그를 사용하여 가격에 20 %를 추가 할 수 있습니다 어쨌든 여기에 코드입니다 그래서 그것이 산출하는 가격은 1.20 배가됩니다. 누구든지이 일을 할 수있는 방법을 알고 있습니까? 감사.

답변

6

<script> 
var selectCallback = function(variant, selector) { 
    if (variant && variant.available) { 
    // valid variant selected 
    $('#add-to-cart').removeClass('disabled').removeAttr('disabled').val('Add to Cart'); // remove unavailable class from add-to-cart button, and re-enable button 
    if (variant.compare_at_price == 0){ 
     $('.product-title .price').html(''+Shopify.formatMoney((variant.price*1.2), "{{shop.money_format}}")+' Excluding VAT'); 
    } else { 
     $('.product-title .price').html('<span>'+Shopify.formatMoney((variant.price*1.2), "{{shop.money_format}}") + '</span> <del>' + Shopify.formatMoney(variant.compare_at_price, "{{shop.money_format}}") + ' Excluding VAT</del>'); 
    } 
    } else { 
    // variant doesn't exist 
    $('#add-to-cart').addClass('disabled').attr('disabled', 'disabled').val('Sold Out'); // set add-to-cart button to unavailable class and disable button 
    var message = variant ? "Sold Out" : "Unavailable"; 
    $('.product-title .price').text(message); // update price-field message 
    } 
}; 
+0

이 매력을 작동하십시오. 고마워요! – Bantros

+0

다음으로 답변으로 표시하십시오 : – iJade

+0

나는 8 분을 기다려야합니다. – Bantros

관련 문제