Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jjacquesf
Copy link

Please review

ShoppingCart.php Outdated
*/
public function getShippingCost($withDiscount = false)
{
$cost = $this->getCost($withDiscount);
Copy link
Owner

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

Copy link
Author

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)
Copy link
Owner

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

Copy link
Author

@jjacquesf jjacquesf Jun 4, 2017

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants