Create new ShippingProvider programmatically

Vote:
 

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!

#199515
Edited, Nov 29, 2018 11:13
Vote:
 
#199536
Nov 29, 2018 17:09
Vote:
 

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

#199537
Nov 29, 2018 17:52
Vote:
 

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);
            }
        }
#199547
Nov 29, 2018 23:06
Vote:
 

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

#199589
Dec 03, 2018 11:00
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.