-
Notifications
You must be signed in to change notification settings - Fork 112
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
Add support to shipping cost #36
base: master
Are you sure you want to change the base?
Conversation
ShoppingCart.php
Outdated
*/ | ||
public function getShippingCost($withDiscount = false) | ||
{ | ||
$cost = $this->getCost($withDiscount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This value is not used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I delete that line.
* @param $withDiscount | ||
* @return int | ||
*/ | ||
public function getShippingCost($withDiscount = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why shipping cost must be in it's own separate method? It is possible to add shipping cost value during general computations using EVENT_COST_CALCULATION. If shipping cost should be based on the calculated cart cost, than probably it is possible to add event EVENT_AFTER_COST_CALCULATION and evaluate value of the cost there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I wrote two additional methods getShippingCost() and getTotal() in order to use something like this:
`
$cart = \Yii::$app->cart;
$cart->attachBehavior('percentDiscount', ['class' => 'common\components\PercentDiscount', 'ammount' => 10]);
$cart->attachBehavior('fixedShippingCost', ['class' => 'common\components\FixedShippingCost', 'ammount' => 89, 'freeSince' => 999]);
$subtotal = \Yii::$app->cart->getCost(true);
$shipping = \Yii::$app->cart->getShippingCost();
$total = \Yii::$app->cart->getTotal(true);
`
If there is a better way to get subtotal, shipping cost and total independently?
Please review