cancel
Showing results for 
Search instead for 
Did you mean: 

Product Listing Page Quantity Box has 0 Quantity Display

Product Listing Page Quantity Box has 0 Quantity Display

in Product Listing Page Quantity Box has 0 Quantity Display and and when click Add to Cart its added in cart as a 1 product in cart,

Magento_Catalog/templates/product/list.phtml here is my list.phtml Code

 

<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Framework\App\Action\Action;

?>
<?php
// phpcs:disable Magento2.Templates.ThisInTemplate.FoundThis

/**
* Product list template
*
* @var $block \Magento\Catalog\Block\Product\ListProduct
*/
?>
<?php
$_productCollection = $block->getLoadedProductCollection();
$_helper = $this->helper(Magento\Catalog\Helper\Output::class);
?>
<?php if (!$_productCollection->count()) :?>
<div class="message info empty"><div><?= $block->escapeHtml(__('We can\'t find products matching the selection.')) ?></div></div>
<?php else :?>
<?= $block->getToolbarHtml() ?>
<?= $block->getAdditionalHtml() ?>
<?php
if ($block->getMode() == 'grid') {
$viewMode = 'grid';
$imageDisplayArea = 'category_page_grid';
$showDescription = false;
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
} else {
$viewMode = 'list';
$imageDisplayArea = 'category_page_list';
$showDescription = true;
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::FULL_VIEW;
}
/**
* Position for actions regarding image size changing in vde if needed
*/
$pos = $block->getPositioned();
?>
<div class="products wrapper <?= /* @noEscape */ $viewMode ?> products-<?= /* @noEscape */ $viewMode ?>">
<ol class="products list items product-items">
<?php /** @var $_product \Magento\Catalog\Model\Product */ ?>
<?php foreach ($_productCollection as $_product) :?>
<li class="item product product-item">
<div class="product-item-info" data-container="product-<?= /* @noEscape */ $viewMode ?>">
<?php
$productImage = $block->getImage($_product, $imageDisplayArea);
if ($pos != null) {
$position = ' style="left:' . $productImage->getWidth() . 'px;'
. 'top:' . $productImage->getHeight() . 'px;"';
}
?>
<?php // Product Image ?>
<a href="<?= $block->escapeUrl($_product->getProductUrl()) ?>"
class="product photo product-item-photo"
tabindex="-1">
<?= $productImage->toHtml() ?>
</a>
<div class="product details product-item-details">
<div class="product-list"> <?php
$_productNameStripped = $block->stripTags($_product->getName(), null, true);
?>
<strong class="product name product-item-name">
<a class="product-item-link"
href="<?= $block->escapeUrl($_product->getProductUrl()) ?>">
<?= /* @noEscape */ $_helper->productAttribute($_product, $_product->getName(), 'name') ?>
</a>
</strong>
<?= $block->getReviewsSummaryHtml($_product, $templateType) ?>
<?php
$shortDescription = $_helper->productAttribute($_product, $_product->getShortDescription(), 'ShortDescription');
$len = strlen($shortDescription);
?>
<div class="list-shortdesc">
<?php echo substr(strip_tags($_product->getShortDescription()),0,120); ?>
<?php if($len > 120) echo '...'; ?>
</div>
<div class="list-sku"><span class="label"><?= $block->escapeHtml(__('Model:')) ?></span><span class="value"><?php /* @escapeNotVerified */ echo $_product->getSku() ?></span></div>
<div class="list-stock"><?php if (!$_product->getData('custom_product')): ?>
<?php if ($_product->isAvailable()) :?>
<div class="stock available"><span><?= $block->escapeHtml(__('In stock')) ?></span></div>
<?php else :?>
<div class="stock unavailable"><span><?= $block->escapeHtml(__('Out of stock')) ?></span></div>
<?php endif; ?>
<?php endif; ?>
<?php if($_product->getData('custom_product')): ?>
<span class='availability in-stock'>Custom Order Product</span>
<?php endif; ?> </div>
<div class="list-price"><span class="product-price"><?= $block->escapeHtml(__('Price:')) ?></span><span class="value"><?= /* @noEscape */ $block->getProductPrice($_product) ?></span></div>

<?= $block->getProductDetailsHtml($_product) ?>

<div class="list-qty"><span class="label"><?= $block->escapeHtml(__('Quantity:')) ?></span><span class="value"> <?php echo $block->getBlockHtml('formkey')?>
<input type="number"
name="qty"
id="qty"
min="1"
value="<?php /* @escapeNotVerified */ echo $block->getProductDefaultQty() * 1 ?>"
title="<?php /* @escapeNotVerified */ echo __('Quantity') ?>" class="input-text qty form-control"
data-validate="<?php echo $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
/></span></div>
</div>


<div class="product-item-inner">

<div class="product actions product-item-actions"<?= strpos($pos, $viewMode . '-actions') ? $block->escapeHtmlAttr($position) : '' ?>>
<div class="detail-btm"><a class="button" href="<?= $block->escapeUrl($_product->getProductUrl()) ?>">Details</a></div>

<div class="actions-primary"<?= strpos($pos, $viewMode . '-primary') ? $block->escapeHtmlAttr($position) : '' ?>>
<?php if ($_product->isSaleable()) :?>
<?php $postParams = $block->getAddToCartPostParams($_product); ?>
<form data-role="tocart-form"
data-product-sku="<?= $block->escapeHtml($_product->getSku()) ?>"
action="<?= $block->escapeUrl($postParams['action']) ?>"
method="post">
<input type="hidden"
name="product"
value="<?= /* @noEscape */ $postParams['data']['product'] ?>">
<input type="hidden" name="<?= /* @noEscape */ Action::PARAM_NAME_URL_ENCODED ?>"
value="<?= /* @noEscape */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
<?= $block->getBlockHtml('formkey') ?>
<button type="submit"
title="<?= $block->escapeHtmlAttr(__('Add to Cart')) ?>"
class="action tocart primary">
<span><?= $block->escapeHtml(__('Add to Cart')) ?></span>
</button>
</form>
<?php else :?>
<?php if ($_product->isAvailable()) :?>
<div class="stock available"><span><?= $block->escapeHtml(__('In stock')) ?></span></div>
<?php else :?>
<div class="stock unavailable"><span><?= $block->escapeHtml(__('Out of stock')) ?></span></div>
<?php endif; ?>
<?php endif; ?>
</div>

</div>
<?php if ($showDescription) :?>
<div class="product description product-item-description">
<?= /* @noEscape */ $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
<a href="<?= $block->escapeUrl($_product->getProductUrl()) ?>"
title="<?= /* @noEscape */ $_productNameStripped ?>"
class="action more"><?= $block->escapeHtml(__('Learn More')) ?></a>
</div>
<?php endif; ?>
</div>
</div>
</div>
</li>
<?php endforeach; ?>
</ol>
</div>
<?= $block->getToolbarHtml() ?>
<?php if (!$block->isRedirectToCartEnabled()) :?>
<script type="text/x-magento-init">
{
"[data-role=tocart-form], .form.map.checkout": {
"catalogAddToCart": {
"product_sku": "<?= $block->escapeJs($_product->getSku()) ?>"
}
}
}
</script>
<?php endif; ?>
<?php endif; ?>
8 REPLIES 8

Re: Product Listing Page Quantity Box has 0 Quantity Display

Hello @R K Solanki 

 

go to admin

 

store >> Configuration >> 

Catalog >> Inventory

 

Please add Minimum Qty Allowed in Shopping Cart with value 1 and check it

 

If works then mark as solution

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Product Listing Page Quantity Box has 0 Quantity Display

@Sunil Patel  i have already set value as 1, but its not work, 
i think value="<?php /* @escapeNotVerified */ echo $block->getProductDefaultQty() * 1 ?>" this code not get value,  but im not sure.

Re: Product Listing Page Quantity Box has 0 Quantity Display

Hello @R K Solanki 

 

Can you check product wise  into backend what is you added for min salable qty

getMinSaleQty

 

go to the product and check it

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Product Listing Page Quantity Box has 0 Quantity Display

@Sunil Patel 
i have checked in Product Details Page,


Product Salable Quantity 
Default Stock : 9999999

Re: Product Listing Page Quantity Box has 0 Quantity Display

Hello @R K Solanki 

 

 

please check min qty allowed 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Product Listing Page Quantity Box has 0 Quantity Display

@Sunil Patel 

Minimum Qty Allowed in Shopping Cart : 1Configuration_Settings_Stores_Magento_Admin.png

Re: Product Listing Page Quantity Box has 0 Quantity Display

Hello @R K Solanki 

 

Magento\Catalog\Block\Product\AbstractProduct.php

 

public function getMinimalQty($product)
{
$stockItem = $this->stockRegistry->getStockItem($product->getId(), $product->getStore()->getWebsiteId());
$minSaleQty = $stockItem->getMinSaleQty();
return $minSaleQty > 0 ? $minSaleQty : null;
}

check this function, it will help you.

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Product Listing Page Quantity Box has 0 Quantity Display

@Sunil Patel  i have seen in Inspect Element, for Quantity Box,
it shows like.

 

for this CODE..

<div class="list-qty">
<span class="label"><?= $block->escapeHtml(__('Quantity:')) ?></span>
<span class="value">
<?php echo $block->getBlockHtml('formkey')?>
<input type="number"
   name="qty"
   id="qty"
   min="1"
   value="<?php /* @escapeNotVerified */ echo $block->getProductDefaultQty() * 1 ?>"
   title="<?php /* @escapeNotVerified */ echo __('Quantity') ?>" class="input-text qty form-control"
   data-validate="<?php echo $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
/>
</span>
</div>
<input type="number" name="qty" id="qty" min="1" value="0" title="Quantity" class="input-text qty form-control" data-validate="null">