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.

  • Ben Tice 31 posts 131 karma points
    Sep 03, 2014 @ 21:31
    Ben Tice
    0

    Can't Add or Override Shipping Service

    Hi all,

    I'm using Umbraco 7 and ucommerce 6. I'm attempting to add a custom volume-based shipping service as described in http://docs.ucommerce.net/ucommerce/v6/extending-ucommerce/shipping-method-service.html.

    I've added a class library to my solution that is referenced by my site:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using UCommerce;
    using UCommerce.Api;
    using UCommerce.EntitiesV2;
    using UCommerce.Transactions.Shipping;

    namespace MyNamespace
    {
        public class VolumeShippingMethodService : IShippingMethodService
        {
            public Money CalculateShippingPrice(Shipment shipment)
            {
                int totalQuantity = 0;
                foreach (OrderLine orderline in shipment.OrderLines)
                {
                    totalQuantity += orderline.Quantity;
                }

                decimal shippingPrice;
                if (totalQuantity < 4)
                {
                    shippingPrice = 5.95m;
                }
                else
                {
                    // free shipping
                    shippingPrice = 0;
                }

                return new Money(shippingPrice, shipment.PurchaseOrder.BillingCurrency);
            }

            public bool ValidateForShipping(Shipment shipment)
            {
                if (shipment.ShipmentAddress != null)
                    throw new InvalidOperationException("Cannot validate shipment for country. Remember to set the shipping address for shipment.");

                var shippingMethod = shipment.ShippingMethod;
                if (shippingMethod == null)
                    throw new InvalidOperationException(
                        "Cannot validate destination country for shipment. It does not contain a shipping method. Remember to add a shipping method to your shipment before validating.");

                return ValidateShippingDestination(shipment.ShipmentAddress,
                                            shippingMethod);
            }

            /// <summary>
            /// Validates the order lines according to their desired destination and configured contries for shipping method
            /// </summary>
            /// <returns></returns>
            protected virtual bool ValidateShippingDestination(OrderAddress shippingAddress, ShippingMethod shippingMethod)
            {
                var eligibleCountries = shippingMethod.EligibleCountries;

                // No eligible countries exist - so the shipment isn't valid
                if (eligibleCountries == null) return false;

                return eligibleCountries.SingleOrDefault(x => x == shippingAddress.Country) != null;
            }
        }
    }

    I've also added the following to the Custom.config file:

    <component id="VolumeShippingMethodService" service="UCommerce.Transactions.Shipping.IShippingMethodService, UCommerce" type="MyNamespace.VolumeShippingMethodService, MyNamespace"/>

    The namespace I'm using is the same as the assembly name.

    I've touched the web.config file, attempted to override SinglePriceService, and have tried adding the component line to shipping.config instead. For the life of me, I can't get this to show up or have any effect.

    I'd be extremely grateful for any help anyone can offer.

    Thank you in advance!

    Ben

     

  • Ben Tice 31 posts 131 karma points
    Sep 08, 2014 @ 15:13
    Ben Tice
    0

    bump :)

Please Sign in or register to post replies

Write your reply to:

Draft