Copied to clipboard

Flag this post as spam?

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


  • phil 58 posts 78 karma points
    Mar 21, 2012 @ 16:41
    phil
    0

    add variant price to tea commerce price

    I was wondering what the best apprach to add the variant price to the pricing in the tea commerce cart i could just add the price onto the unit price for each item in the razor code but wondered if there was a built in feature for this

  • Rune Grønkjær 1371 posts 3102 karma points
    Mar 22, 2012 @ 08:48
    Rune Grønkjær
    0

    Hi Phil,

    The Tea Commerce starter kit have a certain way of dealing with variants. Variants are placed as subnodes to the "main product" and can therefor have their own prices.

    This approach is good for products with one variant type, but will be increasingly unpractical the more variant types you have (e.g. color, size, pattern and so on). In your case you have three variant types, so you're in the unpractical group.

    If your variants have different prices you will need to handle that in the server side code.Luckily for you Tea Commerce have an easy to use event driven .NET API. You might want to look into my blogpost about how to use the Tea Commerce .NET API. There you can see how to access the order and orderlines, and then all you have to do is to manipulate the price.

    Remember: No handling prices client side. All calculations must occur server side for security reasons.

    /Rune

  • phil 58 posts 78 karma points
    Mar 22, 2012 @ 17:25
    phil
    0

    Cheers I have gort it working displaying the way I want it too just one thing I have had to create my own variables for orderlines unit price, total price and order total price as the tea commerce ones are read only is this ok to day also I how to I pull out the VAT percentage for the current country for my own total price variable 

  • Rune Grønkjær 1371 posts 3102 karma points
    Mar 23, 2012 @ 10:07
    Rune Grønkjær
    0

    That is not ok. Sorry :)

    You need to use Tea Commerce's prices as we have built a lot of security and calcutation stuff arround them. What you are doing is "ok" if there is no payment on the website. In that case it will be all about displaying prices. If you need to implement payment of any kind, your client will have to be able to trust the system to handle the prices safely. Furthermore the creditcard payment providers won't work, because they only use the Tea Commerce prices.

    To sum it up. You have to manipulate the prices on each orderline using the Tea Commerce .NET API.

    /Rune

  • phil 58 posts 78 karma points
    Mar 23, 2012 @ 15:37
    phil
    0

    HI rune i have had a look through your blogpost on the  .net api and still struggling to get my head around it to manipulate the prices am i right in thinking I need to use the OrderLineAdded event and add the 3  variant prices to the unit price

  • Rune Grønkjær 1371 posts 3102 karma points
    Mar 26, 2012 @ 08:40
    Rune Grønkjær
    0

    Hi Phil,

    You are almost right. Or maybe I'm missing something.

    Yes, the OrderLineAdded event is the one you need to use. And yes, you change the unit price.

    BUT, you cannot add three prices to the same order line. One order line, one price. So what you will do is:

    1. Hook into the OrderLineAdded event
    2. inspect the new orderline and find out what variant have been chosen (e.g. red, size 30)
    3. Calculate or find the price for one unit of that particular variant
    4. Change the the unit price to the new price.

    /Rune

  • phil 58 posts 78 karma points
    Mar 26, 2012 @ 12:03
    phil
    0

    Cheers for the advise rune i have written the following class and saved it in the App_Code folder in the website but the unit price is still staying the same have i missed something

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using umbraco.cms;
    using umbraco.NodeFactory;
    using TeaCommerce.Data.Extensibility;
    using TeaCommerce.Data;
    namespace TeaCommerce.WebShop.Integration {

        public class NewOrderLine ITeaCommerceExtension
        {
            public void Initialize()
            {
                WebshopEvents.OrderLineAdded += WebshopEvents_OrderLineAdded;
            }

            void WebshopEvents_OrderLineAdded(Order orderOrderLine orderLine)
            {
                string material orderLine.Properties.Single(=p.Alias.Equals("productMaterial"&p.UmbracoLanguageId == order.UmbracoLanguageId).Value;
                string colour orderLine.Properties.Single(=p.Alias.Equals("productColour"&p.UmbracoLanguageId == order.UmbracoLanguageId).Value;
                string finish orderLine.Properties.Single(=p.Alias.Equals("productFinish"&p.UmbracoLanguageId == order.UmbracoLanguageId).Value;

                decimal unitPrice orderLine.UnitPrice;
                decimal materialPrice 0;
                decimal colourPrice 0;
                decimal finishPrice 0;

                if (material != "null")
                {
                    Node materialNode new Node(int.Parse(material));
                    materialPrice decimal.Parse(materialNode.GetProperty("price").Value);
                }
                if (colour != "null")
                {
                    Node colourNode new Node(int.Parse(colour));
                    colourPrice decimal.Parse(colourNode.GetProperty("price").Value);
                }
                if (finish != "null")
                {
                    Node finishNode new Node(int.Parse(finish));
                    finishPrice decimal.Parse(finishNode.GetProperty("price").Value);
                }

                decimal newPrice (unitPrice materialPrice colourPrice finishPrice);

                orderLine.UnitPrice newPrice;
                order.Save();
            }
        }
    }
  • Rune Grønkjær 1371 posts 3102 karma points
    Mar 26, 2012 @ 12:30
    Rune Grønkjær
    0

    Hi Phil,

    The code is probably not being run. I'm not familiar with using the App_code folder, so don't know for sure. Usually we make all our visual studio project as web applications. Then we build them and get a dll, which is put in the bin folder of the website.

    A good idea is testing the site locally on a local iis. Then you can debug the code in visual studio. But that's a whole different story that I can't help you with.

    Maybe try and throw an error and se if it appears in the firebug console. Then you will know the code is being run.

    /Rune

  • phil 58 posts 78 karma points
    Mar 26, 2012 @ 13:09
    phil
    0

    cheers I have now created and copied the dll into the bin folder. When i click the add to cart button I get the error can you see anything that I have missed in the code

    Cart Error: 
    <error><![CDATA[MESSAGE:
    Exception has been thrown by the target of an invocation.
    
    STACKTRACE:
       at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
    
       at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
    
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
    
       at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    
       at TeaCommerce.Presentation.TeaCommerceBase.RequestModule.invokeMethod(restExtension myExtension, Object[] paras)
    
    INNEREXCEPTION:
    System.MissingMethodException: Method not found: 'Boolean Umbraco.Licensing.Validator.IsValid()'.
    
       at TeaCommerce.Licensing.ALicenseValidator.()
    
       at TeaCommerce.Data.Licensing.LicenseValidator.get_Instance()
    
       at TeaCommerce.Data.Order.Save()
    
       at TeaCommerce.SessionController.get_CurrentOrder()
    
       at TeaCommerce.SessionController.CheckCurrentOrderPaymentStatus()
    
       at TeaCommerce.Base.AddOrderLine(Int32 nodeId, Nullable`1 orderLineId, Decimal quantity, Boolean isUnique)
    
       at TeaCommerce.Base.AddUniqueOrderLine(Int32 nodeId, Int64 orderLineId, Decimal quantity)]]></error>
    
  • Rune Grønkjær 1371 posts 3102 karma points
    Mar 26, 2012 @ 13:24
    Rune Grønkjær
    0

    It actually looks like the licensing validation is failing now. Have you installed Contour on to of Tea Commerce? Try reinstalling Tea Commerce. Contour overwrites the umbraco licensing files with at wrong one, thereby breaking Tea Commerce.

    /Rune

  • phil 58 posts 78 karma points
    Mar 26, 2012 @ 13:28
    phil
    0

    Ah thanks yeah had installed contour reinstalled Tea Commerce and works a treat cheers 

  • phil 58 posts 78 karma points
    Mar 26, 2012 @ 13:55
    phil
    0

    sorry 1 more thing when i go to my cart and add 1 to the quantity it adds the 3 varient prices to the unit price again which i don't want is there a way I can only add change the unit price when the item is first added to the cart from the product page and when in the cart and click add quantity the unit price isn't affected 

  • Rune Grønkjær 1371 posts 3102 karma points
    Mar 26, 2012 @ 14:06
    Rune Grønkjær
    0

    Hi Phil,

    You could add a server only property to the orderline, "priceCalculated" and then check that before making the calculations!?

    /Rune

  • phil 58 posts 78 karma points
    Mar 26, 2012 @ 14:28
    phil
    0

    how do i add a new property to the orderline

  • Rune Grønkjær 1371 posts 3102 karma points
    Mar 27, 2012 @ 08:14
    Rune Grønkjær
    0

    Hi Phil,

    You would do that something like this:

    orderLine.AddProperty( new OrderLineProperty"alias", "value", UmbracoLanguageId ) );
    

    And the save the order.

    /Rune

  • phil 58 posts 78 karma points
    Mar 27, 2012 @ 10:23
    phil
    0

    Thanks i've got the following code but get an error The name 'UmbracoLanguageId' does not exist in the current context. Do I need to add a using directive to make this work

    orderLine.AddProperty(new OrderLineProperty("priceCalculated", "false", UmbracoLanguageId));
  • Rune Grønkjær 1371 posts 3102 karma points
    Mar 27, 2012 @ 10:35
    Rune Grønkjær
    0

    It was just an example :)

    The language id can be set to null or the id of the umbraco language you you are using. The order have an umbraco language which you also can use.

    /Rune

  • phil 58 posts 78 karma points
    Mar 27, 2012 @ 11:28
    phil
    0

    I have the folowwing code but its still adding the varants to the unit price everytime I think I can see why because its setting the property priceCalculated everytime before running the if statment so the priceCalculated = true is getting overwritten how to I get around this

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using umbraco.cms;
    using umbraco.NodeFactory;
    using TeaCommerce.Data.Extensibility;
    using TeaCommerce.Data;
    
    namespace TeaCommerce.WebShop.Integration
    {
    
        public class NewOrderLine : ITeaCommerceExtension
        {
            public void Initialize()
            {
                WebshopEvents.OrderLineAdded += WebshopEvents_OrderLineAdded;
            }
    
            void WebshopEvents_OrderLineAdded(Order order, OrderLine orderLine)
            {
                orderLine.AddProperty(new OrderLineProperty("priceCalculated", "false", null));
                order.Save();
    
                string priceCalculated = orderLine.Properties.Single(p => p.Alias.Equals("priceCalculated") && p.UmbracoLanguageId == order.UmbracoLanguageId).Value;
    
                if (priceCalculated != "true")
                {
                    string material = orderLine.Properties.Single(p => p.Alias.Equals("productMaterial") && p.UmbracoLanguageId == order.UmbracoLanguageId).Value;
                    string colour = orderLine.Properties.Single(p => p.Alias.Equals("productColour") && p.UmbracoLanguageId == order.UmbracoLanguageId).Value;
                    string finish = orderLine.Properties.Single(p => p.Alias.Equals("productFinish") && p.UmbracoLanguageId == order.UmbracoLanguageId).Value;
    
                    decimal unitPrice = orderLine.UnitPrice;
                    decimal materialPrice = 0;
                    decimal colourPrice = 0;
                    decimal finishPrice = 0;
    
                    if (material != "")
                    {
                        Node materialNode = new Node(int.Parse(material));
                        materialPrice = decimal.Parse(materialNode.GetProperty("price").Value);
                    }
                    if (colour != "")
                    {
                        Node colourNode = new Node(int.Parse(colour));
                        colourPrice = decimal.Parse(colourNode.GetProperty("price").Value);
                    }
                    if (finish != "")
                    {
                        Node finishNode = new Node(int.Parse(finish));
                        finishPrice = decimal.Parse(finishNode.GetProperty("price").Value);
                    }
    
                    decimal newPrice = (unitPrice + materialPrice + colourPrice + finishPrice);
    
                    orderLine.UnitPrice = newPrice;
                    orderLine.Properties.Single(p => p.Alias.Equals("priceCalculated") && p.UmbracoLanguageId == order.UmbracoLanguageId).Value = "true";
                    order.Save();
                }
            }
        }
    }
    
    
    
Please Sign in or register to post replies

Write your reply to:

Draft