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 for support.

  • Rob Scott 41 posts 94 karma points
    Jun 11, 2015 @ 04:12
    Rob Scott

    Add product to basket with NULL price - use variant price instead

    I've read the following threads but I still don't understand how to override the AddToBasket() method to use a different price.


    I have a bunch of products, and all these products have variants. However, NONE of my products have a price. ALL the prices are associated to a variantSku. There are 1000s of variants, and all of them have different sizes. The price is associated to the size. There could be 1-to-many variants per product.

    I created a custom field (Price) inside the variant. When adding to a basket,

    TransactionLibrary.AddToBasket(quantity, variant.Sku, variant.VariantSku, true);

    I need to be able to pass the price, OR I need to be able to tell the IPricingService to use the variant.variantSku to access the custom data field for price instead from within that variant, rather than the variant.Price

    Threads that I've read through:

    Here's a product and one of it's associated variants so you can get an idea of my issue.



  • Nickolaj Lundgreen 233 posts 1132 karma points
    Jun 11, 2015 @ 06:38
    Nickolaj Lundgreen

    Hi Rob

    Is there a reason you don't use the normal price on the variant? (pressing the "dollar bill" icon for each variant?

    The IPricingService is the correct way to override the default behaviour of price extraction, but im a little curious about way you can't use the build-in field here :)

  • Rob Scott 41 posts 94 karma points
    Jun 11, 2015 @ 11:11
    Rob Scott

    I......did not know that was there haha. I'll look into that tonight when I get home. Thanks for pointing that out I would of never noticed it. Always thought the icons (similar to Umbraco) were meant for updating, deleting, etc. Never thought to look otherwise.

    I'm glad it is there though, b/c I always thought it was weird for such a big application (uCommerce) not to allow prices for variants, and only for products, hence the reason why I created the custom field.

    Thanks and I'll keep you updated.

  • Rob Scott 41 posts 94 karma points
    Jun 14, 2015 @ 14:43
    Rob Scott

    Nickolaj -

    Thanks for that tip, can't believe I missed that. One question I have is that there's (2) price groups in there (when I click on that "dollar sign", EUR and US Dollar. I do not need the EUR.

    How do I assign this PriceGroupPrice with the appropriate properties to each variant?

    Is the below code correct?

    uCommerceVariant = new Product()
               DisplayOnSite = true,
               VariantSku = subVariant.sku,
               Sku = uCommerceProduct.Sku,
               Name = subVariant.itemDescription,
               AllowOrdering = true,
               ProductDefinition = uCommerceProduct.ProductDefinition
    var groupPrice = PriceGroupPrice.Find(x => x.PriceGroup.Name.Equals("US Dollar")).FirstOrDefault();
    groupPrice.Price = 44.44m;
    groupPrice.Product = uCommerceVariant;

    I've also noticed that in the variant's pricing, the "US Dollar" is stored w/ 4 decimal places. Is this correct?

  • Søren Spelling Lund 1797 posts 2786 karma points
    Jun 16, 2015 @ 09:23
    Søren Spelling Lund

    Hi Rob,

    Your code looks about right, although you need to create a new object if a PriceGroupPrice is not found.

    The high precision for prices is used in case you're dealing with very low unit prices where high precision start to matter :)

    Hope this helps.

  • Rob Scott 41 posts 94 karma points
    Jun 16, 2015 @ 10:47
    Rob Scott

    Søren -

    Yup I got this working the other night, basically did what you said, if found, update, if not, create new.

    Thanks for the replies guys!

Please Sign in or register to post replies

Write your reply to: