Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • higgsy 65 posts 92 karma points
    Jan 07, 2014 @ 23:14
    higgsy
    0

    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

  • Morten Skjoldager 440 posts 1499 karma points
    Jan 08, 2014 @ 09:51
    Morten Skjoldager
    0

    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

  • higgsy 65 posts 92 karma points
    Jan 10, 2014 @ 14:46
    higgsy
    0

    Hi Morten,

    Thanks for your response.

    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?

    Many thanks

    Al

  • Morten Skjoldager 440 posts 1499 karma points
    Jan 13, 2014 @ 15:07
    Morten Skjoldager
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft