Copied to clipboard

Flag this post as spam?

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


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Nauman 98 posts 118 karma points
    Sep 06, 2010 @ 06:40
    Nauman
    0

    Apply Vat on cart.aspx page

    Hi Soren

    Is there a way that I can add VAT to the basket total on cart.aspx page? The scenario is, I want customer to select either add VAT to the basket or not to add VAT.

    Customer will have 2 radion buttons, 1) add VAT, 2) do not add VAT on cart.aspx. If 1 is selected VAT should be added to basket total.

    I understand that I can add VAT to the price group but is this possible to have something like above?

    Regards

    Nauman

  • Søren Spelling Lund 1797 posts 2786 karma points
    Sep 07, 2010 @ 09:59
    Søren Spelling Lund
    0

    There's no problem doing something like that. Basically you'll add the radio button to either include or exclude VAT. Depending on how you've got your price groups set up you can either subtract the VAT (if your prices include VAT from the start) or add it (if your prices are set exlcuing VAT).

    The selection the customer makes can be stored on the basket by calling

    CommerceLibrary:SetOrderProperty("IncludeVAT", "true"); // or false ;)

    With that in place I'd do the actual calculation in a pipeline task that you add to the basket pipeline. You can read all about creating pipeline task in the article uCommerce Pipelines Explained. Basically your new pipeline task will look at the order property (IncludeVAT) and perform the VAT calculation and set that on the individual order lines.

    PurchaseOrder.VAT total is calculated automatically for you if you set on the individual order lines.

    Relevant fields to store VAT are PurchaseOrder.VAT, OrderLine.VAT.

    Hope this helps.

  • Nauman 98 posts 118 karma points
    Sep 07, 2010 @ 13:21
    Nauman
    0

    Hi Soren

    Thanks a lot for making the picture clear, however I need your some more help in writing the xslt code.

    On top of cart.aspx I wrote <xsl:value-of select="CommerceLibrary:SetOrderProperty('IncludeVAT', 'true')"></xsl:value-of>

    this I believe will tell ucommerce to add VAT or orderlines?

    How can i execute orderpipeline here to set the VAT to orderlines???? (MY PRICE GROUP IS NOT INCLUDING VAT FROM START)

    Further down the I am executing the basket pipeline <xsl:value-of select="CommerceLibrary:ExecuteBasketPipeline()"></xsl:value-of>

    Regards

    Nauman

  • Søren Spelling Lund 1797 posts 2786 karma points
    Sep 07, 2010 @ 15:47
    Søren Spelling Lund
    0

    For your scenario uCommerce won't add VAT automatically as it's done when you add the product to the basket.

    However you can trigger the internal VAT calculation inside your own pipeline task. You would look up the VAT values based on the current config and do the calculation yourself. The pipeline task could look like this:

    public class MyPipelineTask : IPipelineTask<PurchaseOrder>
    {
        public PipelineExecutionResult Execute(PurchaseOrder subject)
        {
            bool includeVat = false;
            if (!bool.TryParse(subject["IncludeVat"], out includeVat)) return PipelineExecutionResult.Success;
    
            if (includeVat)
            {
                // Find the price group - assume only one configured
                PriceGroup priceGroup = PriceGroup.All().FirstOrDefault(x => !x.Deleted);
    
                // Find that configured price group
                decimal vatRate = priceGroup.VATRate;
    
                foreach (var orderLine in subject.OrderLines)
                {
                    orderLine.VATRate = vatRate;
                    // VAT is stored on a per unit basis
                    orderLine.VAT = orderLine.Price*vatRate;
                    orderLine.Save();
                    // Line totals and VAT totals are calculated by a different task
                }
            }
            return PipelineExecutionResult.Success;
        }
    }

    Once you copy your assembly to the /bin folder you need to configure the pipeline task with uCommerce, more specifically in the basket pipeline.

    The configuration file for the basket pipeline is found in /umbraco/ucommerce/pipelines/basket.config. My basket.config looks like this with the new task in place. My changes are highlighted in bold.

    <configuration>
        <components>
            <!-- Pipeline Instance -->
            <component id="Basket"
                       service="UCommerce.Pipelines.IPipeline`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="UCommerce.Pipelines.Basket.BasketPipeline, UCommerce.Pipelines"
                       lifestyle="Thread">
                <parameters>
                    <tasks>
                        <array>
                            <value>${MyPipeline.MyPipelineTask}</value>
                            <value>${Basket.CalculatePaymentFees}</value>
                            <value>${Basket.CalculateOrderLinesTotals}</value>
                            <value>${Basket.CalculateShippingCostForShipments}</value>
                            <value>${Basket.CalculateShippingTotal}</value>
                            <value>${Basket.CalculatePaymentTotal}</value>
                            <value>${Basket.CalculateVATTotal}</value>
                            <value>${Basket.CalculateOrderTotal}</value>
                            <value>${Basket.Save}</value>
                        </array>
                    </tasks>
                </parameters>
            </component>
    
            <!-- Pipeline Tasks-->
            <component id="MyPipeline.MyPipelineTask"
                       service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="MyUCommerceApp.Pipelines.MyPipelineTask, MyUCommerceApp.Pipelines"
                       lifestyle="Thread" />
            <component id="Basket.CalculatePaymentFees"
                       service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="UCommerce.Pipelines.Basket.CalculatePaymentFeesTask, UCommerce.Pipelines"
                       lifestyle="Thread" />
            <component id="Basket.CalculateOrderLinesTotals"
                       service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="UCommerce.Pipelines.Basket.CalculateOrderLineTotalsTask, UCommerce.Pipelines"
                       lifestyle="Thread" />
            <component id="Basket.CalculateShippingCostForShipments"
                       service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="UCommerce.Pipelines.Basket.CalculateShippingCostForShipmentsTask, UCommerce.Pipelines"
                       lifestyle="Thread" />
            <component id="Basket.CalculateShippingTotal"
                       service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="UCommerce.Pipelines.Basket.CalculateShippingTotalTask, UCommerce.Pipelines"
                       lifestyle="Thread" />
            <component id="Basket.CalculatePaymentTotal"
                       service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="UCommerce.Pipelines.Basket.CalculatePaymentTotalTask, UCommerce.Pipelines"
                       lifestyle="Thread" />
            <component id="Basket.CalculateVATTotal"
                       service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="UCommerce.Pipelines.Basket.CalculateOrderVatTotalTask, UCommerce.Pipelines"
                       lifestyle="Thread" />
            <component id="Basket.CalculateOrderTotal"
                       service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="UCommerce.Pipelines.Basket.CalculateOrderTotalTask, UCommerce.Pipelines"
                       lifestyle="Thread" />
            <component id="Basket.Save"
                       service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="UCommerce.Pipelines.Common.SavePurchaseOrderTask, UCommerce.Pipelines"
                       lifestyle="Thread" />
        </components>
    </configuration>
    
    Hope this helps.
  • Nauman 98 posts 118 karma points
    Sep 16, 2010 @ 12:56
    Nauman
    0

    Hi Soren

    I have gone through your instructions and made a following applyVAT.cs

    namespace applyVAT
    {
        public class MyPipelineTask : IPipelineTask<PurchaseOrder>
        {
            public PipelineExecutionResult Execute(PurchaseOrder subject)
            {
                bool includeVat = true;
                if (!bool.TryParse(subject["IncludeVat"], out includeVat)) return PipelineExecutionResult.Success;


               

                if (includeVat)
                {
                   
                    // Find the price group - assume only one configured
                    PriceGroup priceGroup = PriceGroup.All().FirstOrDefault(x => !x.Deleted);

                    // Find that configured price group
                    //decimal vatRate = priceGroup.VATRate;
                    decimal vatRate = 17.5M; // I am seeting my own VAT here
                   


                    foreach (var orderLine in subject.OrderLines)
                    {
                       
                        orderLine.VATRate = vatRate;
                        // VAT is stored on a per unit basis
                        orderLine.VAT = orderLine.Price * vatRate;
                        orderLine.Save();
                        // Line totals and VAT totals are calculated by a different task
                    }
                }
                return PipelineExecutionResult.Success;
            }
        }
    }

    and the following is my /umbraco/ucommerce/pipelines/basket.config

    <configuration>
        <components>
            <!-- Pipeline Instance -->
            <component id="Basket"
                       service="UCommerce.Pipelines.IPipeline`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="UCommerce.Pipelines.Basket.BasketPipeline, UCommerce.Pipelines"
                       lifestyle="Thread">
                <parameters>
                    <tasks>
                        <array>
                            <value>${applyVAT.MyPipelineTask}</value>
                            <value>${Basket.CalculateOrderLinesTotals}</value>
                            <value>${Basket.CalculateShippingCostForShipments}</value>
                            <value>${Basket.CalculateShippingTotal}</value>
                            <value>${Basket.CalculatePaymentTotal}</value>
                            <value>${Basket.CalculateOrderTotal}</value>
                            <value>${Basket.Save}</value>
                        </array>
                    </tasks>
                </parameters>
            </component>

            <!-- Pipeline Tasks-->
            <component id="applyVAT.MyPipelineTask"
                                       service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                                       type="applyVAT.MyPipelineTask, applyVAT"
                                       lifestyle="Thread" />
            <component id="Basket.CalculateOrderLinesTotals"
                       service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="UCommerce.Pipelines.Basket.CalculateOrderLineTotalsTask, UCommerce.Pipelines"
                       lifestyle="Thread" />
            <component id="Basket.CalculateShippingCostForShipments"
                       service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="UCommerce.Pipelines.Basket.CalculateShippingCostForShipmentsTask, UCommerce.Pipelines"
                       lifestyle="Thread" />
            <component id="Basket.CalculateShippingTotal"
                       service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="UCommerce.Pipelines.Basket.CalculateShippingTotalTask, UCommerce.Pipelines"
                       lifestyle="Thread" />
            <component id="Basket.CalculatePaymentTotal"
                       service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="UCommerce.Pipelines.Basket.CalculatePaymentTotalTask, UCommerce.Pipelines"
                       lifestyle="Thread" />
            <component id="Basket.CalculateOrderTotal"
                       service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="UCommerce.Pipelines.Basket.CalculateOrderTotalTask, UCommerce.Pipelines"
                       lifestyle="Thread" />
            <component id="Basket.Save"
                       service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="UCommerce.Pipelines.Common.SavePurchaseOrderTask, UCommerce.Pipelines"
                       lifestyle="Thread" />
        </components>
    </configuration>

    But VAT is not appling for me, can you please advise where I am getting wrong? Enteires in my basket.config are ok as referenced to my namespace and class name?

    Regards

    Nauman

  • Søren Spelling Lund 1797 posts 2786 karma points
    Sep 20, 2010 @ 15:23
    Søren Spelling Lund
    0

    The configuration looks right. Could you try outputting the basket XML when the basket pipeline is done executing so you can see the values of order line VAT and order total VAT?

    It should return an error if config is incorrect.

  • Nauman 98 posts 118 karma points
    Sep 21, 2010 @ 14:57
    Nauman
    0

    Thanks Soren, I have managed to resolve the above code.

  • Søren Spelling Lund 1797 posts 2786 karma points
    Sep 21, 2010 @ 19:47
    Søren Spelling Lund
    0

    Wonderful. Glad to hear it.

  • Michael Falch Madsen 70 posts 92 karma points
    Oct 12, 2011 @ 11:38
    Michael Falch Madsen
    0

    What was the fault? trying to do similar thing but gets "

    Could not convert from 'ExcludeVAT.MyPipelineTask, ExcludeVAT' to System.Type - Maybe type could not be found"

  • Michael Falch Madsen 70 posts 92 karma points
    Oct 12, 2011 @ 12:18
    Michael Falch Madsen
    0

    Got a step further.. now gets 

    Value cannot be null.

  • Søren Spelling Lund 1797 posts 2786 karma points
    Oct 13, 2011 @ 09:10
    Søren Spelling Lund
    0

    It would be helpful to see where the code fails. I need a little more to go on. Thanks.

  • Kieran Harvey 22 posts 55 karma points
    Sep 14, 2012 @ 03:43
    Kieran Harvey
    1

    I ran into the same problem it was having issues converting the type.

    I changed the pipeline task to use the updated type ie i changed "Entites" to "Entities2" and it worked. 

    change this line in basket.config

    service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"

    to this.

    service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.EntitiesV2.PurchaseOrder, UCommerce]], UCommerce"
Please Sign in or register to post replies

Write your reply to:

Draft