Copied to clipboard

Flag this post as spam?

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


  • Neil Hodges 338 posts 987 karma points
    Aug 06, 2020 @ 10:53
    Neil Hodges
    0

    Can I add custom properties to a Product / Orderline?

    Hi

    I'm needing to add a few properties along with a product. They have no price associated with them and aren't nodes in Umbraco with a price, so don't think I can add them as a bundle.

    Reading this, i can add properties to an Order https://vendr.net/docs/core/1-2-0/key-concepts/properties/#order-line-system-properties

    But not sure how to programmatically add properties to a product/order line?

    These product properties are configured on the front end and just needed adding to the product in the basket as reference.

    I have so far:

     [HttpPost]
        public ActionResult AddToCart(AddToCartDto postModel)
        {
    
            try
            {
                using (var uow = _unitOfWorkProvider.Create())
                {
                    var store = CurrentPage.GetStore();
                    var order = _sessionManager.GetOrCreateCurrentOrder(store.Id)
                        .AsWritable(uow)
                        .AddProduct(postModel.ProductReference, postModel.Quantity);
    
                    //add product properties to product <-----
    
    
                    _orderService.SaveOrder(order);
    
                    uow.Complete();
                }
            }
            catch(ValidationException)
            {
                ModelState.AddModelError("productReference", "Failed to add product to cart");
                return CurrentUmbracoPage();
            }
    
            TempData["addedProductReference"] = postModel.ProductReference;
    
            return RedirectToCurrentUmbracoPage();
    
    
        }
    

    In TC I think we could add them as hidden inputs, is this still the case in Vendr? Or best to add it via ActionResult form post?

  • Matt Brailsford 4125 posts 22224 karma points MVP 9x c-trib
    Aug 06, 2020 @ 12:04
    Matt Brailsford
    100

    Hi Neil,

    There is another AddProduct method that also supports A dictionary of properties to add to the order line.

    https://vendr.net/docs/core/1-2-0/reference/vendr-core/orderextensions/#addproduct-3-of-8

    Hope this helps

    /Matt

  • Neil Hodges 338 posts 987 karma points
    Aug 06, 2020 @ 12:49
    Neil Hodges
    0

    Brilliant, thanks Matt!

  • 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