Copied to clipboard

Flag this post as spam?

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


  • Laurie 6 posts 37 karma points
    May 07, 2013 @ 21:05
    Laurie
    0

    Pricing based on quantity

    Hello

    I need to be able to change the pricing for a product based on the quantity ordered. So for example if the user orders 1-5 then it costs $5, 6- 10 costs $4.50 etc.

    Is there a built in way to do this in Tea Commerce 2.1.1 (or higher) (I note that it wasn't possible in previous versions) or am I going to need to hit the .NET api?  If so is there any sample code for overriding the order line pricing calculation?Thanks

  • Anders Burla Johansen 2560 posts 8256 karma points
    May 08, 2013 @ 08:59
    Anders Burla Johansen
    100

    Hi Laurie

    Here is a simple example. The price is hardcoded here. What you could do it to fetch the price from a custom xml field on your Umbraco product node or what ever way works for your case.

    using TeaCommerce.Api.Dependency;
    using TeaCommerce.Api.InformationExtractors;
    using TeaCommerce.Api.Models;
    using TeaCommerce.Api.PriceCalculators;
    using TeaCommerce.Api.Services;

    namespace CustomShippingProject {
    [SuppressDependency( "TeaCommerce.Api.PriceCalculators.IOrderCalculator", "TeaCommerce.Api" )]
    public class CustomOrderCalculator : OrderCalculator {

    public CustomOrderCalculator( IVatGroupService vatGroupService, ICurrencyService currencyService, IShippingMethodService shippingMethodService, IPaymentMethodService paymentMethodService, IShippingCalculator shippingCalculator, IPaymentCalculator paymentCalculator, IProductInformationExtractor productInformationExtractor ) :
    base( vatGroupService, currencyService, shippingMethodService, paymentMethodService, shippingCalculator, paymentCalculator, productInformationExtractor ) {
    }

    protected override decimal CalculateOrderLineUnitPrice( OriginalUnitPrice originalUnitPrice, OrderLine orderLine, Currency currency, Order order ) {
    decimal price;

    if ( orderLine.Quantity < 6M ) {
    price = 5M;
    } else if ( orderLine.Quantity < 11M ) {
    price = 4.5M;
    } else {
    price = base.CalculateOrderLineUnitPrice( originalUnitPrice, orderLine, currency, order );
    }
    return price;
    }

    }
    }

    Kind regards
    Anders

  • Laurie 6 posts 37 karma points
    May 08, 2013 @ 11:37
    Laurie
    0

    Thanks, that works perfectly.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies