Copied to clipboard

Flag this post as spam?

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


  • Shyam Agarwal 3 posts 73 karma points
    Apr 14, 2021 @ 06:16
    Shyam Agarwal
    0

    Issue with veder plugin

    We are facing an issue while implementing vendr plugin in our project. The problem is mentioned in the attached link please see.

    https://docs.google.com/document/d/1BwtFjNSVKMy0sDkdM2t_yd5-Vtp77ln7LC2eYDNRyrM/edit?usp=sharing

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Apr 14, 2021 @ 08:22
    Matt Brailsford
    0

    Hi Shyam,

    In the future, could you please post the details of your issue directly in the forum post, rather than on an external link as a) links often end up breaking and b) the content of the google doc is not searchable and so anyone with a similar issue will not be able to find this post.

    Bellow is the content of the document as of 2021-04-14 09:15am


    1.Case First when calling CalculatePrice() method getting alway 0 price

    .html Form Code when call CalculatePrice() method-

    <h3>@(Model.Content.CalculatePrice()?.Formatted())</h3>
    

    .cs file Code

       public static string GetProductReference(this IPublishedContent content)
        {
            return content.Key.ToString();
        }
    
        public static IProductSnapshot AsVendrProduct(this IPublishedContent content)
        {
            return VendrApi.Instance.GetProduct(content.GetProductReference(), null);
        }
    
        public static Price CalculatePrice(this IPublishedContent content)
        {
            return content.AsVendrProduct()?.CalculatePrice();
        }
    

    See prize on browser-

    enter image description here

    2.Case Second when calling AddToCart() method getting an error-

    Browser view when click on “Add To Cart” Button-

    enter image description here

    .html form file code-

    <h3>@(Model.Content.CalculatePrice()?.Formatted())</h3>
    @using (Html.BeginUmbracoForm("AddToCart", "CartSurface"))
    {
        @Html.Hidden("productReference", Model.Content.GetProductReference())
        <div class="input-group">
            @Html.TextBox("quantity", 1, new { @type = "number", @class = "form-control input-number" })
        </div>
    
        <div class="input-group-btn">
            <button class="btn btn-warning">Add to Cart <i class="fas fa-cart-plus"></i></button>
        </div>
    }
    

    .cs file code-

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

    Getting error in .cs file screen shot-

    enter image description here

    After clicking “Add To Cart” Button then browser screen showing that type error-

    enter image description here

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Apr 14, 2021 @ 08:25
    Matt Brailsford
    1

    In answer to your question, I believe the final exception tells you exactly what the issue is and that is that on your product node you don't have a price property defined (with the alias price) that is using the Vendr: Price property editor. Or if you do have such a property defined, there is no price value on it for the given orders currency.

    Please check your products document type and ensure you have the relevant properties defined. You can find details on the various properties Vendr expects in the Vendr docs at https://vendr.net/docs/core/1.6.0/key-concepts/umbraco-properties/

    Hope this helps

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft