I'm new to Magento and I've just built a custom module for a store. The module observes the event sales_order_place_before
, and checks with an outside source if an item is still in stock. When the customer wants to pay for the order and a product in the cart is out of stock, I throw an error in my Observer.php
model. It appears as a popup for the customer.
if(!$success){
Mage::throwException("item not in stock");
}
Is it possible to throw this error in multiple languages, for example English and Dutch? And how does that work? I can't seem to make sense of how to use translations in an observer instead of frontend. And since this is just a custom string, it could be anything, I would not be overwriting any Magento error.
EDIT:
My module's config xml (I've removed the actual namespace and module name). Do I define a helper like this? What do I put in the helper?
<config>
<modules>
<Namespace_Modulename>
<version>0.1.0</version>
</Namespace_Modulename>
</modules>
<global>
<helpers>
<translations>
<class>Namespace_Modulename_Helper</class>
</translations>
</helpers>
<events>
<sales_order_place_before>
<observers>
<Namespace_modulename_model_observer>
<type>singleton</type>
<class>Namespace_Modulename_Model_Observer</class>
<method>placingOrder</method>
</Namespace_modulename_model_observer>
</observers>
</sales_order_place_before>
</events>
</global>
<frontend>
<translate>
<modules>
<Namespace_Modulename>
<files>
<default>Namespace_Modulename.csv</default>
</files>
</Namespace_Modulename>
</modules>
</translate>
</frontend>
I have created a helper with an empty class in Helper/Data.php in my module:
class Namespace_Modulename_Helper_Data extends Mage_Core_Helper_Abstract{}
I've added the csv file in app/locale/nl_NL
Best Answer
Please try this but not sure