Hi Anton,
Have you reviewed this page: https://world.episerver.com/documentation/developer-guides/commerce/shipping/Shipping-gateways-and-providers/#shippingproviders ?
Which Commerce version are you using?
Hello Bob,
Yes, we know about those instructions and we want to automate the following steps:
4. In Commerce Manager, go to the Admin tab.
5. Go to Order System > Shipping Providers.
6. Click New.
So in our solution we have a specific class derived from IShippingPlugin to implement custom gateway. And we would like to create a shipping provider based on our gateway and we want to make it automatically on application start (via InitializableModule or so).
We use EPiServer.CommerceManager 12.12.1
The default shipping providers are installed as part of the sql script to create the database. You could check if the rows exist or not and then insert them.
INSERT INTO [dbo].[ShippingOption] ([ShippingOptionId], [Name], [Description], [SystemKeyword], [ClassName], [Created], [Modified]) VALUES (N'18ede71f-3df3-4d9e-a4cb-3d25881c1ec6', N'Generic Gateway', N'', N'Generic', N'Mediachase.Commerce.Plugins.Shipping.Generic.GenericGateway, Mediachase.Commerce.Plugins.Shipping', '20070101 00:00:00.000', '20070101 00:00:00.000')
INSERT INTO [dbo].[ShippingOption] ([ShippingOptionId], [Name], [Description], [SystemKeyword], [ClassName], [Created], [Modified]) VALUES (N'8826e08e-636d-4962-8607-dbf80fe1945c', N'Weight/Jurisdiction Gateway', N'', N'WeightJurisdiction', N'Mediachase.Commerce.Plugins.Shipping.WeightJurisdictionGateway, Mediachase.Commerce.Plugins.Shipping', '20081007 18:21:01.000', '20081008 18:54:12.000')
You could also use the api
private void ConfigureShippingMethods()
{
var marketService = ServiceLocator.Current.GetInstance<IMarketService>();
var enabledMarkets = marketService.GetAllMarkets().Where(x => x.IsEnabled).ToList();
foreach (var language in enabledMarkets.SelectMany(x => x.Languages).Distinct())
{
var languageId = language.TwoLetterISOLanguageName;
var dto = ShippingManager.GetShippingMethods(languageId);
var option = dto.ShippingOption.Rows.Cast<ShippingMethodDto.ShippingOptionRow>().FirstOrDefault(x => x.SystemKeyword.Equals("MyPayment"));
if (option == null)
{
option = dto.ShippingOption.NewShippingOptionRow();
option.ClassName = "";
option.Created = DateTime.UtcNow;
option.Description = "";
option.Modified = DateTime.UtcNow;
option.Name = "";
option.ShippingOptionId = Guid.NewGuid();
option.SystemKeyword = "";
}
ShippingManager.SaveShipping(dto);
}
}
Thanks, Mark! Thats exactly what I need. But when I try to use it I find that I need to save shipping option in DTO:
dto.ShippingOption.AddShippingOptionRow(option);
With this update of your code, shipping option is saved in [dbo].[ShippingOption] and displayed in Commerce Manager's Shipping Providers
Is there any way to create ShippingProvider programmatically? I need a shipping provider, not a shipping method. I could not find any information about this.
Thanks!