app/template/default/Product/js/detail_script.twig line 1

Open in your IDE?
  1.  <script>
  2.     eccube.classCategories = {{ class_categories_as_json(Product)|raw }};
  3.         // 規格2に選択肢を割り当てる。
  4.         function fnSetClassCategories(form, classcat_id2_selected) {
  5.             var $form = $(form);
  6.             var product_id = $form.find('input[name=product_id]').val();
  7.             var $sele1 = $form.find('select[name=classcategory_id1]');
  8.             var $sele2 = $form.find('select[name=classcategory_id2]');
  9.             eccube.setClassCategories($form, product_id, $sele1, $sele2, classcat_id2_selected);
  10.         }
  11.         {% if form.classcategory_id2 is defined %}
  12.         fnSetClassCategories( $('#form1'), {{ form.classcategory_id2.vars.value|json_encode|raw }} );
  13.         fnSetClassCategories( $('#form2'), {{ form.classcategory_id2.vars.value|json_encode|raw }} );
  14.         {% elseif form.classcategory_id1 is defined %}
  15.         eccube.checkStock($('#form1'), {{ Product.id }}, {{ form.classcategory_id1.vars.value|json_encode|raw }}, null);
  16.         eccube.checkStock($('#form2'), {{ Product.id }}, {{ form.classcategory_id1.vars.value|json_encode|raw }}, null);
  17.         {% endif %}
  18.         </script>
  19.         <script>
  20.         $(function() {
  21.             // bfcache無効化
  22.             $(window).bind('pageshow', function(event) {
  23.                 if (event.originalEvent.persisted) {
  24.                     location.reload(true);
  25.                 }
  26.             });
  27.             $('.item_visual').slick({
  28.                 dots: true,
  29.                 arrows: true,
  30.                 prevArrow: '<span class="material-icons slide-arrow prev-arrow"><span>navigate_before</span></span>',
  31.                 nextArrow: '<span class="material-icons  slide-arrow next-arrow">chevron_right</span>',
  32.                 responsive: [{
  33.                     breakpoint: 768,
  34.                     settings: {
  35.                         dots: true
  36.                     }
  37.                 }]
  38.             });
  39.             $('.slideThumb').on('click', function() {
  40.                 var index = $(this).attr('data-index');
  41.                 $('.item_visual').slick('slickGoTo', index, false);
  42.             })
  43.         });
  44.         </script>
  45.         <script>
  46.         $(function() {
  47.             add_carts('#form1');
  48.             add_carts('#form2');
  49.         });
  50.         </script>
  51.     
  52.         <script>
  53.             /*--------------------------------------------------- */
  54.             /* カートに追加
  55.             /*--------------------------------------------------- */
  56.             function add_carts(form_id){
  57.             $(form_id+' .add-carts').on('click', function(event) {
  58.                 {% if form.classcategory_id1 is defined %}
  59.                 // 規格1フォームの必須チェック
  60.                 if ($('#classcategory_id1').val() == '__unselected' || $('#classcategory_id1').val() == '') {
  61.                     $('#classcategory_id1')[0].setCustomValidity('{{ '項目が選択されていません'|trans }}');
  62.                     return true;
  63.                 } else {
  64.                     $('#classcategory_id1')[0].setCustomValidity('');
  65.                 }
  66.                 {% endif %}
  67.                 {% if form.classcategory_id2 is defined %}
  68.                 // 規格2フォームの必須チェック
  69.                 if ($('#classcategory_id2').val() == '__unselected' || $('#classcategory_id2').val() == '') {
  70.                     $('#classcategory_id2')[0].setCustomValidity('{{ '項目が選択されていません'|trans }}');
  71.                     return true;
  72.                 } else {
  73.                     $('#classcategory_id2')[0].setCustomValidity('');
  74.                 }
  75.                 {% endif %}
  76.                 // 個数フォームのチェック
  77.                 if ($('#quantity').val() < 1) {
  78.                     $('#quantity')[0].setCustomValidity('{{ '1以上で入力してください。'|trans }}');
  79.                     return true;
  80.                 } else {
  81.                     $('#quantity')[0].setCustomValidity('');
  82.                 }
  83.                 event.preventDefault();
  84.                 $form = $(form_id);
  85.                 $.ajax({
  86.                     url: $form.attr('action'),
  87.                     type: $form.attr('method'),
  88.                     data: $form.serialize(),
  89.                     dataType: 'json',
  90.                     beforeSend: function(xhr, settings) {
  91.                         // Buttonを無効にする
  92.                         $('.add-carts').prop('disabled', true);
  93.                     }
  94.                 }).done(function(data) {
  95.                     // レスポンス内のメッセージをalertで表示
  96.                     $.each(data.messages, function() {
  97.                         $('#ec-modal-header').html(this);
  98.                     });
  99.                     $('#ec-modal-checkbox').prop('checked', true);
  100.                     // カートブロックを更新する
  101.                     $.ajax({
  102.                         url: "{{ url('block_cart') }}",
  103.                         type: 'GET',
  104.                         dataType: 'html'
  105.                     }).done(function(html) {
  106.                         $('.ec-headerRole__cart').html(html);
  107.                     });
  108.                 }).fail(function(data) {
  109.                     alert('{{ 'カートへの追加に失敗しました。'|trans }}');
  110.                 }).always(function(data) {
  111.                     // Buttonを有効にする
  112.                     $('.add-carts').prop('disabled', false);
  113.                 });
  114.             });
  115.             }
  116.     </script>