logo

Extra Block Types (EBT) - New Layout Builder experience❗

Extra Block Types (EBT) - styled, customizable block types: Slideshows, Tabs, Cards, Accordions and many others. Built-in settings for background, DOM Box, javascript plugins. Experience the future of layout building today.

Demo EBT modules Download EBT modules

❗Extra Paragraph Types (EPT) - New Paragraphs experience

Extra Paragraph Types (EPT) - analogical paragraph based set of modules.

Demo EPT modules Download EPT modules

Scroll

Creating a block in "Customers who bought this item also bought"

22/02/2025, by Anonymous (not verified)
Forums

Good evening!

I have the following situation - I am creating a block in the store: "Customers who bought this item also bought," which should display (recommend) a specific product corresponding to the currently viewed product. The relationship data is established using the Entity reference module. The Views PHP module is also installed to specify the appropriate filters for displaying product recommendations in the custom block.

 

In the Global:PHP filter criteria, I wrote the following code in the filter code field to display the recommended product in the block:

 

if (arg(0) && arg(0) == 'node') {
    $related_ids = array();
    $node = node_load(arg(1));
    $related = field_get_items('node', $node, 'field_pd_related_products');
    if ($related && is_array($related) && sizeof($related) > 0) {
      for ($i=0; $i
        $related_ids[] = $related[$i]['target_id'];
      }
    }
  }
  return (isset($related_ids) && in_array($row->nid, $related_ids) ? FALSE : TRUE );

 

As a result, the block does not appear next to the product display where the relationship is established using the Entity reference module. What is the problem? Is the code correct?