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.

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

    VAT Calculation

    Trying to extend the basket pipeline to allow removal of VAT if certain criteries are met.

    What i want to do:

    If a customer types in a VAT number i want to remove vat from order.

    Have tried http://our.umbraco.org/projects/website-utilities/ucommerce/ucommerce-support/12407-Apply-Vat-on-cartaspx-page but think i have registred the pipeline wrong,

    What i have so far:

    ExcludeVAT.aspx

     

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

     

    and in Basket.config

    ...
    <value>WocaHelper.MyPipeLineTask</value>
    <value>${Basket.CalculateVATTotal}</value>
    <!-- Pipeline Tasks-->
            <component id="WocaHelper.MyPipelineTask"
                       service="UCommerce.Pipelines.IPipelineTask`1[[UCommerce.Entities.PurchaseOrder, UCommerce]], UCommerce"
                       type="WocaHelper.MyPipelineTask, WocaHelper"
                       lifestyle="Thread" />

    in my basket usercontrol (onTextChange event on vatnumber textBox

     

    var basket = SiteContext.Current.OrderContext.GetBasket();
                string vatnumber = txt_vat.Text;
                if (deliverToPaymentAddress1.Checked)
                {
                    if (vatnumber != "" && ddl_country1.SelectedValue == "da-DK")
                    {
                        UCommerce.Xslt.Library.SetOrderProperty("ExcludeVAT", "true");
                        Library.ExecuteBasketPipeline();
                    }
                } 

     

    With this setup i get error: 

    Value cannot be null.

     

  • Kieran Harvey 22 posts 55 karma points
    Sep 14, 2012 @ 03:41
    Kieran Harvey
    0

    I ran into the same problem. I changed the pipeline task to point to the new entites "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