Copied to clipboard

Flag this post as spam?

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


  • Johnny Hall 1 post 21 karma points
    4 days ago
    Johnny Hall
    0

    How to programmatically set the Umbraco Commerce Price property

    Hi everyone, hoping someone can help!

    I’ve set up a store using Umbraco Commerce v13.1.6 and, after following Matt Brailsford's excellent eCommerce tutorial, I now have a fully functioning basket.

    The problem arises when transitioning from manually-added products to populating the store via an API call. While I’ve successfully mapped and saved all the product properties, the Price property continues to evade me.

    I'm aware that the price should be of type Umbraco.Commerce.Price, and I believe it should be as simple as passing the price, the price including tax, and the currency ID. Here’s the relevant code snippet (I'm working with a single currency):

    **

    var currencyGuid = new Guid("f714b451-f510-4275-b389-0190e448bb95");
    var umbracoPrice = new Price(product.Price, 0, currencyGuid);
    

    **

    Then, I'm setting the Price property like this:

    eSyncProductNode.SetValue("price", umbracoPrice);
    

    Oddly enough, this doesn’t throw any errors, but when I check the newly populated products in the backoffice, the Price field remains empty, even though all other properties are successfully mapped.

    I feel like I might be missing something fundamental, but I just can’t figure out what it is. Any advice would be greatly appreciated! Thanks for taking the time to look.

Please Sign in or register to post replies

Write your reply to:

Draft