Copied to clipboard

Flag this post as spam?

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


  • Francis Benyah 10 posts 81 karma points
    5 days ago
    Francis Benyah
    0

    Setting Vendr Product Price Programatically

    Hi Matt

    Just a quick one here.

    How would I go about setting the price property programatcally

    enter image description here

  • Matt Brailsford 2469 posts 12071 karma points MVP 6x c-trib
    5 days ago
    Matt Brailsford
    1

    Hey Francis,

    You should be able to set the price property via Umbraco's content API. You'll need to feed it the expected data formatted for the Price property editor, which needs to be like:

    {
        "27f0ce3e-da98-4492-b442-8010cd31053c": 10.00,
        "14b17a8d-b8cc-4617-ab9d-cc6fb60b0535": 12.00
    }
    

    The GUIDs being the ID's of the Currencies and the values being the price for those currencies.

    To get a list of Currencies you can get these from the from the Vendr Currency Service

    _currencyService.GetCurrencies(storeId);
    

    Hope this helps

    /Matt

  • Francis Benyah 10 posts 81 karma points
    5 days ago
    Francis Benyah
    0

    Hi Matt

    Thanks for the guidance much appreciated.

    I took a stab at this with not much luck. I suspect it is in the way I am structuring the value object.

    I tried the following approaches

    // set price
    productNode.SetValue(DocumentTypeProperties.BaseVendrProductPrice, new { RootNodes.eVendrCurrenciesUSDNodeKey, price});
    

    and also this passing as a dictionary then tried to pass it as KeyValuePair by getting FirstOrDefault

    // set price
    Dictionary<string, int> price = new Dictionary<string, int>
    {
       { RootNodes.eVendrCurrenciesUSDNodeKey, price}
    };
    productNode.SetValue(DocumentTypeProperties.BaseVendrProductPrice, price.FirstOrDefault());
    

    RootNodes.eVendrCurrenciesUSDNodeKey holds the GUID of the currency created in the settings section DocumentTypeProperties.BaseVendrProductPrice holds the alias of the price property on the product document type

    I have tried with the price as a decimal as well in these scenarios.

    Much appreciated.

  • Matt Brailsford 2469 posts 12071 karma points MVP 6x c-trib
    5 days ago
    Matt Brailsford
    0

    Hey Francis,

    Have you tried serializing it to a JSON string?

    /Matt

  • Francis Benyah 10 posts 81 karma points
    5 days ago
    Francis Benyah
    0

    Thanks Matt

    That did it. Totally forgot about that.

Please Sign in or register to post replies

Write your reply to:

Draft