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
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3512028-3.patch | 1.11 KB | init90 |
Issue fork google_tag-3512028
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
Comment #3
init90Comment #5
japerryConfirmed the bug with a test and fixed!