cubecart / v6

CubeCart Version 6
https://cubecart.com
72 stars 59 forks source link

Code Refactor: Orders List Tasks #3488

Closed bhsmither closed 6 months ago

bhsmither commented 6 months ago

Currently, the admin template orders.index.php has hard-coded tasks in a drop-down selector below the list of orders: nothing, print, delete.

Suggest this become coded as a {foreach}:

/// Existing code                  <select name="multi-action" class="textbox">
                     {foreach $LIST_ORDER_TASKS as $tasks}
                     {if $tasks.opt_group_name}
                     <optgroup label="{$tasks.opt_group_name}">
                     {/if}
                     {foreach $tasks.selections as $task}
                       <option value="{$task.value}" style="{$task.style}">{$task.string}</option>
                     {/foreach}
                     {if $tasks.opt_group_name}
                     </optgroup>
                     {/if}
                     {/foreach}
/// Existing code                  </select>

The array to be built in the source code (near line 779):

/// Existing code    $where = (isset($where) && !empty($where)) ? $where : false;

$smarty_data['order_tasks'][] = array(
        'opt_group_name' => "Test", // Leave blank for no option grouping for this group
        'selections' => array(
            array('value' => "", 'string' => $lang['orders']['option_nothing'], 'style' => ""),
            array('value' => "print", 'string' => $lang['orders']['option_print'], 'style' => ""),
            array('value' => "delete", 'string' => $lang['orders']['option_delete'], 'style' => "color: red"),
        )
);
$GLOBALS['smarty']->assign('LIST_ORDER_TASKS', $smarty_data['order_tasks']);

foreach ($GLOBALS['hooks']->load('admin.order.index.table_orders') as $hook) {
    include $hook;
}

/// Existing code    for ($i = 1;$i <= 6; ++$i) {

Note the new hook! This hook could be placed just after:

$GLOBALS['smarty']->assign('LIST_ORDER_STATUS', $smarty_data['order_status']);

or just before assigning the statuses and tasks to Smarty.

So as to provide a means for plugins to push onto the list of Order Status options, as well as to push onto the list of Task options.

An additional task might involve selecting specific orders for an export to a CSV file.

abrookbanks commented 6 months ago

Thanks. I didn't follow your logic of having the hook after the assign method but my take on this seems to work ok.

This can allow for new order statuses but it's quite far reaching. For now this is useful for extra tasks other then print & delete.