Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nicolas Gangloff 19 posts 99 karma points
    Apr 04, 2013 @ 03:49
    Nicolas Gangloff
    0

    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

  • Merijn van Mourik 58 posts 128 karma points
    Apr 04, 2013 @ 08:14
    Merijn van Mourik
    0

    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

  • Anders Burla 2560 posts 8256 karma points
    Apr 04, 2013 @ 09:17
    Anders Burla
    0

    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

  • Nicolas Gangloff 19 posts 99 karma points
    Apr 04, 2013 @ 17:25
    Nicolas Gangloff
    0

    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

  • Anders Burla 2560 posts 8256 karma points
    Apr 05, 2013 @ 14:37
    Anders Burla
    0

    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

  • Nicolas Gangloff 19 posts 99 karma points
    Apr 05, 2013 @ 17:02
    Nicolas Gangloff
    0

    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

  • Anders Burla 2560 posts 8256 karma points
    Apr 07, 2013 @ 11:23
    Anders Burla
    0

    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

  • Nicolas Gangloff 19 posts 99 karma points
    Apr 08, 2013 @ 02:18
    Nicolas Gangloff
    0

    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

  • Anders Burla 2560 posts 8256 karma points
    Apr 08, 2013 @ 08:03
    Anders Burla
    0

    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

  • Nicolas Gangloff 19 posts 99 karma points
    Apr 10, 2013 @ 17:36
    Nicolas Gangloff
    0

    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): 

    Error loading Razor Script /cart/mini-cart.cshtml
    Value cannot be null. Parameter name: context

    and 

    Error loading Razor Script /widgets/list.cshtml
    Value cannot be null. Parameter name: context

    Here is a very simple code snippet: 

    namespace MyNameSpace
    {
        [TeaCommerce.Api.Dependency.SuppressDependency("TeaCommerce.Api.PriceCalculators.ShippingCalculator")]
        public class ShippingCalculator : TeaCommerce.Api.PriceCalculators.ShippingCalculator
        {
            public ShippingCalculator(IVatGroupService vatGroupService, ICurrencyService currencyService)
                : base(vatGroupService, currencyService)
            { }

    protected override decimal CalculatePrice(ShippingMethod shippingMethod, Currency currency, Order order) { // Code here }
    }

    Can you see anything I did wrong?

    Thanks

  • Anders Burla 2560 posts 8256 karma points
    Apr 11, 2013 @ 20:31
    Anders Burla
    0

    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

  • Nicolas Gangloff 19 posts 99 karma points
    Apr 12, 2013 @ 16:55
    Nicolas Gangloff
    0

    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:

    namespace MyNamespace
    {
        public class ShippingCalculator : TeaCommerce.Api.PriceCalculators.ShippingCalculator
        {
            public ShippingCalculator(IVatGroupService vatGroupService, ICurrencyService currencyService)
                : base(vatGroupService, currencyService)
            {
            }
     
            protected override decimal CalculatePrice(ShippingMethod shippingMethod, Currency currency, Order order)
            {
                return 1000M;
            }
        }
    }

    I also added the following line in umbraco/plugins/tea-commerce/plugins/configuration:

    <componenttype="MyNamespace.ShippingCalculator, MyAssembly"service="TeaCommerce.Api.PriceCalculators.IShippingCalculator, TeaCommerce.Api" />

    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: 

    [TeaCommerce.Api.Dependency.SuppressDependency("TeaCommerce.Api.PriceCalculators.ShippingCalculator")]

    When the homepage loads, it stumbled on line 14 in cart/mini-cart.cshtml: 

    if ( TC.HasCurrentOrder( storeId ) ) {

    and line 18 in product/list.cshtml 

      if ( TC.HasCurrentOrder( storeId ) ) { 

    Then error is the same is both places (I know that is probably not very helpful):

    System.ArgumentNullException
    Value cannot be null. 
    Parameter name: context 

    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

     

     

  • Merijn van Mourik 58 posts 128 karma points
    Apr 13, 2013 @ 00:23
    Merijn van Mourik
    0

    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

  • Anders Burla 2560 posts 8256 karma points
    Apr 15, 2013 @ 09:11
    Anders Burla
    0

    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

  • Anders Burla 2560 posts 8256 karma points
    Apr 15, 2013 @ 09:13
    Anders Burla
    0

    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

  • Nicolas Gangloff 19 posts 99 karma points
    Apr 16, 2013 @ 17:05
    Nicolas Gangloff
    0

    Anders,

    I ran TC.hasCurrentOrder({}) in the console and it returns:

    • false without SuppressDepency statement, products are showing up but can't step in ShippingCalculator
    • null with SuppressDepency, errors on home page and products are not showing up and can't do anything
  • Nicolas Gangloff 19 posts 99 karma points
    Apr 19, 2013 @ 16:13
    Nicolas Gangloff
    0

    Hi Anders,

    Do you have any new development on my issue?

    Thank you for the support!

  • Anders Burla 2560 posts 8256 karma points
    Apr 22, 2013 @ 10:21
    Anders Burla
    0

    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

  • Nicolas Gangloff 19 posts 99 karma points
    Apr 22, 2013 @ 17:00
    Nicolas Gangloff
    0

    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!

  • Anders Burla 2560 posts 8256 karma points
    Apr 23, 2013 @ 14:49
    Anders Burla
    100

    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

  • Nicolas Gangloff 19 posts 99 karma points
    Apr 24, 2013 @ 14:20
    Nicolas Gangloff
    0

    Thank you Anders, that did it. Can't wait for the final 2.0.1 build!

Please Sign in or register to post replies

Write your reply to:

Draft