Kyttias
12-23-2014, 04:45 PM
Nvm, got it work finally. -o-
If you send another value, for a discount, through the buy form, you can access it in class_stockitem.php in the getcost function. But this is just to fix the display on the confirmation screen.
public function getcost($salestax = 0, $quantity = ""){
// Get the total cost of this stock item
$mysidia = Registry::get("mysidia");
if(empty($quantity)) $quantity = $mysidia->input->post("quantity");
$discount = $mysidia->input->post("discount");
$costbeforediscount = $this->price*$quantity*(1+$salestax/100);
$cost = $costbeforediscount * ((100-$discount) / 100);
return $cost;
}
To show users a discounted price, you'll need to do this in the display function of class_itemshop.php -
# A 5% discount:
$discount = 5;
$price = $item->price * ((100-$discount) / 100);
And replace the $item->price where it would show the item's price when rendering the item to just $price.
To actually make a discount percentage go through in terms of calculations you'll have to modify the purchase() function in class_itemshop.php -
$cost = $item->getcost($this->salestax, $item->quantity) * ((100-$discount) / 100);
Sorry for the vague ramblings, it's actually the first part I had trouble with (getting the proper amount to show on the confirmation screen), but maybe someone will have gotten something out of rest of this.
If you send another value, for a discount, through the buy form, you can access it in class_stockitem.php in the getcost function. But this is just to fix the display on the confirmation screen.
public function getcost($salestax = 0, $quantity = ""){
// Get the total cost of this stock item
$mysidia = Registry::get("mysidia");
if(empty($quantity)) $quantity = $mysidia->input->post("quantity");
$discount = $mysidia->input->post("discount");
$costbeforediscount = $this->price*$quantity*(1+$salestax/100);
$cost = $costbeforediscount * ((100-$discount) / 100);
return $cost;
}
To show users a discounted price, you'll need to do this in the display function of class_itemshop.php -
# A 5% discount:
$discount = 5;
$price = $item->price * ((100-$discount) / 100);
And replace the $item->price where it would show the item's price when rendering the item to just $price.
To actually make a discount percentage go through in terms of calculations you'll have to modify the purchase() function in class_itemshop.php -
$cost = $item->getcost($this->salestax, $item->quantity) * ((100-$discount) / 100);
Sorry for the vague ramblings, it's actually the first part I had trouble with (getting the proper amount to show on the confirmation screen), but maybe someone will have gotten something out of rest of this.