Skip to content

Commit b66222c

Browse files
MAGETWO-70706: simplify product lists #2 #9019
2 parents 01805b2 + 67e3d28 commit b66222c

File tree

15 files changed

+661
-677
lines changed

15 files changed

+661
-677
lines changed

app/code/Magento/Catalog/view/frontend/templates/product/list.phtml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ $_helper = $this->helper('Magento\Catalog\Helper\Output');
4242
$pos = $block->getPositioned();
4343
?>
4444
<div class="products wrapper <?= /* @escapeNotVerified */ $viewMode ?> products-<?= /* @escapeNotVerified */ $viewMode ?>">
45-
<?php $iterator = 1; ?>
4645
<ol class="products list items product-items">
4746
<?php /** @var $_product \Magento\Catalog\Model\Product */ ?>
4847
<?php foreach ($_productCollection as $_product): ?>
49-
<?= /* @escapeNotVerified */ ($iterator++ == 1) ? '<li class="item product product-item">' : '</li><li class="item product product-item">' ?>
48+
<li class="item product product-item">
5049
<div class="product-item-info" data-container="product-grid">
5150
<?php
5251
$productImage = $block->getImage($_product, $image);
@@ -112,7 +111,7 @@ $_helper = $this->helper('Magento\Catalog\Helper\Output');
112111
</div>
113112
</div>
114113
</div>
115-
<?= ($iterator == count($_productCollection)+1) ? '</li>' : '' ?>
114+
</li>
116115
<?php endforeach; ?>
117116
</ol>
118117
</div>

app/code/Magento/Catalog/view/frontend/templates/product/list/items.phtml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ switch ($type = $block->getType()) {
174174
<?php endif; ?>
175175
<div class="products wrapper grid products-grid products-<?= /* @escapeNotVerified */ $type ?>">
176176
<ol class="products list items product-items">
177-
<?php $iterator = 1; ?>
178177
<?php foreach ($items as $_item): ?>
179178
<?php $available = ''; ?>
180179
<?php if (!$_item->isComposite() && $_item->isSaleable() && $type == 'related'): ?>
@@ -183,9 +182,9 @@ switch ($type = $block->getType()) {
183182
<?php endif; ?>
184183
<?php endif; ?>
185184
<?php if ($type == 'related' || $type == 'upsell'): ?>
186-
<?= /* @escapeNotVerified */ ($iterator++ == 1) ? '<li class="item product product-item" style="display: none;">' : '</li><li class="item product product-item" style="display: none;">' ?>
185+
<li class="item product product-item" style="display: none;">
187186
<?php else: ?>
188-
<?= /* @escapeNotVerified */ ($iterator++ == 1) ? '<li class="item product product-item">' : '</li><li class="item product product-item">' ?>
187+
<li class="item product product-item">
189188
<?php endif; ?>
190189
<div class="product-item-info <?= /* @escapeNotVerified */ $available ?>">
191190
<?= /* @escapeNotVerified */ '<!-- ' . $image . '-->' ?>
@@ -252,7 +251,7 @@ switch ($type = $block->getType()) {
252251
<?php endif; ?>
253252
</div>
254253
</div>
255-
<?= ($iterator == count($items)+1) ? '</li>' : '' ?>
254+
</li>
256255
<?php endforeach ?>
257256
</ol>
258257
</div>

app/code/Magento/Catalog/view/frontend/templates/product/listing.phtml

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -38,61 +38,60 @@ $_helper = $this->helper('Magento\Catalog\Helper\Output');
3838
}
3939
?>
4040
<div class="products wrapper <?= /* @escapeNotVerified */ $viewMode ?>">
41-
<?php $iterator = 1; ?>
4241
<ol class="products list items">
4342
<?php foreach ($_productCollection as $_product): ?>
44-
<?= /* @escapeNotVerified */ ($iterator++ == 1) ? '<li class="item product">' : '</li><li class="item product">' ?>
45-
<div class="product">
46-
<?php // Product Image ?>
47-
<a href="<?= /* @escapeNotVerified */ $_product->getProductUrl() ?>" class="product photo">
48-
<?= $block->getImage($_product, $image)->toHtml() ?>
49-
</a>
50-
<div class="product details">
51-
<?php
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
5251

53-
$info = [];
54-
$info['name'] = '<strong class="product name">'
55-
. ' <a href="' . $_product->getProductUrl() . '" title="'
56-
. $block->stripTags($_product->getName(), null, true) . '">'
57-
. $_helper->productAttribute($_product, $_product->getName(), 'name')
58-
. '</a></strong>';
59-
$info['price'] = $block->getProductPrice($_product);
60-
$info['review'] = $block->getReviewsSummaryHtml($_product, $templateType);
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);
6160

62-
if ($_product->isSaleable()) {
63-
$info['button'] = '<button type="button" title="' . __('Add to Cart') . '" class="action tocart"'
64-
. ' data-mage-init=\'{ "redirectUrl": { "event": "click", url: "' . $block->getAddToCartUrl($_product) . '"} }\'>'
65-
. '<span>' . __('Add to Cart') . '</span></button>';
66-
} else {
67-
$info['button'] = $_product->getIsSalable() ? '<div class="stock available"><span>' . __('In stock') . '</span></div>' :
68-
'<div class="stock unavailable"><span>' . __('Out of stock') . '</span></div>';
69-
}
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+
}
7069

