We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
make an example for using discount please.
The text was updated successfully, but these errors were encountered:
Example with personal discount for logged users:
<?php namespace app\behaviors; use Yii; use yz\shoppingcart\DiscountBehavior; class PersonalDiscount extends DiscountBehavior { /** * @param \yz\shoppingcart\CostCalculationEvent $event */ public function onCostCalculation($event) { // saved in percentages $discount = Yii::$app->user->identity ? Yii::$app->user->identity->discount : 0; $event->discountValue = $event->baseCost * ($discount / 100); } }
Yii::$app->cart->attachBehavior('personalDiscount', ['class' => 'app\behaviors\PersonalDiscount']);
<p>Total cost: <?= Yii::$app->cart->getCost() ?></p> <p>Total cost with discount: <?= Yii::$app->cart->getCost(true) ?></p>
Sorry, something went wrong.
Instead step 1 & 2 can use this variant:
Yii::$app->cart->on(ShoppingCart::EVENT_COST_CALCULATION, function ($event) { $discount = Yii::$app->user->identity ? Yii::$app->user->identity->discount : 0; $event->discountValue = $event->baseCost * ($discount / 100); });
No branches or pull requests
make an example for using discount please.
The text was updated successfully, but these errors were encountered: