Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError string * int in Inventory Tab on new Product #4359

Open
Hanmac opened this issue Nov 15, 2024 · 3 comments
Open

TypeError string * int in Inventory Tab on new Product #4359

Hanmac opened this issue Nov 15, 2024 · 3 comments
Labels

Comments

@Hanmac
Copy link
Contributor

Hanmac commented Nov 15, 2024

Preconditions (*)

  1. 20.10, but earlier should be affected too

Steps to reproduce (*)

  1. Create a New Product (so it is a Product without StockItem yet)

Expected result (*)

  1. [Screenshots, logs or description]
  2. Normal Inventory Tab

Actual result (*)

  1. [Screenshots, logs or description]

This piece, <?php echo $this->getFieldValue('notify_stock_qty')*1 ?>, can cause this error:

TypeError: Unsupported operand types: string * int in /var/www/app/design/adminhtml/default/default/template/catalog/product/tab/inventory.phtml:131
Stack trace:
#0 /var/www/app/code/core/Mage/Core/Block/Template.php(273): include()
#1 /var/www/app/code/core/Mage/Core/Block/Template.php(310): Mage_Core_Block_Template->fetchView()
#2 /var/www/app/code/core/Mage/Core/Block/Template.php(323): Mage_Core_Block_Template->renderView()
#3 /var/www/app/code/core/Mage/Adminhtml/Block/Template.php(67): Mage_Core_Block_Template->_toHtml()
#4 /var/www/app/code/core/Mage/Core/Block/Abstract.php(926): Mage_Adminhtml_Block_Template->_toHtml()
#5 /var/www/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tabs.php(77): Mage_Core_Block_Abstract->toHtml()
#6 /var/www/app/code/core/Mage/Core/Block/Abstract.php(299): Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs->_prepareLayout()
#7 /var/www/app/code/core/Mage/Core/Model/Layout.php(474): Mage_Core_Block_Abstract->setLayout()
#8 /var/www/app/code/core/Mage/Core/Model/Layout.php(490): Mage_Core_Model_Layout->createBlock()
#9 /var/www/app/code/core/Mage/Core/Model/Layout.php(234): Mage_Core_Model_Layout->addBlock()
#10 /var/www/app/code/core/Mage/Core/Model/Layout.php(200): Mage_Core_Model_Layout->_generateBlock()
#11 /var/www/app/code/core/Mage/Core/Model/Layout.php(205): Mage_Core_Model_Layout->generateBlocks()
#12 /var/www/app/code/core/Mage/Core/Controller/Varien/Action.php(345): Mage_Core_Model_Layout->generateBlocks()
#13 /var/www/app/code/core/Mage/Core/Controller/Varien/Action.php(256): Mage_Core_Controller_Varien_Action->generateLayoutBlocks()
#14 /var/www/app/code/core/Mage/Adminhtml/Controller/Action.php(293): Mage_Core_Controller_Varien_Action->loadLayout()
#15 /var/www/app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php(218): Mage_Adminhtml_Controller_Action->loadLayout()
#16 /var/www/app/code/core/Mage/Core/Controller/Varien/Action.php(421): Mage_Adminhtml_Catalog_ProductController->newAction()
#17 /var/www/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(255): Mage_Core_Controller_Varien_Action->dispatch()
#18 /var/www/app/code/core/Mage/Core/Controller/Varien/Front.php(181): Mage_Core_Controller_Varien_Router_Standard->match()
#19 /var/www/app/code/core/Mage/Core/Model/App.php(358): Mage_Core_Controller_Varien_Front->dispatch()
#20 /var/www/app/Mage.php(740): Mage_Core_Model_App->run()
#21 /var/www/index.php(56): Mage::run()
#22 {main}

because this:

public function getFieldValue($field)
{
    if ($this->getStockItem()) {
        return $this->getStockItem()->getDataUsingMethod($field);
    }

    return Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_ITEM . $field);
}

in a rare case, the product doesn't have a stock item (new product),
it uses the StoreConfig, and other than this line, it isn't cast to float there:

public function getNotifyStockQty()
{
    if ($this->getUseConfigNotifyStockQty()) {
        return (float) Mage::getStoreConfig(self::XML_PATH_NOTIFY_STOCK_QTY);
    }
    return (float) $this->getData('notify_stock_qty');
}

@sreichel your Opinion on the Fix? Just adding (float) to the templates?

@Hanmac Hanmac added the bug label Nov 15, 2024
@kiatng
Copy link
Contributor

kiatng commented Nov 18, 2024

How about value="<?php echo (float)$this->getFieldValue('notify_stock_qty') ?>"?

@sreichel
Copy link
Contributor

sreichel commented Nov 18, 2024

All admin system configurations for Mage_CatalogInventory_Model_Stock_Item::XML_PATH_ITEM . $field should return a float value. Not?

We not use Mage::getStoreConfigAsFloat()?

Edit: your public function getNotifyStockQty() seems outdated, it should already use Mage::getStoreConfigAsFloat()?!?

@kiatng
Copy link
Contributor

kiatng commented Nov 18, 2024

3rd-party code may use getFieldValue() to return non-float from custom settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants