Adds a feature to the BO to search for tracking/shipping numbers.
#
#----------[ OPEN ]----------
#
admin/header.php
#
#----------[ FIND ]----------
#
<option value="4" '.(Tools::getValue('bo_search_type') == 4 ? 'selected="selected"' : '').'>'.translate('invoices').'</option>
#
#----------[ BEFORE, ADD ]----------
#
<option value="8" '.(Tools::getValue('bo_search_type') == 8 ? 'selected="selected"' : '').'>'.translate('tracking numbers').'</option>
#
#----------[ OPEN ]----------
#
admin/tabs/AdminSearch.php
#
#----------[ FIND ]----------
#
function postProcess()
#
#----------[ BEFORE, ADD ]----------
#
/**
* Search a shipping number in the orders
*
* @params string $query String to find in the catalog
*/
public function searchShippingNumber($query)
{
$this->_list['shipping_numbers'] = Order::searchByShippingNumber($query);
}
#
#----------[ FIND ]----------
#
/* IP */
// 6 - but it is included in the customer block
#
#----------[ AFTER, ADD ]----------
#
/* Shipping Number */
if (!$searchType OR $searchType == 8)
{
$this->fieldsDisplay['shipping_numbers'] = (array(
'ID' => array('title' => $this->l('Order #')),
'shipping_number' => array('title' => $this->l('Tracking #')),
'customer' => array('title' => $this->l('Name')),
'address1' => array('title' => $this->l('Address')),
'city' => array('title' => $this->l('Suburb')),
'state' => array('title' => $this->l('State')),
'postcode' => array('title' => $this->l('Postcode')),
'country' => array('title' => $this->l('Country')),
'phone' => array('title' => $this->l('Phone')),
'date' => array('title' => $this->l('Delivery Date')),
'actions' => array('title' => $this->l('View'))
));
/* Normal shipping number search */
$this->searchShippingNumber($query);
}
#
#----------[ FIND ]----------
#
$nbCategories = $nbProducts = $nbCustomers = 0;
#
#----------[ REPLACE WITH ]----------
#
$nbCategories = $nbProducts = $nbCustomers = $nbShippingNumbers = 0;
#
#----------[ FIND ]----------
#
/* Display error if nothing has been matching */
if (!$nbCategories AND !$nbProducts AND !$nbCustomers)
#
#----------[ REPLACE WITH ]----------
#
/* Display shipping numbers if any has been matching */
if (isset($this->_list['shipping_numbers']) AND !empty($this->_list['shipping_numbers']) AND $nbShippingNumbers = sizeof($this->_list['shipping_numbers']))
{
echo '<h3>'.$nbShippingNumbers.' '.($nbShippingNumbers > 1 ? $this->l('tracking numbers') : $this->l('tracking number')).' '.$this->l('found with').' <b>"'.Tools::htmlentitiesUTF8($query).'"</b></h3>
<table cellspacing="0" cellpadding="0" class="table widthfull">
<tr>';
foreach ($this->fieldsDisplay['shipping_numbers'] AS $field)
echo '<th'.(isset($field['width']) ? 'style="width: '.$field['width'].'"' : '').'>'.$field['title'].'</th>';
echo '</tr>';
$irow = 0;
foreach ($this->_list['shipping_numbers'] AS $k => $shipping_number)
{
$carrier = new Carrier($shipping_number['id_carrier']);
echo '
<tr class="'.($irow++ % 2 ? 'alt_row' : '').'">
<td>'.$shipping_number['id_order'].'</td>
<td>'.$shipping_number['shipping_number'].'</td>
<td>'.stripslashes($shipping_number['firstname']).' '.stripslashes($shipping_number['lastname']).'</td>
<td>'.$shipping_number['address1'].'</td>
<td>'.$shipping_number['city'].'</td>
<td>'.$shipping_number['state'].'</td>
<td class="center">'.$shipping_number['postcode'].'</td>
<td>'.$shipping_number['country'].'</td>
<td>'.($shipping_number['phone_mobile'] ? $shipping_number['phone_mobile'] : $shipping_number['phone']).'</td>
<td align="center">'.Tools::displayDate($shipping_number['delivery_date'], (int)$cookie->id_lang, true).'</td>
<td class="center" width="40px">
<a href="'.str_replace('@', $shipping_number['shipping_number'], $carrier->url).'" target="_blank">
<img src="../img/admin/supplier.gif" alt="'.$this->l('Track order').'" /></a>
<a href="'.$currentIndex.'?tab=AdminOrders&id_order='.$shipping_number['id_order'].'&vieworder&token='.Tools::getAdminToken('AdminOrders'.(int)(Tab::getIdFromClassName('AdminOrders')).(int)($cookie->id_employee)).'">
<img src="../img/admin/details.gif" alt="'.$this->l('View order').'" /></a>
</td>
</tr>';
}
echo '</table>
<div class="clear"> </div>';
}
/* Display error if nothing has been matching */
if (!$nbCategories AND !$nbProducts AND !$nbCustomers AND !$nbShippingNumbers)
#
#----------[ OPEN ]----------
#
classes/Order.php
#
#----------[ FIND ]----------
#
public function deleteAssociations()
{
return (Db::getInstance()->Execute('
DELETE FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int)($this->id)) !== false);
}
#
#----------[ AFTER, ADD ]----------
#
/**
* Light back office search for shipping numbers
*
* @param string $query Searched string
* @return array Corresponding shipping number
*/
public static function searchByShippingNumber($query)
{
global $cookie;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT o.`shipping_number`, o.`id_order`, o.`delivery_date`, o.`id_carrier`, a.`firstname`, a.`lastname`, a.`address1`, a.`city`, a.`postcode`, a.`phone_mobile`, a.`phone`, s.`name` as state, cl.`name` as country
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'address` a ON (a.`id_address` = o.`id_address_delivery`)
LEFT JOIN `'._DB_PREFIX_.'state` s ON (s.`id_state` = a.`id_state`)
LEFT JOIN `'._DB_PREFIX_.'country_lang` cl ON (cl.`id_country` = a.`id_country` AND cl.`id_lang` = '.(int)($cookie->id_lang).')
WHERE o.shipping_number LIKE \'%'.pSQL($query).'%\'
ORDER BY o.`shipping_number` DESC');
}