changement for pack gestion
This commit is contained in:
parent
0a9afab232
commit
7cb36d6b0d
@ -100,7 +100,9 @@
|
||||
$id_order = (int) $id_order;
|
||||
}
|
||||
|
||||
$details[(int)$id_order] = array();
|
||||
if(!isset($details[(int)$id_order])){
|
||||
$details[(int)$id_order] = array();
|
||||
}
|
||||
|
||||
$code_art = explode("_", trim($data[9]));
|
||||
if(count($code_art)>1) {
|
||||
@ -110,7 +112,9 @@
|
||||
$id_attribute = 0;
|
||||
}
|
||||
|
||||
// GET CARRIER ID
|
||||
$order = new Order((int) $id_order);
|
||||
|
||||
// GET CARRIER ID
|
||||
$carrier_found = false;
|
||||
$id_active_carrier = false;
|
||||
$id_inactive_carrier = false;
|
||||
@ -163,85 +167,95 @@
|
||||
'quantity' => (int) trim($data[10])
|
||||
);
|
||||
|
||||
$order = new Order((int) $id_order);
|
||||
$order_details[(int)$id_order] = array();
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT `id_order_detail`, `product_id`, `product_attribute_id`, `product_quantity` - GREATEST(`product_quantity_return`, `product_quantity_refunded`) AS `quantity`
|
||||
FROM `'._DB_PREFIX_.'order_detail`
|
||||
WHERE `id_order` = '.(int) $id_order.'
|
||||
') as $key => $row) {
|
||||
$sent = (int) Db::getInstance()->getValue('
|
||||
SELECT SUM(`quantity`)
|
||||
FROM `'._DB_PREFIX_.'philea_parcel`
|
||||
WHERE `id_order_detail` = '.(int) $row['id_order_detail'].'
|
||||
');
|
||||
$id_order_details[] = (int) $row['id_order_detail'];
|
||||
if(!isset($order_details[(int)$id_order])){
|
||||
$order_details[(int)$id_order] = array();
|
||||
|
||||
if(Pack::isPack((int)$row['product_id'])) {
|
||||
$items = Pack::getSimplePack($row['product_id']);
|
||||
foreach($items as $item) {
|
||||
if(!isset($order_details[$id_order][$item['id_product_item'].'_0'])) {
|
||||
$order_details[$id_order][$item['id_product_item'].'_0'] = array(
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT DISTINCT `id_order_detail`, `product_id`, `product_attribute_id`, `product_quantity` - GREATEST(`product_quantity_return`, `product_quantity_refunded`) AS `quantity`
|
||||
FROM `'._DB_PREFIX_.'order_detail`
|
||||
WHERE `id_order` = '.(int) $id_order.'
|
||||
') as $key => $row) {
|
||||
$sent = (int) Db::getInstance()->getValue('
|
||||
SELECT SUM(`quantity`)
|
||||
FROM `'._DB_PREFIX_.'philea_parcel`
|
||||
WHERE `id_order_detail` = '.(int) $row['id_order_detail'].'
|
||||
');
|
||||
$id_order_details[] = (int) $row['id_order_detail'];
|
||||
if(Pack::isPack((int)$row['product_id'])) {
|
||||
$items = Pack::getSimplePack($row['product_id']);
|
||||
foreach($items as $item) {
|
||||
if(!isset($order_details[(int)$id_order][$item['id_product_item'].'_0'])) {
|
||||
$order_details[(int)$id_order][$item['id_product_item'].'_0'] = array(
|
||||
'id_order_details' => array(),
|
||||
'quantity_to_sent' => 0
|
||||
);
|
||||
}
|
||||
$order_details[$id_order][$item['id_product_item'].'_0']['quantity_to_sent'] += (($row['quantity'] - $sent) * $item['quantity']);
|
||||
$order_details[$id_order][$item['id_product_item'].'_0']['id_order_details'][$row['id_order_detail']] = array(
|
||||
'detail_quantity' => ($row['quantity'] - $sent),
|
||||
'id_order_detail' => $row['id_order_detail']
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if(!isset($order_details[(int)$id_order][$row['product_id'].'_'.$row['product_attribute_id']])) {
|
||||
$order_details[(int)$id_order][$row['product_id'].'_'.$row['product_attribute_id']] = array(
|
||||
'id_order_details' => array(),
|
||||
'quantity_to_sent' => 0
|
||||
);
|
||||
}
|
||||
$order_details[$id_order][$item['id_product_item'].'_0']['quantity_to_sent'] += (($row['quantity'] - $sent) * $item['quantity']);
|
||||
$order_details[$id_order][$item['id_product_item'].'_0']['id_order_details'][$row['id_order_detail']] = array(
|
||||
$order_details[(int)$id_order][$row['product_id'].'_'.$row['product_attribute_id']]['quantity_to_sent'] += ($row['quantity'] - $sent);
|
||||
$order_details[(int)$id_order][$row['product_id'].'_'.$row['product_attribute_id']]['id_order_details'][$row['id_order_detail']] = array(
|
||||
'detail_quantity' => ($row['quantity'] - $sent),
|
||||
'id_order_detail' => $row['id_order_detail']
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if(!isset($order_details[$id_order][$row['product_id'].'_'.$row['product_attribute_id']])) {
|
||||
$order_details[$id_order][$row['product_id'].'_'.$row['product_attribute_id']] = array(
|
||||
'id_order_details' => array(),
|
||||
'quantity_to_sent' => 0
|
||||
);
|
||||
}
|
||||
$order_details[$id_order][$row['product_id'].'_'.$row['product_attribute_id']]['quantity_to_sent'] += ($row['quantity'] - $sent);
|
||||
$order_details[$id_order][$item['id_product_item'].'_0']['id_order_details'][$row['id_order_detail']] = array(
|
||||
'detail_quantity' => ($row['quantity'] - $sent),
|
||||
'id_order_detail' => $row['id_order_detail']
|
||||
);
|
||||
}
|
||||
}
|
||||
} // end foreach lines
|
||||
|
||||
foreach($order_details as $order => $order_detail){
|
||||
foreach ($order_detail as $key => $product) {
|
||||
if(isset($details[(int)$order][$key]) && $details[(int)$order][$key]['quantity'] <= $product['quantity_to_sent']) {
|
||||
if(count($details[(int)$order][$key]['shipping_numbers'])>1) {
|
||||
foreach($details[(int)$order][$key]['shipping_numbers'] as $shipping_number) {
|
||||
if(isset($details[(int)$order][$key])) {
|
||||
if($details[(int)$order][$key]['quantity'] <= $product['quantity_to_sent']) {
|
||||
if(count($details[(int)$order][$key]['shipping_numbers'])>1) {
|
||||
foreach($details[(int)$order][$key]['shipping_numbers'] as $shipping_number) {
|
||||
foreach($product['id_order_details'] as $id_order_detail => $row) {
|
||||
Db::getInstance()->ExecuteS('
|
||||
INSERT INTO `'._DB_PREFIX_.'philea_parcel`
|
||||
VALUES (
|
||||
'.(int) $id_order_detail.',
|
||||
'.(int) $row['detail_quantity'].',
|
||||
"'.pSQL($shipping_number['number']).'",
|
||||
"'.$shipping_number['date'].'"
|
||||
)
|
||||
');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach($product['id_order_details'] as $id_order_detail => $row) {
|
||||
Db::getInstance()->ExecuteS('
|
||||
INSERT INTO `'._DB_PREFIX_.'philea_parcel`
|
||||
VALUES (
|
||||
'.(int) $id_order_detail.',
|
||||
'.(int) $row['detail_quantity'].',
|
||||
"'.pSQL($shipping_number['number']).'",
|
||||
"'.$shipping_number['date'].'"
|
||||
"'.pSQL($details[(int)$order][$key]['shipping_numbers'][0]['number']).'",
|
||||
"'.$details[(int)$order][$key]['shipping_numbers'][0]['date'].'"
|
||||
)
|
||||
');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach($product['id_order_details'] as $id_order_detail => $row) {
|
||||
Db::getInstance()->ExecuteS('
|
||||
INSERT INTO `'._DB_PREFIX_.'philea_parcel`
|
||||
VALUES (
|
||||
'.(int) $id_order_detail.',
|
||||
'.(int) $row['detail_quantity'].',
|
||||
"'.pSQL($details[(int)$order][$key]['shipping_numbers'][0]['number']).'",
|
||||
"'.$details[(int)$order][$key]['shipping_numbers'][0]['date'].'"
|
||||
)
|
||||
');
|
||||
}
|
||||
} else {
|
||||
$message = "Commande : ".$order."\r\n Produit : ".$key."\r\n Quantity to sent : ".$product['quantity_to_sent']."\r\n Quantity : ".$details[(int)$order][$key]['quantity'];
|
||||
mail('marion@antadis.com', '[BBB] Erreurs quantity expe Philea', $message);
|
||||
}
|
||||
} else {
|
||||
$message = "Commande : ".$order."\r\n Produit : ".$key."\r\n Produit non présent dans le fichier expe philea";
|
||||
mail('marion@antadis.com', '[BBB] Erreurs produit expe Philea', $message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($details);
|
||||
unset($order_details);
|
||||
} // end if lines
|
||||
|
||||
$id_order_details = array_unique($id_order_details);
|
||||
@ -440,12 +454,14 @@
|
||||
$history = new OrderHistory();
|
||||
$history->id_order = (int) $order->id;
|
||||
$history->changeIdOrderState(4, (int) $order->id);
|
||||
$history->addWithemail(true, $templateVars);
|
||||
//$history->addWithemail(true, $templateVars);
|
||||
$history->add();
|
||||
} elseif(in_array($order->id, $status_partially_sent)) {
|
||||
$history = new OrderHistory();
|
||||
$history->id_order = (int) $order->id;
|
||||
$history->changeIdOrderState(17, (int) $order->id);
|
||||
$history->addWithemail(true, $templateVars);
|
||||
//$history->addWithemail(true, $templateVars);
|
||||
$history->add();
|
||||
}
|
||||
|
||||
$subjects = array(
|
||||
@ -476,9 +492,9 @@
|
||||
mkdir($repo_archive);
|
||||
}
|
||||
|
||||
copy($datFile, $repo_archive . preg_replace( '@BAL$@', 'DAT', $fileinfo->getFilename() ));
|
||||
unlink($inFolder.$fileinfo->getFilename());
|
||||
unlink($datFile);
|
||||
// copy($datFile, $repo_archive . preg_replace( '@BAL$@', 'DAT', $fileinfo->getFilename() ));
|
||||
// unlink($inFolder.$fileinfo->getFilename());
|
||||
// unlink($datFile);
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user