Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Создать произвольные поля покупателя с запретом редактирования


vadim
 Share

Recommended Posts

Добрый день камрады. Помогите вот с таким вопросом:

В админке есть произвольные поля покупателей. как их добавлять понятно,

но хотелось бы сделать так - например я добавил в админке какие-то значения нового поля у определенного покупателя, мне нужно чтоб он их видел в личном кабинете но не мог редактировать.

Где прописать возможность их редактировать?

Может есть модуль для кастомных полей, или нужно в код и базу лезть? Если в базе, то где именно и какое значение выставлять?

Дайте направление плиз куда копать.

Заранее спасибо.

Link to comment
Share on other sites


Разобрался сам. Может пригодится кому.

Нужно просто в файле edit.tpl в параметрах custom_field в поля например <textarea> или <input> добавить значение readonly

Пример:

<?php if ($custom_field['type'] == 'textarea') { ?>
          <div class="form-group<?php echo ($custom_field['required'] ? ' required' : ''); ?> custom-field" data-sort="<?php echo $custom_field['sort_order']; ?>">
            <label class="col-sm-2 control-label" for="input-custom-field<?php echo $custom_field['custom_field_id']; ?>"><?php echo $custom_field['name']; ?></label>
            <div class="col-sm-10">
              <textarea readonly name="custom_field[<?php echo $custom_field['custom_field_id']; ?>]" rows="5" placeholder="<?php echo $custom_field['name']; ?>" id="input-custom-field<?php echo $custom_field['custom_field_id']; ?>"  class="form-control"><?php echo (isset($account_custom_field[$custom_field['custom_field_id']]) ? $account_custom_field[$custom_field['custom_field_id']] : $custom_field['value']) ; ?></textarea>
              <?php if (isset($error_custom_field[$custom_field['custom_field_id']])) { ?>
              <div class="text-danger"><?php echo $error_custom_field[$custom_field['custom_field_id']]; ?></div>
              <?php } ?>
            </div>
          </div>

Можно в админке сделать новую вкладку в покупателе для этого дела. Например анкета:

в файле \admin\view\template\customer\customer_form.tpl - создаете и называете вкладку, например:
<li><a href="#tab-history-piople" data-toggle="tab">Анкета</a></li>

Далее создаете div соответствующий вкладке, например: <div class="tab-pane" id="tab-history-piople">
  В этот div вставляете (сначала вырезаете ctrl+x) строки начинающиеся с
   <?php foreach ($custom_fields as $custom_field) { ?>
                      <?php if ($custom_field['location'] == 'account') { ?>
                      <?php if ($custom_field['type'] == 'select') { ?>
  
  и до окончания всех полей custom_field
     <?php if (isset($error_custom_field[$custom_field['custom_field_id']])) { ?>
                          <div class="text-danger"><?php echo $error_custom_field[$custom_field['custom_field_id']]; ?></div>
                          <?php } ?>
                        </div>
                      </div>
                     <?php } ?>
                      <?php } ?>
                      <?php } ?>
это конец полей
  

соответственно в новой вкладке появятся Ваши произвольные поля. Дальше только от Вашей фантазии.

 

У меня получилось вот так:

2Z7Xw9e.png

в кабинете вот так

htQUw8S.png

 

Соответственно покупатель видит какие то данные, которые добавили в админке, но редактировать их не может.

Link to comment
Share on other sites


Да, кстати если хотите чтоб эти поля не высвечивались при регистрации - отключите или закомментируйте их в файлах Вашей темы 

в register.tpl

Начинаются с 
<?php foreach ($custom_fields as $custom_field) { ?>
          <?php if ($custom_field['location'] == 'address') { ?>
          <?php if ($custom_field['type'] == 'select') { ?>

 

 

а в register.php отключите (удалите строки ниже) проверку валидации

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

		$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);

		foreach ($custom_fields as $custom_field) {
			if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
				$this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
			}
		}

 

  • +1 1
Link to comment
Share on other sites


Остался у меня вопрос -как к произвольному полю <Textarea> в админке подцепить редактор для форматирования текста?

j9SHf9h.png

Link to comment
Share on other sites


19 часов назад, florapraktik сказал:

А где эти данные хранятся? и как они туда попадают?

nf9wXwj.png

Произвольные поля покупателя уже встроены в движке опенкарта начиная со 2й версии, соответственно они хранятся в базе в таблицах custom_field

 

GgaNbDU.png

Edited by vadim
  • +1 1
Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.