PrestaShop Forum

The best place in the world to ask questions about PrestaShop and get advice from our passionate community!

PrestaShop Forum

Jump to content

[MODULE] Quantity Discounts - Display the quantity discounts in a more visible place.

66 replies to this topic
#1
tomerg3

    PrestaShop Superstar

  • US Moderators
  • 5754 posts
This Module displays the quantity discounts as a final price (no %), directly below the product price (instead of a tab lower down the page).

The discount price will also update based on attribute impact.

Tested on PS 1.2, 1,3 and 1.4

http://www.presto-ch...-discounts.html

V1.1 was just released, it fixes a little bug when the prices were over 999

V1.2 released, it includes a fix for currencies with , for decimal amounts (IE Euro), and for prices over 999

V1.2.1 released, it includes a fix for currency signs with special characters (IE , . or digits)

V1.2.2 released, it includes support for PS 1.4

V1.2.3 Released
* Fix for "Product Price" discount (not a % or fixed amount).
* Added automatic upgrade notification.


V1.2.4 released
* Fix for "Quantity Discounts" text (was not translatable in last version).

Attached Files


Posted Image
For the latest updates discount coupons and new module information follow us on Twitter , Facebook ,and tips on our Blog
Please do not send general questions via PM, that is what the forum is for...

#2
Dimar

    PrestaShop Apprentice

  • Members
  • PipPip
  • 165 posts
Thanks tomerg3 by this aggregate. Works for Me. ;) By

#3
Dimar

    PrestaShop Apprentice

  • Members
  • PipPip
  • 165 posts
There is something I would like to add:

How to aggregate text above discounts that it says: Price for Quantity: ??

Thanks

#4
tomerg3

    PrestaShop Superstar

  • US Moderators
  • 5754 posts
V1.1 was just released, it fixes a little bug when the prices were over 999
Posted Image
For the latest updates discount coupons and new module information follow us on Twitter , Facebook ,and tips on our Blog
Please do not send general questions via PM, that is what the forum is for...

#5
jhnstcks

    PrestaShop Fanatic

  • Moderators
  • 1913 posts
Yet another excellant module tomerg3, one thing though, i have changed the word quantities to read "or more products", but would like to add the word each after the price, otherwise it might be a bit misleading to some customers.

Attached Files


Helpful hints and tips to Empower your Prestashop site - Join us on Facebook and get involved, tell us the things that help you.
If you think someone's answer helped, please give him/her a Positive Reputation vote by liking their post.
E-commerce hosting from Scotserve, fast, reliable and affordable.

#6
tomerg3

    PrestaShop Superstar

  • US Moderators
  • 5754 posts

From 1275543728:

Yet another excellant module tomerg3, one thing though, i have changed the word quantities to read "or more products", but would like to add the word each after the price, otherwise it might be a bit misleading to some customers.


in quantitydiscount.tpl line #33 add the text at the end of the line (before the end ")


discountStr += "{$qd_quantity_discount.quantity|intval} or more ";

Posted Image
For the latest updates discount coupons and new module information follow us on Twitter , Facebook ,and tips on our Blog
Please do not send general questions via PM, that is what the forum is for...

#7
t7E4n5L1

    PrestaShop Newbie

  • Members
  • Pip
  • 6 posts
jhnstcks: Mind sharing how you got to modify "quantities" to something else?


tomerg3: What jhnstcks wants to do is actually add the word "each" to the price in the quantity discount, not after the quantity. Without that specification, it looks as if if you buy 2 items, the price shown was for the 2 items and not the new price for each item.

So basically turning this:
2 quantities : $99.99

into this:
2 quantities : $99.99 each

#8
jhnstcks

    PrestaShop Fanatic

  • Moderators
  • 1913 posts
this is a snippet of my code
function writeDiscountsContent(price) {ldelim}
var discountStr = "

"
var discountedPrice = 0;
{foreach from=$qd_quantity_discounts item='qd_quantity_discount' name='quantity_discounts'}
discountStr += "{$qd_quantity_discount.quantity|intval} "
{if $qd_quantity_discount.quantity|intval > 1}
discountStr += "{l s='or more products' mod='quantitydiscounts'}: ";
{else}
discountStr += "{l s='product' mod='quantitydiscounts'}: ";
{/if}
{if $qd_quantity_discount.id_discount_type|intval == 1}
discountedPrice = price - (price * {$qd_quantity_discount.value} / 100);
{else}
discountedPrice = price - {$qd_quantity_discount.value};
{/if}
discountStr += formatCurrency(discountedPrice, currencyFormat, currencySign, currencyBlank) + " each
";
{/foreach}
discountStr += "

