Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mymodule_preprocess_commerce_product(&$variables)
- {
- $product = $variables['elements']['#commerce_product'];
- // get products taxonomy terms ids
- $pr_brand_id = $product->get('field_brand')->target_id;
- $pr_category_id = $product->get('field_product_categories')->target_id;
- // get nid of size table (depends on category and brand)
- $query = \Drupal::entityQuery('node')
- ->condition('type', 'size_table')
- ->condition('field_brands', $pr_brand_id)
- ->condition('field_categories', $pr_category_id);
- $nids = $query->execute();
- // set variable with table's render
- if (count($nids)) {
- $nid = reset($nids);
- $node = \Drupal::entityTypeManager()->getStorage('node')->load($nid);
- $view = $node->body->view('default');
- $variables['size_table'] = render($view);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement