app/Plugin/StripePaymentGateway42/Resource/template/default/Product/detail.js.twig line 1

Open in your IDE?
  1. <script>
  2.     function detailRequestButton (){
  3.         var $form = $('#form1');
  4.         var $cat_sel1 = $form.find('select[name=classcategory_id1]');
  5.         var $cat_sel2 = $form.find('select[name=classcategory_id2]');
  6.         var $quantity = $form.find('input[name="quantity"]');
  7.         // add wrapper
  8.         var $cart_wrapper = $form.find('.ec-productRole__btn')
  9.         $("<div id='payment-request-button'></div>").insertBefore($cart_wrapper)
  10.         var getProduct = function(){
  11.             return $form.find('input[name=product_id]').val() || null;
  12.         }
  13.         var getProductClass = function(){
  14.             return $form.find('input[name=ProductClass]').val() || null;
  15.         }
  16.         var getQuantity = function(){
  17.             return $form.find("input[name='quantity']").val() || 0;
  18.         }
  19.         
  20.         var getPrice = function(){
  21.             var classcat_id1 = $cat_sel1.val() || "__unselected2";
  22.             var classcat_id2 = $cat_sel2.val() || "";
  23.             classcat2 = undefined
  24.             if (eccube.hasOwnProperty('productsClassCategories')) {
  25.                 // 商品一覧時
  26.                 classcat2 = eccube.productsClassCategories[product_id][classcat_id1]['#' + classcat_id2];
  27.             } else {
  28.                 // 詳細表示時
  29.                 if (typeof eccube.classCategories[classcat_id1] !== 'undefined') {
  30.                     classcat2 = eccube.classCategories[classcat_id1]['#' + classcat_id2];
  31.                 }
  32.             }
  33.             var quantity = $quantity.val();
  34.             if(quantity < 0){
  35.                 return 0;
  36.             }
  37.             if(classcat2 == undefined){
  38.                 return 0
  39.             }else if(classcat2.price02_inc_tax){
  40.                 return parseInt(classcat2.price02_inc_tax.replace(",", "")) * quantity;
  41.             }else{
  42.                 return 0;
  43.             }
  44.         }
  45.         // register paybutton
  46.         var paymentRequest = registerPayButton({
  47.                 // shipping_fetch_url : 'https://279a4a530961.ngrok.io/plugin/stripe_payment_gateway/pr_shipping',
  48.                 // pay_url            : "https://279a4a530961.ngrok.io/plugin/stripe_payment_gateway/pr_pay",
  49.                 getData            :   function() {
  50.                     return [
  51.                             {
  52.                                 "product"   :   getProduct(),
  53.                                 "productClass" : getProductClass(),
  54.                                 "quantity"  :   getQuantity(),
  55.                             }
  56.                         ];
  57.                     
  58.                 },
  59.                 request_data: {
  60.                     country     :   "JP",
  61.                     currency    :   "{{ payrequest.currency_code }}",
  62.                     total       :   {
  63.                         label: "{{ payrequest.label }}",
  64.                         amount: {{ payrequest.amount }}
  65.                     },
  66.                     requestPayerName    : true,
  67.                     requestPayerEmail   : true,
  68.                     requestShipping     : true,
  69.                     requestPayerPhone   : true,
  70.                 },
  71.                 onSuccess   :   function(){
  72.                     location.href = "{{ url('shopping_complete') }}"
  73.                 }
  74.             })
  75.         var onUpdatePayment = function(){
  76.             var price = getPrice() || 0;
  77.             
  78.             paymentRequest.update({
  79.                 total   :   {
  80.                     label   :   "{{ payrequest.label }}",
  81.                     amount  :   price
  82.                 }
  83.             })
  84.         }
  85.         $cat_sel2.on('change', onUpdatePayment)
  86.         $cat_sel1.on('change', onUpdatePayment)
  87.         $quantity.on('change', onUpdatePayment)
  88.         return paymentRequest;
  89.     };
  90. detailRequestButton();  
  91. </script>
  92. <style>
  93. #payment-request-button{
  94.     width: 60%;
  95.     margin-bottom: 16px;
  96.     width: 100%;
  97. }
  98. @media (min-width: 768px){
  99.     #payment-request-button{
  100.         width: 60%;
  101.         margin-bottom: 16px;
  102.         min-width: 350px;
  103.     }
  104. }
  105. </style>