Как добавить пользовательские поля в список клиентов?(OpenCart) - PullRequest
0 голосов
/ 01 декабря 2018

Как я могу получить пользовательские поля в функцию getList и добавить их в список клиентов в бэкэнде opencart?

следующий код - это функция getForm формы

// Custom Fields
$this->load->model('customer/custom_field');

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

$custom_fields = $this->model_customer_custom_field->getCustomFields();

$confirmation_info = $this->model_sale_confirmation->getConfirmation($confirmation_id);

foreach ($custom_fields as $custom_field) {
    $data['custom_fields'][] = array(
        'custom_field_id'    => $custom_field['custom_field_id'],
        'custom_field_value' => $this->model_customer_custom_field->getCustomFieldValues($custom_field['custom_field_id']),
        'name'               => $custom_field['name'],
        'value'              => $custom_field['value'],
        'type'               => $custom_field['type'],
        'location'           => $custom_field['location'],
        'sort_order'         => $custom_field['sort_order']
    );
}

$data['download']  = $this->url->link('tool/upload/download', 'user_token=' . $this->session->data['user_token'], true);

if (isset($this->request->post['custom_field'])) {
    $data['confirmation_custom_field'] = $this->request->post['custom_field'];
} elseif (!empty($confirmation_info)) {
    $data['confirmation_custom_field'] = json_decode($confirmation_info['custom_field'], true);
} else {
    $data['confirmation_custom_field'] = array();
}

1 Ответ

0 голосов
/ 01 декабря 2018

Значения пользовательских полей хранятся в формате Json в столбце таблицы пользовательских полей oc_customer.Таким образом, вы можете получить эти значения в функции getList и передать их в массиве клиентов следующим образом

$data['customers'][] = array(
'account_custom_field'=>json_decode($result['custom_field'], true),

Теперь вам нужно получить имя настраиваемых полей для отображения в списке клиентов в виде столбцов таблицы.

// Custom Fields
$this->load->model('customer/custom_field');

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

$custom_fields = $this->model_customer_custom_field->getCustomFields();

$confirmation_info = $this->model_sale_confirmation->getConfirmation($confirmation_id);

foreach ($custom_fields as $custom_field) {
    $data['custom_fields'][] = array(
        'custom_field_id'    => $custom_field['custom_field_id'],
        'custom_field_value' => $this->model_customer_custom_field->getCustomFieldValues($custom_field['custom_field_id']),
        'name'               => $custom_field['name'],
        'value'              => $custom_field['value'],
        'type'               => $custom_field['type'],
        'location'           => $custom_field['location'],
        'sort_order'         => $custom_field['sort_order']
    );
}

Вы можете создать больше столбцов в таблице

{% for custom_field in custom_fields %}
    <th>{{custom_field.name}}</th>
{% endfor %}

В каждой строке клиента вы можете найти поле custom_field в данных пользовательского поля клиента, сопоставив идентификатор пользовательского поля и затем отобразив данныев этом конкретном столбце

Этот массив предоставит вам имена столбцов, а затем, сопоставив custom_value_id из пользовательских значений JSON Decode клиента, вы сможете отобразить ..

{% for custom_field in custom__fields %}
    {% if customer.account_custom_field[custom_field.custom_field_id] %} 
            {{customer.account_custom_field[custom_field.custom_field_id]}} 
    {% endif %}
{% endfor %}

Требуются дополнительные усилия дляотобразить столбец, соответствующий пользовательскому значению, в правом столбце, поэтому используйте подсказку.

...