Quantcast
Channel: Optimizely Search & Navigation
Viewing all articles
Browse latest Browse all 6894

Error programmatically creating Shipping Method

$
0
0

I'm getting this error:

"ForeignKeyConstraint FK_ShippingOption_ShippingMethod requires the child key values (18ede71f-3df3-4d9e-a4cb-3d25881c1ec6) to exist in the parent table."

and here is my code:

private ShippingMethodDto.ShippingMethodRow CreateShippingMethod(string shippingMethodName, Guid shippingOptionID)
        {
            ShippingMethodDto shippingMethod = new ShippingMethodDto();
            ShippingMethodDto.ShippingMethodRow shippingMethodRow = shippingMethod.ShippingMethod.NewShippingMethodRow();
            shippingMethodRow[shippingMethod.ShippingMethod.ShippingMethodIdColumn] = Guid.NewGuid();
            shippingMethodRow[shippingMethod.ShippingMethod.LanguageIdColumn] = LanguageId;
            shippingMethodRow[shippingMethod.ShippingMethod.NameColumn] = shippingMethodName;
            shippingMethodRow[shippingMethod.ShippingMethod.DisplayNameColumn] = shippingMethodName;
            shippingMethodRow[shippingMethod.ShippingMethod.DescriptionColumn] = "";
            //shippingMethodRow[shippingMethod.ShippingMethod.CurrencyColumn] = shippingMethodInfo.Currency;
            shippingMethodRow[shippingMethod.ShippingMethod.BasePriceColumn] = 0m;
            shippingMethodRow[shippingMethod.ShippingMethod.ShippingOptionIdColumn]= shippingOptionID;
            shippingMethodRow[shippingMethod.ShippingMethod.IsActiveColumn] = true;
            shippingMethodRow[shippingMethod.ShippingMethod.IsDefaultColumn] = false;
            //shippingMethodRow[shippingMethod.ShippingMethod.OrderingColumn] = shippingMethodInfo.Ordering;
            shippingMethodRow[shippingMethod.ShippingMethod.CreatedColumn] = DateTime.UtcNow;   //TODO
            shippingMethodRow[shippingMethod.ShippingMethod.ModifiedColumn] = DateTime.UtcNow;   //TODO
            shippingMethod.ShippingMethod.Rows.Add(shippingMethodRow);
            ShippingManager.SaveShipping(shippingMethod);
            return shippingMethodRow;
        }
// used like this:
 var methods = ShippingManager.GetShippingMethodsByMarket(currentMarket.GetCurrentMarket().MarketId.Value, true);
shippingMethod = CreateShippingMethod("deliveryMethodName", methods.ShippingOption[0].ShippingOptionId);

it's essentially complaining about the shipping Option ID that i'm passing in, but that ID is being loaded via EPiServer libs anyway. What am i missing?


Viewing all articles
Browse latest Browse all 6894

Trending Articles