Problem/Motivation

We call 'view_item_list' from 'commerce_product_view_item_list' views handler.

It has the following code:

        if ($result->_entity instanceof ProductVariationInterface) {
          $items[] = $result->_entity;
        }
        elseif ($result->_entity instanceof ProductInterface) {
          $items[] = $result->_entity->getDefaultVariation();
        }

In the 'elseif' section, we get the default variation but don't check that the product can be without variation in some circumstances. As a result, the next error occurs:

TypeError: Drupal\google_tag\Plugin\GoogleTag\Event\Commerce\ViewItemList::Drupal\google_tag\Plugin\GoogleTag\Event\Commerce\{closure}(): Argument #1 ($item) must be of type Drupal\commerce_product\Entity\ProductVariationInterface, null given in Drupal\google_tag\Plugin\GoogleTag\Event\Commerce\ViewItemList->Drupal\google_tag\Plugin\GoogleTag\Event\Commerce\{closure}() (line 61 of /var/www/html/project/web/modules/contrib/google_tag/src/Plugin/GoogleTag/Event/Commerce/ViewItemList.php).

Proposed resolution

Check that the product has a variation

CommentFileSizeAuthor
#3 3512028-3.patch1.11 KBinit90

Issue fork google_tag-3512028

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

init90 created an issue. See original summary.

init90’s picture

Status: Active » Needs review
StatusFileSize
new1.11 KB

japerry made their first commit to this issue’s fork.

japerry’s picture

Status: Needs review » Fixed

Confirmed the bug with a test and fixed!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • japerry committed eb2f8df9 on 2.0.x authored by init90
    fix: #3512028 Skip products without a variation in view_item_list
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.