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?
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.
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.
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);
}
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?
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?
Is this in an AJAX call? If so, you have to make sure the model your passing back is populated.
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
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.
Scratch that. Even ExtendedData is null so the ONLY piece of data we have an this point is the LineItem Key.
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.Thanks, Rusty. That makes sense.
We'll try pulling the details from the Basket object.
You'll have to reverse that since model.Items only has the line item key and the quantity set.
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?
Get product key would be off the line item extended data collection
is working on a reply...