Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //<![CDATA[
- $(function() {
- var collectionPriceRules = [];
- var priceProductRules = {$product->price};
- var lengthRules = {count($quantity_discounts)};
- var qty_max = 0;
- {foreach from=$quantity_discounts item='quantity_discount' name='quantity_discounts'}
- var objPriceRules = {};
- var qty_prod = {$quantity_discount.quantity|intval};
- objPriceRules.qty_max = (qty_max == 0) ? 0 : qty_max;
- objPriceRules.qty_min = qty_prod;
- qty_max = qty_prod;
- {if $quantity_discount.price >= 0 OR $quantity_discount.reduction_type == 'amount'}
- objPriceRules.type= "ammount";
- objPriceRules.price=(priceProductRules-{$quantity_discount.real_value|floatval});
- {else}
- objPriceRules.type= "%";
- objPriceRules.price = (priceProductRules-((priceProductRules*{$quantity_discount.real_value|floatval})/100));
- {/if}
- collectionPriceRules.push(objPriceRules);
- {/foreach}
- /*var regularPrice = {};
- regularPrice.type = 'regular';
- regularPrice.price = priceProductRules;
- regularPrice.qty_min = 1;
- regularPrice.qty_max = priceProductRules;
- collectionPriceRules.push(regularPrice); */
- var orderPrices = function(qty, callback) {
- function compare(a,b) {
- if (a.price < b.price)
- return -1;
- else
- return 1;
- return 0;
- }
- if ( qty == null && undefined !== callback) {
- callback(collectionPriceRules.sort(compare));
- } else if (null !== qty) {
- var data = collectionPriceRules.sort(compare);
- var newCollection = [];
- for(var i in data) {
- if ( (qty <= data[i].qty_max || 0 == data[i].qty_max)
- && qty >= data[i].qty_min)
- {
- var indx = i;
- }
- newCollection.push(data[i])
- }
- var aux = newCollection[0];
- newCollection[0] = newCollection[indx];
- newCollection[indx] = aux;
- callback(newCollection);
- }
- }
- var docfrag = document.createDocumentFragment();
- orderPrices(1900, function(collPrices) {
- if (collPrices.length) {
- for (var ob in collPrices) {
- var li = document.createElement("li");
- li.className = 'price_item';
- if (ob == 0) {
- // this is low price
- li.className += ' price_highlight';
- li.textContent = "$"+collPrices[ob].price.toFixed(2) + " Sq Ft ";
- } else {
- li.textContent = "$"+collPrices[ob].price.toFixed(2) + " SF ";
- }
- var span = document.createElement("span");
- var strQtyMax = (parseInt(collPrices[ob].qty_max) > 0)
- ? " - " +collPrices[ob].qty_max
- : "+" ;
- span.innerText = " ("+collPrices[ob].qty_min + strQtyMax +") Sq Ft";
- li.appendChild(span);
- docfrag.appendChild(li);
- $('#list_price').append(docfrag);
- }
- }
- console.log("Minor price!");
- console.log(collPrices);
- console.log("------------");
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement