How to get link to product image?

Created on 19 April 2023, about 1 year ago
Updated 29 May 2023, about 1 year ago

Hey, I just started working with this module. It is a bit over my head but I have made some progress modifying the source on my end. However I could use some direction.

Problem/Motivation

I'm generating a google product feed. As of now I have added additional tags to the CommerceProductVarationNormalizer.php in the getNormalization() function. I'm not sure if that is the correct place, but it works.

Now the issue I am running into is getting an image link from a media (or image) field on the product type or the product variation. Do you have any suggestions on going about this?

Thanks!

πŸ’¬ Support request
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States sleewok

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

Comments & Activities

  • Issue created by @sleewok
  • πŸ‡΅πŸ‡ΉPortugal introfini
    
        // Not all the products have an image set
        if (empty($product->field_product_images->first()->entity)) {
          $field_config = $product->getFieldDefinition('field_product_images');
          $default_image = $field_config->getSetting('default_image');
          $entityrepository = \Drupal::service('entity.repository');
          $defaultImageFile = $entityrepository->loadEntityByUuid('file', $default_image['uuid']);
          $image_uri = $defaultImageFile->getFileUri();
        } else {
          $image_uri = $product->field_product_images->first()->entity->getFileUri();
        }
    
        $values['g:image_link'] = file_create_url($image_uri);
    
Production build 0.69.0 2024