Send email order OPENCART

150 Views Asked by At

I can't say it directly, I have to explain what I want to do so you understand.

I have made an extension whereby orders are taken by 2 employees in the following way: 1 you 1 me

So in order.

I want to send the orders directly to the email. But I want to send the order exactly to the employee who took the order.

In the database, this table has the name "retrieved" in which there are 2 numbers: 5 and 4. If it is 5 = employee 1, if it is 4 = employee 2.

This is the code I made that should send orders to the email that took the order. But what do you see? It sends the orders, only to the FIRST email. Even if the order is accepted by the other person, it still goes into the first email. I have tried variations with if, ssmd but to no avail. That's why I have to ask here, what can I do? Also note that this module is inserted in (public_html/catalog/model/checkout/order.php). I don't know if this is right or not.

`

    $order_query = $this->db->query("SELECT preluat FROM " . DB_PREFIX . "order WHERE order_id = '" . (int)$order_id . "'");
    $order = $order_query->row;
    
    if ($order) {
        $lady1_email = "[email protected]";
        $lady2_email = "[email protected]";
    
        switch ($order['preluat']) {
            case '4':
                $to_email = $lady1_email;
                break;
            case '5':
                $to_email = $lady2_email;
                break;
        }
           if ($to_email != "") {
                $subject = "New order received";
                $body = "Dear Lady,\n\nA new order has been allocated to you. Please check your order list and start processing it as soon as possible.\n\nOrder details:\nOrder ID: " . $order['order_id'] . "\nCustomer Name: " . $order['firstname'] . " " . $order['lastname'] . "\nOrder Total: " . $order['total'] . "\n\nBest regards,\nYour Employer";
        
                $mail = new Mail();
                $mail->protocol = $this->config->get('config_mail_protocol');
                $mail->parameter = $this->config->get('config_mail_parameter');
                $mail->hostname = $this->config->get('config_smtp_host');
                $mail->username = $this->config->get('config_smtp_username');
                $mail->password = $this->config->get('config_smtp_password');
                $mail->port = $this->config->get('config_smtp_port');
                $mail->timeout = $this->config->get('config_smtp_timeout');
                $mail->setTo($to_email);
                $mail->setFrom($this->config->get('config_email'));
                $mail->setSender($order['store_name']);
                $mail->setSubject($subject);
                $mail->setText($body);
                $mail->send();
            }
    }*/

I want the code to work as I have detailed. To send orders correctly to the employees email depending on how the order is approved.

0

There are 0 best solutions below