Search code examples
prestashop

How can i find responsible code for "resend email " in order view page admin in prestashop?


i am trying to implement dynamic order email template mapping based on order status when order status is changed from a custom grid, i am trying to find the controller or code which is responsible for the "resend email" button or send order email functionality which is in admin view order page.

Any idea where would be that code for send mail ? Take a look at this picture for better understanding enter image description here


Solution

  • This is this code:

    } elseif (Tools::isSubmit('sendStateEmail') && Tools::getValue('sendStateEmail') > 0 && Tools::getValue('id_order') > 0) {
        if ($this->tabAccess['edit'] === '1') {
            $order_state = new OrderState((int)Tools::getValue('sendStateEmail'));
    
            if (!Validate::isLoadedObject($order_state)) {
                $this->errors[] = Tools::displayError('An error occurred while loading order status.');
            } else {
                $history = new OrderHistory((int)Tools::getValue('id_order_history'));
    
                $carrier = new Carrier($order->id_carrier, $order->id_lang);
                $templateVars = array();
                if ($order_state->id == Configuration::get('PS_OS_SHIPPING') && $order->shipping_number) {
                    $templateVars = array('{followup}' => str_replace('@', $order->shipping_number, $carrier->url));
                }
    
                if ($history->sendEmail($order, $templateVars)) {
                    Tools::redirectAdmin(self::$currentIndex.'&id_order='.$order->id.'&vieworder&conf=10&token='.$this->token);
                } else {
                    $this->errors[] = Tools::displayError('An error occurred while sending the e-mail to the customer.');
                }
            }
        } else {
            $this->errors[] = Tools::displayError('You do not have permission to edit this.');
        }
    }
    

    It's from controllers/admin/AdminOrdersController.php