Find out the language the store is using during checkout - programming question

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Hace 12 años
Hello!

I'm writing a plugin for a local (Colombia) payment system. That payment system has several languages on which the user can make his/her transaction. When the user is redirected to the payment gateway, I want him/her to arrive on the correct language!

I need to know what language the store is using (example: "en" for english OR "es" for spanish).

I tried using this property "postProcessPaymentRequest.Order.Customer.Language.LanguageCulture" but it is null at that point in checkout.

What object/property can i use to grab this information.

Thanks a lot in advance,

Abe
Hace 12 años
Check out IWorkContext.WorkingLanguage. You can get the current instance by adding a paramter of type IWorkContext in the payment method's constructor.
Hace 12 años
Wow many thanks!! Excellent answer.

How is it possible that i can add things like that to the constructor at will??? MVC???

What i did, added to the fields and the ctor the work context:


       private readonly IWorkContext _workContext;

        public PagosOnlinePaymentProcessor(
                 PagosOnlinePaymentSettings pagosOnlinePaymentSettings,
                 ISettingService settingService, IWebHelper webHelper,
                 IWorkContext workContext)
        {
            this._pagosOnlinePaymentSettings = pagosOnlinePaymentSettings;
            this._settingService = settingService;
            this._webHelper = webHelper;
            this._workContext = workContext;
        }



Then I got the language like this:



     string systemLanguage = _workContext.WorkingLanguage.LanguageCulture;

Hace 12 años
aduarte wrote:
Wow many thanks!! Excellent answer.

How is it possible that i can add things like that to the constructor at will??? MVC???

What i did, added to the fields and the ctor the work context:


       private readonly IWorkContext _workContext;

        public PagosOnlinePaymentProcessor(
                 PagosOnlinePaymentSettings pagosOnlinePaymentSettings,
                 ISettingService settingService, IWebHelper webHelper,
                 IWorkContext workContext)
        {
            this._pagosOnlinePaymentSettings = pagosOnlinePaymentSettings;
            this._settingService = settingService;
            this._webHelper = webHelper;
            this._workContext = workContext;
        }



Then I got the language like this:



     string systemLanguage = _workContext.WorkingLanguage.LanguageCulture;




Dependency Injection is a common design pattern in enterprise applications that injects dependencies into dependent objects. If you search for DependencyRegistrar classes you will find all the dependencies that are registered for injection.

You can find a sample plugin with dependency injection on my blog. http://blog.csharpwebdeveloper.com
Hace 12 años
This works because of the use of Autofac (its an inversion of control container). It it used to instantiate plugins, among other things (like controllers, services, etc). It can automatically create classes having constructor parameters as long as it knows how to resolve each parameter. Have a look at Nop.Web.Framework.DependencyRegistrar to see how the implementations are registered in the container.
Hace 12 años
Thanks for your answers, this is amazing, I have so much to learn.

skyler, great blog by the way...
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.