app/Plugin/SlnRegular4/Resource/template/Product/list.twig line 1

Open in your IDE?
  1. <script>
  2.     $(function () {
  3.         $('form[id^="productForm"').each(function(index, elm) {
  4.             $form = $(elm);
  5.             var product_id = $form.find('input[name=product_id]').val();
  6.             onClassCategorySelect($form, product_id);
  7.         });
  8.         // 規格1選択時
  9.         $('select[name=classcategory_id1]')
  10.             .change(function() {
  11.                 var $form = $(this).parents('form');
  12.                 var product_id = $form.find('input[name=product_id]').val();
  13.                 var $sele1 = $(this);
  14.                 // var $sele2 = $form.find('select[name=classcategory_id2]');
  15.                 onClassCategorySelect($form, product_id, $sele1.val(), '__unselected');
  16.             });
  17.         // 規格2選択時
  18.         $('select[name=classcategory_id2]')
  19.             .change(function() {
  20.                 var $form = $(this).parents('form');
  21.                 var product_id = $form.find('input[name=product_id]').val();
  22.                 var $sele1 = $form.find('select[name=classcategory_id1]');
  23.                 var $sele2 = $(this);
  24.                 onClassCategorySelect($form, product_id, $sele1.val(), $sele2.val());
  25.             });
  26.     });
  27.     function onClassCategorySelect($form, product_id, product_class_cat1, product_class_cat2) {
  28.         var productData = [];
  29.         
  30.         {% for product_id, productInfo in productData %}
  31.             productData['{{ product_id }}'] = [];
  32.             productData['{{ product_id }}']['hasClassCat1'] = {{ productInfo['hasClassCat1'] ? 'true' : 'false'  }};
  33.             productData['{{ product_id }}']['hasClassCat2'] = {{ productInfo['hasClassCat2'] ? 'true' : 'false' }};
  34.             productData['{{ product_id }}']['price2IncTaxMin'] = '{{ productInfo['price2IncTaxMin']|price }}';
  35.             productData['{{ product_id }}']['price2IncTaxMax'] = '{{ productInfo['price2IncTaxMax']|price }}';
  36.             productData['{{ product_id }}']['price02IncTaxMin'] = '{{ productInfo['price02IncTaxMin']|price }}';
  37.             productData['{{ product_id }}']['price02IncTaxMax'] = '{{ productInfo['price02IncTaxMax']|price }}';
  38.             productData['{{ product_id }}']['price2IncTaxs'] = [];
  39.             {% for key, price2IncTax in productInfo['price2IncTaxs'] %}
  40.                 productData['{{ product_id }}']['price2IncTaxs']['{{ key }}'] = '{{ price2IncTax|price }}';
  41.             {% endfor %}
  42.             productData['{{ product_id }}']['price02IncTaxs'] = [];
  43.             {% for key, price02IncTax in productInfo['price02IncTaxs'] %}
  44.                 productData['{{ product_id }}']['price02IncTaxs']['{{ key }}'] = '{{ price02IncTax|price }}';
  45.             {% endfor %}
  46.         {% endfor %}
  47.         var prod = productData[product_id];
  48.         if (prod === undefined) {
  49.             return;
  50.         }
  51.         
  52.         if (prod['hasClassCat2']) {
  53.             if (product_id === undefined || product_class_cat1 === undefined || product_class_cat1 === '__unselected' || product_class_cat2 === '__unselected') {
  54.                 interPrice2MultCat($form, prod['price02IncTaxMin'], prod['price02IncTaxMax'], prod['price2IncTaxMin'], prod['price2IncTaxMax']);
  55.                 return;
  56.             }
  57.             var key = product_id + "_" + product_class_cat1 + "_" + product_class_cat2;
  58.             var price02 = prod['price02IncTaxs'][key];
  59.             var price2 = prod['price2IncTaxs'][key];
  60.             if (price2 !== undefined) {
  61.                 interPrice2SingleCat($form, price02, price2);
  62.             }
  63.             else {
  64.                 interPrice2SingleCat($form, price02);
  65.             }
  66.         }
  67.         else if (prod['hasClassCat1']) {
  68.             if (product_id === undefined || product_class_cat1 === undefined || product_class_cat1 === '__unselected') {
  69.                 interPrice2MultCat($form, prod['price02IncTaxMin'], prod['price02IncTaxMax'], prod['price2IncTaxMin'], prod['price2IncTaxMax']);
  70.                 return;
  71.             }
  72.             var key = product_id + "_" + product_class_cat1;
  73.             var price02 = prod['price02IncTaxs'][key];
  74.             var price2 = prod['price2IncTaxs'][key];
  75.             if (price2 !== undefined) {
  76.                 interPrice2SingleCat($form, price02, price2);
  77.             }
  78.             else {
  79.                 interPrice2SingleCat($form, price02);
  80.             }
  81.         }
  82.         else {
  83.             interPrice2SingleCat($form, prod['price02IncTaxMin'], prod['price2IncTaxMin']);
  84.         }
  85.     }
  86.     function interPrice2MultCat($form, price02Min, price02Max, price2Min, price2Max) {
  87.         var $elm = $form.parent().find('.price02-default').first();
  88.         if (price02Min !== price2Min || price02Max !== price2Max) {
  89.             $elm.text(price2Min + ' (初回割引価格 ' + price02Min + ') ~ ' + price2Max + ' (初回割引価格 ' + price02Max + ')');
  90.         }
  91.         else {
  92.             $elm.text(price02Min + ' ~ ' + price02Max);
  93.         }
  94.     }
  95.     function interPrice2SingleCat($form, price02, price2) {
  96.         var $elm = $form.parent().find('.price02-default').first();
  97.         if (price2 !== undefined && price02 !== price2) {
  98.             $elm.text(price2 + ' (初回割引価格 ' + price02 + ')');
  99.         }
  100.         else {
  101.             $elm.text(price02);
  102.         }
  103.     }
  104.     function test() {
  105.         var elm;
  106.         {% if pagination.totalItemCount > 0 %}
  107.             {% for Product in pagination %}
  108.                 elm = $('li.ec-shelfGrid__item:eq({{ loop.index0 }}) > a >  p.price02-default');
  109.                 {% if hasPrice2Data[Product.id] %}
  110.                     {% set productInfo = productData[Product.id] %}
  111.                     {% set price2IncTaxMin = productInfo['price2IncTaxMin'] %}
  112.                     {% set price2IncTaxMax = productInfo['price2IncTaxMax'] %}
  113.                     {% if price2IncTaxMin == price2IncTaxMax %}
  114.                         {% if Product.getPrice02IncTaxMin != price2IncTaxMin %}
  115.                             {# 単一規格かつ販売価格と異なる #}
  116.                             elm.text('{{ price2IncTaxMin|price }} (初回割引価格 {{ Product.getPrice02IncTaxMin|price }})');
  117.                         {% endif %}
  118.                     {% else %}
  119.                         {# 複数規格 #}
  120.                         elm.text('{{ price2IncTaxMin|price }} (初回割引価格 {{ Product.getPrice02IncTaxMin|price }}) ~ {{ price2IncTaxMax|price }} (初回割引価格 {{ Product.getPrice02IncTaxMax|price }})');
  121.                     {% endif %}
  122.                 {% endif %}
  123.             {% endfor %}
  124.         {% endif %}
  125.     }
  126. </script>