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 25 posts 96 karma points
    May 21, 2020 @ 16:59
    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 2958 posts 15629 karma points MVP 7x c-trib
    May 21, 2020 @ 18:23
    Matt Brailsford
    101

    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 25 posts 96 karma points
    May 22, 2020 @ 06:05
    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 2958 posts 15629 karma points MVP 7x c-trib
    May 22, 2020 @ 06:10
    Matt Brailsford
    1

    Hey Francis,

    Have you tried serializing it to a JSON string?

    /Matt

  • Francis Benyah 25 posts 96 karma points
    May 22, 2020 @ 07:02
    Francis Benyah
    0

    Thanks Matt

    That did it. Totally forgot about that.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies