Unfortunately it won't let me build the project because:
'System.Collections.Generic.ICollection<UCommerce.EntitiesV2.OrderLine>' does not contain a definition for 'PurchaseOrders' ...
'UCommerce.EntitiesV2.Shipment' does not contain a definition for 'ShippingMethods' ...
'UCommerce.EntitiesV2.Shipment' does not contain a definition for 'OrderAddresses' ...
'UCommerce.EntitiesV2.Shipment' does not contain a definition for 'ShippingMethods' ...
Do you know what I am missing?
Here is my code:
using System;
using System.Linq;
using UCommerce;
using UCommerce.EntitiesV2;
using UCommerce.Transactions.Shipping;
namespace AirAmbulanceCustomShippingService
{
public class AirAmbulanceCustomShippingService : IShippingMethodService
{
public string Name { get; set; }
public Money CalculateShippingPrice(Shipment shipment)
{
var numberOfItems = shipment.OrderLines.Count();
decimal shippingPrice = 0;
switch (numberOfItems)
{
case 1:
shippingPrice = 150;
break;
case 2:
shippingPrice = 250;
break;
case 3:
shippingPrice = 350;
break;
default:
shippingPrice = 450;
break;
}
return new Money(shippingPrice, shipment.OrderLines.PurchaseOrders.Single().Currencies.Single());
}
public bool ValidateForShipping(Shipment shipment)
{
if (shipment.ShipmentAddressId <= 0)
throw new InvalidOperationException("Cannot validate shipment for country. Remember to set the shipping address for shipment.");
var shippingMethod = shipment.ShippingMethods.SingleOrDefault();
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.OrderAddresses.Single(), shipment.ShippingMethods.Single());
}
/// <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;
if (eligibleCountries == null) return false;
return eligibleCountries.SingleOrDefault(x => x.CountryId == shippingAddress.CountryId) != null;
}
}
}
The article describes how to use the V1 API, which is not available in uCommerce 2.0. Whereever you see a ShippingMethods.Single() call in the article you can use ShippingMetod instead. The reason is that our old ORM had an interesting way of expressing relationships in the sense that it would do many to many relationships for everything, even one to one.
Forgot to point out that there's an article, which details the differences between the two APIs Migrating Code to UCommerce.EntitiesV2. It should be useful until all the docs are updated to V2.
Problem with creating a custom shipping method
Hi I'm trying to create a custom shipping method as it describes on this page:
http://www.publicvoid.dk/BuildingACustomShippingMethodService.aspx
Unfortunately it won't let me build the project because:
'System.Collections.Generic.ICollection<UCommerce.EntitiesV2.OrderLine>' does not contain a definition for 'PurchaseOrders' ...
'UCommerce.EntitiesV2.Shipment' does not contain a definition for 'ShippingMethods' ...
'UCommerce.EntitiesV2.Shipment' does not contain a definition for 'OrderAddresses' ...
'UCommerce.EntitiesV2.Shipment' does not contain a definition for 'ShippingMethods' ...
Hi Paul,
The article describes how to use the V1 API, which is not available in uCommerce 2.0. Whereever you see a ShippingMethods.Single() call in the article you can use ShippingMetod instead. The reason is that our old ORM had an interesting way of expressing relationships in the sense that it would do many to many relationships for everything, even one to one.
Hope this helps.
Thanks Søren that did the trick
For anyone else doing similar I also had difficulty with the line
Using the following worked though:
Forgot to point out that there's an article, which details the differences between the two APIs Migrating Code to UCommerce.EntitiesV2. It should be useful until all the docs are updated to V2.
is working on a reply...