简体   繁体   中英

I want to use Mail::send functionality for sending email on order confirmation?

I want to use mail::send() for sending the notification to admin when order is placed in prestashop.My mail are working for customers but i want to send a mail to shop admin too regarding order placement.And one more thing i dont want to use any seperate plugin for this,I have my payment module in which at the end order status is changed after placing a order.So, I just need to use Mail::send() in that file in order to send notification.

   Mail::Send(
       (int)$order->id_lang,
       'order_conf',
       Mail::l('Order confirmation', (int)$order->id_lang),
       $data,
       $this->context->customer->email,
       $this->context->customer->firstname.' '.$this->context->customer->lastname,
       null,
       null,
       $file_attachement,
       null, _PS_MAIL_DIR_, false, (int)$order->id_shop
    );

something like this need to implement but this is not working directly. All suggestions are welcome. Thanks in advance.

Send is a static function of Mail, you can use it anywhere in the project PrestaShop. An example of use is this:

        $context = Context::getContext();
        $id_shop = (int)$context->shop->id;
        $id_lang = (int)$context->language->id;

        $configuration = Configuration::getMultiple(
            array(
                    'MA_LAST_QTIES',
                    'PS_STOCK_MANAGEMENT',
                    'PS_SHOP_EMAIL',
                    'PS_SHOP_NAME'
            ), null, null, $id_shop
        );

        Mail::Send(
            $id_lang,
            'checker',
            Mail::l('Ordini', $id_lang),
            array('template_vars'=>$vars),
            $dest_mail,
            null,
            (string)$configuration['PS_SHOP_EMAIL'],
            (string)$configuration['PS_SHOP_NAME'],
            null,
            null,
            dirname(__FILE__).'/mails/',
            false,
            $id_shop
        );

this model I use it. if there are doubts here

In you example code you are sending email to client instead of shop admin. You should change it like this:

Mail::Send(
   (int)$order->id_lang,
   'order_conf',
   Mail::l('Order confirmation', (int)$order->id_lang),
   $data,
   Configuration:get('PS_SHOP_EMAIL')/*or directly desired email address*/,
   '',
   null,
   null,
   $file_attachement,
   null, _PS_MAIL_DIR_, false, (int)$order->id_shop
);

You can also use mail alerts module for this functionality.

Good luck.

    class sendEmail extends MailCore {
    public function mailSend($data, $language){
    if($language == 'en'){
        $toSendLang = "new_order_en";
    }else {
        $toSendLang = "new_order_nl";
    }
      $shop_email = strval(Configuration::get('PS_SHOP_EMAIL'));
            Mail::Send(
                            $data['mailIdLang'],
                            $toSendLang,
                            Mail::l('Order confirmation', $data['mailIdLang']),
                            $data['templateVars'],
                            $shop_email,
                            ''.' '.'',
                            null,
                            null,
                            null,
                            null, dirname(__FILE__).'/mails/', false, $data['idShop']
                        );


}
             }

Guys, this is the class I have use to send the email to admin and surely it works.You just have to make a object of this class and use it.If any one is having any query about this they can ask from me.If anyone found this answer useful just give a upvote.Thanks for giving the suggestions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM