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 04, 2014 @ 14:30
    Ben Tice
    0

    Unable to Add Custom Shipping Service - Umbraco 7 uCommerce 6

    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);
            }

            ///
            /// Validates the order lines according to their desired destination and configured contries for shipping method
            ///
            ///
            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 (brackets omitted to avoid post getting flagged as spam):

    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

     

  • Morten Skjoldager 440 posts 1499 karma points
    Sep 10, 2014 @ 09:17
    Morten Skjoldager
    100

    So the name of the assembly is MyNamesapce? Just want to make sure :) 

    Also you need to make sure that you have only one components.config in your entire site. Sometimes VS and other tools publish files to various locations under the root.

    If you search for components.config, how many hits do you get? This error is fixed in a later version of uCommerce, so if you're running an old version you should upgrade!

    Best regards

    Morten

  • Ben Tice 31 posts 131 karma points
    Sep 10, 2014 @ 16:14
    Ben Tice
    0

    Thanks Morten! The issue was multiple configs. I'm using v6.1.0.14195.

    Ben

  • Josh Doolan 9 posts 29 karma points
    Oct 19, 2014 @ 21:27
    Josh Doolan
    0

    I experienced this same issue - Fresh umbraco install ucom: 6.1.0.14195

    Morten's suggestion cured my issue as well.

    Refresh you obj  folder (delete it)  - touch your web.config; and they should appear.

    Cheers, 

    Josh

  • The One Technologies Developer 6 posts 56 karma points
    Mar 21, 2015 @ 11:26
    The One Technologies Developer
    0

    How to add custome field or custome variable in Transaction.GetBasket.PurchaseOrder because i want to pass "product description" to worldpay for shopper response in email but i don't know how to do this. Or any other way to pass Product description to worldpay through ucommerce.

    Code:

     Dim opProduct As Product
      opProduct = CatalogLibrary.GetProduct(oLine.Sku)
      oBasket.AddProduct(SiteContext.Current.CatalogContext.CurrentCatalog.PriceGroup, opProduct, 1)



Please Sign in or register to post replies

Write your reply to:

Draft