Copied to clipboard

Flag this post as spam?

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


  • Tobbe 81 posts 387 karma points c-trib
    Sep 12, 2013 @ 13:29
    Tobbe
    0

    Create new Shipping Calculator

    Hello

    I am trying to create a new shipping calculator, to do this I've tried to follow the documentation (http://documentation.teacommerce.net/net-api/price-calculators/shipping-calculator/). Ive created a new class (CustomShippingCalculator.cs) in App_Code and then just copied the code from the docs. So this is what I got:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using TeaCommerce.Api.Dependency;
    using TeaCommerce.Api.Models;
    using TeaCommerce.Api.PriceCalculators;
    using TeaCommerce.Api.Services;
    
    
    namespace TeaCommerce.API.PriceCalculators /*<--- is this correct?*/ { 
      [SuppressDependency( "TeaCommerce.Api.PriceCalculators.IShippingCalculator", "TeaCommerce.Api" )]
      public class CustomShippingCalculator : ShippingCalculator {
    
        public CustomShippingCalculator( IVatGroupService vatGroupService, ICurrencyService currencyService )
          : base( vatGroupService, currencyService ) {
        }
    
        protected override decimal CalculatePrice( ShippingMethod shippingMethod, Currency currency, long countryId, long? countryRegionId ) {
          //Estimated shipping price - no order is present
          return 100M;
        }
    
        protected override decimal CalculatePrice( ShippingMethod shippingMethod, Currency currency, Order order ) {
          //Calculate price based on order
          return 50M;
        }
      }
    }
    

    But the freight cost for orders is still the same they where before I added this.. Why doesnt this work? and what should I do to get it to work?

  • Anders Burla 2560 posts 8256 karma points
    Sep 12, 2013 @ 13:48
    Anders Burla
    0

    You should build a dll and add it to the bin folder instead of just having it in the App_Code folder.

    Kind regards
    Anders

  • Tobbe 81 posts 387 karma points c-trib
    Sep 12, 2013 @ 14:41
    Tobbe
    0

    hmm, how do I do that?

  • Anders Burla 2560 posts 8256 karma points
    Sep 13, 2013 @ 10:31
    Anders Burla
    0

    Create a Visual Studio class library and then build it and it will output a dll that you can copy to the /bin folder of your website.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jan 16, 2018 @ 11:55
    Alex Skrypnyk
    0

    Hi Anders,

    I have a problem with running CustomShippingCalculator for orders

    using TeaCommerce.Api.Dependency;
    using TeaCommerce.Api.Models;
    using TeaCommerce.Api.PriceCalculators;
    using TeaCommerce.Api.Services;
    
    [SuppressDependency("TeaCommerce.Api.PriceCalculators.IShippingCalculator", "TeaCommerce.Api")]
    public class CustomShippingCalculator : ShippingCalculator
    {
        public CustomShippingCalculator(IVatGroupService vatGroupService, ICurrencyService currencyService)
            : base(vatGroupService, currencyService)
        {
        }
        protected override Price CalculatePrice(ShippingMethod shippingMethod, Currency currency, Order order)
        {
    
            if (!string.IsNullOrWhiteSpace(order.Properties["glsShippingCost"]))
            {
                var currentShippingPrice = decimal.Parse(order.Properties["glsShippingCost"]);
    
                if (order.ShipmentInformation.TotalPrice.WithVat != currentShippingPrice)
                {
                    return new Price(currentShippingPrice, order.VatRate, currency);
                }
            }
    
            return base.CalculatePrice(shippingMethod, currency, order);
        }
    }
    
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jan 16, 2018 @ 11:55
    Alex Skrypnyk
    0

    It's not working in separate dll and in app_code

Please Sign in or register to post replies

Write your reply to:

Draft