-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Before & After prices in templates #51
Comments
@sanderha did you find any solution? If yes, can you share it? |
@wernerkrauss If using the discounts module, to be able to show before/after price we have to calculate it for each item. Not sure which project I did that on. On other shop projects I ended up creating a specific "BeforePrice" field on EDIT: /**
* A bunch of this code is taken from \Shop\Discount\Calculator::calculate()
*
* @return int
*/
public function calcAfterDiscountPrice()
{
$classname = $this->owner->ClassName;
$total = 0;
// if its not a Product it'll be an OrderItem
$orderitem = $classname === 'Product' ? $this->owner->Item() : $this->owner;
$orderitem->setQuantity(1); // else it will take quantity from cart, we just want a basic discount per item for showing
$infoitem = new ItemPriceInfo($orderitem);
$discount = $this->getActiveDiscount();
if (!$discount) {
return $total;
}
// item discounts will update info items
$action = $discount->Type === "Percent" ?
new \ItemPercentDiscount([$infoitem], $discount) :
new \ItemFixedDiscount([$infoitem], $discount);
$action->perform();
// select best item-level discounts
$bestadjustment = $infoitem->getBestAdjustment();
if ($bestadjustment) {
$amount = $bestadjustment->getValue();
// prevent discounting more than original price
if ($amount > $infoitem->getOriginalTotal()) {
$amount = $infoitem->getOriginalTotal();
}
$total += $amount;
}
$total = $classname === 'Product' ? $this->owner->sellingPrice() - $total : $this->owner->UnitPrice() - $total;
return $total;
} |
Hello
I've created a Discount and added some products to it, that should be affected by this discount. What is the smartest way to create Before/after prices in templates to reflect the discount the customer will receive?
The text was updated successfully, but these errors were encountered: