0

i dont know how make a function with custom var for getQty for use in my custom message. My block code:

 
class Sc_StockMessages_Block_Messages extends Mage_Catalog_Block_Product_Abstract {
    public function getMessage(){
    $_product = $this->getProduct(); 
    $quantity=Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty(); 
    if($quantity<= Mage::getStoreConfig('stockmessages/option/stockmessages_min_qty')) { 
    echo Mage::getStoreConfig('stockmessages/option/stockmessages_message')  . intval($quantity) . " ";

And my custom phtml is...:

$stockQty = $this->getMessage(); 

    echo $this->__($stockQty);

My result is: The stock is below than %s items 10 (i want to make the value 10 associate with the var %s, how i can do this? Thanks.

0

If you want put variable to message, try do it that way:

$_product = $this->getProduct();
$qty = array();
$qty[] = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty()
$message = vsprintf(Mage::getStoreConfig('stockmessages/option/stockmessages_message'), $qty);
0

Something here you can play around with in the view;

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

        <?php if ($inventoryQty <= 10): ?>

                <div class="availability out-of-stock">
                    <span>
                    The stock is below than <?php echo $inventoryQty ?> items
                    </span>
                </div>

            <?php else: ?>
                    <span>
                    IN STOCK
                    </span>
            <?php endif; ?>
  • My message is writed direct in admin backend from text and called from this block, is not possible to use message writed in code.. – Matheus Silva Itep Feb 28 '15 at 14:20
  • Ah, I totally miss read the question. – mg33dev Feb 28 '15 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.