merge the 2 different codes to get 1 code
-
13-12-2019 - |
Question
we are working on marketplace [multi vendor] site. we are using 2 different types of codes to load the quantity in different places in the site.
code 1 :
<span id="valueqty_<?php echo $products->getId(); ?>"><?php echo (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($products)->getQty(); ?></span>
<input type = "text" id = "qty_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" "name = "qty" value = "<?php echo (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($products)->getQty(); ?>" />
code 2 :
<?php
if(Mage::getStoreConfig('marketplace/marketplace_products/product_hint_status') && Mage::getStoreConfig('marketplace/marketplace_products/product_qty')){?>
<img src="<?php echo $this->getSkinUrl('marketplace/images/quest.png'); ?>" class='questimg' title="<?php echo Mage::getStoreConfig('marketplace/marketplace_products/product_qty') ?>"/>
<?php
} ?>
<div class="input-box">
<input type="stock" class="required-entry validate-number input-text" name="stock" id="stock" value="<?php echo number_format($qtyStock, 2, '.', '')?>"/>
</div>
I want to keep the type , id , name of code 1 and i want to use the "code 2 " part to get the quantity. I want to merge the code1 and code 2.
In code 1 , i want to keep html, css , javascript part. in code 2, i want to keep php part.
I need the code after merging code 1 and code 2
please let me know if you need any clarifications
Solution
use this
<?php
if(Mage::getStoreConfig('marketplace/marketplace_products/product_hint_status') && Mage::getStoreConfig('marketplace/marketplace_products/product_qty')){?>
<img src="<?php echo $this->getSkinUrl('marketplace/images/quest.png'); ?>" class='questimg' title="<?php echo Mage::getStoreConfig('marketplace/marketplace_products/product_qty') ?>"/>
<?php
} ?>
<?php $qtyStock=(int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($products)->getQty(); ?>
<span id="valueqty_<?php echo $products->getId(); ?>"><?php echo (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($products)->getQty(); ?></span>
<input type = "text" id = "qty_<?php echo $products->getId(); ?>" onkeydown="validateNumbers(event)" name = "qty" value = "<?php echo $qtyStock ?>" />
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange