Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 2 of 2
Display Inventory Qty
 
The Sunday Paper
Sr. Member
 
Total Posts:  202
Joined:  2008-08-06
 

Is there a way to show the inventory quantity conditionally on the Product View and Category View pages, depending on whether the product has “Manage Stock” enabled?

For products that we’re not managing stock on, I’d like to have it not show “Quantity: 0,” and just use a PHP “if” statement to somehow conditionalize the code that shows it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
flytrapcare.com
Member
 
Total Posts:  46
Joined:  2009-08-09
 
nasha - 15 September 2009 09:30 PM

Does any body know how to show quantity for configurable product in dropdownlist .help me out

I second this one!  Does anyone know how to show this for a configurable product?

 
Magento Community Magento Community
Magento Community
Magento Community
 
croswel
Member
 
Total Posts:  37
Joined:  2008-12-15
 
Moshe - 02 March 2008 05:15 PM

try this:

<?=Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()?>

I’ve tried to use it on the following file : checkout/cart/item/default.phtml

but it doesn’t work! here is my code

$total = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();    

for (
$x=1$x<=$total$x=$x+1{
    $selected 
'';
    if (
$x == $this->getQty()) {
        $selected 
.= ' selected="selected"';
     
}
     
echo '<option value="' $x '"' $selected '>' $x '</option>';
}
?>
</select>

any help would be appreciated smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
itchytrig
Sr. Member
 
Avatar
Total Posts:  162
Joined:  2008-10-03
UK
 

Hi,

Quite an old thread now, but still hanging out for a solution to get stock shown against products in list.phtml

Tried adding:
<?= (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_item)->getQty()?>

But its a no go…

Anyone figured this out for sections and search results yet? IE in the template list.phtml

?

 
Magento Community Magento Community
Magento Community
Magento Community
 
alexhost
Member
 
Avatar
Total Posts:  69
Joined:  2009-04-10
Kiev, Ukraine
 

for configurable product can use following

/* if product are configurable get it's real simple product */

if($item->getProduct()->isConfigurable()){

$option 
$item->getOptionByCode('simple_product');

//var_dump($option->getData());     

$getSimpleRealProductId $option->getData('product_id');
$getSimpleRealProduct Mage::getModel('catalog/product')->load($getSimpleRealProductId);



$availableForStock $getSimpleRealProduct->_data['stock_item']->_data['qty']-$getSimpleRealProduct->_data['stock_item']->getMinQty();
$minQty $getSimpleRealProduct->_data['stock_item']->getMinQty();
$productQty $getSimpleRealProduct->_data['stock_item']->_data['qty'];


//for test
//echo "$productQty";
//$productMaxSaleQty = $item->getProduct()->_data['stock_item']->getMaxSaleQty();
//$this->getCheckoutSession()->addNotice (" $productQty  $productMaxSaleQty ");
//

}

/* if product are configurable get it's real simple product */
 
Magento Community Magento Community
Magento Community
Magento Community
 
samshuai
Sr. Member
 
Total Posts:  114
Joined:  2009-03-21
China
 

this my code.

<?php if($_product->isConfigurable()): ?>
                <?php             
                    $_associatedProducts 
$_product->getTypeInstance(true)->getUsedProductCollection($_product);    
                    foreach (
$_associatedProducts as $p{
                        $productQty 
= (int) $p->_data['stock_item']->_data['qty'];
                        
$totalQty += $productQty;
                    
}
                    
if($totalQty == 1){
                     
echo "ONLY ONE LEFT";
                    
}
                ?>
        <?php 
else: ?>
            <?php 
                
if ((int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty() == 1){
                    
echo "ONLY ONE LEFT";
                
}
            ?>
        <?php 
endif; ?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
FEKIT
Member
 
Total Posts:  31
Joined:  2010-04-07
 
samshuai - 18 August 2010 01:59 AM

this my code.

<?php if($_product->isConfigurable()): ?>
                <?php             
                    $_associatedProducts 
$_product->getTypeInstance(true)->getUsedProductCollection($_product);    
                    foreach (
$_associatedProducts as $p{
                        $productQty 
= (int) $p->_data['stock_item']->_data['qty'];
                        
$totalQty += $productQty;
                    
}
                    
if($totalQty == 1){
                     
echo "ONLY ONE LEFT";
                    
}
                ?>
        <?php 
else: ?>
            <?php 
                
if ((int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty() == 1){
                    
echo "ONLY ONE LEFT";
                
}
            ?>
        <?php 
endif; ?>

I’m not sure where this code should go… tried adding it to app/design/frontend/base/default/template/catalog/product/view/type/configurable.phtml (magento 1.4) but i’m not seeing the quantity available in the drop down. Are you able to point me in the right direction?

 
Magento Community Magento Community
Magento Community
Magento Community
 
designer84
Sr. Member
 
Total Posts:  102
Joined:  2009-08-20
 
samshuai - 18 August 2010 01:59 AM

this my code.

<?php if($_product->isConfigurable()): ?>
                <?php             
                    $_associatedProducts 
$_product->getTypeInstance(true)->getUsedProductCollection($_product);    
                    foreach (
$_associatedProducts as $p{
                        $productQty 
= (int) $p->_data['stock_item']->_data['qty'];
                        
$totalQty += $productQty;
                    
}
                    
if($totalQty == 1){
                     
echo "ONLY ONE LEFT";
                    
}
                ?>
        <?php 
else: ?>
            <?php 
                
if ((int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty() == 1){
                    
echo "ONLY ONE LEFT";
                
}
            ?>
        <?php 
endif; ?>

Keeps saying $totalQty is undefined. What did you define this as? if I comment it out then I get the qty....

 
Magento Community Magento Community
Magento Community
Magento Community
 
chadjmorgan
Sr. Member
 
Avatar
Total Posts:  252
Joined:  2010-06-04
Michigan
 
designer84 - 26 May 2011 08:25 PM

samshuai - 18 August 2010 01:59 AM
this my code.
<?php if($_product->isConfigurable()): ?>
                <?php             
                    $_associatedProducts 
$_product->getTypeInstance(true)->getUsedProductCollection($_product);    
                    foreach (
$_associatedProducts as $p{
                        $productQty 
= (int) $p->_data['stock_item']->_data['qty'];
                        
$totalQty += $productQty;
                    
}
                    
if($totalQty == 1){
                     
echo "ONLY ONE LEFT";
                    
}
                ?>
        <?php 
else: ?>
            <?php 
                
if ((int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty() == 1){
                    
echo "ONLY ONE LEFT";
                
}
            ?>
        <?php 
endif; ?>

Keeps saying $totalQty is undefined. What did you define this as? if I comment it out then I get the qty....

Im guessing this is because you are telling it to add to the variable $totalQty when it was never defined or had a value…

You may be interested in my custom stock status extension that could save you some time. You can check it out here: http://www.magentocommerce.com/magento-connect/chadjmorgan/extension/4085/configurable_product_custom_stock_status

 
Magento Community Magento Community
Magento Community
Magento Community
 
ElsonSolano
Member
 
Total Posts:  34
Joined:  2011-06-02
 

Hi there,

Is it possible to change the quanitity text input in the add to cart page into drop down box at the same time the value of the drop down box is different depending on the product?

I want something to be like this.

Example.

An Apple Product should have a drop down box that has this values:
- 10
- 20
- 30

A Mango Product should have a drop down box that has this values:
- 30
- 75
- 100

Is there something to be configured or to be coded to have this result.

 
Magento Community Magento Community
Magento Community
Magento Community
 
parkerdeano
Jr. Member
 
Total Posts:  11
Joined:  2011-02-08
 

Hi Elson, did you ever find an anser to having different multiples in the dropdown selection? Most of my products are in batches of 20, apart from a few that are available in batches of 1. I can’t work this out or find an answer anywhere.

Thanks.

ElsonSolano - 21 June 2011 03:57 PM

Hi there,

Is it possible to change the quanitity text input in the add to cart page into drop down box at the same time the value of the drop down box is different depending on the product?

I want something to be like this.

Example.

An Apple Product should have a drop down box that has this values:
- 10
- 20
- 30

A Mango Product should have a drop down box that has this values:
- 30
- 75
- 100

Is there something to be configured or to be coded to have this result.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sourcetech
Jr. Member
 
Total Posts:  17
Joined:  2011-08-16
 

Code works perfectly! I’ve been trying to get 2 sites to show stock and sku forever!

BUT Is there some way of changing this so any products that are NOT managed stock DONT show a stock level?

We have a lot of bespoke products we build in-house which are not necessarily in stock. The way the script works at the moment, it shows the stock level even if it’s set to “not managed”

Can anyone help please?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Amasty
Mentor
 
Avatar
Total Posts:  3988
Joined:  2009-11-10
 

Hello,

You can also have a look at Custom Stock Status extension that can automatically show stock quantity with the dynamic quantity range based statuses, like ‘Low’ for 1-10 items, ‘Medium’ for 11-99 products and so on. You can also set status manually for any of the products.

In addition to stock statuses based on quantity, the extension gives a vast choice of other product labels: ‘Coming soon’, ‘Out of Stock’, ‘Arrives on Monday’, etc. You will even be able to specify the text, which will be displayed, when customers hover mouse over a status icon.

You can see extension usage examples in the screenshots below and get to know more at http://amasty.com/custom-stock-status.html

Image Attachments
css2-scr.pngcss6-scr.pngcss-frontend-backend-2.pngexample.png
 
Magento Community Magento Community
Magento Community
Magento Community
 
SjoerdSmeets
Jr. Member
 
Total Posts:  5
Joined:  2011-09-17
 
SCY - 25 March 2009 09:52 PM

Thanks to the great posts and this is a more specific way of how to set it up quickly:

Simple product:

Open app\design\frontend\default\[your_theme]\template\catalog\product\view\type\simple.phtml
Find

<class="availability"><?php echo $this->__('Quantity in stock:'?></p>
Change into
<class="availability"><?php echo $this->__('Quantity in stock:'?><?=(int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()?></p>
Save and done!

Grouped produt:

Open app\design\frontend\default\[your_theme]\template\catalog\product\view\type\grouped.phtml
Find
<td class="a-center">
            
<?php if ($_item->isSaleable()) : ?>
                
<input name="super_group[<?php echo $_item->getId() ?>]" value="<?php echo $_item->getQty()*1 ?>" type="text" class="input-text qty" />
            
<?php else: ?>
                <?php 
echo $this->__('Out of stock.'?>
            <?php 
endif; ?>
            
</td>
Insert the following code above it,
<td class="a-center">
            
<?php if($_product->isSaleable()): ?>
                <?
= (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($_item)->getQty()?>
            <?php 
else: ?><?php echo $this->__('Out of Stock'?><?php endif; ?> 
            
</td>
Lastly, find:
<thead>
        <
tr>
            <
th><?php echo $this->__('Product Name'?></th>
            <
th class="a-right"><?php echo $this->__('Price'?></th>
            
<?php if ($_product->isSaleable()): ?>
            
<th class="a-center"><?php echo $this->__('Qty'?></th>
            
<?php endif; ?>
        
</tr>
    </
thead>

and change to:
<thead>
        <
tr>
            <
th><?php echo $this->__('Product Name'?></th>
            <
th class="a-right"><?php echo $this->__('Price'?></th>
            <
th class="a-right"><?php echo $this->__('Availability'?></th>
            
<?php if ($_product->isSaleable()): ?>
            
<th class="a-center"><?php echo $this->__('Qty'?></th>
            
<?php endif; ?>
        
</tr>
    </
thead>
You may refer to the screen shot attached.

Is it possible to show 5+ in grouped product when qty is more than 5 ?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 2 of 2