";


If you notice the 3rd last line of code at the end i have added "each", just before the end of the span

Attached Files


Helpful hints and tips to Empower your Prestashop site - Join us on Facebook and get involved, tell us the things that help you.
If you think someone's answer helped, please give him/her a Positive Reputation vote by liking their post.
E-commerce hosting from Scotserve, fast, reliable and affordable.

#9
t7E4n5L1

    PrestaShop Newbie

  • Members
  • Pip
  • 6 posts
jhnstcks: Could you let us know how you managed to modify the word "quantities"?. I'd rather have it show that in 'units' instead. Thanks in advance.

To recap what jhnstcks said:

In the quantitydiscounts package, open quantitydiscounts.tpl, look at line 44:
        discountStr += formatCurrency(discountedPrice, currencyFormat, currencySign, currencyBlank) + "
";


Change it to this
        discountStr += formatCurrency(discountedPrice, currencyFormat, currencySign, currencyBlank) + " each 
 ";


#10
gofer_p

    PrestaShop Newbie

  • Members
  • Pip
  • 21 posts
I love this module but I am having one problem. Although I have discounts set to $50 of each unit if the customer buys more than 5 the product page shows $-49 and not $-50. The calculation in the cart is correct but the display abouve product price is not. How do I fix this. Link to page here

I too would like to add the word each after the price.

Thank you

#11
ElManchi

    PrestaShop Newbie

  • Members
  • Pip
  • 5 posts
I love so much this module but I am having one problem.

In code, I see that price is fetched from html, but in spanish version with euro, price have comma (10,35 €). When returns price in float, price is not correct.

Funtion in quantitydiscounts.tpl:

function fetchCurrentPrice() {ldelim}
var val = $("#our_price_display").text();
var qd_price = "";

for (var i = 0 ; i < val.length ; i++)
if (/[0-9.,]/.test(val.charAt(i)))
qd_price += val.charAt(i);

return parseFloat(new_price);


I need that "comma" char switch to "point" char.


Thnx.

#12
weraw

    PrestaShop Apprentice

  • Members
  • PipPip
  • 46 posts
How can i set in my code to show the quantity discounts only four Group_id=1, Group_id=2, Group_id=3 and for the rest it is not showing!

Regards
//WeraW

#13
LeGastronome

    PrestaShop Apprentice

  • Members
  • PipPip
  • 235 posts
Thanks for this module but I have wrong price calculation.

Someone have the same trouble ?
17,90 - 5% = 16,15 ?!!!

Thanks

#14
tomerg3

    PrestaShop Superstar

  • US Moderators
  • 5754 posts
There is a small bug with the module for certain price formats, it's on my to-do list....
Posted Image
For the latest updates discount coupons and new module information follow us on Twitter , Facebook ,and tips on our Blog
Please do not send general questions via PM, that is what the forum is for...

#15
LeGastronome

    PrestaShop Apprentice

  • Members
  • PipPip
  • 235 posts
I saw lines where convertion are done, but you took price from prestashop var. is it correct ?

#16
eskaigualker

    PrestaShop Newbie

  • Members
  • Pip
  • 21 posts
Instead of getting the price from the html text, I prefer to add this line in the function hookTop (from quantitydiscounts.php): $smarty->assign('precio', $product->getPriceWithoutReduct());
Then in quantitydiscounts.tpl I change the writeDiscountsContent function declaration to:
function writeDiscountsContent() {ldelim}

And add this: var price={$precio}

This works perfectly in "spanish"

#17
jujuforce

    PrestaShop Newbie

  • Members
  • Pip
  • 4 posts

From 1284110188:

Instead of getting the price from the html text, I prefer to add this line in the function hookTop (from quantitydiscounts.php): $smarty->assign('precio', $product->getPriceWithoutReduct());
Then in quantitydiscounts.tpl I change the writeDiscountsContent function declaration to:
function writeDiscountsContent() {ldelim}

And add this: var price={$precio}

This works perfectly in "spanish"


This was not working for me, items were getting the price of other items from the shop...

Well here is my fix :

function fetchCurrentPrice() {ldelim}
var val = $("#our_price_display").text();
var qd_price = "";
for (var i = 0 ; i < val.length ; i++)
if (/[0-9.,]/.test(val.charAt(i)))
if (val.charAt(i) == ',')
qd_price += '.';
else
qd_price += val.charAt(i);

return parseFloat(qd_price);
{rdelim}


