You are here

public function Frontpage::view in Commerce Demo 8

Builds the frontpage.

Return value

array A render array.

1 string reference to 'Frontpage::view'
commerce_demo.routing.yml in ./commerce_demo.routing.yml
commerce_demo.routing.yml

File

src/Controller/Frontpage.php, line 43

Class

Frontpage

Namespace

Drupal\commerce_demo\Controller

Code

public function view() {
  $product_view_builder = $this->entityTypeManager
    ->getViewBuilder('commerce_product');
  $build = [
    '#theme' => 'commerce_demo_frontpage',
  ];
  $product_storage = $this->entityTypeManager
    ->getStorage('commerce_product');
  $product_ids = $product_storage
    ->getQuery()
    ->condition('field_special_categories.entity.uuid', '5ac7df92-6021-4de7-886d-4618bc7513ec')
    ->range(0, 6)
    ->sort('changed', 'DESC')
    ->execute();
  $featured_products = $product_storage
    ->loadMultiple($product_ids);
  foreach ($featured_products as $product) {
    $build['#featured_products'][] = $product_view_builder
      ->view($product, 'catalog');
  }
  return $build;
}