V
V
Valentine2020-01-12 00:52:14
PHP
Valentine, 2020-01-12 00:52:14

How to output data from payment_address to order list in opencart 3?

It is necessary to display the sender's full name in the list of orders on the seller's account instead of the user's First and Last names in the Customer field, I'm just starting to study it all, so I can do stupid actions and for 3 days I can't do it myself ..
in the controller file I don't know how to specify the path correctly to display $order_info['payment_firstname'], instead of 'name' => $result['firstname'] . ' ' . $result['lastname'], since these data are in two different functions, I don't understand how to specify that you need a name with an order info and not an account name.. I did this

'name'       => $result['payment_firstname'] . ' ' . $result['payment_lastname'],

and so
'name'       => $order_info['payment_firstname'] . ' ' . $order_info['payment_lastname'],

here is the whole code
<?php
class ControllerAccountOrder extends Controller {
  public function index() {
    if (!$this->customer->isLogged()) {
      $this->session->data['redirect'] = $this->url->link('account/order', '', true);

      $this->response->redirect($this->url->link('account/login', '', true));
    }

    $this->load->language('account/order');

    $this->document->setTitle($this->language->get('heading_title'));
    
    $url = '';

    if (isset($this->request->get['page'])) {
      $url .= '&page=' . $this->request->get['page'];
    }
    
    $data['breadcrumbs'] = array();

    $data['breadcrumbs'][] = array(
      'text' => $this->language->get('text_home'),
      'href' => $this->url->link('common/home')
    );

    $data['breadcrumbs'][] = array(
      'text' => $this->language->get('text_account'),
      'href' => $this->url->link('account/account', '', true)
    );
    
    $data['breadcrumbs'][] = array(
      'text' => $this->language->get('heading_title'),
      'href' => $this->url->link('account/order', $url, true)
    );

    if (isset($this->request->get['page'])) {
      $page = $this->request->get['page'];
    } else {
      $page = 1;
    }

    $data['orders'] = array();

    $this->load->model('account/order');

    $order_total = $this->model_account_order->getTotalOrders();

    $results = $this->model_account_order->getOrders(($page - 1) * 10, 10);

    foreach ($results as $result) {
      $product_total = $this->model_account_order->getTotalOrderProductsByOrderId($result['order_id']);
      $voucher_total = $this->model_account_order->getTotalOrderVouchersByOrderId($result['order_id']);

      $data['orders'][] = array(
        'order_id'   => $result['order_id'],
        'name'       => $result['firstname'] . ' ' . $result['lastname'],
        'status'     => $result['status'],
        'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
        'products'   => ($product_total + $voucher_total),
        'total'      => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
        'view'       => $this->url->link('account/order/info', 'order_id=' . $result['order_id'], true),
      );
    }

    $pagination = new Pagination();
    $pagination->total = $order_total;
    $pagination->page = $page;
    $pagination->limit = 10;
    $pagination->url = $this->url->link('account/order', 'page={page}', true);

    $data['pagination'] = $pagination->render();

    $data['results'] = sprintf($this->language->get('text_pagination'), ($order_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($order_total - 10)) ? $order_total : ((($page - 1) * 10) + 10), $order_total, ceil($order_total / 10));

    $data['continue'] = $this->url->link('account/account', '', true);

    $data['column_left'] = $this->load->controller('common/column_left');
    $data['column_right'] = $this->load->controller('common/column_right');
    $data['content_top'] = $this->load->controller('common/content_top');
    $data['content_bottom'] = $this->load->controller('common/content_bottom');
    $data['footer'] = $this->load->controller('common/footer');
    $data['header'] = $this->load->controller('common/header');

    $this->response->setOutput($this->load->view('account/order_list', $data));
  }

  public function info() {
    $this->load->language('account/order');

    if (isset($this->request->get['order_id'])) {
      $order_id = $this->request->get['order_id'];
    } else {
      $order_id = 0;
    }

    if (!$this->customer->isLogged()) {
      $this->session->data['redirect'] = $this->url->link('account/order/info', 'order_id=' . $order_id, true);

      $this->response->redirect($this->url->link('account/login', '', true));
    }

    $this->load->model('account/order');

    $order_info = $this->model_account_order->getOrder($order_id);

    if ($order_info) {
      $this->document->setTitle($this->language->get('text_order'));

      $url = '';

      if (isset($this->request->get['page'])) {
        $url .= '&page=' . $this->request->get['page'];
      }

      $data['breadcrumbs'] = array();

      $data['breadcrumbs'][] = array(
        'text' => $this->language->get('text_home'),
        'href' => $this->url->link('common/home')
      );

      $data['breadcrumbs'][] = array(
        'text' => $this->language->get('text_account'),
        'href' => $this->url->link('account/account', '', true)
      );

      $data['breadcrumbs'][] = array(
        'text' => $this->language->get('heading_title'),
        'href' => $this->url->link('account/order', $url, true)
      );

      $data['breadcrumbs'][] = array(
        'text' => $this->language->get('text_order'),
        'href' => $this->url->link('account/order/info', 'order_id=' . $this->request->get['order_id'] . $url, true)
      );

      if (isset($this->session->data['error'])) {
        $data['error_warning'] = $this->session->data['error'];

        unset($this->session->data['error']);
      } else {
        $data['error_warning'] = '';
      }

      if (isset($this->session->data['success'])) {
        $data['success'] = $this->session->data['success'];

        unset($this->session->data['success']);
      } else {
        $data['success'] = '';
      }

      if ($order_info['invoice_no']) {
        $data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no'];
      } else {
        $data['invoice_no'] = '';
      }

      $data['order_id'] = $this->request->get['order_id'];
      $data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));

      if ($order_info['payment_address_format']) {
        $format = $order_info['payment_address_format'];
      } else {
        $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
      }

      $find = array(
        '{firstname}',
        '{lastname}',
        '{company}',
        '{address_1}',
        '{address_2}',
        '{city}',
        '{postcode}',
        '{zone}',
        '{zone_code}',
        '{country}'
      );

      $replace = array(
        'firstname' => $order_info['payment_firstname'],
        'lastname'  => $order_info['payment_lastname'],
        'company'   => $order_info['payment_company'],
        'address_1' => $order_info['payment_address_1'],
        'address_2' => $order_info['payment_address_2'],
        'city'      => $order_info['payment_city'],
        'postcode'  => $order_info['payment_postcode'],
        'zone'      => $order_info['payment_zone'],
        'zone_code' => $order_info['payment_zone_code'],
        'country'   => $order_info['payment_country']
      );

      $data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));

      $data['payment_method'] = $order_info['payment_method'];

Need to replace infu c
$data['orders'][] = array(
        'order_id'   => $result['order_id'],
        'name'       => $result['firstname'] . ' ' . $result['lastname'],
        'status'     => $result['status'],
        'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
        'products'   => ($product_total + $voucher_total),
        'total'      => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
        'view'       => $this->url->link('account/order/info', 'order_id=' . $result['order_id'], true),
      );
on info c
$replace = array(
        'firstname' => $order_info['payment_firstname'],
        'lastname'  => $order_info['payment_lastname'],
        'company'   => $order_info['payment_company'],
        'address_1' => $order_info['payment_address_1'],
        'address_2' => $order_info['payment_address_2'],
        'city'      => $order_info['payment_city'],
        'postcode'  => $order_info['payment_postcode'],
        'zone'      => $order_info['payment_zone'],
        'zone_code' => $order_info['payment_zone_code'],
        'country'   => $order_info['payment_country']
      );
5e1af96b4f2ce368256680.png5e1af9769ad4a470841210.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question