app/Plugin/Shiro8Download42/Resource/template/default/Product/product.twig line 1

Open in your IDE?
  1. <script>
  2. $(function() {
  3.     $('.add-cart').replaceWith($('#plugin_shiro8_download_product').clone().removeAttr('id').removeClass('d-none').show());
  4.     $('#plugin_shiro8_download_product').remove(); // オリジナル削除
  5.     
  6.     // 規格1選択時
  7.     $('select[name=classcategory_id1]')
  8.     .change(function() {
  9.         var $form = $(this).parents('form');
  10.         var product_id = $form.find('input[name=product_id]').val();
  11.         var $sele1 = $(this);
  12.         var $sele2 = $form.find('select[name=classcategory_id2]');
  13.         // 規格1のみの場合
  14.         if (!$sele2.length) {
  15.             checkShiro8Download($form, product_id, $sele1.val(), null);
  16.             
  17.         }
  18.     });
  19.     // 規格2選択時
  20.     $('select[name=classcategory_id2]')
  21.     .change(function() {
  22.         var $form = $(this).parents('form');
  23.         var product_id = $form.find('input[name=product_id]').val();
  24.         var $sele1 = $form.find('select[name=classcategory_id1]');
  25.         var $sele2 = $(this);
  26.         checkShiro8Download($form, product_id, $sele1.val(), $sele2.val());
  27.     });
  28.     
  29.     
  30.     //defaultの処理を再セット
  31.     $('.add-cart').on('click', function(event) {
  32.         {% if form.classcategory_id1 is defined %}
  33.         // 規格1フォームの必須チェック
  34.         if ($('#classcategory_id1').val() == '__unselected' || $('#classcategory_id1').val() == '') {
  35.             $('#classcategory_id1')[0].setCustomValidity('{{ '項目が選択されていません'|trans }}');
  36.             return true;
  37.         } else {
  38.             $('#classcategory_id1')[0].setCustomValidity('');
  39.         }
  40.         {% endif %}
  41.         {% if form.classcategory_id2 is defined %}
  42.         // 規格2フォームの必須チェック
  43.         if ($('#classcategory_id2').val() == '__unselected' || $('#classcategory_id2').val() == '') {
  44.             $('#classcategory_id2')[0].setCustomValidity('{{ '項目が選択されていません'|trans }}');
  45.             return true;
  46.         } else {
  47.             $('#classcategory_id2')[0].setCustomValidity('');
  48.         }
  49.         {% endif %}
  50.         // 個数フォームのチェック
  51.         if ($('#quantity').val() < 1) {
  52.             $('#quantity')[0].setCustomValidity('{{ '1以上で入力してください。'|trans }}');
  53.             return true;
  54.         } else {
  55.             $('#quantity')[0].setCustomValidity('');
  56.         }
  57.         event.preventDefault();
  58.         $form = $('#form1');
  59.         $.ajax({
  60.             url: $form.attr('action'),
  61.             type: $form.attr('method'),
  62.             data: $form.serialize(),
  63.             dataType: 'json',
  64.             beforeSend: function(xhr, settings) {
  65.                 // Buttonを無効にする
  66.                 $('.add-cart').prop('disabled', true);
  67.             }
  68.         }).done(function(data) {
  69.             // レスポンス内のメッセージをalertで表示
  70.             $.each(data.messages, function() {
  71.                 $('#ec-modal-header').html(this);
  72.             });
  73.             $('.ec-modal').show()
  74.             // カートブロックを更新する
  75.             $.ajax({
  76.                 url: "{{ url('block_cart') }}",
  77.                 type: 'GET',
  78.                 dataType: 'html'
  79.             }).done(function(html) {
  80.                 $('.ec-headerRole__cart').html(html);
  81.             });
  82.         }).fail(function(data) {
  83.             alert('{{ 'カートへの追加に失敗しました。'|trans }}');
  84.         }).always(function(data) {
  85.             // Buttonを有効にする
  86.             $('.add-cart').prop('disabled', false);
  87.         });
  88.     });
  89. });
  90. function checkShiro8Download($form, product_id, classcat_id1, classcat_id2) {
  91.     {% if is_granted('ROLE_USER') == false %}
  92.         classcat_id2 = classcat_id2 ? classcat_id2 : '';
  93.         var classcat2;
  94.         classcat2 = {{ product_class_categories|json_encode|raw }};
  95.         classcat2 = classcat2[classcat_id1]['#' + classcat_id2];
  96.         
  97.         // 在庫(品切れ)
  98.         var $cartbtn = $('.add-cart');
  99.         if (classcat2 && classcat2.dl_find === true) {
  100.             $cartbtn.prop('disabled', true);
  101.             $cartbtn.text('{{ 'plugin_shiro8_download42.default.product.list.title1'|trans }}');
  102.         } else {
  103.             $cartbtn.prop('disabled', false);
  104.             $cartbtn.text('{{ 'front.product.add_cart'|trans }}');
  105.         }
  106.     {% endif %}
  107. }
  108. </script>
  109. <div id="plugin_shiro8_download_product" class="d-none">
  110.     {% if hasProductFileAndSignIn %}
  111.             <button type="submit" class="buy-btn add-cart">
  112.                 <div class="cart-in"><img src="{{ asset('assets/img/btn_ic_cart.svg', 'user_data') }}" alt="カート">
  113.                     カートに入れる
  114.                 </div>
  115.             </button>
  116.     {% else %}
  117.             <button type="submit" class="buy-btn add-cart" disabled="disabled">
  118.                 <div class="cart-in"><img src="{{ asset('assets/img/btn_ic_cart.svg', 'user_data') }}" alt="カート">
  119.                     ログイン状態でないと、購入ができません。
  120.                 </div>
  121.             </button>
  122.     {% endif %}
  123. </div>