Replace your fetchCurrentPrice function with the one above (it's in quantitydiscounts.tpl)
Magasin de vente de cartes pour magicien : http://www.cartesmagie.com

#18
dt88

    PrestaShop Apprentice

  • Members
  • PipPip
  • 64 posts
this is a great idea but I cant figure out what is going on with this code
all the $ display is incorrect but it calculates in the cart correctly

first line, 10% off is 117.057, calculates correctly in cart, but shows $0.90 in the discount window, should show 1053.513
second, $15 off, shows $-14, calucates correctly in cart, should show 1155.57
same deal with the 3rd line was meant to be $100 shows -99

<!-- MODULE Discounts -->
{if isset($qd_quantity_discounts) AND $qd_quantity_discounts}
<style>
ul#idTab
{ldelim}
display: none;
{rdelim}
</style>
[removed]

/**
* fetch the current price from the buy block text, parse it into a float and return it
*/
function fetchCurrentPrice() {ldelim}
var val = $("#our_price_display").text();
var qd_price = "";
for (var i = 0 ; i < val.length ; i++)
if (/[0-9.,]/.test(val.charAt(i)))
qd_price += val.charAt(i);

return parseFloat(qd_price);
{rdelim}

/**
* generate the discount area content (quantities and calculated discounted price)
* using the given single unit price
*/
function writeDiscountsContent(price) {ldelim}
var discountStr = "

";
var discountedPrice = 0;

{foreach from=$qd_quantity_discounts item='qd_quantity_discount' name='quantity_discounts'}
discountStr += "{$qd_quantity_discount.quantity|intval} ";
{if $qd_quantity_discount.quantity|intval > 1}
discountStr += "{l s='quantities' mod='quantitydiscounts'}: ";
{else}
discountStr += "{l s='quantity' mod='quantitydiscounts'}: ";
{/if}
{if $qd_quantity_discount.id_discount_type|intval == 1}
discountedPrice = price - (price * {$qd_quantity_discount.value} / 100);
{else}
discountedPrice = price - {$qd_quantity_discount.value};
{/if}
discountStr += formatCurrency(discountedPrice, currencyFormat, currencySign, currencyBlank) + "
";
{/foreach}
discountStr += "

";

return discountStr;
{rdelim}

$(document).ready(function () {ldelim}
// remove the legacy quantities div and the tab above it
$("#quantityDiscount").prev().css('display','none');
$("#quantityDiscount").css('display','none');

// hook the updateDisplay javascript call
var origUpdateDisplay = window.updateDisplay;

window.updateDisplay = function() {ldelim}
origUpdateDisplay();

var discountStr = writeDiscountsContent(fetchCurrentPrice());
$('#discounts_block').replaceWith(discountStr);
{rdelim}

var discountStr = writeDiscountsContent(fetchCurrentPrice());

price_found = false;
$("#buy_block").children().each(function() {ldelim}
// skip anything before the price div
if ( $(this).attr('class') == "price" ) {ldelim}
price_found = true;
{rdelim}

if (!price_found) {ldelim}
return;
{rdelim}

// now skip any of the price sub items (old_price, reduction_percent, pack_price, price-ecotax)
id = $(this).attr('id');
if ( id == "" || id == "old_price" || id == "reduction_percent" || id == "pack_price" || id == "price-ecotax" )
return;

// ok, found something else so this is the end of the price block - print our stuff and reset the
// found flag (so we don't print on the next element as well)
$(discountStr).insertBefore($(this));
price_found = false;
{rdelim});

{rdelim});
[removed]

{/if}
<!-- / MODULE Discounts -->



also, on another note, would be awesome if we could get these prices to show in the product listing, but its hard for me to play with it without it working properly. I was thinking on the stock standard template to pop it under the sale price, but have it list with abbreviations, smaller text and different colour

$1000
x3+ > $950ea
x5+ > $900ea
x10+ > $850ea

Attached Files


Live Life.

#19
tomerg3

    PrestaShop Superstar

  • US Moderators
  • 5754 posts
V1.2 released, it includes a fix for currencies with , for decimal amounts (IE Euro), and for prices over 999
Posted Image
For the latest updates discount coupons and new module information follow us on Twitter , Facebook ,and tips on our Blog
Please do not send general questions via PM, that is what the forum is for...

#20
Fant63

    PrestaShop Apprentice

  • Members
  • PipPip
  • 135 posts
Unfortunately, he did not properly considered ((

Attached Files

  • Attached File  1.jpg   98bytes   372 downloads