Вывести настраиваемое поле в списке заказов

Тема в разделе "Общие вопросы", создана пользователем avm, 13 авг 2022.

  1. avm

    avm Новичок

    Сообщения:
    29
    Симпатии:
    0
    Всем доброго!

    Прочитав тему, вывел в списке заказов, поле группа покупателей

    после строки
    customer' => $result['customer'],
    добавил
    'customer_group_name' => $result['customer_group_name'],

    заменил
    $sql = "SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, (SELECT os.name FROM " . DB_PREFIX . "order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int)$this->config->get('config_language_id') . "') AS order_status, o.shipping_code, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified FROM `" . DB_PREFIX . "order` o";
    на это
    $sql = "SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, cgd.name AS customer_group_name, (SELECT os.name FROM " . DB_PREFIX . "order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int) $this->config->get('config_language_id') . "') AS order_status, o.shipping_code, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "customer_group_description cgd ON(cgd.customer_group_id = o.customer_group_id)";

    после строки
    {{ column_customer }}</a> {% endif %}</td>
    добавил
    <td class="text-left">Группа</td>

    после строки
    <td class="text-left">{{ order.customer }}</td>
    добавил
    <td class="text-left">{{ order.customer_group_name }}</td>

    Screenshot_44.png

    Подскажите пожалуйста, хотелось бы вывести настраиваемое поле (custom fields) в списке заказов order_list.twig.
    С php пока на вы, буду признателен за любой конструктивный ответ.

    Спасибо!
     
  2. Blast

    Blast Продвинутый пользователь

    Сообщения:
    212
    Симпатии:
    74
    заменить запрос в модели
    $sql = "SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, o.custom_field, cgd.name AS customer_group_name, (SELECT os.name FROM " . DB_PREFIX . "order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int) $this->config->get('config_language_id') . "') AS order_status, o.shipping_code, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "customer_group_description cgd ON(cgd.customer_group_id = o.customer_group_id)";

    в контроллере добавить
    'custom_field' => json_decode($result['custom_field'], true)[тут_ид_настраиваемого_поля],

    ну и во вьюхе вывести в нужном месте
    {{ order.custom_field }}
     
    avm нравится это.
  3. avm

    avm Новичок

    Сообщения:
    29
    Симпатии:
    0
    @Blast, Спасибо за ответ и решение! попробую.
     
  4. avm

    avm Новичок

    Сообщения:
    29
    Симпатии:
    0
    @Blast подскажи пожалуйста
    в контроллере добавить
    [тут_ид_настраиваемого_поля] - в каком виде тут добавить id ?
    пробовал так [1], еще так ['custom_field_id=1']
     
    Последнее редактирование: 19 авг 2022
  5. Blast

    Blast Продвинутый пользователь

    Сообщения:
    212
    Симпатии:
    74
    просто цифрой [1]
    чтобы отображалось нужно сделать заказ из под юзера с заполненными настраиваемыми полями. в старых заказах не будет отображаться
     
  6. avm

    avm Новичок

    Сообщения:
    29
    Симпатии:
    0
    Так первоначально и сделал
    controller
    'custom_field' => json_decode($result['custom_field'], true)[1],

    model

    $sql = "SELECT o.order_id, CONCAT(o.firstname, ' ', o.lastname) AS customer, o.custom_field, cgd.name AS customer_group_name, (SELECT os.name FROM " . DB_PREFIX . "order_status os WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int) $this->config->get('config_language_id') . "') AS order_status, o.shipping_code, o.total, o.currency_code, o.currency_value, o.date_added, o.date_modified FROM `" . DB_PREFIX . "order` o LEFT JOIN " . DB_PREFIX . "customer_group_description cgd ON(cgd.customer_group_id = o.customer_group_id)";

    template

    <td class="text-left">{{ order.custom_field }}</td>

    Ошибка Notice: Undefined offset: 1 in
     
  7. Blast

    Blast Продвинутый пользователь

    Сообщения:
    212
    Симпатии:
    74
    в контроллере до
    $data['orders'][] = array(
    добавить
    $custom_field = json_decode($result['custom_field'], true);

    потом переписать
    'custom_field' => isset($custom_field[1]) ? $custom_field[1] : '',

    у настраиваемого поля Расположение в Аккаунте или в Адресе?
     
  8. avm

    avm Новичок

    Сообщения:
    29
    Симпатии:
    0
    Забыл) упоминуть, в аккаунте.
    Переделал по вашей инструкции, ошибок нет, колонка в списке пустая.
    почитал немного, вывел print_r ($custom_field);
    Array ( [account] => Array ( [1] => Рога и копыта ) )
    что не так, самостоятельно не пойму.
     
    Последнее редактирование: 19 авг 2022
  9. Blast

    Blast Продвинутый пользователь

    Сообщения:
    212
    Симпатии:
    74
    тогда так наверное
    'custom_field' => isset($custom_field['account'][1]) ? $custom_field['account'][1] : '',
     
    avm нравится это.
  10. avm

    avm Новичок

    Сообщения:
    29
    Симпатии:
    0
    @Blast, спасибо огромное за помощь!
    Вывод кастомного поля работает, вопрос решен.