Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
listing.phtml
Go to the documentation of this file.
1 <?php
7 // @codingStandardsIgnoreFile
8 
9 ?>
10 <?php
16 ?>
17 <?php
18 $start = microtime(true);
19 $_productCollection = $block->getLoadedProductCollection();
20 $_helper = $this->helper('Magento\Catalog\Helper\Output');
21 ?>
22 <?php if (!$_productCollection->count()): ?>
23 <p class="message note"><?= /* @escapeNotVerified */ __('We can\'t find products matching the selection.') ?></p>
24 <?php else: ?>
25 <?= $block->getToolbarHtml() ?>
26 <?= $block->getAdditionalHtml() ?>
27 <?php
28  if ($block->getMode() == 'grid') {
29  $viewMode = 'grid';
30  $image = 'category_page_grid';
31  $showDescription = false;
33  } else {
34  $viewMode = 'list';
35  $image = 'category_page_list';
38  }
39 ?>
40 <div class="products wrapper <?= /* @escapeNotVerified */ $viewMode ?>">
41  <ol class="products list items">
42  <?php foreach ($_productCollection as $_product): ?>
43  <li class="item product">
44  <div class="product">
45  <?php // Product Image ?>
46  <a href="<?= /* @escapeNotVerified */ $_product->getProductUrl() ?>" class="product photo">
47  <?= $block->getImage($_product, $image)->toHtml() ?>
48  </a>
49  <div class="product details">
50  <?php
51 
52  $info = [];
53  $info['name'] = '<strong class="product name">'
54  . ' <a href="' . $_product->getProductUrl() . '" title="'
55  . $block->stripTags($_product->getName(), null, true) . '">'
56  . $_helper->productAttribute($_product, $_product->getName(), 'name')
57  . '</a></strong>';
58  $info['price'] = $block->getProductPrice($_product);
59  $info['review'] = $block->getReviewsSummaryHtml($_product, $templateType);
60 
61  if ($_product->isSaleable()) {
62  $info['button'] = '<button type="button" title="' . __('Add to Cart') . '" class="action tocart"'
63  . ' data-mage-init=\'{ "redirectUrl": { "event": "click", url: "' . $block->getAddToCartUrl($_product) . '"} }\'>'
64  . '<span>' . __('Add to Cart') . '</span></button>';
65  } else {
66  $info['button'] = $_product->getIsSalable() ? '<div class="stock available"><span>' . __('In stock') . '</span></div>' :
67  '<div class="stock unavailable"><span>' . __('Out of stock') . '</span></div>';
68  }
69 
70  $info['links'] = '<div class="product links" data-role="add-to-links">'
71  . '<a href="#" data-post=\'' . $this->helper('Magento\Wishlist\Helper\Data')->getAddParams($_product) . '\' class="action towishlist" data-action="add-to-wishlist">'
72  . '<span>' . __('Add to Wish List') . '</span></a>'
73  . '<a href="' . $block->getAddToCompareUrl($_product) . '" class="action tocompare">'
74  . '<span>' . __('Add to Compare') . '</span></a></div>';
75  $info['actions'] = '<div class="product action">' . $info['button'] . $info['links'] . '</div>';
76 
77  if ($showDescription) {
78  $info['description'] = '<div class="product description">'
79  . $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description')
80  . ' <a href="' . $_product->getProductUrl() . '" class="action more">'
81  . __('Learn More') . '</a></div>';
82  } else {
83  $info['description'] = '';
84  }
85 
86  $details = $block->getInfoOrder() ?: ['name','price','review','description','actions'];
87  foreach ($details as $detail) {
88  /* @escapeNotVerified */ echo $info[$detail];
89  }
90  ?>
91 
92  </div>
93  </div>
94  </li>
95  <?php endforeach; ?>
96  </ol>
97 </div>
98 <?= $block->getToolbarHtml() ?>
99 <?php endif; ?>
100 <?= /* @escapeNotVerified */ $time_taken = microtime(true) - $start ?>
$showDescription
Definition: listing.phtml:36
__()
Definition: __.php:13
$templateType
Definition: listing.phtml:37
$start
Definition: listing.phtml:18
$_product
Definition: summary.phtml:12
$block
Definition: block.php:8
$_productCollection
Definition: listing.phtml:19
$image
Definition: listing.phtml:35
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52
$_helper
Definition: listing.phtml:20