0

How to create an email template with cart products, I want to create my own module with cart products and want to send the mail to the admin. How can I do this please educate with brief note.

Thanks in Advance :)

  • When press add to cart button then mail send to admin ? Please describe more your requirement. – Msquare Mar 29 at 5:01
0

If you know how to create custom module you have to observer for place order event. (you can use this event checkout_onepage_controller_success_action). And in this observer you will get all products in cart and you can send email from this place. follow this link: send email. In events.xml use above event instead of customer_register_success.

EXAMPLE:
events.xml

<?xml version="1.0"?>
 <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_onepage_controller_success_action"> <!--place order-->
        <observer name="vendor_observer_place_order" instance="Vendor\ModuleName\Observer\PlaceOrder" />
    </event>
 </config>

PlaceOrder.php

    <?php
    namespace Vendor\ModuleName\Observer;
    use Magento\Framework\Event\ObserverInterface;
    use HostAdvice\EmailDemo\Helper\Email;
    class PlaceOrder implements ObserverInterface
    {
        private $helperEmail;

        public function __construct(
            Email $helperEmail
        ) {
            $this->helperEmail = $helperEmail;
        }
        public function execute(\Magento\Framework\Event\Observer $observer)
        {
            return $this->helperEmail->sendEmail();
        }
| improve this answer | |
  • how i will run this session when i click button the mail should be send – Sabareesh Mar 10 at 6:06
0

Create plugin for send email when add to cart process

app\code\VendoreName\ModuleName\etc

di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Controller\Cart\Add">
        <plugin name="add_email_before_add_to_cart" type="VendoreName\ModuleName\Plugin\Checkout\Controller\Cart\Add"/>
    </type>
</config>

app\code\VendoreName\ModuleName\Plugin\Checkout\Controller\Cart

Add.php

<?php

namespace VendoreName\ModuleName\Plugin\Checkout\Controller\Cart;

class Add   
{
    public function afterExecute(
        \Magento\Checkout\Controller\Cart\Add $subject,
        \Closure $proceed
    ) {
            //add You required logic to send email 
    }
}

I Hope This Helps You.

| improve this answer | |

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.