I'm trying to add a quantity field to the related products section on my product page. I'm overriding module-catalog/view/frontend/templates/product/list/items.phtml
in my theme. So far, here is my 'related'
case section:
case 'related':
/** @var \Magento\Catalog\Block\Product\ProductList\Related $block */
if ($exist = $block->getItems()->getSize()) {
$type = 'related';
$class = $type;
$image = 'related_products_list';
$title = __('Related Products');
$items = $block->getItems();
$limit = 0;
$shuffle = 0;
$canItemsAddToCart = $block->canItemsAddToCart();
$showWishlist = false;
$showCompare = false;
$showCart = true;
$templateType = null;
$description = false;
}
break;
I set $showCart
to true
so I can now see an add to cart button under the related product, and it is functioning by adding one item to the cart. I tried adding the following code above the button in items.phtml
for the quantity field:
<div class="product-qty">
<label><?php echo __('Quantity:'); ?></label>
<input type="number"
name="qty"
id="qty"
maxlength="12"
value="<?php /* @escapeNotVerified */ echo $block->getProductDefaultQty() * 1 ?>"
title="<?php /* @escapeNotVerified */ echo __('Qty') ?>" class="input-text qty"
data-validate="<?php echo $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"/>
Once I add this code, no matter what I put in the quantity field, it always adds one product. Is there something I'm missing for the add to cart
button to add the quantity I enter in the quantity field?