Created
February 16, 2024 01:19
-
-
Save andronex/1c08a449ed636d37c464e34031127bfb to your computer and use it in GitHub Desktop.
Добавление поля в карточку заказа minishop2 с ajax подгрузкой данных
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case 'msOnManagerCustomCssJs': | |
if ($page != 'orders') return; | |
$modx->controller->addLastJavascript(MODX_ASSETS_URL.'components/XXXXXX/js/mgr/default.js'); | |
break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('MODX_API_MODE', true); | |
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/index.php'; | |
$modx->getService('error','error.modError'); | |
$modx->setLogLevel(modX::LOG_LEVEL_ERROR); | |
$modx->setLogTarget('FILE'); | |
if ($_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest') { | |
$modx->sendRedirect($modx->makeUrl($modx->getOption('site_start'),'','','full')); //отфильтровываем все не ajax запросы | |
} | |
if (!$modx->hasPermission('msorder_view')) { //проверяем имеет ли текущий пользователь права на просмотр заказа | |
die('Доступ запрещен!'); | |
} | |
$id = (int) $_POST['id']; | |
$user = $modx->getObject('modUser', $id); | |
if (!$user) { | |
die('ошибка'); | |
} | |
die($user->Profile->get('email')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ext.ComponentMgr.onAvailable('minishop2-window-order-update', function(){ | |
var user_id = this.record.user_id;//получаем пользователя текущего заказа | |
var uric = this.record.addr_uric; | |
changeFields(this, user_id); | |
function changeFields (self) { | |
self.fields.items[2].items[1].items[1].columnWidth = 0.3; //меняем размеры колонок | |
self.fields.items[2].items[1].items[0].columnWidth = 0.3; | |
self.fields.items[2].items[1].items.push({ //добавляем новый input diplayfield | |
columnWidth: 0.3, | |
border: false, | |
layout: 'form', | |
items: [ | |
{ | |
anchor: '100%', | |
fieldLabel: 'Email', | |
name: 'non_rec', | |
xtype: 'displayfield', | |
html: 'Еще не загружено', | |
id: 'emailFieldAjax' //создаем alias для того, чтобы в дальнейшем получить объект через getCmp | |
}, | |
{ | |
anchor: '100%', | |
fieldLabel: 'Юридическое лицо', | |
name: 'uric', | |
value: uric?"Да":"Нет", | |
xtype: 'displayfield', | |
html: uric?"Да":"Нет", | |
id: 'uricField' | |
} | |
] | |
}); | |
Ext.Ajax.request({ //делаем ajax запрос на наш контроллер | |
url: '/assets/components/XXXXXX/action.php', | |
success: function(resp) { | |
Ext.getCmp('emailFieldAjax').setValue(resp.responseText); //получаем то, что вернул наш контроллер | |
}, | |
failure: function(resp) { | |
Ext.Msg.alert('Внимание', 'Ошибка ajax запроса'); | |
}, | |
params: { id: user_id } | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment