Product Variation meta tags not working

Created on 30 June 2024, 3 months ago
Updated 3 July 2024, 3 months ago

Problem/Motivation

Dear Community,

I have a product page with multiple variations in 3 different colors. Their urls are

/product?v=1
/product?v=2
/product?v=3

However I can only make the "Product" meta tag work not the "Product Variation" tag.

From the Product meta tag settings, I can access the product variations token, such as [commerce_product:variations:0:entity:field_image:0:large] to display the image from the variation. However the problem is that I have 3 variations. But using the token above only gave me either the first, second or third variation's value but not dynamically the current product variation's value. Here is what I need.

  • When customer viewing the page /product?v=1, I need the token to be [commerce_product:variations:0:entity:field_image:0:large].
  • When customer viewing the page /product?v=2, I need the token to be [commerce_product:variations:1:entity:field_image:0:large].
  • When customer viewing the page /product?v=3, I need the token to be [commerce_product:variations:2:entity:field_image:0:large].

I hope this makes sense?

I tried to resolve this problem by setting the metatags in Product Variation. But all the settings in Product Variation are in vain and not effective at all.

Any advice how to get the product variation specific meta tags displayed?

Thank you!

πŸ’¬ Support request
Status

Active

Version

2.0

Component

User interface

Created by

πŸ‡ΊπŸ‡ΈUnited States iseeaflyingcrane

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @iseeaflyingcrane
  • πŸ‡ΊπŸ‡ΈUnited States iseeaflyingcrane
  • πŸ‡ΊπŸ‡ΈUnited States DamienMcKenna NH, USA

    I think the root problem is that Commerce product variants don't have their own "canonical" route.

    If you look at the Product entity file it has a "canonical" link specification in the entity's definition:

     *   links = {
     *     "canonical" = "/product/{commerce_product}",
    

    If you look at the ProductVariant entity file it doesn't have the "canonical" item in the links definition.

    Metatag requires that the current page points to a specific route, especially in order to access the tokens that belong with that entity. This is how it works for nodes, users, terms, etc. Because product variants don't have their own route all of this entity logic doesn't work as expected.

    I did open a feature request for Commerce to add this route ( ✨ Add a canonical URL for the ProductVariant entity Active ), we'll see what becomes of it.

    The alternative approach is to use the [commerce:current_variation] tokens, as defined in commerce_product.tokens.inc, and add them on the Product entity's meta tag defaults. You might also take a look at the Token page of the Help page, it will show you the entire token tree and it might help track down what you need.

  • πŸ‡ΊπŸ‡ΈUnited States iseeaflyingcrane

    Thank you @DamienMcKenna for the response. I hope they will add the canonical link to the product variation entity. I am not sure how to use the current token. Can you elaborate how to to do this?

    The alternative approach is to use the [commerce:current_variation] tokens, as defined in commerce_product.tokens.inc, and add them on the Product entity's meta tag defaults. You might also take a look at the Token page of the Help page, it will show you the entire token tree and it might help track down what you need.

    Thanks again!

  • πŸ‡ΊπŸ‡ΈUnited States iseeaflyingcrane

    Never mind. I found it after upgrading commerce module. Thank you!

Production build 0.71.5 2024