SaaS CMS has officially launched! Learn more now.

Type of Variants in the Cart

SG
SG
Vote:
 

Hello,

Wondering is their any way to find out type of variants added to the cart? ex: cart.GetAllLineItems() returns InMemoryLine item - how do I know what's variant type without loading content item using variant code.

Regards,

SG

#324809
Jul 02, 2024 14:38
Vote:
 

Hi Shakti,

Yes, however you will first need to extend your lineitems with a metafield / property to do this do the following:

  1. Extend the metafield for lineitems or extend the lineitems in the serializablecart to include an additional property.
  2. When saving lineitems to the cart ensure you retrieve the variant type and then store this against the lineitem.
  3. Retrieve the line item and the metafield / property.

I have put together some example code that could possibly be used however you will need to test yourself:

https://gist.github.com/paulmcgann/92a9a18ff2ca51061aa9a6729a468f2c

https://gist.github.com/paulmcgann/b1411560893e26be5cac3db4d3a10df1

#324825
Jul 02, 2024 21:35
SG - Jul 03, 2024 7:58
Thanks Paul
Vote:
 

Hi Shakti

It would probably be most efficient to load the variant by code. The variants are already cached in Commerce. So loading the variant is usually an insignificant operation. Which scenario do you have where you need to know the type of the variant, without loading the actual variant.

If you store the catalog entry type on the line item, you may waste space in the database. And you risk the data integrity (e.g.g if you change a type somewhere else, and don't update it in the carts).

#325022
Jul 07, 2024 11:36
Vote:
 

GitHub - vimvq1987/CatalogContentTypeResolver could be a good way to resolve the content type without having to load the content itself

#325103
Jul 09, 2024 6:10
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.