I want to be able to add a quantity box to the products that show up in the 'Up-Sell products' list that is shown on the product detail page
1 Answer
Now this code working for me.
app/design/frontend/Theme/theme_child/Magento_Catalog/templates/product/list/upsell.phtml
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/* @var $block \Magento\Catalog\Block\Product\AbstractProduct */
?>
<?php
switch ($type = $block->getType()) {
case 'upsell':
/** @var \Magento\Catalog\Block\Product\ProductList\Upsell $block */
if ($exist = count($block->getItemCollection()->getItems())) {
$type = 'upsell';
$class = $type;
$image = 'upsell_products_list';
$title = __('Recommended Product Upsell');
$items = $block->getItemCollection()->getItems();
$limit = $block->getItemLimit('upsell');
$shuffle = 0;
$showWishlist = true;
$showCompare = true;
$showCart = true;
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::DEFAULT_VIEW;
$description = false;
$canItemsAddToCart = false;
}
break;
case 'other':
break;
}
?>
<?php if ($exist):?>
<?php if ($type == 'related' || $type == 'upsell'): ?>
<?php if ($type == 'upsell'): ?>
<div class="block <?php echo $class; ?>" data-mage-init='{"relatedProducts":{"relatedCheckbox":".related.checkbox"}}' data-limit="<?php echo $limit; ?>" data-shuffle="<?php echo $shuffle; ?>">
<?php else: ?>
<div class="block <?php echo $class; ?>" data-mage-init='{"upsellProducts":{}}' data-limit="<?php echo $limit; ?>" data-shuffle="<?php echo $shuffle; ?>">
<?php endif; ?>
<?php else: ?>
<div class="block <?php echo $class; ?>">
<?php endif; ?>
<header class='group-title1'><h2><?php echo $title;?> </h2></header>
<div class="block-content content" aria-labelledby="block-<?php echo $class?>-heading">
<div class="owl-container">
<div id="upsell_product_slider" class="owl-carousel">
<?php $iterator = 1; ?>
<?php
$i = 0;
$rows = 1;
echo count($items);
?>
<?php foreach ($items as $_item): ?>
<?php $available = ''; ?>
<?php
$productImage = $block->getImage($_item, $image);
?>
<?php if ($i++%$rows==0) { ?>
<div class="item">
<?php } ?>
<div class="item-inner">
<div class="image-container">
<a href="<?php echo $block->getProductUrl($_item) ?>" class="product-item-photo">
<?php echo $productImage->toHtml() ?>
</a>
<!--div class="box-hover">
</div-->
</div>
<div class="product details box-info">
<div class="name-rating">
<strong class="product name product-item-name"><a class="product-item-link" title="<?php echo $block->escapeHtml($_item->getName()) ?>" href="<?php echo $block->getProductUrl($_item) ?>">
<?php echo $block->escapeHtml($_item->getName()) ?></a>
</strong>
<?php if ($templateType): ?>
<?php echo $block->getReviewsSummaryHtml($_item, $templateType,true); ?>
<?php endif; ?>
</div>
<?php echo $block->getProductPrice($_item); ?>
</div>
<?php if ($showCart): ?>
<div class="product actions product-item-actions">
<form data-role="tocart-form" action="<?php echo $block->getAddToCartUrl($_item); ?>" method="post">
<div style="float: left;">
<input type="number"
name="qty"
style="width:50px;"
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())) ?>"
/>
<?php echo $block->getBlockHtml('formkey'); ?>
<button type="submit" title="<?php echo $block->escapeHtml(__('Add to Cart')); ?>" class="action tocart primary" style="float:right;margin-left: 10px;">
<span><?php /* @escapeNotVerified */echo __('Add to Cart'); ?></span>
</button>
</div>
</form>
</div>
<?php endif; ?>
</div>
<?php if($i%$rows==0 || $i == count($items)) { ?>
</div>
<?php } ?>
<?php endforeach ?>
</div>
</div>
</div>
</div>
<?php endif;?>
<script type="text/javascript">
require(["jquery"], function($){
$("#upsell_product_slider").owlCarousel({
items : 4,
itemsDesktop : [1200,3],
itemsDesktopSmall : [992,3],
itemsTablet: [767,2],
itemsMobile : [400,1],
autoPlay : true,
slideSpeed : 3000,
navigation : true,
stopOnHover : true,
pagination : true,
pagination : true
});
});
</script>
-
This will not working when product have "Minimum Qty Allowed in Shopping Cart" and "Qty Increments" settings. Sep 6, 2022 at 9:24