We are building a website which somewhat acts like a marketplace. The website sells bags which are manufactured in different countries. The website owner acts as a mediator between the customer and the manufacturer
What i need is when a product is bought an email should be fired to the manufacturer of the bag. The email includes name of the product, its buyer, shipping address and contact information of the buyer.
If more than one product is bought different email should be fired to the manufacturer of those particular product.
Is there any extension available in the market which supports such a functionality. I tried to search but all i came across was marketplaces which our client can't afford.
Another way i thought was to enter a field for each product wherein the email of manufacturer is entered. When a prouduct is bought on checkout_process_complete event the email should be fired. As i am not that pro in magento custom extension building can anyone suggest me which way should i go ?
If i go for building a custom module from where i can start from ?
Any help will be appreciated
Thanks
Best Answer
Building this from scratch shouldn't be to difficult. Basically you need a few things
If you're not familiar with creating extensions take a look at this Smashing Magazine tutorial or Alan Storm's Hello World tutorial. They both cover a good portion of the different kinds of elements an extension can have tho you will probably only need a Helper and a Model.
First we will start with an
observer
. In this case I would recommend thesales_order_invoice_save_after
event. This is triggered whenever an invoice is created so you can be fairly sure the items you're emailing to the manufacturer are paid for by the customer.We will need a
config.xml
that contains, amongst some other stuff, the observerHere we've added a models node so to have access to the models class in our module and an observer that listens to the
sales_order_invoice_save_after
event calling the Observer model, methodsendMail
. You can change the names of the observer and method if you like.Next up the
Observer
modelSo what happens here. We get the order from the observer data, extract the items and loop through them only processing the simple products since a configurable product is no use to the manufacturer.
For each simple product we get the
manufacturer_email
attribute (which you should add manually to each product) and use it as an index key adding a string with SKU and quantity along with it.This leaves us with an array that has one or more indexes which represents each manufacturer to be mailed and per key a string with the items for that manufacturer.
Now onwards to email that array! Inchoo has a great article on custom emails in Magento so read that to edit your
config.xml
. I will just add the code part for the model and the email template you could use. Earlier I talked about a Helper class you would need. I think your email template won't work unless you have a basic helper in your method so just to be sure and go ahead and create it.app/code/.../[Namespace]/[Module]/Helper/Data.php
Your
Observer
model, remember the// here goes the email part
part? Below code goes there.this will send an email per manufacturer loading the email template with the orderid as reference and the items string we've created earlier. Any other information you might want in your email you can retrieve from the order and pass along in the array. The name of the key you assign it to will correspond to
{{var thekeyname}}
in the email template later on.And for the email template, something like this should do it.
And that should be it!
Just remember this is untested code I pieced together so make sure to test it thoroughly before using it in an production environment. It will probably need a tweak here or there.