Hope someone can help, as been trying for hours and hours tonight to crack this:
admin.php?dispatch=cart.cart_list
By default it is sorting by customer and i can see in
app/controllers/backend/cart.php
$sorting = db_sort($params, $sortings, 'customer', 'asc');
Now i know i can simply add or rather replace with:
$sorting = db_sort($params, $sortings, 'date', 'desc');
which does work, but i want to override this really within my addon, ive tried with a hook from what hook i found in that file, tried with cart.post.php and under $mode to do a redirect with fn_redirect and another method but then broke search... im sure im missing some real easy way of doing this? can someone help?
Try to create the cart.pre.php and use the following code for the cart_list mode:
if (empty($_REQUEST['sort_by'])) {
$_REQUEST['sort_by'] = 'date';
}
Try to create the cart.pre.php and use the following code for the cart_list mode:
if (empty($_REQUEST['sort_by'])) {
$_REQUEST['sort_by'] = 'date';
}
Thanks for getting back to me mate, i removed the cart.post.php file i added and created cart.pre.php file in /app/addons/abandoned_cart_extended/controllers/backend/ with the following code:
if (!defined(‘BOOTSTRAP’)) { die(‘Access denied’); }
if ($mode == ‘cart_list’) {
if (empty($_REQUEST['sort_by'])) {
$_REQUEST['sort_by'] = 'date';
}
}
But when i went to:
admin.php?dispatch=cart.cart_list
Did not seem to do anything, just defaulted to the Customer sorting as defined in cart.php default backend controller file
Any ideas? really want to avoid editing the cart.php controller ideally.
Thanks again mate
Ok worked it out, thought would try it directly in the URL and did not sort by date, but if i also done sort_order=desc it worked so with the following it done the trick! so simple, i tried for hours and hours yesterday trying different things, php, js work arounds haha
Thanks for your help mate as just got me in the right direction, for anyone else this is the solution:
if ($mode == 'cart_list') {
if (empty($_REQUEST['sort_by'])) {
$_REQUEST['sort_by'] = 'date';
$_REQUEST['sort_order'] = 'desc';
}
}
Works 4.6 like this
app/functions/fn_cart.php
Change This
$sorting = db_sort($params, $sortings, 'customer', 'asc');
To This
$sorting = db_sort($params, $sortings, 'date', 'desc');
But how can i add in
app/addons/my_changes
Unfortunately, the fn_get_carts function does not have hooks
Try to use cart.pre.php controller and add something like this
use Tygh\Registry;
if (!defined(‘BOOTSTRAP’)) { die(‘Access denied’); }
if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’) {
return;
}
if ($mode == ‘cart_list’ && !isset($_REQUEST[‘sort_by’])) {
$_REQUEST[‘sort_by’] = ‘date’;
}
(!) Not tested