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.

  • Lasse Kofoed 38 posts 155 karma points
    Feb 17, 2015 @ 18:33
    Lasse Kofoed
    0

    ChangePriceGroup and recalculate tax

    Hi there

    How can i trigger a complete relaculations of tax on the basket. ?

    Im using UCommerce.Api.CatalogLibrary.ChangePriceGroup(priceGroup, true) to change the pricegroup.

    But items already in the basket, maintains the tax from when first added to the basket.

    I have tried TransactionLibrary.ExecuteBasketPipeline() , and read somewhere that the recalc tax is only done when new items are added to the basket. But is does not seam to have a effect on the items already in the basket.

    Can some one point me in the right direction.

    Thank you in advance.

  • Lasse Kofoed 38 posts 155 karma points
    Feb 18, 2015 @ 15:33
    Lasse Kofoed
    0

    I found that if I change the PriceGroup with the UCommerce.Api.CatalogLibrary.ChangePriceGroup(priceGroup, true), and delete all orderlines and re-add them again, the total tax is correct.

    /// This is some dirty hacking shit.. !!
        try
        {
            List<OrderLine> oldOrderlines = new List<OrderLine>();
            oldOrderlines.AddRange(order.OrderLines);
    
    
            foreach (OrderLine ol in oldOrderlines)
            {
                order.RemoveOrderLine(ol);
            }
    
    
            foreach (OrderLine ol in oldOrderlines)
            {
                TransactionLibrary.AddToBasket(ol.Quantity, ol.Sku, ol.VariantSku, addToExistingLine: false);
            }
    
            order.Save();
            TransactionLibrary.ExecuteBasketPipeline();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    

    I really dont like the way of handling this. How can i trigger a calculate tax on all products in the basket ?

  • Morten Skjoldager 436 posts 1492 karma points
    Feb 24, 2015 @ 11:40
    Morten Skjoldager
    100

    Hi Lasse, you're right, that is a bad behaviour :) 

    We are looking into this right now.

    The best way forward would be to do it like this (on top of my head):

    I think you would have to override the CatalogLibrary yourself, and when change pricegroup is called, then you could call the code underneath. See on docs here how to achieve it:

    http://docs.ucommerce.net/ucommerce/v6.6/extending-ucommerce/override-default-behavior-in-the-api.html (same method applies to CatalogLibrary).

           private bool TryUpdatePricingToMatchNewPriceGroup(PriceGroup priceGroup, OrderLine orderLine)
            {
                var product = _productRepository.SingleOrDefault(x => x.Sku == orderLine.Sku && x.VariantSku == orderLine.VariantSku);
                if (product == null) return false;
    
                Money unitPrice = _pricingService.GetProductPrice(product, priceGroup);
    
                if (unitPrice == null) return false;
    
                // Override price group's currency with currency
                // from unit price in case a custom pricing
                // service decides to override currency.
                priceGroup.Currency = unitPrice.Currency;
    
                var unitTax = _taxService.CalculateTax(product, priceGroup, unitPrice);
    
                if (unitTax == null) return false;
    
                orderLine.Price = unitPrice.Value;
                orderLine.VAT = unitTax.Value;
                orderLine.VATRate = priceGroup.VATRate;
    
                return true;
            }

    Hope this helps

    Best regards 

    Morten

  • Kasper Vesth 2 posts 22 karma points
    Jun 01, 2015 @ 15:39
    Kasper Vesth
    0

    I know the answer has been marked as accepted, but I have a followup to this. I am using uCommerce 6.6.3 and as far as I can see in the source code, the api does call the TryUpdatePricingToMatchNewPriceGroup subroutine. But the price isn't updated when I call the function. I can see the PriceGroup is changed correctly and if I manipulate the basket by adding another product of the same type it recalculates the entire basket. Am I missing something? 

    I am calling it like this: 

    UCommerce.Api.CatalogLibrary.ChangePriceGroup(priceGroup, true);

Please Sign in or register to post replies

Write your reply to:

Draft