Kriss Kriss - 3 months ago 21
Ajax Question

Using Ajax request on Override AdminOrdersController in PrestaShop 1.6

I saw similar topics, but it did not help :(

PS: 1.6.1.1

Overview:
Is there any "magic" code that override of AdminOrdersController must include to gets ajax request (jQuery) ?

Details:
I have Ajax request called on Orders List page. When this request is "reciced" by function located in oryginal AdminOrdersController , it runs fine !

But just when I move the function that gets the call from Ajax, to separated file in /override/controllers/admin/ , it fails. -> no answer from request.

Why ???

I suppose I should add something that "gives" URL for Ajax, but I don't know what...

Thanks in advace !

This is JS with Ajax request. It works even without URL parameter, becouse it calls the currant page.

$(function() { $('.notice_show').on('click', function() {
var $scope = $(this);
var $tr = $scope.closest('tr');
var $length = $tr.find('td').length;
var $ajax_run = null;
var $element = null;
var $notice_show_content = null;

if (!$scope.data('show')) {
$scope.data('show', true);
$tr.after('<tr class="not_show"><td colspan="'+$length+'"><span class="not_show_ajax_running"><i class="icon-refresh icon-spin icon-fw"></i></span><span class="notice_show_content"></span></td></tr>');
$element = $tr.next('.not_show');
$notice_show_content = $element.find('.notice_show_content');
$ajax_run = $element.find('.not_show_ajax_running');
$ajax_run.show();
$.ajax({
data: {
get_notice: true,
id_order: $scope.attr('attr-id')
},
dataType: 'json',
type: 'POST',
success: function($response) {
if ($response.error) {
$.notify($response.error, 'error', 2000);
} else {
$notice_show_content.html($response.content);
}
},
complete: function() {
$ajax_run.hide();
}
});
} else {
$scope.data('show', false);
$tr.next('.not_show').remove();
}


});
});

This is function added to AdminOrdersController. It works ONLY IF it's added to the oryginal file. If it's in override folder it fails.

public function renderList()
{

return parent::renderList();

if (Tools::isSubmit('get_notice') && ($id_order = Tools::getValue('id_order', NULL))) {
$result = array(
'error' => false,
'content' => ''
);
$order = new Order($id_order);
if (Validate::isLoadedObject($order)) {
$notices = NoticeOrder::get($order->id);
if ($notices) {
foreach($notices as &$notice) {
$emp = new Employee($notice->id_employee);
if (Validate::isLoadedObject($emp)) {
$notice->employee = $emp->firstname . ' ' . $emp->lastname;
} else {
$notice->employee = '';
}
}
$this->context->smarty->assign(array(
'notice' => $notices,
'not_add' => true
));

$result['content'] = $this->createTemplate('_notice.tpl')->fetch();

$address = new Address($order->id_address_delivery);

if (Validate::isLoadedObject($address)) {
if ($address->other) {
$this->context->smarty->assign(array(
'addresses' => array(
'delivery' => $address
),
));
$result['content'] .= $this->createTemplate('_other.tpl')->fetch();
}
}

} else {
$result['error'] = $this->l('Notice not found');
}
} else {
$result['error'] = $this->l('Order not found');
}

echo Tools::jsonEncode($result);
die;
}

}

Answer

Your problem is here and not related with AJAX

public function renderList()
{

return parent::renderList(); // !!! code below this line will not work
...
Comments