Advertisement
Guest User

testjs

a guest
Dec 19th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //<![CDATA[    
  2.     $(function() {
  3.  
  4.         var collectionPriceRules = [];
  5.         var priceProductRules = {$product->price};
  6.  
  7.         var lengthRules = {count($quantity_discounts)};
  8.         var qty_max = 0;
  9.  
  10.         {foreach from=$quantity_discounts item='quantity_discount' name='quantity_discounts'}
  11.  
  12.             var objPriceRules = {};
  13.             var qty_prod =  {$quantity_discount.quantity|intval};
  14.            
  15.             objPriceRules.qty_max = (qty_max == 0) ? 0 : qty_max;
  16.             objPriceRules.qty_min = qty_prod;
  17.             qty_max = qty_prod;
  18.  
  19.         {if $quantity_discount.price >= 0 OR $quantity_discount.reduction_type == 'amount'}
  20.             objPriceRules.type= "ammount";
  21.             objPriceRules.price=(priceProductRules-{$quantity_discount.real_value|floatval});
  22.         {else}
  23.             objPriceRules.type= "%";
  24.             objPriceRules.price = (priceProductRules-((priceProductRules*{$quantity_discount.real_value|floatval})/100));
  25.         {/if}
  26.  
  27.         collectionPriceRules.push(objPriceRules);
  28.  
  29.         {/foreach}        
  30.        
  31.         /*var regularPrice = {};
  32.         regularPrice.type = 'regular';
  33.         regularPrice.price = priceProductRules;
  34.         regularPrice.qty_min = 1;
  35.         regularPrice.qty_max = priceProductRules;
  36.         collectionPriceRules.push(regularPrice); */
  37.  
  38.         var orderPrices = function(qty, callback) {
  39.            
  40.             function compare(a,b) {
  41.                 if (a.price < b.price)
  42.                     return -1;
  43.                 else
  44.                     return 1;
  45.                 return 0;
  46.             }
  47.  
  48.             if ( qty == null && undefined !== callback) {
  49.                 callback(collectionPriceRules.sort(compare));
  50.             } else if (null !== qty) {
  51.  
  52.                 var data = collectionPriceRules.sort(compare);
  53.                 var newCollection = [];
  54.                 for(var i in data) {
  55.                     if ( (qty <= data[i].qty_max || 0 == data[i].qty_max)
  56.                          && qty >= data[i].qty_min)
  57.                     {
  58.                         var indx = i;
  59.                     }
  60.                     newCollection.push(data[i])
  61.                 }
  62.                 var aux = newCollection[0];
  63.                 newCollection[0] = newCollection[indx];
  64.                 newCollection[indx] = aux;
  65.                 callback(newCollection);
  66.             }  
  67.         }
  68.        
  69.         var docfrag = document.createDocumentFragment();
  70.  
  71.         orderPrices(1900, function(collPrices) {
  72.             if (collPrices.length) {
  73.  
  74.                 for (var ob in collPrices) {
  75.                     var li = document.createElement("li");
  76.                     li.className  = 'price_item';
  77.                     if (ob == 0) {
  78.                         // this is low price
  79.                         li.className  += ' price_highlight';
  80.                         li.textContent = "$"+collPrices[ob].price.toFixed(2) + " Sq Ft ";
  81.                     } else {
  82.                         li.textContent = "$"+collPrices[ob].price.toFixed(2) + " SF ";
  83.                     }
  84.                     var span = document.createElement("span");
  85.                     var strQtyMax = (parseInt(collPrices[ob].qty_max) > 0)
  86.                                     ? " - " +collPrices[ob].qty_max
  87.                                     : "+" ;
  88.                     span.innerText = " ("+collPrices[ob].qty_min + strQtyMax +") Sq Ft";
  89.                     li.appendChild(span);
  90.                     docfrag.appendChild(li);
  91.                     $('#list_price').append(docfrag);
  92.                 }
  93.             }
  94.  
  95.             console.log("Minor price!");
  96.             console.log(collPrices);
  97.             console.log("------------");
  98.         });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement