Jump to content

Use Ajax Cart Script To Product Page


Recommended Posts

Hi to all!

I would kindly ask your help about a major issue I face and I am not sure if I can manage to accomplish. I am am trying to create a script in product page which will calculate and display the total price depending on the quantity set by the user.

It is exactly the same script used in cart in which there is a plus (+) and a minus (-) button used to adjust the quantity.

Spending many hours trying to get this script 'copied' to product page I didn't have any success.

Any suggestions would be welcomed

Edited by gtsagat (see edit history)
Link to comment
Share on other sites

Thanks a lot for your help Nemo, but unforunately, this was my main problem. I use quantity discounts.

I was thinking to make script on my own and make a query to the database in order to get the discount having the id of the product. Then subsctract the discount from the original price and multiply the result with the quantity.

 

I am not sure if this is correct but since I am new to prestashop I cannot think something easier.

Link to comment
Share on other sites

uhm... well if it is so, maybe you can save the quantity discounts' already calculated price in hidden fields. Given them ids like (product_quantity_3) so that you can target them in your script.

 

Then write something like

real_price = $('#product_quantity_'+$('input_number).val()).val();

 

Should work, but you need to calculate the flat discount price before inside smarty

Link to comment
Share on other sites

I have start creating a function in class Product.php taking as parameters the id_product, the input quantity and the price before discount.

 

Something like this

 

 

public static function specificPriceCustom($id_product, $quantity, $standardPrice)

{

$specificPrice = SpecificPrice::getByProductId((int)$id_product);

 

foreach ($specificPrice as &$row) {

 

if ( $row["from_quantity"] >= $quantity ){

if ( $row["reduction_type"] == "percentage"):

$price = $standardPrice - $standardPrice*$row["reduction"] ;

elseif ( $row["reduction_type"] == "amount"):

$price = $standardPrice - $standardPrice*$row["price"] ;

endif;

 

$price = $price * $quantity;

return $price ;

}

}

}

 

It is not very elegant solution so I will try yours too. I really appreciate your help Nemo! I will let you know about the result.

Edited by gtsagat (see edit history)
Link to comment
Share on other sites

  • 4 weeks later...

Nemo thanks a lot for your advise. I did a hybrid solution between your idea and mine and everything works fine now.

 

Keep advising :-)

 

 

Hi gtsagat!

 

I am looking for the exact same thing! Are you willing to share the working solution?

 

 

Br,

Tobias

Link to comment
Share on other sites

Hello Tobias!

Unfortunately, I have the code in my office and I will be there tomorrow (Monday morning). So I will definitely share it with you. Since it is my first website with prestashop, it's a bit complex aproach but it works.

Link to comment
Share on other sites

Hello Tobias!

 

before I will give you my solution I would like to warn you that I don't know (yet :-) ) much about prestashop so, the solution is not very elegant and doesn' t follow any protocol. But as I said it works.

 

Let's start.

1. In the themes folder edit the product.tpl as follows:

add this

<script type="text/javascript" src="{$base_dir}themes/matrice/js/ajax-product-price.js"></script>

somewhere in the top of the page along with the other scripts.

 

I have created a new file for the ajax because I couldn't manage to work with prestashop' s ajax. If you know how, you may ommit this.

 

2. add the following (in product.tpl)

 

<p id="quantity_wanted_p"{if (!$allow_oosp && $product->quantity == 0) OR $virtual OR !$product->available_for_order OR $PS_CATALOG_MODE} style="display: none;"{/if}>

<label>{l s='Quantity'} : </label><br>

<input type="button" value="" id="add1" class="add" />

<input type="text" name="qty" id="quantity_wanted" class="qty" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}{if $product->minimal_quantity > 1}{$product->minimal_quantity}{else}1{/if}{/if}" size="2" maxlength="3" {if $product->minimal_quantity > 1}onkeyup="checkMinimalQuantity({$product->minimal_quantity});"{/if} />

<input type="button" value="" id="minus1" class="minus" />

<span class="priceCalculate">{$productPrice}</span>  

<span id="our_price_display"><span class="currencySign"> {$currencySign}</span> 

{if $tax_enabled}

{if $priceDisplay == 1}{l s='tax excl.'}{else}{l s='tax incl.'}{/if}

{/if}</span></span>

<input type="hidden" value="{$productPrice}" id="price" />

<input type="hidden" value="{$product->id}" id="id_product" />

 

 

