Saturday, October 4, 2014

Total discounted price code in prestashop

By the default, The discounted price is not always available on any page when it is needed. In this tutorial, i will show you how to query the discounted price. i created a function that can be use on any controller if you need to get the discounted price.
 
function get_price_discounted($prod_id)
{
    //get first the discount of an item
    $sql1 ='SELECT reduction
    FROM '._DB_PREFIX_.'specific_price
    WHERE id_product = '.$prod_id ;
    $discount = Db::getInstance()->getValue($sql1);
 
    //get the current price of an item
    $sql2 ='SELECT price
    FROM '._DB_PREFIX_.'product
    WHERE id_product = '.$prod_id ;
    $priceOrig = Db::getInstance()->getValue($sql2);
 
    //return the discounted value of a product
    return $discountedPrice = ($priceOrig - ($priceOrig * $discount));
}
//use the function and assign it to a TPL variable
'discounted_price' => $this->get_price_discounted(Tools::getValue('id_product'));

No comments:

Post a Comment