I am setting a product with multiple variants and each variants will have price and sku modifier. I use the OrderLineUpdating and OrderLineAdding event handler to calculate the product price based on selected variant. All is working for the SKU but, and this is silly, I am having so trouble updating the order line UnitPrice object. I didn't find a way to update that price!
UnitPrice is an object of Price type and to create a Price object, I need to know the VatRate (which I can get from the order line) and the currency. Order line has a currencyid variable but I didn't find a way to create a Currency object from currencyid.
Once again, this seems very silly and it would be so much easier to just have a method to update the price in the Price object.
So please point me to the good direction or tell me if I am too tired (I should go to bed anyway)!
"The public API is unable to change or create settings such as currencies, countries, delivery methods, payment methods, etc. These settings must be set up manually from the administration and remains static from there on."
Maybe this is also the case for the unit price of the product? Since the unit price is stored in the Document? From security concerns I think it would be a good thing the unit price cannot be updated from the JavaScript api.... else someone in the frontend would be able to abuse it to calculate a lower price? Please correct me if I'm wrong...
You found some old documentation -Tea Commerce 2.0 is much more open and flexible than 1.x. You should not change the UnitPrice object because the is recalculated everytime the order changes using the default OrderCalculator. You have two options. One is to implement your own OrderCalculator inherit from our default one. The other was is to override the OriginalUnitPrices collection with your custom prices. This is the prices that is copied from the umbraco node - so you could add your own prices here.
To get a specific currency, shipping method or other modesl you need to use our services. You can find all model services in TeaCommerce.Api assembly. So a currency would be Currency currency = CurrencyService.Instance.Get( storeId, currencyId);
Unfortunately, I haven't been able to make either methods work. I implemented my own OrderCalculator but for some reasons, it doesn't step in my code. I tried to override all methods but no luck here. I am surprised as I have implemented my own ShippingCalculator and that worked great.
As for the second method, in OrderLinesAdded and OrderLinesUpdated events, I created my new OriginalUnitPrices collection and replaced it with the one in the order line. But that doesn't seem to do anything either.
I guess it worked after I saved the order. That makes sense ;-)
As for the shipping calculator, I just created a class that inherits from TeaCommerce.Api.PriceCalculators.ShippingCalculator then overrode CalculatePrice, nothing more and that works. I try the same method with TeaCommerce.Api.PriceCalculators.OrderCalculator and TeaCommerce.Api.PriceCalculators.ProductCalculator, but the overriden methods are never hit (I tried them all). All new classes are part of the same project. I would be interested to figure that out.
You need to let Tea Commerce know that you have a new provider for the calculator (don't know how it knows about your shipping calculator). Write me an email: info at teacommerce.net and I will send you the latest 2.0.1 build - which is stable. We have changed the way you suppress a dependency in Tea Commerce to be much easier.
It seems the build 2.0.1b7 you sent me the other day breaks the registration process (even the shipping calculator didn't work anymore). I just sent you an email to request the new build.
Yeah we did a breaking change for the dependendy stuff to make it easier in 2.0.1. The way you do it now is to use the SuppressDependency attribute on your class. Then pass in the fullname of the dependency that you want to override/suppress. So a shipping calculator would be:
Now, I upgraded to the build you emailed me (2.0.1b7), Shipping calculator breaks as expected. I then removed the line in umbraco/plugins/tea-commerce/plugins/configuration and added the SuppressDependency statement for my class:
So the shipping calculator is working? But you get an error in your solution. Is that because of your custom shipping calculator or? Could you try and use the console in your browser to use the JavaScript API to call TC.hasCurrentOrder to see if it also fails or it has something to do with the Razor stuff.
Just trying to figure out if the shipping calculator is the cause of the error or it is something else.
The I is because it is an interface and that is the reference we use in Tea Commerce. Always suppress the interface and not the concreate class. The reason why whings wont work at the moment is that when you suppress a wrong interface then the entire setup process for Tea Commerce will fail and no dependencies is loaded.
Thank you Anders for the explanation. However, I am disappointed to see it still didn't work after I made the changes to suppress IShippingCalculator dependency. I also tried to override IShippingCalculator instead of ShippingCalculator but the problem remain the same. Would that help if I'd email you a dropbox link for my solution + database backup so you can see for yourself? It's been a while I have been having this issue and it is becoming problematic for the project.
I have refactored the SuppressDependency for the final 2.0.1 of Tea Commerce. Write us an email to info at teacommerce.net and I will send you the latest build and also a test project I did that has a custom shipping calculator.
Updating order line price with .net API in 2.0.x
Hi,
I am setting a product with multiple variants and each variants will have price and sku modifier. I use the OrderLineUpdating and OrderLineAdding event handler to calculate the product price based on selected variant. All is working for the SKU but, and this is silly, I am having so trouble updating the order line UnitPrice object. I didn't find a way to update that price!
UnitPrice is an object of Price type and to create a Price object, I need to know the VatRate (which I can get from the order line) and the currency. Order line has a currencyid variable but I didn't find a way to create a Currency object from currencyid.
Once again, this seems very silly and it would be so much easier to just have a method to update the price in the Price object.
So please point me to the good direction or tell me if I am too tired (I should go to bed anyway)!
Thanks
Nico
Hi,
I found this in some older documentation:
http://rune.gronkjaer.dk/en-US/2011/02/21/tea-commerce-net-api-explained/
"The public API is unable to change or create settings such as currencies, countries, delivery methods, payment methods, etc. These settings must be set up manually from the administration and remains static from there on."
Maybe this is also the case for the unit price of the product? Since the unit price is stored in the Document? From security concerns I think it would be a good thing the unit price cannot be updated from the JavaScript api.... else someone in the frontend would be able to abuse it to calculate a lower price? Please correct me if I'm wrong...
Merijn
Hi Merjin
You found some old documentation -Tea Commerce 2.0 is much more open and flexible than 1.x. You should not change the UnitPrice object because the is recalculated everytime the order changes using the default OrderCalculator. You have two options. One is to implement your own OrderCalculator inherit from our default one. The other was is to override the OriginalUnitPrices collection with your custom prices. This is the prices that is copied from the umbraco node - so you could add your own prices here.
To get a specific currency, shipping method or other modesl you need to use our services. You can find all model services in TeaCommerce.Api assembly. So a currency would be
Currency currency = CurrencyService.Instance.Get( storeId, currencyId);
Kind regards
Anders
Thanks for the answer Anders.
Unfortunately, I haven't been able to make either methods work. I implemented my own OrderCalculator but for some reasons, it doesn't step in my code. I tried to override all methods but no luck here. I am surprised as I have implemented my own ShippingCalculator and that worked great.
As for the second method, in OrderLinesAdded and OrderLinesUpdated events, I created my new OriginalUnitPrices collection and replaced it with the one in the order line. But that doesn't seem to do anything either.
Any idea what could be wrong?
Thanks
How did you register the shipping calculator and how about the order calculator?
Did you save the order after you changed the original unit prices? Else the order wont recalculate..
Kind regards
Anders
I guess it worked after I saved the order. That makes sense ;-)
As for the shipping calculator, I just created a class that inherits from TeaCommerce.Api.PriceCalculators.ShippingCalculator then overrode CalculatePrice, nothing more and that works. I try the same method with TeaCommerce.Api.PriceCalculators.OrderCalculator and TeaCommerce.Api.PriceCalculators.ProductCalculator, but the overriden methods are never hit (I tried them all). All new classes are part of the same project. I would be interested to figure that out.
Thanks
Hi Nicolas
You need to let Tea Commerce know that you have a new provider for the calculator (don't know how it knows about your shipping calculator). Write me an email: info at teacommerce.net and I will send you the latest 2.0.1 build - which is stable. We have changed the way you suppress a dependency in Tea Commerce to be much easier.
Kind regards
Anders
Hi Anders,
It seems the build 2.0.1b7 you sent me the other day breaks the registration process (even the shipping calculator didn't work anymore). I just sent you an email to request the new build.
Thanks
Nicolas
Hi Nicolas
Email returned :)
Yeah we did a breaking change for the dependendy stuff to make it easier in 2.0.1.
The way you do it now is to use the SuppressDependency attribute on your class. Then pass in the fullname of the dependency that you want to override/suppress. So a shipping calculator would be:
SuppressDependency[“TeaCommerce.Api.PriceCalculators.ShippingCalculator”]
Kind regards
Anders
Anders,
That doesn't seem to work as I get those errors are displayed after I compile the DLL with the SuppressDependency attribute (no errors without):
and
Here is a very simple code snippet:
Can you see anything I did wrong?
Thanks
Hi Nicolas
I cant see any errors. Could you try just to return 1000M; in the calculate price method. Just to make it as simple as possible to debug.
Kind regards
Anders
Hi Anders,
I am at a dead end and don't know how to resolve this problem. Sorry for the long post. Maybe I need a more recent build?
I started from scratch, installed 2.0.0 starter kit. I added a new project with the following code:
I also added the following line in umbraco/plugins/tea-commerce/plugins/configuration:
This worked fine and shipping is $1000
Now, I upgraded to the build you emailed me (2.0.1b7), Shipping calculator breaks as expected. I then removed the line in umbraco/plugins/tea-commerce/plugins/configuration and added the SuppressDependency statement for my class:
When the homepage loads, it stumbled on line 14 in cart/mini-cart.cshtml:
and line 18 in product/list.cshtml
Then error is the same is both places (I know that is probably not very helpful):
Note that those 2 errors also happen is 2.0.0 when I did set the right service in umbraco/plugins/tea-commerce/plugins/configuration
Hi Anders,
Can I join in this? I'm working on a specific product that changes price on every order.
I would love to have some example code on CalculatePrice for the ProductCalculator.
I still run on 2.0. Just finished my Buckaroo payment provider ...
Thanks,
Merijn
Hi Nicolas
So the shipping calculator is working? But you get an error in your solution. Is that because of your custom shipping calculator or? Could you try and use the console in your browser to use the JavaScript API to call TC.hasCurrentOrder to see if it also fails or it has something to do with the Razor stuff.
Just trying to figure out if the shipping calculator is the cause of the error or it is something else.
Kind regards
Anders
Hi Merjin
I think it would be best to start a new topic not to pollute this topic. But the CalculatePrice method in the default does just do this simple stuff:
return originalUnitPrice.Value
Kind regards
Anders
Anders,
I ran TC.hasCurrentOrder({}) in the console and it returns:
Hi Anders,
Do you have any new development on my issue?
Thank you for the support!
Hi Nicolas
The line with the suppress dependency should be like this:
[TeaCommerce.Api.Dependency.SuppressDependency("TeaCommerce.Api.PriceCalculators.IShippingCalculator")]
The I is because it is an interface and that is the reference we use in Tea Commerce. Always suppress the interface and not the concreate class. The reason why whings wont work at the moment is that when you suppress a wrong interface then the entire setup process for Tea Commerce will fail and no dependencies is loaded.
Kind regards
Anders
Thank you Anders for the explanation. However, I am disappointed to see it still didn't work after I made the changes to suppress IShippingCalculator dependency. I also tried to override IShippingCalculator instead of ShippingCalculator but the problem remain the same. Would that help if I'd email you a dropbox link for my solution + database backup so you can see for yourself? It's been a while I have been having this issue and it is becoming problematic for the project.
Thank you!
Hi Nicolas
I have refactored the SuppressDependency for the final 2.0.1 of Tea Commerce. Write us an email to info at teacommerce.net and I will send you the latest build and also a test project I did that has a custom shipping calculator.
Kind regards
Anders
Thank you Anders, that did it. Can't wait for the final 2.0.1 build!
is working on a reply...