Adding products from external source (console app)
Hello,
My name is Fabrice and I'm new to Umbraco and Ucommerce.
I have successfully installed Umbraco 4.04, the latest uCommerce and uCommerceStore and I have integrated it into Visual Studio 2010 (asp.net 3.5)
For my project I need to add and update products to uCommerce daily from an external source (web service).
My first idea was to create a .Net console application which will do the import and i'll schedule it daily. Is that a good way to do the job ?
For first test purpose I tried to add/update products to uCommerce demo store from my Console app but I have issues setting the project for the console app and calling uCommerce API.
Here is how I did :
I have added a reference to businesslogic.dll, cms.dll, umbraco.dll, uCommerce.dll, subsonic.core.dll to the app project and I have copy paste the content of the web.config from my Umbraco install into a new app.config for the console.
I have added also "using UCommerce.Entities;" in the main file. There is also "using UCommerce.EntitiesV2;" but I dont know which one is the best...
var product = new Product { Sku = "SKU-123456", Name = "My Product", AllowOrdering = true, DisplayOnSite = true, ProductDefinitionId = 1, // Set to an existing defintion ThumbnailImageMediaId = 1 // ID from Umbraco (nullable int) };
product.Save();
but I get a NullReferenceException, Object reference not set to an instance of an object. when I call the Save method.
I would be very gratefull if you could help me to figure out how to set up the console project and how to call the uCommerce API.
uCommerce versions prior to 1.0.4.0 were bound tightly to http context even in the data access layer. That's the null reference exception you're seeing. If you download version 1.0.4.0 you won't have that problem. Download uCommerce 1.0.0.4.0 from our site.
Upgrading is simple. You just install the package on top of your existing installation.
Great ! Yes it solved the problem !Thank you very much
For info, after updated, I didnt change anything from the config that I described below (except that I used a ProductDefinitionID that exist, thanks Lasse) to make it work.
Adding products from external source (console app)
Hello,
My name is Fabrice and I'm new to Umbraco and Ucommerce.
I have successfully installed Umbraco 4.04, the latest uCommerce and uCommerceStore and I have integrated it into Visual Studio 2010 (asp.net 3.5)
For my project I need to add and update products to uCommerce daily from an external source (web service).
My first idea was to create a .Net console application which will do the import and i'll schedule it daily. Is that a good way to do the job ?
For first test purpose I tried to add/update products to uCommerce demo store from my Console app but I have issues setting the project for the console app and calling uCommerce API.
Here is how I did :
I have added a reference to businesslogic.dll, cms.dll, umbraco.dll, uCommerce.dll, subsonic.core.dll to the app project and I have copy paste the content of the web.config from my Umbraco install into a new app.config for the console.
I have added also "using UCommerce.Entities;" in the main file. There is also "using UCommerce.EntitiesV2;" but I dont know which one is the best...
First, I just tried to call the code to add a product from http://blog.lasseeskildsen.net/post/uCommerce-How-To-Create-A-Product-Using-The-API.aspx:
var product = new Product
{
Sku = "SKU-123456",
Name = "My Product",
AllowOrdering = true,
DisplayOnSite = true,
ProductDefinitionId = 1, // Set to an existing defintion
ThumbnailImageMediaId = 1 // ID from Umbraco (nullable int)
};
product.Save();
but I get a NullReferenceException, Object reference not set to an instance of an object. when I call the Save method.
I would be very gratefull if you could help me to figure out how to set up the console project and how to call the uCommerce API.
Thank you very much,
Fabrice
Hi Fabrice,
You should use UCommerce.Entities for the code sample above.
Have you verified that you have a product definition with id = 1? If you have, can you post your app.config?
- Lasse
Hi Fabrice,
uCommerce versions prior to 1.0.4.0 were bound tightly to http context even in the data access layer. That's the null reference exception you're seeing. If you download version 1.0.4.0 you won't have that problem. Download uCommerce 1.0.0.4.0 from our site.
Upgrading is simple. You just install the package on top of your existing installation.
Great, I'll update now and keep you in touch.
Thank you very much !
If the answer is help please mark as the solution as it makes it much easier for us to keep track of issues we need to address. Thanks.
Great ! Yes it solved the problem !Thank you very much
For info, after updated, I didnt change anything from the config that I described below (except that I used a ProductDefinitionID that exist, thanks Lasse) to make it work.
is working on a reply...