Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
items.phtml
Go to the documentation of this file.
1 <?php
7 // @codingStandardsIgnoreFile
8 
9 /* @var $block \Magento\Catalog\Block\Product\AbstractProduct */
10 ?>
11 
12 <?php
13 switch ($type = $block->getType()) {
14 
15  case 'related-rule':
16  if ($exist = $block->hasItems()) {
17  $type = 'related';
18  $class = $type;
19 
20  $image = 'related_products_list';
21  $title = __('Related Products');
22  $items = $block->getAllItems();
23  $limit = $block->getPositionLimit();
24  $shuffle = (int) $block->isShuffled();
25  $canItemsAddToCart = $block->canItemsAddToCart();
26 
27  $showAddTo = true;
28  $showCart = false;
29  $templateType = null;
30  $description = false;
31  }
32  break;
33 
34  case 'related':
36  if ($exist = $block->getItems()->getSize()) {
37  $type = 'related';
38  $class = $type;
39 
40  $image = 'related_products_list';
41  $title = __('Related Products');
42  $items = $block->getItems();
43  $limit = 0;
44  $shuffle = 0;
45  $canItemsAddToCart = $block->canItemsAddToCart();
46 
47  $showAddTo = true;
48  $showCart = false;
49  $templateType = null;
50  $description = false;
51  }
52  break;
53 
54  case 'upsell-rule':
55  if ($exist = $block->hasItems()) {
56  $type = 'upsell';
57  $class = $type;
58 
59  $image = 'upsell_products_list';
60  $title = __('We found other products you might like!');
61  $items = $block->getAllItems();
62  $limit = $block->getPositionLimit();
63  $shuffle = (int) $block->isShuffled();
64 
65  $showAddTo = false;
66  $showCart = false;
67  $templateType = null;
68  $description = false;
69  $canItemsAddToCart = false;
70  }
71  break;
72 
73  case 'upsell':
75  if ($exist = count($block->getItemCollection()->getItems())) {
76  $type = 'upsell';
77  $class = $type;
78 
79  $image = 'upsell_products_list';
80  $title = __('We found other products you might like!');
81  $items = $block->getItemCollection()->getItems();
82  $limit = $block->getItemLimit('upsell');
83  $shuffle = 0;
84 
85  $showAddTo = false;
86  $showCart = false;
87  $templateType = null;
88  $description = false;
89  $canItemsAddToCart = false;
90  }
91  break;
92 
93  case 'crosssell-rule':
95  if ($exist = $block->hasItems()) {
96  $type = 'crosssell';
97  $class = $type;
98 
99  $image = 'cart_cross_sell_products';
100  $title = __('More Choices:');
101  $items = $block->getItemCollection();
102 
103  $showAddTo = true;
104  $showCart = true;
106  $description = false;
107  $canItemsAddToCart = false;
108  }
109  break;
110 
111  case 'crosssell':
113  if ($exist = count($block->getItems())) {
114  $type = 'crosssell';
115  $class = $type;
116 
117  $image = 'cart_cross_sell_products';
118  $title = __('More Choices:');
119  $items = $block->getItems();
120 
121  $showAddTo = true;
122  $showCart = true;
124  $description = false;
125  $canItemsAddToCart = false;
126  }
127  break;
128 
129  case 'new':
130  if ($exist = $block->getProductCollection()) {
131  $type = 'new';
132  $mode = 'grid';
133  $type = $type . ' ' . $mode;
134 
135  $class = 'widget' . ' ' . $type;
136 
137  $image = 'new_products_content_widget_grid';
138  $title = __('New Products');
139  $items = $exist;
140 
141  $showAddTo = true;
142  $showCart = true;
144  $description = ($mode == 'list') ? true : false;
145  $canItemsAddToCart = false;
146  }
147  break;
148 
149  default:
150  $exist = null;
151 }
152 ?>
153 
154 <?php if ($exist):?>
155 
156  <?php if ($type == 'related' || $type == 'upsell'): ?>
157  <?php if ($type == 'related'): ?>
158  <div class="block <?= /* @escapeNotVerified */ $class ?>" data-mage-init='{"relatedProducts":{"relatedCheckbox":".related.checkbox"}}' data-limit="<?= /* @escapeNotVerified */ $limit ?>" data-shuffle="<?= /* @escapeNotVerified */ $shuffle ?>">
159  <?php else: ?>
160  <div class="block <?= /* @escapeNotVerified */ $class ?>" data-mage-init='{"upsellProducts":{}}' data-limit="<?= /* @escapeNotVerified */ $limit ?>" data-shuffle="<?= /* @escapeNotVerified */ $shuffle ?>">
161  <?php endif; ?>
162  <?php else: ?>
163  <div class="block <?= /* @escapeNotVerified */ $class ?>">
164  <?php endif; ?>
165  <div class="block-title title">
166  <strong id="block-<?= /* @escapeNotVerified */ $class ?>-heading" role="heading" aria-level="2"><?= /* @escapeNotVerified */ $title ?></strong>
167  </div>
168  <div class="block-content content" aria-labelledby="block-<?= /* @escapeNotVerified */ $class ?>-heading">
169  <?php if ($type == 'related' && $canItemsAddToCart): ?>
170  <div class="block-actions">
171  <?= /* @escapeNotVerified */ __('Check items to add to the cart or') ?>
172  <button type="button" class="action select" role="select-all"><span><?= /* @escapeNotVerified */ __('select all') ?></span></button>
173  </div>
174  <?php endif; ?>
175  <div class="products wrapper grid products-grid products-<?= /* @escapeNotVerified */ $type ?>">
176  <ol class="products list items product-items">
177  <?php foreach ($items as $_item): ?>
178  <?php $available = ''; ?>
179  <?php if (!$_item->isComposite() && $_item->isSaleable() && $type == 'related'): ?>
180  <?php if (!$_item->getRequiredOptions()): ?>
181  <?php $available = 'related-available'; ?>
182  <?php endif; ?>
183  <?php endif; ?>
184  <?php if ($type == 'related' || $type == 'upsell'): ?>
185  <li class="item product product-item" style="display: none;">
186  <?php else: ?>
187  <li class="item product product-item">
188  <?php endif; ?>
189  <div class="product-item-info <?= /* @escapeNotVerified */ $available ?>">
190  <?= /* @escapeNotVerified */ '<!-- ' . $image . '-->' ?>
191  <a href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>" class="product photo product-item-photo">
192  <?= $block->getImage($_item, $image)->toHtml() ?>
193  </a>
194  <div class="product details product-item-details">
195  <strong class="product name product-item-name"><a class="product-item-link" title="<?= $block->escapeHtml($_item->getName()) ?>" href="<?= /* @escapeNotVerified */ $block->getProductUrl($_item) ?>">
196  <?= $block->escapeHtml($_item->getName()) ?></a>
197  </strong>
198 
199  <?= /* @escapeNotVerified */ $block->getProductPrice($_item) ?>
200 
201  <?php if ($templateType): ?>
202  <?= $block->getReviewsSummaryHtml($_item, $templateType) ?>
203  <?php endif; ?>
204 
205  <?php if ($canItemsAddToCart && !$_item->isComposite() && $_item->isSaleable() && $type == 'related'): ?>
206  <?php if (!$_item->getRequiredOptions()): ?>
207  <div class="field choice related">
208  <input type="checkbox" class="checkbox related" id="related-checkbox<?= /* @escapeNotVerified */ $_item->getId() ?>" name="related_products[]" value="<?= /* @escapeNotVerified */ $_item->getId() ?>" />
209  <label class="label" for="related-checkbox<?= /* @escapeNotVerified */ $_item->getId() ?>"><span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span></label>
210  </div>
211  <?php endif; ?>
212  <?php endif; ?>
213 
214  <?php if ($showAddTo || $showCart): ?>
215  <div class="product actions product-item-actions">
216  <?php if ($showCart): ?>
217  <div class="actions-primary">
218  <?php if ($_item->isSaleable()): ?>
219  <?php if ($_item->getTypeInstance()->hasRequiredOptions($_item)): ?>
220  <button class="action tocart primary" data-mage-init='{"redirectUrl": {"url": "<?= /* @escapeNotVerified */ $block->getAddToCartUrl($_item) ?>"}}' type="button" title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>">
221  <span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
222  </button>
223  <?php else: ?>
224  <?php $postDataHelper = $this->helper('Magento\Framework\Data\Helper\PostHelper');
225  $postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()])
226  ?>
227  <button class="action tocart primary"
228  data-post='<?= /* @escapeNotVerified */ $postData ?>'
229  type="button" title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>">
230  <span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
231  </button>
232  <?php endif; ?>
233  <?php else: ?>
234  <?php if ($_item->getIsSalable()): ?>
235  <div class="stock available"><span><?= /* @escapeNotVerified */ __('In stock') ?></span></div>
236  <?php else: ?>
237  <div class="stock unavailable"><span><?= /* @escapeNotVerified */ __('Out of stock') ?></span></div>
238  <?php endif; ?>
239  <?php endif; ?>
240  </div>
241  <?php endif; ?>
242 
243  <?php if ($showAddTo): ?>
244  <div class="secondary-addto-links actions-secondary" data-role="add-to-links">
245  <?php if ($addToBlock = $block->getChildBlock('addto')): ?>
246  <?= $addToBlock->setProduct($_item)->getChildHtml() ?>
247  <?php endif; ?>
248  </div>
249  <?php endif; ?>
250  </div>
251  <?php endif; ?>
252  </div>
253  </div>
254  </li>
255  <?php endforeach ?>
256  </ol>
257  </div>
258  </div>
259 </div>
260 <?php endif;?>
$title
Definition: default.phtml:14
$block setTitle( 'CMS Block Title') -> setIdentifier('fixture_block') ->setContent('< h1 >Fixture Block Title</h1 >< a href=" store url</a><p> Config value
Definition: block.php:9
if( $block->getQuote() ->hasVirtualItems())( 'Other items in your order') ?></strong >< a hrefforeach( $block->getVirtualQuoteItems() as $_item)(__( 'Product Name')) ?>"><? endforeach
Definition: items.phtml:31
if( $block->isPagerDisplayed())() ?></td ></tr ><?php endif ?>< tr >< th class $items
Definition: items.phtml:30
if( $form)() ?>< script > require(['jquery' mage mage
Definition: save.phtml:15
__()
Definition: __.php:13
$templateType
Definition: list.phtml:37
$block
Definition: block.php:8
$type
Definition: item.phtml:13
$_item
Definition: default.phtml:11
$_option $_optionId $class
Definition: date.phtml:13
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
Definition: grid.phtml:15
if( $type=='related' &&$canItemsAddToCart)( 'Check items to add to the cart or') ?>< button type endif
Definition: items.phtml:169
$showCart
Definition: grid.phtml:22