How to load a variable inside the message via custom module?

Asked

Viewed 128 times

1

I am making a module for displaying the quantity of stock on the product page only if the quantity is less than that defined in the options. beauty, but my question is: O estoque está com menos que %s unidades . I want to know how to reference the variable %s within my message!? code used to build the config.xml

    <stockmessages>
        <option>
            <stockmessages_enable>1</stockmessages_enable>
            <stockmessages_min_qty>5</stockmessages_min_qty>
            <stockmessages_message>The stock is below than %s items</stockmessages_message>
        </option>
    </stockmessages>

This allows me to load a default message, for sure, and follow the code when using it in my default.phtml:

<p class="availability in-stock"><?php $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) . " ";} ?></p>

The question is how to insert a variable into the custom message and take the option to have the value click on the final message. Thank you

1 answer

0

I think what you want is something like this:

<p class="availability in-stock">
    <?php 
        $quantity = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty(); 
        if($quantity <= Mage::getStoreConfig('stockmessages/option/stockmessages_min_qty')) { 
            $frase = Mage::getStoreConfig('stockmessages/option/stockmessages_message') . intval($quantity) . " ";
            echo $this ou Mage:helper('seu modulo')->__($frase . ' %s', $quantity);
        } 
    ?>
</p>

You can make a Else putting the message default.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.