</p>

 

This is the code which outputs the calculated price along with the + - buttons

 

3. As you will see inside ajax-product-price.js, there is a reference in 'themes/matrice/priceAjaxCalulation.php' which does the calcuation of the price, according to the quantity set by the user, taking in consideration the quantity discounts.

 

The code of priceAjaxCalulation.php is the following. You will see a function (dbconnect()) for the db conncetion. I didn't know how to connect to the db in prestashop's way. So you may change this by connecting to the database in the proper way.

Finally there is the specificPriceCustom() function which does our job

 

 

<?

 

function dbconnect()

{

date_default_timezone_set("Europe/Athens");

include("db_config.php");

 

 

$dblink = mysql_pconnect($HOST, $USER, $PASS);

if ( !$dblink )

{

 

header("HTTP/1.0 500 Internal Server Error");

exit();

}

@mysql_query("set character_set_client=$CHAR_SET", $dblink);

@mysql_query("set character_set_connection=$CHAR_SET", $dblink);

@mysql_query("set collation_connection=$COLLATION", $dblink);

@mysql_query("set character_set_results=$COLLATION", $dblink);

@mysql_query("set time_zone='+02:00'", $dblink);

 

if( !mysql_select_db($DATABASE, $dblink) )

{

echo mysql_errno().": ".mysql_error();

exit();

}

 

return $dblink;

}

 

 

$db = dbconnect();

 

$id_product = $_POST["id_product"];

$quantity = $_POST["quantity"];

$standardPrice = $_POST["standard_price"];

 

 

function getByProductId($db,$id_product)

{

$query = mysql_query('

SELECT *

FROM `ps_specific_price`

WHERE `id_product` = '.(int)$id_product, $db);

//$output = mysql_fetch_array ($query);

 

return $query;

}

 

function specificPriceCustom($db, $id_product, $quantity, $standardPrice)

{

$specificPrice = getByProductId($db, (int)$id_product);

$totalRows = mysql_num_rows ($specificPrice);

$rowCount = 0;

$previousPrice = $standardPrice;

 

while ( $row = mysql_fetch_array($specificPrice)) {

$rowCount++;

 

 

if ( $row["reduction_type"] == "percentage" && $row["reduction"]== "1"):

$price = round ($previousPrice * $quantity, 2, PHP_ROUND_HALF_DOWN);

 

return $price ;

elseif ( $quantity < $row["from_quantity"] ):

$price = round ($previousPrice * $quantity, 2, PHP_ROUND_HALF_DOWN);

 

return $price ;

 

elseif ($quantity == $row["from_quantity"]|| $rowCount == $totalRows):

 

if ( $row["price"] == "-1" ):

if ( $row["reduction_type"] == "percentage" ):

$price = $standardPrice - $standardPrice*$row["reduction"] ;

elseif ( $row["reduction_type"] == "amount"):

$price = $standardPrice -$row["reduction"] ;

endif;

else:

$price = $row["price"] ;

endif;

 

$price = round ($price * $quantity,2, PHP_ROUND_HALF_DOWN);

return $price ;

 

 

endif;

 

if ( $row["price"] == "-1" ):

if ( $row["reduction_type"] == "percentage" ):

$previousPrice = $standardPrice - $standardPrice*$row["reduction"] ;

elseif ( $row["reduction_type"] == "amount"):

$previousPrice = $standardPrice -$row["reduction"] ;

endif;

else:

$previousPrice = $row["price"] ;

endif;

 

}

$price = $standardPrice * $quantity ;

return $price;

}

 

echo specificPriceCustom($db, $id_product, $quantity, $standardPrice);

?>

Link to comment
Share on other sites

Hi,

 

Hmm, what content should i put in ajax-product.price.js? Also, should i but the code bellow in a file which i will name PriceAjaxCalculation?

 

 

<?
function dbconnect()
{
date_default_timezone_set("Europe/Athens");
include("db_config.php");

$dblink = mysql_pconnect($HOST, $USER, $PASS);
if ( !$dblink )
{
header("HTTP/1.0 500 Internal Server Error");
exit();
}
@mysql_query("set character_set_client=$CHAR_SET", $dblink);
@mysql_query("set character_set_connection=$CHAR_SET", $dblink);
@mysql_query("set collation_connection=$COLLATION", $dblink);
@mysql_query("set character_set_results=$COLLATION", $dblink);
@mysql_query("set time_zone='+02:00'", $dblink);
if( !mysql_select_db($DATABASE, $dblink) )
{
echo mysql_errno().": ".mysql_error();
exit();
}
return $dblink;
}

$db = dbconnect();
$id_product = $_POST["id_product"];
$quantity = $_POST["quantity"];
$standardPrice = $_POST["standard_price"];

function getByProductId($db,$id_product)
{
$query = mysql_query('
SELECT *
FROM `ps_specific_price`
WHERE `id_product` = '.(int)$id_product, $db);
//$output = mysql_fetch_array ($query);
return $query;
}
function specificPriceCustom($db, $id_product, $quantity, $standardPrice)
{
$specificPrice = getByProductId($db, (int)$id_product);
$totalRows = mysql_num_rows ($specificPrice);
$rowCount = 0;
$previousPrice = $standardPrice;
while ( $row = mysql_fetch_array($specificPrice)) {
$rowCount++;

if ( $row["reduction_type"] == "percentage" && $row["reduction"]== "1"):
$price = round ($previousPrice * $quantity, 2, PHP_ROUND_HALF_DOWN);
return $price ;
elseif ( $quantity < $row["from_quantity"] ):
$price = round ($previousPrice * $quantity, 2, PHP_ROUND_HALF_DOWN);
return $price ;
elseif ($quantity == $row["from_quantity"]|| $rowCount == $totalRows):
if ( $row["price"] == "-1" ):
if ( $row["reduction_type"] == "percentage" ):
$price = $standardPrice - $standardPrice*$row["reduction"] ;
elseif ( $row["reduction_type"] == "amount"):
$price = $standardPrice -$row["reduction"] ;
endif;
else:
$price = $row["price"] ;
endif;
$price = round ($price * $quantity,2, PHP_ROUND_HALF_DOWN);
return $price ;

endif;
if ( $row["price"] == "-1" ):
if ( $row["reduction_type"] == "percentage" ):
$previousPrice = $standardPrice - $standardPrice*$row["reduction"] ;
elseif ( $row["reduction_type"] == "amount"):
$previousPrice = $standardPrice -$row["reduction"] ;
endif;
else:
$previousPrice = $row["price"] ;
endif;
}
$price = $standardPrice * $quantity ;
return $price;
}
echo specificPriceCustom($db, $id_product, $quantity, $standardPrice);
?>

 

 

Br,

Tobias

Link to comment
Share on other sites

Sorry, you are correct.

The code I gave you above, should be indeed in a file called PriceAjaxCalculation.php

Also the code for the 'ajax-product-price.js' is the following. Don't forget to change the url according to your needs

 

$(function()

{

$(".add").click(function()

{

var currentVal = parseInt($(this).next(".qty").val());

if (currentVal != NaN)

{

$(this).next(".qty").val(currentVal + 1);

}

$.ajax({

type: "POST",

 

url: baseDir + "themes/matrice/priceAjaxCalulation.php",

data: {id_product: $('#id_product').val(), quantity: $('#quantity_wanted').val(), standard_price: $('#price').val()},

 

success: function(data) //on recieve of reply

{

 

$('.priceCalculate').fadeOut(100).html(data).fadeIn(200); //Set output element html

 

}

})

});

 

$(".minus").click(function()

{

var currentVal = parseInt($(this).prev(".qty").val());

if (currentVal != NaN && currentVal > 1)

{

$(this).prev(".qty").val(currentVal - 1);

}

$.ajax({

type: "POST",

 

url: baseDir + "themes/matrice/priceAjaxCalulation.php",

data: {id_product: $('#id_product').val(), quantity: $('#quantity_wanted').val(), standard_price: $('#price').val()},

 

success: function(data) //on recieve of reply

{

 

$('.priceCalculate').fadeOut(100).html(data).fadeIn(200); //Set output element html

 

}

})

});

});

Edited by gtsagat (see edit history)
Link to comment
Share on other sites

Hi,

 

Thanks you. I got everythig working except for the price. It will not update the price when i change quantity.

 

Can it has something to do with priceAjaxCalculation.php's connection to the server? In my setup of prestashop i cannot find the file db_config.php. Is that a file that you've created and write the content of it on the forum?

 

 

Br,

Tobias

Link to comment
Share on other sites

Sorry you are correct once more.

The db_config.php is just a file containing the connection parameters. So, set the variables below with the values needed to connect to your database.

 

 

$HOST = '';

$USER = '';

$PASS = '';

$DATABASE = '';

$CHAR_SET = 'UTF8';

$COLLATION = "UTF8";

 

You can ommit the inclusion of db_config.php and just put the above variables in the function

Edited by gtsagat (see edit history)
Link to comment
Share on other sites

Hi GTSAGAT,

 

Thanks a lot for sharing this, it does work nicely.

 

I do not know a lot about Js, Ajax and so... but I was wondering if you could have a solution for this problem ;

 

I would like to tweak your code to change the + / - into a slider with a event-listener. So everytime the slider is changed, the price gets updated.

 

The reason behind is I am using your code to make a "price per cm2" system where my product price becomes the unitary price and your code makes the final price.

 

The next step would be to get 2 sliders to define width and height, have the values multiplied and set to the quantity.

 

I know there are some plugins out there doing this but all expensive and not compatible with Attr. Wizard Pro which I use.

 

Thanks in advance for any help you could eventually give me.

 

Tcheers !!

 

Laurent LORETTE

Edited by in-focus (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Hi again gtsagat. I dont quite get it to work. I get the following error message, do you know what can be wrong?

 

( ! ) SCREAM: Error suppression ignored for ( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\themes\MegaShop\priceAjaxCalculation.php on line 77 Call Stack # Time Memory Function Location 1 0.0009 272936 {main}( ) ..\priceAjaxCalculation.php:0 2 0.0032 275056 specificPriceCustom( ) ..\priceAjaxCalculation.php:127 3 0.0039 275248 mysql_num_rows ( ) ..\priceAjaxCalculation.php:77

( ! ) SCREAM: Error suppression ignored for ( ! ) Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\themes\MegaShop\priceAjaxCalculation.php on line 81 Call Stack # Time Memory Function Location 1 0.0009 272936 {main}( ) ..\priceAjaxCalculation.php:0 2 0.0032 275056 specificPriceCustom( ) ..\priceAjaxCalculation.php:127 3 0.0042 275344 mysql_fetch_array ( ) ..\priceAjaxCalculation.php:81

Link to comment
Share on other sites

  • 1 month later...

Sorry for the delayed answer. I had some serious health problems....

Laurent I am not sure that I can help you with this. I hope that you found a solution duting all this past period.

 

I made some corrections to the previous code. In addition (for tobbecokta problem) it is not necessary the manual connection to the DB.

 

You need to replace the priceAjaxCalulation.php and the ajax-product-price.js with the following

 

priceAjaxCalulation.php

<?

ini_set('display_errors',0);

require '../../config/config.inc.php'; // path to your config.inc.php file

$id_product = $_POST["id_product"];

$quantity = $_POST["quantity"];

$standardPrice = $_POST["standard_price"];

$check_quantity_discounts = $_POST["check_quantity_discounts"];

function getByProductId($db,$id_product)

{

$sql = '

SELECT *

FROM `ps_specific_price`

WHERE `id_product` = '.(int)$id_product ;

 

$query = Db::getInstance()->getRow($sql);

return $query;

}

function getMaxPointer($db,$id_product, $quantity)

{

$sql = "

SELECT *

FROM `ps_specific_price`

WHERE `from_quantity` >= $quantity and `id_product` = ".(int)$id_product." order by `from_quantity` asc" ;

 

$query = Db::getInstance()->getRow($sql);

 

return $query;

}

function getPreviousPointer($db,$id_product, $quantity)

{

$sql = "

SELECT *

FROM `ps_specific_price`

WHERE `from_quantity` < $quantity and `id_product` = ".(int)$id_product." order by `from_quantity` desc" ;

 

$query = Db::getInstance()->getRow($sql);

 

return $query;

}

function getMaxQuantity($db,$id_product)

{

$sql = "

SELECT *

FROM `ps_specific_price`

WHERE `id_product` = ".(int)$id_product." order by `from_quantity` desc" ;

 

$query = Db::getInstance()->getRow($sql);

 

return $query;

}

function getMinQuantity($db,$id_product)

{

$sql = "

SELECT *

FROM `ps_specific_price`

WHERE `id_product` = ".(int)$id_product." order by `from_quantity` asc" ;

 

$query = Db::getInstance()->getRow($sql);

 

return $query;

}

function getMinQuantityCount($db,$id_product)

{

$sql = "

SELECT COUNT(*)

FROM `ps_specific_price`

WHERE `id_product` = ".(int)$id_product." order by `from_quantity` asc" ;

 

$query = Db::getInstance()->getValue($sql);

 

return $query;

}

function specificPriceCustom($db, $id_product, $quantity, $standardPrice){

 

$standardPrice = str_replace (",",".", $standardPrice);

$row = getMaxPointer($db, (int)$id_product, $quantity);

$from_quantity = $row["from_quantity"];

 

$maxrow = getMaxQuantity($db, (int)$id_product);

$maxQuantity = $maxrow["from_quantity"];

$userCheck = $maxrow["id_customer"];

 

$minrow = getMinQuantity($db, (int)$id_product);

$minQuantity = $minrow["from_quantity"];

 

$totalRows = getMinQuantityCount($db, (int)$id_product);

if ( $from_quantity == $quantity && $from_quantity!=$maxQuantity ):

if ( $row["price"] == "-1" ):

if ( $row["reduction_type"] == "percentage" ):

$price = $standardPrice - $standardPrice*$row["reduction"] ;

elseif ( $row["reduction_type"] == "amount"):

$price = $standardPrice - $row["reduction"] ;

endif;

else:

$price = $row["price"] ;

endif;

 

$price = $quantity * number_format ( $price, 2 );

return $price;

 

elseif ( $from_quantity > $quantity && $quantity > $minQuantity):

$row = getPreviousPointer($db,(int)$id_product, $row["from_quantity"]);

if ( $row["price"] == "-1" ):

if ( $row["reduction_type"] == "percentage" ):

$price = $standardPrice - $standardPrice*$row["reduction"] ;

elseif ( $row["reduction_type"] == "amount"):

$price = $standardPrice - $row["reduction"] ;

endif;

else:

$price = $row["price"] ;

endif;

 

$price = $quantity * number_format ( $price, 2 );

return $price;

elseif ( $quantity >= $maxQuantity ):

 

if ( $totalRows == "1" ):

if ( $maxrow["price"] == "-1" ):

if ( $maxrow["reduction_type"] == "percentage" ):

$price = $standardPrice - $standardPrice*$maxrow["reduction"] ;

elseif ( $maxrow["reduction_type"] == "amount"):

$price = $standardPrice - $maxrow["reduction"] ;

endif;

else:

$price = $maxrow["price"] ;

endif;

 

$price = $quantity * number_format ( $price, 2 );

return $price;

elseif ( $userCheck == 0):

if ( $maxrow["price"] == "-1" ):

if ( $maxrow["reduction_type"] == "percentage" ):

$price = $standardPrice - $standardPrice*$maxrow["reduction"] ;

elseif ( $maxrow["reduction_type"] == "amount"):

$price = $standardPrice - $maxrow["reduction"] ;

endif;

else:

$price = $maxrow["price"] ;

endif;

 

$price = $quantity * number_format ( $price, 2 );

return $price;

else:

$row = getPreviousPointer($db,(int)$id_product, $maxQuantity);

endif;

 

if ( $row["price"] == "-1" ):

if ( $row["reduction_type"] == "percentage" ):

$price = $standardPrice - $standardPrice*$row["reduction"] ;

elseif ( $row["reduction_type"] == "amount"):

$price = $standardPrice - $row["reduction"] ;

endif;

else:

$price = $row["price"] ;

endif;

 

$price = $quantity * number_format ( $price, 2 );

return $price;

 

else:

$price = $quantity * $standardPrice;

return $price;

endif;

 

}

function specificPricePlain($db, $id_product, $quantity, $standardPrice){

 

$price = $quantity * $standardPrice;

return $price;

 

}

if ( $check_quantity_discounts != ""):

echo specificPriceCustom($db, $id_product, $quantity, $standardPrice);

else:

echo specificPricePlain($db, $id_product, $quantity, $standardPrice);

endif;

 

 

 

?>

 

 

ajax-product-price.js

$(function()

{

$(".add").click(function()

{

var currentVal = parseInt($(this).next(".qty").val());

if (currentVal != NaN && currentVal > 1)

{

$(this).next(".qty").val(currentVal - 1);

}

$.ajax({

type: "POST",

 

url: baseDir + "themes/matrice/priceAjaxCalulation.php",

data: {id_product: $('#id_product').val(), quantity: $('#quantity_wanted').val(), standard_price: $('#price').val(), check_quantity_discounts: $('#check_quantity_discounts').val()},

 

success: function(data) //on recieve of reply

{

 

$('.priceCalculate').fadeOut(100).html(data).fadeIn(200); //Set output element html

//recommend reading up on jquery selectors they are awesome

// http://api.jquery.com/category/selectors/

}

})

});

$(".minus").click(function()

{

var currentVal = parseInt($(this).prev(".qty").val());

if (currentVal != NaN )

{

$(this).prev(".qty").val(currentVal + 1);

}

$.ajax({

type: "POST",

 

url: baseDir + "themes/matrice/priceAjaxCalulation.php",

data: {id_product: $('#id_product').val(), quantity: $('#quantity_wanted').val(), standard_price: $('#price').val(), check_quantity_discounts: $('#check_quantity_discounts').val()},

 

success: function(data) //on recieve of reply

{

 

$('.priceCalculate').fadeOut(100).html(data).fadeIn(200); //Set output element html

//recommend reading up on jquery selectors they are awesome

// http://api.jquery.com/category/selectors/

}

})

});

 

$('.qty').bind('keyup', function(event){

var currentVal = parseInt($(this).prev(".qty").val());

if (currentVal != NaN && currentVal > 1)

{

$(this).prev(".qty").val(currentVal - 1);

}

$.ajax({

type: "POST",

 

url: baseDir + "themes/matrice/priceAjaxCalulation.php",

data: {id_product: $('#id_product').val(), quantity: $('#quantity_wanted').val(), standard_price: $('#price').val(), check_quantity_discounts: $('#check_quantity_discounts').val()},

 

success: function(data) //on recieve of reply

{

 

$('.priceCalculate').fadeOut(100).html(data).fadeIn(200); //Set output element html

//recommend reading up on jquery selectors they are awesome

// http://api.jquery.com/category/selectors/

}

})

});

 

});

 

 

finally in the product.tpl replace with the following:

 

<div id="quantity_wanted_p"{if (!$allow_oosp && $product->quantity == 0) OR $virtual OR !$product->available_for_order OR $PS_CATALOG_MODE} style="display: none;"{/if}>

<label>{l s='Quantity'} : </label>

 

 

<input type="button" value="" id="add1" class="add" /><input type="text" name="qty" id="quantity_wanted" class="qty" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}{if $product->minimal_quantity > 1}{$product->minimal_quantity}{else}1{/if}{/if}" size="2" maxlength="3" {if $product->

minimal_quantity > 1}onkeyup="checkMinimalQuantity({$product->minimal_quantity});"{/if} /><input type="button" value="" id="minus1" class="minus" />

<input type="hidden" value="{$qd_quantity_discounts}" id="check_quantity_discounts" />

 

 

<span id="our_price_display">

<span class="priceCalculate">

{if isset($quantityBackup)}

{assign var=quantityBackup value=$quantityBackup|intval}

{else}

{if $product->minimal_quantity > 1}

{assign var=quantityBackup value=$product->minimal_quantity}

{else}

{assign var=quantityBackup value="1"}

{/if}

{/if}

{math equation="( x * y )" x=$product->getPrice(true, $smarty.const.NULL, 2) y=$quantityBackup }

 

<!--{$product->getPrice(true, $smarty.const.NULL, 2)}-->

</span>

<span class="currencySign"> {$currencySign}</span></span>

<span class="taxref">

{if $tax_enabled}

{if $priceDisplay == 1}{l s='tax excl.'}{else}{l s='tax incl.'}{/if}

{/if}

</span>

<input type="hidden" value="{if $productPriceWithoutRedution > $productPrice} {convertPrice price=$productPriceWithoutRedution}{else}{convertPrice price=$productPrice}{/if}" id="price" />

<input type="hidden" value="{$product->id}" id="id_product" />

</div>

Link to comment
Share on other sites

  • 7 months later...

I can't get it to work at all. Any input is welcome !

 

I get the following error message on my product page, what did I do wrong? I use Prestashop 1.5.6.1.

 

The error:

 

getRow($sql); return $query; } function getMaxPointer($db,$id_product, $quantity) { $sql = " SELECT * FROM `ps_specific_price` WHERE `from_quantity` >= $quantity and `id_product` = ".(int)$id_product." order by `from_quantity` asc" ; $query = Db::getInstance()->getRow($sql); return $query; } function getPreviousPointer($db,$id_product, $quantity) { $sql = " SELECT * FROM `ps_specific_price` WHERE `from_quantity` < $quantity and `id_product` = ".(int)$id_product." order by `from_quantity` desc" ; $query = Db::getInstance()->getRow($sql); return $query; } function getMaxQuantity($db,$id_product) { $sql = " SELECT * FROM `ps_specific_price` WHERE `id_product` = ".(int)$id_product." order by `from_quantity` desc" ; $query = Db::getInstance()->getRow($sql); return $query; } function getMinQuantity($db,$id_product) { $sql = " SELECT * FROM `ps_specific_price` WHERE `id_product` = ".(int)$id_product." order by `from_quantity` asc" ; $query = Db::getInstance()->getRow($sql); return $query; } function getMinQuantityCount($db,$id_product) { $sql = " SELECT COUNT(*) FROM `ps_specific_price` WHERE `id_product` = ".(int)$id_product." order by `from_quantity` asc" ; $query = Db::getInstance()->getValue($sql); return $query; } function specificPriceCustom($db, $id_product, $quantity, $standardPrice){ $standardPrice = str_replace (",",".", $standardPrice); $row = getMaxPointer($db, (int)$id_product, $quantity); $from_quantity = $row["from_quantity"]; $maxrow = getMaxQuantity($db, (int)$id_product); $maxQuantity = $maxrow["from_quantity"]; $userCheck = $maxrow["id_customer"]; $minrow = getMinQuantity($db, (int)$id_product); $minQuantity = $minrow["from_quantity"]; $totalRows = getMinQuantityCount($db, (int)$id_product); if ( $from_quantity == $quantity && $from_quantity!=$maxQuantity ): if ( $row["price"] == "-1" ): if ( $row["reduction_type"] == "percentage" ): $price = $standardPrice - $standardPrice*$row["reduction"] ; elseif ( $row["reduction_type"] == "amount"): $price = $standardPrice - $row["reduction"] ; endif; else: $price = $row["price"] ; endif; $price = $quantity * number_format ( $price, 2 ); return $price; elseif ( $from_quantity > $quantity && $quantity > $minQuantity): $row = getPreviousPointer($db,(int)$id_product, $row["from_quantity"]); if ( $row["price"] == "-1" ): if ( $row["reduction_type"] == "percentage" ): $price = $standardPrice - $standardPrice*$row["reduction"] ; elseif ( $row["reduction_type"] == "amount"): $price = $standardPrice - $row["reduction"] ; endif; else: $price = $row["price"] ; endif; $price = $quantity * number_format ( $price, 2 ); return $price; elseif ( $quantity >= $maxQuantity ): if ( $totalRows == "1" ): if ( $maxrow["price"] == "-1" ): if ( $maxrow["reduction_type"] == "percentage" ): $price = $standardPrice - $standardPrice*$maxrow["reduction"] ; elseif ( $maxrow["reduction_type"] == "amount"): $price = $standardPrice - $maxrow["reduction"] ; endif; else: $price = $maxrow["price"] ; endif; $price = $quantity * number_format ( $price, 2 ); return $price; elseif ( $userCheck == 0): if ( $maxrow["price"] == "-1" ): if ( $maxrow["reduction_type"] == "percentage" ): $price = $standardPrice - $standardPrice*$maxrow["reduction"] ; elseif ( $maxrow["reduction_type"] == "amount"): $price = $standardPrice - $maxrow["reduction"] ; endif; else: $price = $maxrow["price"] ; endif; $price = $quantity * number_format ( $price, 2 ); return $price; else: $row = getPreviousPointer($db,(int)$id_product, $maxQuantity); endif; if ( $row["price"] == "-1" ): if ( $row["reduction_type"] == "percentage" ): $price = $standardPrice - $standardPrice*$row["reduction"] ; elseif ( $row["reduction_type"] == "amount"): $price = $standardPrice - $row["reduction"] ; endif; else: $price = $row["price"] ; endif; $price = $quantity * number_format ( $price, 2 ); return $price; else: $price = $quantity * $standardPrice; return $price; endif; } function specificPricePlain($db, $id_product, $quantity, $standardPrice){ $price = $quantity * $standardPrice; return $price; } if ( $check_quantity_discounts != ""): echo specificPriceCustom($db, $id_product, $quantity, $standardPrice); else: echo specificPricePlain($db, $id_product, $quantity, $standardPrice); endif; ?> € tax incl.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...