3

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

  • Before starting building that yourself I would recommend to check if one of the Multi-Vendor-Extension on Magento Connect works for you – Stefan Gregori Dec 19 '13 at 8:54
  • can you please suggest one which i should try – Dexter Dec 19 '13 at 11:28
  • am sorry, but I am not able to do that because there are just to many out there and I am not that into this kind of extensions. As a clue, if you think one will fit but you not sure, ask the developer of the extension itself by contacting them over magento connect. till now, always got good answers there or may you get offer to make it fit your needs! – Stefan Gregori Dec 19 '13 at 12:57
  • 2
    You need to take a look at Unirgy uDropship for your needs. Trying to recreate this extension will be like trying to reinvent the wheel. In the end, it will be cheaper to just buy the extension. – kab8609 Dec 19 '13 at 15:26
5

Building this from scratch shouldn't be to difficult. Basically you need a few things

  • An observer that observes some event which is triggered when an order is completed
  • Some email functionality
  • A field per product indicating who to email to

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 the sales_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 observer

<?xml version="1.0"?>
<config>
   <global>
      <models>
         <[module]>
            <class>[Namespace]_[Module]_Model</class>
         </[module]>
      </models>
      <events>
         <sales_order_invoice_save_after>
            <observers>
               <[module]_invoice_email>
                  <type>singleton</type>
                  <class>[module]/observer</class>
                  <method>sendEmail</method>
               </[module]_invoice_email>
            </observers>
         </sales_order_invoice_save_after>     
      </events>
   </global>
</config>

Here 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, method sendMail. You can change the names of the observer and method if you like.

Next up the Observer model

class [Namespace]_[Module]_Model_Observer
{

   /**
    * Send email to appropriate manufacturer 
    * @param   Varien_Event_Observer $observer
    * @return  this
    */
   public function sendMail(Varien_Event_Observer $observer)
   {
      $order = $observer->getOrder();

      $email_stacks = array();
      foreach ($order->getAllItems() as $item)
      {
         // only add simple products to email, not a configurable product for example
         if ($item->getData('product_type')!=Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)
            continue;

         $manufacturer = $item->getProduct()->getData('manufacturer_email');

         if (!isset($email_stacks[$manufacturer])) $email_stacks[$manufacturer] = "";

         $email_stacks[$manufacturer] .= "{$item->getData('sku')} {$item->getData('qty_ordered')}x<br/>\n";
      }

      // here goes the email part

      return $this;
   }
}

So 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

class [Namespace]_[Module]_Helper_Data extends Mage_Core_Helper_Abstract
{
}

Your Observer model, remember the // here goes the email part part? Below code goes there.

foreach ($email_stacks as $emailaddress => $items_string)
{
   $template = Mage::getModel('core/email_template')->loadDefault('[the_name_of_your_template]');

   $template->send($emailaddress, null, array(
      'orderid' => $order->getIncrementId(),
      'items' => $items_string
   ));
}

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.

<!--@subject New items order @-->
<div>
<h1>Order {{var orderid}}</h1>
<p>{{var items}}</p>
</div>

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.

1

What you are describing sounds like a "drop-ship" situation. There are several Magento apps that will allow you to integrate with drop shippers (marketplace merchants) easily. Another benefit to these is the ability to calculate shipping based on the product and that product's origin.

Here is a link to drop ship extensions on Magento: http://www.magentocommerce.com/magento-connect/catalogsearch/result/?q=drop+ship&pl=0

There is a large price range, but there is also a large variance in the features offered by different modules. What you are asking for is extremely complicated to code properly. Purchasing any of these extensions will almost certainly be more cost efficient than building it yourself. Be sure to spend time researching the extensions and asking the developer questions to make sure what you buy will be a good fit.

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.