71-
$info['links'] = '<div class="product links" data-role="add-to-links">'
72-
. '<a href="#" data-post=\'' . $this->helper('Magento\Wishlist\Helper\Data')->getAddParams($_product) . '\' class="action towishlist" data-action="add-to-wishlist">'
73-
. '<span>' . __('Add to Wish List') . '</span></a>'
74-
. '<a href="' . $block->getAddToCompareUrl($_product) . '" class="action tocompare">'
75-
. '<span>' . __('Add to Compare') . '</span></a></div>';
76-
$info['actions'] = '<div class="product action">' . $info['button'] . $info['links'] . '</div>';
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>';
7776

78-
if ($showDescription) {
79-
$info['description'] = '<div class="product description">'
80-
. $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description')
81-
. ' <a href="' . $_product->getProductUrl() . '" class="action more">'
82-
. __('Learn More') . '</a></div>';
83-
} else {
84-
$info['description'] = '';
85-
}
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+
}
8685

87-
$details = $block->getInfoOrder() ?: ['name','price','review','description','actions'];
88-
foreach ($details as $detail) {
89-
/* @escapeNotVerified */ echo $info[$detail];
90-
}
91-
?>
86+
$details = $block->getInfoOrder() ?: ['name','price','review','description','actions'];
87+
foreach ($details as $detail) {
88+
/* @escapeNotVerified */ echo $info[$detail];
89+
}
90+
?>
9291

92+
</div>
9393
</div>
94-
</div>
95-
<?= ($iterator == count($_productCollection)+1) ? '</li>' : '' ?>
94+
</li>
9695
<?php endforeach; ?>
9796
</ol>
9897
</div>

