We would like to create all custom product defintions programatically to ensure that when we release updates to the site we dont have to manually create all of the new definitions in the uCommerce production version. Looking at the API it looks like we should be able to do this using some code such as:
The issue is where/when this code can be executed. Being an umbraco 4.11 site, we implemented an ApplicationEventHandler and put this code in the OnApplicationStarted method - however we received the error:
System.Web.HttpException: Request is not available in this context
This was thrown on the productDefintion.Save() line.
Upgrading sounds good, however a couple of questions spring to mind:
What is the upgrade process? We downloaded uCommerce 4.0.6.13304 and the Avenue Clothing Demo Razor 2.0.0.13249 and these are listed as installed packages in umbraco.
Are there any breaking changes in the API or such like?
No there shouldn't be anything in particular. The only thing is that the uCommerce api are integrated into the core instead of the raxor store. But the upgrade should take care of everything. You should just download the new packages and install first uCommerce 5 and the the corresponding razor store.
Creating Defintions programatically
Hi,
We would like to create all custom product defintions programatically to ensure that when we release updates to the site we dont have to manually create all of the new definitions in the uCommerce production version. Looking at the API it looks like we should be able to do this using some code such as:
ProductDefinitionField productDefinitionField = new ProductDefinitionField();
productDefinitionField.DataType =
DataType.FirstOrDefault(def => def.DefinitionName.ToLower() == "boolean");
productDefinitionField.DisplayOnSite = false;
productDefinitionField.IsVariantProperty = false;
productDefinitionField.Name = "Test";
ProductDefinition productDefinition =
ProductDefinition.FirstOrDefault(node => node.Name == "Plastic Sheet");
if (productDefinition != null)
{
productDefinition.AddProductDefinitionField(productDefinitionField);
productDefinition.Save();
}
The issue is where/when this code can be executed. Being an umbraco 4.11 site, we implemented an ApplicationEventHandler and put this code in the OnApplicationStarted method - however we received the error:
System.Web.HttpException: Request is not available in this context
This was thrown on the productDefintion.Save() line.
Any pointers would be greatly appreciated.
Regards,
Al
Hi higgsy.
This is fixed in uCommerce 5. If you upgrade you should have the fix right there.
Go to http://www.ucommerce.net/en/products/developer.aspx
If this is not an option please continue reading :=)
You need the proper API's to do this. Those you use requires an HttpContext which is not the case due to
System.Web.HttpException: Request is not available in this context
Depending on version you can follow this blogpost to make this work:
http://www.publicvoid.dk/BulkImportFromThirdPartySystemsUsingTheUCommerceAPI.aspx
http://www.publicvoid.dk/UsingTheUCommerce3APIInAWindowsApplication.aspx
Hope this helps
Morten
Hi Morten,
Thanks for your response.
Upgrading sounds good, however a couple of questions spring to mind:
Many thanks
Al
Hello Higgsy,
No there shouldn't be anything in particular. The only thing is that the uCommerce api are integrated into the core instead of the raxor store. But the upgrade should take care of everything. You should just download the new packages and install first uCommerce 5 and the the corresponding razor store.
Best regards
Morten
is working on a reply...