How to override CurrencyService and IDependencyRegistrar processing order

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 anos atrás
Hi

I'm working on a project that requires a different currency pricing model to the one currently in nopcommerce out of the box.

Basically as discussed before on this forum my client needs to be able to set specific prices for different currencies.

While I'm aware that this may not be the most acceptable way of pricing this is not my concern, I need to provide my client with a way to price products in line with their standard model.

So with that in mind I need to create a new CurrencyService that when requested provides a different price not based on conversion rate but price fields in the database.

I can see from some of the Plugins have a DependencyRegistrar.cs files that inherit from IDependencyRegistrar and I assume if I create a new plugin and register my CurrencyService it will be added as required when the constructer is called.

My main question is how do I unregister the CurrencyService that comes with Nop from my plugin and what order are the Depenencys registered i.e. how do I know when the correct CurrencyService is being used?

Hope you can help.
Thanks
Jon
11 anos atrás
Hi Jon,

Interesting.

I am unclear are the prices for each country stored in the base currency?

If so you don't need to turn the converter off just feed it the correct base price for the country?
11 anos atrás
The plan I think I've come up with is to add multiple currency fields to the ProductVariant editor.

e.g.
Price [10.00] [GBP]
Old Price [16.00] [GBP]

Price [13.00] [EURO]
Old Price [20.00] [EURO]

Something like the way the Description field work for different languages.

So when the Currency is requested it will pull the information from the database and deliver it to the model.

Hope thats makes sense, if not let me know.
11 anos atrás
Well it makes some sense to store different prices for different countries for each product.

But I'd store them in 1 currency eg £ and fix the conversion rates. I think you can still put fixed conversion rates in?

That way you don't have to remove all the currency conversion stuff.

Have you considered that if you don't store the prices in 1 currency some of the discounting may screw up?

eg -£10 off discount.
11 anos atrás
Thanks for your input I think it's becoming more clear to me now.

I understand your suggestion to use conversion rates but as discussed unfortunately this won’t work as it'll cause all kinds of strange prices and they will not be inline with current (paper) catalog prices and this is obviously a problem.

It looks like I'm going to have to edit the CatalogController as I have a feeling that I'm not going to be able to do what I need without it. I also think I'm also going to need to make changes to multiple services as the PriceCalculationService seems to provide the initial price but does not take in to account the currency as this is later updated using the CurrencyService.

Is there a good reason so much of the pricing logic is in the controllers and not abstracted somewhere else so it can be swapped out more easily?

I agree that there may be issues with the prices missing from the system but I'll need to deal with this in the Admin area by making the field requried.
11 anos atrás
I just wanted to say i definatley see what you mean about pricing based on exchange rates, I've done a little more thinking and agree with Price, Currency, Discount etc... all dependent on 1 price makes the logic and price management much more simple.

I think there's a lot of work involved in extracting this from the controllers and also implementing the different requirments for all the places the prices are modified.

I'm going to discuss this further with the client we'll see if it's worth the investment.

Really appreciate your time in helping me with this.

Cheers
Jon
11 anos atrás
webmonger wrote:


Price [10.00] [GBP]
Old Price [16.00] [GBP]

Price [13.00] [EURO]
Old Price [20.00] [EURO]



Hmm I don't think you understand what I'm getting at so I'll use the example above.

If you use a fixed currency conversion factor of say 1.3 euro to the pound

you would enter as follows

for UK
Price [10.00] [GBP]
Old Price [16.00] [GBP]

for Europe
Price [10.00] [GBP] = 13.00 Euro
Old Price [15.38] [GBP] = ~20.00 Euro

I haven't investigated where/how discounting applies but I'm guessing as the discount fixed amount is entered in the store currency then it is applied before conversion.

So for example in your solution for a £5.00 discount

for uk price is £10.00 - £5.00 = £5.00
for euro price is E13.00 - £5.00 = E8.00 (if you remove the currency conversion)

my way using fixed conversion of E1.3 = £1 (this doesn't change)

for uk price is £10.00 - £5.00 = £5.00
for euro price is £10.00 - £5.00 = E6.50 (converted @1.3)

It would I think even be easier to let the admins enter the prices in euro/whatever and convert and store into the base store currency than to start trying to rip the conversion stuff out and fix the discounting issues.

HTH

Dave
11 anos atrás
To answer the question about adding a new CurrencyService, if your DependencyRegistrar class has a higher Order property than the standard one, any class you register towards an interface will override the base one.  You don't need to unregister the base class as long as you register yours towards the same interface.
11 anos atrás
Hi Andy, thanks for your input I completely missed the Order field :)

Hi Dave I understand your point that makes sense when the conversion rate is fixed however in this case the conversion is not based on a percentage it's based on a product price in a catalog so:

Example Product 1:
Price [10.95] [GBP]
Price [14.20] [EURO]

Example Product 2:
Price [4.95] [GBP]
Price [7.45] [EURO]

Example Product 1:
The conversion rate for this product is 1.2968

Example Product 2:
The conversion rate for this product is 1.5050

I dont see a way to change the exchange rate for each individual product price (and that would be impossible to manage) and therefor I think it would probably be easier to associate the multiple currency prices with the product variant if you see what I mean.

However as you rightly pointed out if there are any issues with empty price fields or fixed rate discounts it will cause major calculation issues as each discount will need to be added with a fixed rate for each currency.

This would be a very good reason to extract the price calculations out of the Controllers so they can be overridden without editing the controller every time.

As I say I think I'll explain how complex this issue is and we'll see if it's worth doing.

Cheers
Jon
11 anos atrás
webmonger wrote:


Example Product 1:
Price [10.95] [GBP]
Price [14.20] [EURO]

Example Product 2:
Price [4.95] [GBP]
Price [7.45] [EURO]

Example Product 1:
The conversion rate for this product is 1.2968

Example Product 2:
The conversion rate for this product is 1.5050


o.O it never ceases to amaze me how batshit insane some client requests are.

however here is how you sort this out with 1 fixed exchange rate (1.3)

Example Product 1:
Price(UK) [10.95] [GBP]
Price(Euroland) [10.93] [GBP] = 14.209 [Euro]

Example Product 2:
Price(UK)  [4.95] [GBP]
Price(Euroland) [5.74] [GBP] = 7.462 [Euro]

You don't use the UK price to find the Euro cost you use the Euroland price in GBP to get the Euro cost. That way the discount in GBP still works

However it's up to you but I do think stripping out all the currency conversion code and crippling half the discount system  or rewriting it is going to be a massive headache.

Best of luck whatever you decide.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.