app/code/Magento/Catalog/view/frontend/templates/product/widget/new/column/new_default_list.phtml

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,59 +14,58 @@
1414
</div>
1515
<div class="block-content">
1616
<?php $suffix = $block->getNameInLayout(); ?>
17-
<?php $iterator = 1; ?>
1817
<ol class="product-items" id="widget-new-products-<?= /* @escapeNotVerified */ $suffix ?>">
1918
<?php foreach ($_products->getItems() as $_product): ?>
20-
<?= /* @escapeNotVerified */ ($iterator++ == 1) ? '<li class="product-item">' : '</li><li class="product-item">' ?>
21-
<div class="product-item-info">
22-
<a class="product-item-photo" href="<?= /* @escapeNotVerified */ $_product->getProductUrl() ?>"
23-
title="<?= /* @escapeNotVerified */ $block->stripTags($_product->getName(), null, true) ?>">
24-
<?= $block->getImage($_product, 'side_column_widget_product_thumbnail')->toHtml() ?>
25-
</a>
26-
<div class="product-item-details">
27-
<strong class="product-item-name">
28-
<a href="<?= /* @escapeNotVerified */ $_product->getProductUrl() ?>"
29-
title="<?= /* @escapeNotVerified */ $block->stripTags($_product->getName(), null, true) ?>)" class="product-item-link">
30-
<?= /* @escapeNotVerified */ $this->helper('Magento\Catalog\Helper\Output')->productAttribute($_product, $_product->getName(), 'name') ?>
31-
</a>
32-
</strong>
33-
<?= /* @escapeNotVerified */ $block->getProductPriceHtml($_product, '-widget-new-' . $suffix) ?>
34-
<div class="product-item-actions">
35-
<div class="actions-primary">
36-
<?php if ($_product->isSaleable()): ?>
37-
<?php if ($_product->getTypeInstance()->hasRequiredOptions($_product)): ?>
38-
<button type="button" title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>"
39-
class="action tocart primary"
40-
data-mage-init='{"redirectUrl":{"url":"<?= /* @escapeNotVerified */ $block->getAddToCartUrl($_product) ?>"}}'>
41-
<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
42-
</button>
19+
<li class="product-item">
20+
<div class="product-item-info">
21+
<a class="product-item-photo" href="<?= /* @escapeNotVerified */ $_product->getProductUrl() ?>"
22+
title="<?= /* @escapeNotVerified */ $block->stripTags($_product->getName(), null, true) ?>">
23+
<?= $block->getImage($_product, 'side_column_widget_product_thumbnail')->toHtml() ?>
24+
</a>
25+
<div class="product-item-details">
26+
<strong class="product-item-name">
27+
<a href="<?= /* @escapeNotVerified */ $_product->getProductUrl() ?>"
28+
title="<?= /* @escapeNotVerified */ $block->stripTags($_product->getName(), null, true) ?>)" class="product-item-link">
29+
<?= /* @escapeNotVerified */ $this->helper('Magento\Catalog\Helper\Output')->productAttribute($_product, $_product->getName(), 'name') ?>
30+
</a>
31+
</strong>
32+
<?= /* @escapeNotVerified */ $block->getProductPriceHtml($_product, '-widget-new-' . $suffix) ?>
33+
<div class="product-item-actions">
34+
<div class="actions-primary">
35+
<?php if ($_product->isSaleable()): ?>
36+
<?php if ($_product->getTypeInstance()->hasRequiredOptions($_product)): ?>
37+
<button type="button" title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>"
38+
class="action tocart primary"
39+
data-mage-init='{"redirectUrl":{"url":"<?= /* @escapeNotVerified */ $block->getAddToCartUrl($_product) ?>"}}'>
40+
<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
41+
</button>
42+
<?php else: ?>
43+
<?php
44+
$postDataHelper = $this->helper('Magento\Framework\Data\Helper\PostHelper');
45+
$postData = $postDataHelper->getPostData($block->getAddToCartUrl($_product), ['product' => $_product->getEntityId()]);
46+
?>
47+
<button type="button" title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>"
48+
class="action tocart primary"
49+
data-post='<?= /* @escapeNotVerified */ $postData ?>'>
50+
<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
51+
</button>
52+
<?php endif; ?>
4353
<?php else: ?>
44-
<?php
45-
$postDataHelper = $this->helper('Magento\Framework\Data\Helper\PostHelper');
46-
$postData = $postDataHelper->getPostData($block->getAddToCartUrl($_product), ['product' => $_product->getEntityId()]);
47-
?>
48-
<button type="button" title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>"
49-
class="action tocart primary"
50-
data-post='<?= /* @escapeNotVerified */ $postData ?>'>
51-
<span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
52-
</button>
54+
<?php if ($_product->getIsSalable()): ?>
55+
<div class="stock available" title="<?= /* @escapeNotVerified */ __('Availability') ?>">
56+
<span><?= /* @escapeNotVerified */ __('In stock') ?></span>
57+
</div>
58+
<?php else: ?>
59+
<div class="stock unavailable" title="<?= /* @escapeNotVerified */ __('Availability') ?>">
60+
<span><?= /* @escapeNotVerified */ __('Out of stock') ?></span>
61+
</div>
62+
<?php endif; ?>
5363
<?php endif; ?>
54-
<?php else: ?>
55-
<?php if ($_product->getIsSalable()): ?>
56-
<div class="stock available" title="<?= /* @escapeNotVerified */ __('Availability') ?>">
57-
<span><?= /* @escapeNotVerified */ __('In stock') ?></span>
58-
</div>
59-
<?php else: ?>
60-
<div class="stock unavailable" title="<?= /* @escapeNotVerified */ __('Availability') ?>">
61-
<span><?= /* @escapeNotVerified */ __('Out of stock') ?></span>
62-
</div>
63-
<?php endif; ?>
64-
<?php endif; ?>
64+
</div>
6565
</div>
6666
</div>
6767
</div>
68-
</div>
69-
<?= ($iterator == count($_products->getItems())+1) ? '</li>' : '' ?>
68+
</li>
7069
<?php endforeach; ?>
7170
</ol>
7271
<?= $block->getPagerHtml() ?>

0 commit comments

Comments
 (0)