Start a new topic

Shipping method based on total price in cart

Hello

I just created a custom shipping method class for my store. It works fine, but I can't find the way to getting total price form cart. 

How do I get a total price from cart for evaluating shipment method and shipment price?

For example, if a customer ordering more than 50$ in the shopping cart. The shipping will be free normal shipping and discounted priority shipping.

I saw that there is total price in storefront, but I didn't see any storefront in Nuget.

Thank you


ShippingMethod.CalculateRates(IEvaluationContext context) received ShippingEvaluationContext type which contains property ShippingEvaluationContext.ShoppingCart. 

You can use ShoppingCart.Total or ShoppingCart.Subtotal or other totals property to calculate shipping rate. But I'm will suggest use Promotions module to manage shipping discounts.


1 person likes this

Thank you so much 

Hello again

I try to localize shipping methods for multiple languages. 
I try to get language code from cart by using this.

shippingEvalContext.ShoppingCart.LanguageCode

But I got empty string as a result.

So I can't make a condition for switching language.

Thank you again

Is our omission Cart.LanguageCode do not set in storefront. Now it fixed by this commit https://github.com/VirtoCommerce/vc-storefront/commit/429ef079bdc9397e90df77987bdade6a1e293d25


But I would recommend to make all  localization direct on storefront theme with using theme resources  and liquid filters ( | t ) or by using angular translate directive https://github.com/angular-translate/angular-translate

this will be right approach for  any localization.


1 person likes this

Do you have any example for using liquid filters to translate shipping methods? Since I'm new to using liquid theme


Thank you

Hello.

You can add shipping method keyword (i.e. "usps-night") to corresponding locale JSON-file (these files are located in theme\locales folder). For example:


en.default.json


 

...
"shipping-methods": {
  "usps-night": "USPS Night Delivery"
}
...

 

 And then on you template:

 

{% assign shipping_method_locale_key = 'shipping-methods.' | append: shipping_method.handle %}
<p>{{ shipping_method_locale_key | t }}</p>

 

 


Login or Signup to post a comment