Knowing the number of variants

Hi !

I have a few requests:

  • Would it be possible to add an “available” attribute (I know it’s possible to check the inventory_quantity but it’s more convenient in templating language to have directly an available attribute).
  • I have a use case where I need to render the results differently based on wether the products has 1 or multiple variants. However I can’t see any way to know the variants count. Is it possible to add such an attribute? :slight_smile:

Thanks!

1 Like
  1. This is actually really easily doable in the front-end code.
    Our instantsearch widgets have a transformData method which can modify the object sent to the templates.
    Our Hits widget is actually adding a can_order like this:

    product.can_order = product.inventory_policy === 'continue' || product.inventory_quantity > 0;
    

    You can also do the same with the autocomplete.

    suggestion: function displaySuggestion (hit) {
      if (hit.inventory_quantity) {
        hit.available = hit.inventory_quantity > 0;
      }
      return algolia.render(params.templates.hit, hit);
    }
    
  2. I’ve just deployed a change adding this count: variants_count (see ChangeLog). However, as described in this thread, we won’t do it for any product vairant’s data. :slight_smile:

To be fully honest here, I’m not completely confident about adding fields concerning the list of variants inside a variant record which is considered a product thanks to distinct. That sentence alone showcases perfectly the complexity induced here. That’s likely a separation which should be done, to avoid confusion, in two indices, a “variants” one and a “products” one, but this is unfortunately not doable without a breaking change.

1 Like

Thank you for adding this. I was indeed quite confused by the fact that everything is called products but actually refer to variants :p.

Quick question actually regarding the inventory_quantity. Is it the global inventory quantity (sum of all variants), or the inventory_quantity of the variant returned? What I actually need is really a way to know if the rpoduct as a whole is unavailable.

Also, I’m quite new to Algolia and trying to get my grasp around it, but is there any way to sort by product title alphabetically or is this acutally not something Algolia was thought for?

But in all cases, thanks a lot for your very fast replies :).

Unfortunately, knowing if a product is globally out of stock won’t be possible.

About the sorting by title, you can indeed add a sort order by “Name” as you can see here :

This will increase your records count though, but it can definitely be a sort order you can have.

So… may we as well add the “product” available property as a “product_available”? :smiley:

I’m really sorry, but this is starting to look exactly as I don’t want it to look like, and I think I should stop it here.
While I understand you have a valid use-case here, this is just the beginning of something that isn’t what we planned with this integration.

If other shops start asking for this I’ll be happy to reconsider it, but in the meantime I’ll just put it in our backlog. This will need to wait for a revamp of this integration to generate two different indices.

Definitely agree, it would make it even more confusing with this mixup of products and variants (although the design was a bit wrong on your end from the start here ;).

You’re right, and I take the full blame for this move!