I need to be able to send transactional emails that include a conditional sentence. I want to include a sentence in the order confirmation emails for any orders that contain certain products. There plenty of examples of how to use conditionals within a transaction emails based on the built in variables, but I want to base the conditional on my own variable that I'll create programmatically from within my own extension.
The mailer class Mage_Core_Model_Email_Template_Mailer does have a public setTemplateParams method, but as that method just calls the base classes setData method, even if I could access that method to set my own parameters it would overwrite the core template parameters that are necessary to show the contents of the basket.
How to achieve this?
You should create a new order attribute where you save your conditional sentence.
Then you can access your attribute easily in the transactional email template via {{htmlescape var=$order.getYourAttribute()}}
The attribute you are creating is related to which entity product or customers
For customer you can get it by
{{var order.getCustomer().getAttrName()}}
Related
This question is about the "correct" design pattern, not about functional code. I want to adhere to best-practices and use the right feature in Laravel.
I have a model called Order which contains users' product orders.
Order has several columns, like which product, quantity, etc, and is stored in mysql, with a belongsTo() call to the User model.
When I place an order using the OrderController, I call an outside API that I set up using a Service class.
Here's the main part of the question:
I need to add certain fields that the API requires, but on my end are always the same, so it would make sense to me to pack these into an object of their own and just append that object to the end of my Order data before submission.
So where is the "Best" place to put this extra data? In my model? In a Service class? I'm leaning toward the service class, but that just doesn't feel right.
You have an action that gives a single or a collection of a model. So the best practice for adding some extra data to those results is using JsonResource and ResourceCollection. By using them you can easily add anything you want in the ToArray method.
Lumen doesn't have Illuminate\Http by default but you can add it to your project.
Official Http package of laravel
Eloquent: API Resources Documentation.
I want to extract Order information and customer information from new order email which is sent to the customer after purchasing any product from Magento Website.
I have tried a lot but not getting any results as such.
Is this possible in Magento, I am stuck up in this problem since days.Does any one have a solution to this?
The sending of new order emails is handled in Mage_Sales_Model_Order.
Most Magento model classes (all which extend Mage_Core_Model_Abstract) implement the Template Method pattern - not to be confused with view templates. The template methods can be used to hook in to save, load, and delete workflows in two ways:
Method rewrites via config-based class overrides (another Magento treat)
Observe events dispatched in the template methods.
By far the preferred technique for hooking into model execution is the event-observer system. Additionally, there are hundreds of events dispatched throughout Magento for any given execution.
Hello I have trying to learn Magento, So would be appreciated if anyone helps.
I saw people initiate class
Mage::getResouceModel('report/product_sold_collection');
Then they iterate over the collection using foreach loop and use
getOrderedQty() method.
Like in this thread.
total sales of each product in magento
Where is this method defined? In which class ?
That method doesn't exist. All Magento Objects (that is, objects which inherit from Varien_Object) allow you to get and set data properties.
$object->setData('the_thing',$value);
echo $object->getData('the_thing')
On top of this, there's also special setter and getter methods implemented with PHP's "magic methods". That is, you can get/set a data property by camel casing it's name, and calling it like this
$object->setMyThing($value);
echo $object->getMyThing();
I searched the Magento codebase, and there's no definition for a "getOrderedQty" method. That means it's one of the above mentioned magic methods.
I'm currently trying to programmatically insert a ModelClientValidationStringLengthRule ModelValidator via a custom attribute, and wishing to avoid adding to the AdditionalValues dictionary in order to make use of existing functionality.
This is due to using a CMS, and wanting to control the length of the string via the CMS rather than within a model.
I assume I would do this in the OnMetadataCreated event in the custom attribute, however I cannot see how to add to the ModelValidator collection, only get them via GetValidators...
Anyone have any ideas?
Thanks in advance,
Dave
Rather than adding a custom attribute, you want to inject a validator based upon a condition.
You can use the class I detail in this answer to inject your validator based upon the conditions in your CMS.
Using magento layout files - is it possible to include a block, only if an admin setting is true.
Exactly like you can do using the ifconfig property when using action method="setTemplate".
Not directly. The ifconfig mechanism is the only conditional like structure in the Layout Update XML system that ships with Magento.
If you're comfortable creating modules and custom blocks class though, you can achieve the results you want pretty easily.
Create a custom Block class that extends whatever block you're interested in conditionally adding.
Create a new _toHtml method in your class with the conditional logic you want. If the tests pass have your method return parent::_toHtml, otherwise have it return an empty string.