Merge branch 'ticket-10133' into develop

This commit is contained in:
Marion Muszynski 2016-09-15 10:25:14 +02:00
commit 1128f0583c

View File

@ -427,6 +427,122 @@ class AdminOrders extends AdminTab
}
}
// update order state if it's partial
if($order->getCurrentState() == 17) {
$partial = true;
$to_send = Db::getInstance()->ExecuteS('
SELECT `id_order_detail`, (`product_quantity` - IF(`product_quantity_return` > 0, `product_quantity_return`, `product_quantity_refunded`)) AS `quantity`, `product_id`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $order->id.'
AND (`product_quantity` - IF(`product_quantity_return` > 0, `product_quantity_return`, `product_quantity_refunded`)) > 0
');
if(count($to_send) == 0) {
$partial = false;
} else {
// include_once dirname(__FILE__).'/../../modules/privatesales/Sale.php';
// $quantities_sent = array();
// $product_ids = array();
// foreach(Db::getInstance()->ExecuteQ('
// SELECT `product_id`
// FROM `'._DB_PREFIX_.'order_detail`
// WHERE `id_order` = '.(int) $order->id.'
// ') as $row) {
// $product_ids[] = (int) $row['product_id'];
// }
//
// /**
// * @Override Philea
// */
// if(Db::getInstance()->getRow('
// SELECT *
// FROM `'._DB_PREFIX_.'philea_parcel`
// WHERE `id_order` = '.(int) $order->id.'
// ')) {
// foreach(Db::getInstance()->ExecuteS('
// SELECT c.`id_product`
// FROM `'._DB_PREFIX_.'product_ps_cache` c
// WHERE c.`id_product` IN ('.implode(', ', $products_ids).')
// ') as $row) {
// $quantities_sent[(int) $row['id_product']] = -1;
// }
// }
// $parcel_quantities = array();
// foreach($to_send as $ts) {
// if(!isset($quantities_sent[(int) $ts['product_id']])) {
// $parcel_quantities[(int) $ts['id_order_detail']] = $ts;
// }
// }
// if(count($parcel_quantities) > 0) {
// $partial = false;
// $sent_logistics = array();
// foreach(Db::getInstance()->ExecuteS('
// SELECT SUM(`quantity`) AS `quantity`, `id_order_detail`
// FROM `'._DB_PREFIX_.'lapostews`
// WHERE `id_order_detail` IN ('.implode(', ', array_keys($parcel_quantities)).')
// GROUP BY `id_order_detail`
// ') as $row) {
// $sent_logistics[(int) $row['id_order_detail']] = (int) $row['quantity'];
// }
// foreach(Db::getInstance()->ExecuteS('
// SELECT SUM(`quantity`) AS `quantity`, `id_order_detail`
// FROM `'._DB_PREFIX_.'exapaqws`
// WHERE `id_order_detail` IN ('.implode(', ', array_keys($parcel_quantities)).')
// GROUP BY `id_order_detail`
// ') as $row) {
// $sent_logistics[(int) $row['id_order_detail']] = (int) $row['quantity'];
// }
// if(count($sent_logistics) == 0) {
// $partial = true;
// } else {
// foreach($parcel_quantities as $k => $v) {
// if(!isset($sent_logistics[(int) $k])) {
// $partial = true;
// break;
// } else {
// if($sent_logistics[(int) $k] < $v['quantity']) {
// $partial = true;
// break;
// }
// }
// }
// }
// } else {
// $partial = false;
// }
}
if(!$partial) {
global $cookie;
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'order_history`
VALUES (
DEFAULT,
'.(int) $cookie->id_employee.',
'.(int) $order->id.',
'.Configuration::get('PS_OS_SHIPPING').',
NOW()
)
');
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'order_state_current`
VALUES (
'.(int) $order->id.',
'.Configuration::get('PS_OS_SHIPPING').',
NOW()
)
ON DUPLICATE KEY UPDATE
`id_order_state` = '.Configuration::get('PS_OS_SHIPPING').',
`date_upd` = NOW()
');
$newOS = new OrderState((int)(Configuration::get('PS_OS_SHIPPING')), $order->id_lang);
Module::hookExec('updateOrderStatus', array('newOrderStatus' => $newOS, 'id_order' => (int)($order->id)));
}
}
}
else
$this->_errors[] = Tools::displayError('No product or quantity selected.');