Copied to clipboard

Flag this post as spam?

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


  • Chris 47 posts 127 karma points
    Sep 29, 2016 @ 16:35
    Chris
    0

    StoreLineItemModel Product is NULL

    In the UpdateBasket override method as we loop through to find which line item quantity changed the Product property is NULL (and ProductKey is 000-000) even though it has a value on the front-end as the basket is rendered.

    The item is available for purchase and is added normally by clicking the "Add To Basket" button from the Catalog page. The LineItemType is Product.

    Possible reasons why this is occurring? Is it by design?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Sep 29, 2016 @ 16:47
    Rusty Swayne
    0

    Is this in an AJAX call? If so, you have to make sure the model your passing back is populated.

  • Chris 47 posts 127 karma points
    Sep 29, 2016 @ 17:02
    Chris
    0

    Hi Rusty,

    It is. We are simply overriding the default UpdateBasket method (inheriting from StoreBasketController) without any special code. The moment we hit the method override

    public override ActionResult UpdateBasket(StoreBasketModel model)
    

    model.Items[0].Product is NULL.

    This also happens when we use the default endpoint and go directly to the BasketControllerBase UpdateBasket method instead of using our override.

    If we do have to repopulate the Product ourselves what is the best way to do so? The only properties I see are the LineItem key and maybe the merchProductVariantKey buried in the ExtendedData, but that seems like a long-winded way to get the Product.

  • Chris 47 posts 127 karma points
    Sep 29, 2016 @ 17:34
    Chris
    0

    Scratch that. Even ExtendedData is null so the ONLY piece of data we have an this point is the LineItem Key.

    enter image description here

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Sep 29, 2016 @ 17:47
    Rusty Swayne
    0

    That's probably all the data I needed to update the quantity in the default script (since in the UI, I only needed to update the quantity (which is also showing a value).

    The way it works is the form (App_Plugins/Merchello/Views/StoreBasket/BasketForm.cshtml) is serialized in the JS and posted back to the UpdateMethod.

    The only form values in there are the LineItemKey (hidden field) and the Quantity text box - since those are the only two things needed to be updated.

    You do have access to the Basket property which should be fully populated, so using the LineItemKey and the Quantity you can find the "actual" basket item.

  • Chris 47 posts 127 karma points
    Sep 29, 2016 @ 17:56
    Chris
    0

    Thanks, Rusty. That makes sense.

    We'll try pulling the details from the Basket object.

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Sep 29, 2016 @ 18:05
    Rusty Swayne
    101

    You'll have to reverse that since model.Items only has the line item key and the quantity set.

         // definitely a better way to do this - but wanted to give a quick example
        //  to show you need the Basket.Item NOT the model.Item
        foreach (var item in model.Items.Where(item => this.Basket.Items.First(x => x.Key == item.Key).Quantity != item.Quantity))
        {
             var basketItem = this.Basket.Items.FirstOrDefault(x => x.Key == item.Key);
        }
    
  • Chris 47 posts 127 karma points
    Sep 29, 2016 @ 18:10
    Chris
    0

    You're correct. Sorry I posted too soon before realizing the data was coming from model.Items.

    On a related note, we can't seem to access the GetProductKey() extension methods even though we've included both Merchello.Core and Merchello.Core.Models. Are we missing a reference or are those methods out of scope somehow?

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Sep 29, 2016 @ 18:19
    Rusty Swayne
    0

    Get product key would be off the line item extended data collection

      var productKey = lineItem.ExtendedData.GetProductKey();
    
Please Sign in or register to post replies

Write your reply to:

Draft