Magento Forum

   
Decimal Quantity Increments in magento 1.5
 
versatilewt
Jr. Member
 
Total Posts:  5
Joined:  2010-06-24
 

In Magento 1.4.1.1, Quantity Increments could be floats/decimals. Now, it seems that only integer values are supported, (while it seems the code indicates that decimals should still be supported).

Does anyone have any advice on how to remedy the issue?

 
Magento Community Magento Community
Magento Community
Magento Community
 
versatilewt
Jr. Member
 
Total Posts:  5
Joined:  2010-06-24
 

I am using Magento ver. 1.5.1.0 figured out how to fix my Qty Increments problem in magento admin. Please note you need to have inventory enabled, ‘Qty Uses Decimals’ set to yes, and enable qty increments.

I haven’t done this in my own module, which i probably should

IN /app/design/adminhtml/default/default/template/catalog/product/tab/inventory.phtml

line 155

validate-digits

should be

validate-number

“update cart” still rounds out the increment to an integer, however normal add-to-cart will respect decimal quantity

 
Magento Community Magento Community
Magento Community
Magento Community
 
amitsamsukha
Jr. Member
 
Avatar
Total Posts:  3
Joined:  2011-02-28
 

in Magento Currently only integer increments supported
i have developed Decimal Increments into Magento 1.6
Steps are As Follows:
1. As Said By versatilewt change
/app/design/adminhtml/default/default/template/catalog/product/tab/inventory.phtml
into line 155
from

validate-digits

to
validate-number

2. After that change suggestQty Function into
app/code/core/Mage/CatalogInventory/Model/Stock/Item.php

/**
     * Returns suggested qty increments for the item based on requested qty
     *
     * @param int|float $qty
     * @return int|float
     * Updated By Amit Samsukha<amitsamsukha@gmail.com> @ 17 Jan, 2011
     */
    public function suggestQty($qty)
    
{
        $origQty 
$qty;
        
$qty = (float) $qty;

        
// Maybe some wrong value
        
if ($qty <= 0{
            
return $origQty;
        
}

        
// We do not manage stock
        
if (!$this->getManageStock()) {
            
return $origQty;
        
}

        
// No qty increments enabled
        
$qtyIncrements $this->getQtyIncrements();
        
$qtyIncrements = (float) $qtyIncrements
        
var_dump(qtyIncrements);
        if (!
$qtyIncrements || ($qtyIncrements == 1)) {
            
return $origQty;
        
}

        
// Fix qty to be integer if needed
        
if (!$this->getIsQtyDecimal()) {
            $qty 
= (int) $qty;
        
}

        
// Maybe qty is evenly divided - no fixture needed
        
if (fmod($qty $qtyIncrements) == 0{
            
return $qty;
        
}

        $qty 
$qty fmod($qty $qtyIncrements) + $qtyIncrements;
        if (!
$qty{
            
// Value was closer to zero, so suggest first lowest minimal increment
            
$qty $qtyIncrements;
        
}
        
return $qty;
    
}

3. than a small change into updateItems Function into
app/code/core/Mage/Checkout/Model/Cart.php @ line 390

update Notice message that converts float into int
from

$message $messageFactory->notice(Mage::helper('checkout')->__('Quantity was recalculated from %d to %d'$itemInfo['before_suggest_qty']$qty));
to
$message $messageFactory->notice(Mage::helper('checkout')->__('Quantity was recalculated from %s to %s'$itemInfo['before_suggest_qty']$qty));

4. Now change function checkQtyIncrements in
app/code/core/Mage/CatalogInventory/Model/Stock/Item.php
from

if ($qtyIncrements && ($qty $qtyIncrements != 0)) {
to
if ($qtyIncrements && (fmod($qty $qtyIncrements)!= 0)) {

Now you are all done with Decimal Quantity Increments...

Image Attachments
item.jpgcart.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top