fix conflicts

This commit is contained in:
Marion Muszynski 2016-12-08 15:46:19 +01:00
commit f4e2256c65
8 changed files with 1647 additions and 1100 deletions

View File

@ -3,8 +3,9 @@ $_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/../../config/config.inc.php'; include dirname(__FILE__).'/../../config/config.inc.php';
if(isset($_SERVER['REMOTE_ADDR'])) { if(isset($_SERVER['REMOTE_ADDR'])) {
exit; exit;
} }
// CHECKING RUNNING OF CRON_SALE_CACHE // CHECKING RUNNING OF CRON_SALE_CACHE
$fileName = 'cron_sale_cache.php'; $fileName = 'cron_sale_cache.php';
$output = shell_exec("ps -ax | grep $fileName | wc -l"); $output = shell_exec("ps -ax | grep $fileName | wc -l");
@ -26,39 +27,39 @@ if($row = Db::getInstance()->getRow('
WHERE `id_sale` = '.(int) $row['id_sale'].' WHERE `id_sale` = '.(int) $row['id_sale'].'
'); ');
if($associated_products > 0) { if($associated_products > 0) {
// SEND ART01 // SEND ART01
Db::getInstance()->ExecuteS(' Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'philea_sync` UPDATE `'._DB_PREFIX_.'philea_sync`
SET `status` = 1 SET `status` = 1
WHERE `id_sync` = '.(int) $row['id_sync'].' WHERE `id_sync` = '.(int) $row['id_sync'].'
LIMIT 1 LIMIT 1
'); ');
system('cd '.dirname(__FILE__).'/script && php send_article.php '.(int) $row['id_sale']); system('cd '.dirname(__FILE__).'/script && php send_article.php '.(int) $row['id_sale']);
sleep(20); sleep(20);
// SEND REC01 - pas de gestion recption fournisseur sur bbb // SEND REC01 - pas de gestion recption fournisseur sur bbb
Db::getInstance()->ExecuteS(' Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'philea_sync` UPDATE `'._DB_PREFIX_.'philea_sync`
SET `status` = 2 SET `status` = 2
WHERE `id_sync` = '.(int) $row['id_sync'].' WHERE `id_sync` = '.(int) $row['id_sync'].'
LIMIT 1 LIMIT 1
'); ');
/*system('cd '.dirname(__FILE__).'/script && php send_recep_orderform.php '.(int) $row['id_sale']);*/ /*system('cd '.dirname(__FILE__).'/script && php send_recep_orderform.php '.(int) $row['id_sale']);*/
} }
} }
if($row = Db::getInstance()->getRow(' if($row = Db::getInstance()->getRow('
SELECT * SELECT *
FROM `'._DB_PREFIX_.'philea_sync` FROM `'._DB_PREFIX_.'philea_sync`
WHERE `status` = 3 WHERE `status` = 3
ORDER BY `date_add` ASC ORDER BY `date_add` ASC
')) { ')) {
// SEND CDC02 // SEND CDC02
Db::getInstance()->ExecuteS(' Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'philea_sync` UPDATE `'._DB_PREFIX_.'philea_sync`
SET `status` = 4 SET `status` = 4
WHERE `id_sync` = '.(int) $row['id_sync'].' WHERE `id_sync` = '.(int) $row['id_sync'].'
LIMIT 1 LIMIT 1
'); ');
system('cd '.dirname(__FILE__).'/script && php send_commande.php '.(int) $row['id_sale']); system('cd '.dirname(__FILE__).'/script && php send_commande.php '.(int) $row['id_sale']);
} }

View File

@ -40,8 +40,8 @@ if(is_object($iterator) && count($iterator)) {
foreach($xml->Listing->Message as $message) { foreach($xml->Listing->Message as $message) {
//$result[] = ((string) $message['bloquant'] == 'False'? '<span>[W]': '<span style="color:red;">[E]').' '.(string) $message['codeArticle'].' : </span>'.(string) $message; //$result[] = ((string) $message['bloquant'] == 'False'? '<span>[W]': '<span style="color:red;">[E]').' '.(string) $message['codeArticle'].' : </span>'.(string) $message;
if((string) $message['bloquant'] == 'True') { if((string) $message['bloquant'] != 'False') {
$result[] = ((string) $message['bloquant'] == 'False'? '': '<span style="color:red;">[E]').' '.(string) $message['codeArticle'].' : </span>'.(string) $message; $result[] = '<span style="color:red;">[E] '.(string) $message['codeArticle'].' : </span>'.(string) $message;
$errors[] = (string) $message['codeArticle'].' : '.(string) $message; $errors[] = (string) $message['codeArticle'].' : '.(string) $message;
} }
} }
@ -51,9 +51,8 @@ if(is_object($iterator) && count($iterator)) {
if($result == '') { if($result == '') {
$result = "RAS"; $result = "RAS";
} else { } else {
$errors = nl2br(implode("\r\n", $errors)); $errors = implode("\n", $errors);
$errors = wordwrap($errors, 70, "\r\n"); mail('marion@antadis.com', '[BBB] article bloquant Philea', $file."\n".$errors);
mail('marion@antadis.com', '[BBB] bloquant Philea', $errors);
} }
Db::getInstance()->Execute(' Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'philea_syncreport` UPDATE `'._DB_PREFIX_.'philea_syncreport`
@ -80,10 +79,9 @@ if(is_object($iterator) && count($iterator)) {
if($result == '') { if($result == '') {
$result = "RAS"; $result = "RAS";
} else { } else {
$errors = nl2br(implode("\r\n", $errors)); $errors = implode("\n", $errors);
$errors = wordwrap($errors, 70, "\r\n"); mail('marion@antadis.com', '[BBB] cmd bloquante Philea', $file."\n".$errors);
mail('marion@antadis.com', '[BBB] blocant Philea', $datFile."\r\n".$errors); //mail('jacques@bebeboutik.com', '[BBB] cmd bloquante Philea', $errors);
//mail('jacques@bebeboutik.com', '[BBB] blocant Philea', $errors);
} }
Db::getInstance()->Execute(' Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'philea_syncreport` UPDATE `'._DB_PREFIX_.'philea_syncreport`

View File

@ -69,11 +69,14 @@
$content = file_get_contents($datFile); $content = file_get_contents($datFile);
$lines = preg_split('@\n@',$content); $lines = preg_split('@\n@',$content);
$id_order_details = array(); $id_order_details = array();
$shipping_numbers = array(); $shipping_numbers = array();
$parcel_carrier = array(); $parcel_carrier = array();
if(!empty($lines)) { if(!empty($lines)) {
$details = array();
$order_details = array();
// GET DATA
foreach( $lines as $line ) { foreach( $lines as $line ) {
$data = array(); $data = array();
@ -98,7 +101,9 @@
$id_order = (int) $id_order; $id_order = (int) $id_order;
} }
$order = new Order((int) $id_order); if(!isset($details[(int)$id_order])){
$details[(int)$id_order] = array();
}
$code_art = explode("_", trim($data[9])); $code_art = explode("_", trim($data[9]));
if(count($code_art)>1) { if(count($code_art)>1) {
@ -107,350 +112,380 @@
$id_product = $code_art[0]; $id_product = $code_art[0];
$id_attribute = 0; $id_attribute = 0;
} }
if($detail = Db::getInstance()->getRow('
SELECT `id_order_detail`, `product_quantity` - GREATEST(`product_quantity_return`, `product_quantity_refunded`) AS `quantity`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $id_order.'
AND `product_id` = '.(int) $id_product.'
AND `product_attribute_id` = '.(int) $id_attribute.'
')) {
$sent = (int) Db::getInstance()->getValue('
SELECT SUM(`quantity`)
FROM `'._DB_PREFIX_.'philea_parcel`
WHERE `id_order_detail` = '.(int) $detail['id_order_detail'].'
');
$to_send = (int) $detail['quantity'] - $sent; $order = new Order((int) $id_order);
if((int) $data[10] <= $to_send) { // GET CARRIER ID
if(trim($data[5]) != '') { $carrier_found = false;
Db::getInstance()->ExecuteS(' $id_active_carrier = false;
INSERT INTO `'._DB_PREFIX_.'philea_parcel` $id_inactive_carrier = false;
VALUES ( if (isset($data[8]) && $data[8]){
'.(int) $detail['id_order_detail'].', $carrier_name = trim($data[8]);
'.(int) $data[10].', if($carrier_name == 'COLINT') {
"'.pSQL(trim($data[5])).'", $carrier_name = 'SOCOLMDSS';
"'.pSQL(substr($data[7], 0, 4).'-'.substr($data[7], 4, 2).'-'.substr($data[7], 6, 2).' 18:00:00').'" }
) $carriers = philea_magistor::getCarriersIdByRef($carrier_name);
'); if ($carriers){
foreach ($carriers as $carrier) {
$id_order_details[] = (int) $detail['id_order_detail']; if ($carrier['name'] == 'GLS' && $carrier_name == 'DPD') {
$shipping_numbers[] = '"'.pSQL(trim($data[5])).'"'; continue;
// GET CARRIER ID
$carrier_found = false;
$id_active_carrier = false;
$id_inactive_carrier = false;
if (isset($data[8]) && $data[8]){
$carrier_name = trim($data[8]);
$carriers = philea_magistor::getCarriersIdByRef($carrier_name);
if ($carriers){
foreach ($carriers as $carrier) {
if ($carrier['name'] == 'GLS' && $carrier_name == 'DPD') {
continue;
}
if ($carrier['active'] == 1 && $carrier['deleted'] == 0) {
$id_active_carrier = (int) $carrier['id_carrier'];
}
if ($carrier['active'] == 0 && $carrier['deleted'] == 0) {
$id_inactive_carrier = (int) $carrier['id_carrier'];
}
if ((int) $order->id_carrier == (int) $carrier['id_carrier']){
$carrier_found = (int) $order->id_carrier;
}
}
}
} }
if ($carrier['active'] == 1 && $carrier['deleted'] == 0) {
$id_active_carrier = (int) $carrier['id_carrier'];
}
if ($carrier['active'] == 0 && $carrier['deleted'] == 0) {
$id_inactive_carrier = (int) $carrier['id_carrier'];
}
if ((int) $order->id_carrier == (int) $carrier['id_carrier']){
$carrier_found = (int) $order->id_carrier;
}
}
}
}
if ($carrier_found) if ($carrier_found)
$id_carrier = (int) $carrier_found; $id_carrier = (int) $carrier_found;
elseif ($id_active_carrier) elseif ($id_active_carrier)
$id_carrier = (int) $id_active_carrier; $id_carrier = (int) $id_active_carrier;
elseif ($id_inactive_carrier) elseif ($id_inactive_carrier)
$id_carrier = (int) $id_inactive_carrier; $id_carrier = (int) $id_inactive_carrier;
else else
$id_carrier = (int) $order->id_carrier; $id_carrier = (int) $order->id_carrier;
if(isset($id_carrier) && $id_carrier) { if(isset($id_carrier) && $id_carrier) {
$parcel_carrier[(int) $id_order.'|'.trim($data[5])] = $id_carrier; $parcel_carrier[(int) $id_order.'|'.trim($data[5])] = $id_carrier;
} else { // MISSING CARRIER }
$errors[] = array(
$data[3], $shipping_numbers[] = '"'.pSQL(trim($data[5])).'"';
$data[8], // carrier name
$data[9], // code article productId_attributeId if(!isset($details[(int)$id_order][$id_product.'_'.$id_attribute])) {
$data[10], // quantity $details[(int)$id_order][$id_product.'_'.$id_attribute] = array(
$data[5], // shipping number 'shipping_numbers' => array(),
$data[7], 'quantity' => 0
'carrier_missing', );
}
$details[(int)$id_order][$id_product.'_'.$id_attribute]['quantity'] += (int) trim($data[10]);
$details[(int)$id_order][$id_product.'_'.$id_attribute]['shipping_numbers'][] = array(
'number' => trim($data[5]),
'date' => pSQL(substr($data[7], 0, 4).'-'.substr($data[7], 4, 2).'-'.substr($data[7], 6, 2).' 18:00:00'),
'quantity' => (int) trim($data[10])
);
if(!isset($order_details[(int)$id_order])){
$order_details[(int)$id_order] = 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 { // SHIPPING NUMBER IS EMPTY } else {
$errors[] = array( if(!isset($order_details[(int)$id_order][$row['product_id'].'_'.$row['product_attribute_id']])) {
$data[3], $order_details[(int)$id_order][$row['product_id'].'_'.$row['product_attribute_id']] = array(
$data[8], 'id_order_details' => array(),
$data[9], 'quantity_to_sent' => 0
$data[10], );
$data[5], }
$data[7], $order_details[(int)$id_order][$row['product_id'].'_'.$row['product_attribute_id']]['quantity_to_sent'] += ($row['quantity'] - $sent);
'empty_shipping_number', $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 {
// TOO MUCH
$errors[] = array(
$data[3],
$data[8],
$data[9],
$data[10],
$data[5],
$data[7],
'wrong_quantities',
);
} }
} else { }
// NOT FOUND } // end foreach lines
$errors[] = array(
$data[3], foreach($order_details as $order => $order_detail){
$data[8], foreach ($order_detail as $key => $product) {
$data[9], if(isset($details[(int)$order][$key])) {
$data[10], if($details[(int)$order][$key]['quantity'] <= $product['quantity_to_sent']) {
$data[5], if(count($details[(int)$order][$key]['shipping_numbers'])>1) {
$data[7], foreach($details[(int)$order][$key]['shipping_numbers'] as $shipping_number) {
'product_not_found', 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($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);
$shipping_numbers = array_unique($shipping_numbers);
if(count($id_order_details) > 0) {
$id_orders = array();
$orders_infos = array();
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order`, p.`shipping_number`, p.`date_add`
FROM `'._DB_PREFIX_.'philea_parcel` p
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (p.`id_order_detail` = d.`id_order_detail`)
WHERE d.`id_order_detail` IN ('.implode(', ', $id_order_details).')
AND p.`shipping_number` IN ('.implode(', ', $shipping_numbers).')
GROUP BY d.`id_order`, p.`shipping_number`
') as $row) {
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'shipping_history`
VALUES (
'.(int) $row['id_order'].',
"'.pSQL($row['shipping_number']).'",
"'.pSQL($row['date_add']).'",
'.(int) $parcel_carrier[(int) $row['id_order'].'|'.$row['shipping_number']].',
0
)
');
$id_orders[] = (int) $row['id_order'];
if(!isset($orders_infos[(int) $row['id_order']])) {
$orders_infos[(int) $row['id_order']] = array();
}
$orders_infos[(int) $row['id_order']][] = array($row['shipping_number'], $row['date_add'], (int) $parcel_carrier[(int) $row['id_order'].'|'.$row['shipping_number']]);
}
$id_orders = array_unique($id_orders);
$products = Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, d.`id_order`, c.`id_sale`, d.`product_quantity` - GREATEST(d.`product_quantity_refunded`, d.`product_quantity_return`) AS `quantity`
FROM ps_order_detail d
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c ON (d.`product_id` = c.`id_product`)
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
');
$sent_sales = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_order`, `id_sale`
FROM `'._DB_PREFIX_.'shipping_history`
WHERE `id_order` IN ('.implode(', ', $id_orders).')
AND `id_sale` != 0
GROUP BY `id_order`, `id_sale`
') as $row) {
if(!isset($sent_sales[(int) $row['id_order']])) {
$sent_sales[(int) $row['id_order']] = array();
}
$sent_sales[(int) $row['id_order']][] = (int) $row['id_sale'];
}
$to_send = array();
foreach($products as $product) {
if ((int) $product['quantity'] > 0
&& (!isset($sent_sales[(int) $product['id_order']])
|| !in_array((int) $product['id_sale'], $sent_sales[(int) $product['id_order']]))) {
$to_send[] = $product;
} }
} }
$id_order_details = array_unique($id_order_details); unset($products);
$shipping_numbers = array_unique($shipping_numbers);
if(count($id_order_details) > 0) { $sent_products = array();
$id_orders = array(); foreach(Db::getInstance()->ExecuteS('
$orders_infos = array(); SELECT l.`id_order_detail`, SUM(l.`quantity`) AS `quantity`
FROM `'._DB_PREFIX_.'lapostews` l
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (l.`id_order_detail` = d.`id_order_detail`)
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
GROUP BY l.`id_order_detail`
') as $row) {
$sent_products[(int) $row['id_order_detail']] = (int) $row['quantity'];
}
foreach(Db::getInstance()->ExecuteS('
SELECT l.`id_order_detail`, SUM(l.`quantity`) AS `quantity`
FROM `'._DB_PREFIX_.'philea_parcel` l
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (l.`id_order_detail` = d.`id_order_detail`)
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
GROUP BY l.`id_order_detail`
') as $row) {
$sent_products[(int) $row['id_order_detail']] = (int) $row['quantity'];
}
foreach(Db::getInstance()->ExecuteS(' $orders_to_send = array();
SELECT d.`id_order`, p.`shipping_number`, p.`date_add` $orders_list = array();
FROM `'._DB_PREFIX_.'philea_parcel` p
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (p.`id_order_detail` = d.`id_order_detail`)
WHERE d.`id_order_detail` IN ('.implode(', ', $id_order_details).')
AND p.`shipping_number` IN ('.implode(', ', $shipping_numbers).')
GROUP BY d.`id_order`, p.`shipping_number`
') as $row) {
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'shipping_history`
VALUES (
'.(int) $row['id_order'].',
"'.pSQL($row['shipping_number']).'",
"'.pSQL($row['date_add']).'",
'.(int) $parcel_carrier[(int) $row['id_order'].'|'.$row['shipping_number']].',
0
)
');
$id_orders[] = (int) $row['id_order']; $total = count($to_send);
if(!isset($orders_infos[(int) $row['id_order']])) {
$orders_infos[(int) $row['id_order']] = array(); foreach($to_send as $product) {
} if(!in_array((int) $product['id_order'], $orders_list)) {
$orders_infos[(int) $row['id_order']][] = array($row['shipping_number'], $row['date_add'], (int) $parcel_carrier[(int) $row['id_order'].'|'.$row['shipping_number']]); $orders_list[] = (int) $product['id_order'];
} }
if(!in_array((int) $product['id_order'], $orders_to_send)) {
$id_orders = array_unique($id_orders); if(!isset($sent_products[(int) $product['id_order_detail']])
|| $product['quantity'] > $sent_products[(int) $product['id_order_detail']]) {
$products = Db::getInstance()->ExecuteS(' $orders_to_send[] = (int) $product['id_order'];
SELECT d.`id_order_detail`, d.`id_order`, c.`id_sale`, d.`product_quantity` - GREATEST(d.`product_quantity_refunded`, d.`product_quantity_return`) AS `quantity`
FROM ps_order_detail d
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c ON (d.`product_id` = c.`id_product`)
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
');
$sent_sales = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_order`, `id_sale`
FROM `'._DB_PREFIX_.'shipping_history`
WHERE `id_order` IN ('.implode(', ', $id_orders).')
AND `id_sale` != 0
GROUP BY `id_order`, `id_sale`
') as $row) {
if(!isset($sent_sales[(int) $row['id_order']])) {
$sent_sales[(int) $row['id_order']] = array();
}
$sent_sales[(int) $row['id_order']][] = (int) $row['id_sale'];
}
$to_send = array();
foreach($products as $product) {
if ((int) $product['quantity'] > 0
&& (!isset($sent_sales[(int) $product['id_order']])
|| !in_array((int) $product['id_sale'], $sent_sales[(int) $product['id_order']]))) {
$to_send[] = $product;
} }
} }
}
unset($products); unset($sent_products);
unset($to_send);
$sent_products = array(); $orders_sent = array();
foreach(Db::getInstance()->ExecuteS(' foreach($orders_list as $order) {
SELECT l.`id_order_detail`, SUM(l.`quantity`) AS `quantity` if(!in_array($order, $orders_to_send)) {
FROM `'._DB_PREFIX_.'lapostews` l $orders_sent[] = $order;
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (l.`id_order_detail` = d.`id_order_detail`)
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
GROUP BY l.`id_order_detail`
') as $row) {
$sent_products[(int) $row['id_order_detail']] = (int) $row['quantity'];
} }
foreach(Db::getInstance()->ExecuteS(' }
SELECT l.`id_order_detail`, SUM(l.`quantity`) AS `quantity`
FROM `'._DB_PREFIX_.'philea_parcel` l unset($orders_list);
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (l.`id_order_detail` = d.`id_order_detail`)
WHERE d.`id_order` IN ('.implode(', ', $id_orders).') $status_sent = array();
GROUP BY l.`id_order_detail` $status_partially_sent = array();
') as $row) {
$sent_products[(int) $row['id_order_detail']] = (int) $row['quantity']; foreach($orders_sent as $order) {
if((int) Db::getInstance()->getValue('
SELECT `id_order_state`
FROM `'._DB_PREFIX_.'order_history`
WHERE `id_order` = '.(int) $order.'
ORDER BY `date_add` DESC LIMIT 1
') != 4) {
$status_sent[] = (int) $order;
} }
}
$orders_to_send = array(); foreach($id_orders as $order) {
$orders_list = array(); if(!in_array($order, $status_sent)) {
if(!in_array((int) Db::getInstance()->getValue('
$total = count($to_send);
foreach($to_send as $product) {
if(!in_array((int) $product['id_order'], $orders_list)) {
$orders_list[] = (int) $product['id_order'];
}
if(!in_array((int) $product['id_order'], $orders_to_send)) {
if(!isset($sent_products[(int) $product['id_order_detail']])
|| $product['quantity'] > $sent_products[(int) $product['id_order_detail']]) {
$orders_to_send[] = (int) $product['id_order'];
}
}
}
unset($sent_products);
unset($to_send);
$orders_sent = array();
foreach($orders_list as $order) {
if(!in_array($order, $orders_to_send)) {
$orders_sent[] = $order;
}
}
unset($orders_list);
$status_sent = array();
$status_partially_sent = array();
foreach($orders_sent as $order) {
if((int) Db::getInstance()->getValue('
SELECT `id_order_state` SELECT `id_order_state`
FROM `'._DB_PREFIX_.'order_history` FROM `'._DB_PREFIX_.'order_history`
WHERE `id_order` = '.(int) $order.' WHERE `id_order` = '.(int) $order.'
ORDER BY `date_add` DESC LIMIT 1 ORDER BY `date_add` DESC LIMIT 1
') != 4) { '), array(4, 17, 9, 19))) {
$status_sent[] = (int) $order; $status_partially_sent[] = (int) $order;
}
}
foreach($id_orders as $order) {
if(!in_array($order, $status_sent)) {
if(!in_array((int) Db::getInstance()->getValue('
SELECT `id_order_state`
FROM `'._DB_PREFIX_.'order_history`
WHERE `id_order` = '.(int) $order.'
ORDER BY `date_add` DESC LIMIT 1
'), array(4, 17, 9, 19))) {
$status_partially_sent[] = (int) $order;
}
}
}
unset($orders_sent);
unset($orders_to_send);
foreach($orders_infos as $id_order => $parcels) {
$order = new Order($id_order);
$customer = new Customer((int) $order->id_customer);
foreach($parcels as $parcel) {
$products_sent = '';
$products_names = array();
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, d.`product_name`, SUM(p.`quantity`) AS `quantity`
FROM `'._DB_PREFIX_.'philea_parcel` p
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (p.`id_order_detail` = d.`id_order_detail`)
WHERE d.`id_order` = '.(int) $id_order.'
AND p.`shipping_number` = "'.pSQL($parcel[0]).'"
AND p.`date_add` = "'.pSQL($parcel[1]).'"
GROUP BY d.`id_order_detail`
') as $p) {
$products_sent .= '<br />'."\r\n".$p['quantity'].' x '.$p['product_name'];
}
$carrier = new Carrier($parcel[2], (int) $order->id_lang);
if((int) $order->id_lang == 3) {
if(preg_match('/colissimo/i', $carrier->name)) {
$carrier->url .= '&language=es_ES';
}
$content_html = '<strong>Contenido del paquete:</strong>';
$content_txt = 'Contenido del paquete:';
} else {
$content_html = '<strong>Contenu du colis :</strong>';
$content_txt = 'Contenu du colis :';
}
$templateVars = array(
'{followup}' => str_replace('@', $parcel[0], $carrier->url),
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
'{id_order}' => (int) $order->id,
'{product_list}' => !empty($products_sent)? $content_html.$products_sent: '',
'{product_list_txt}' => !empty($products_sent)? $content_txt.strip_tags($products_sent): '',
);
$order->shipping_number = $parcel[0];
$order->update();
if(in_array($order->id, $status_sent)) {
$history = new OrderHistory();
$history->id_order = (int) $order->id;
$history->changeIdOrderState(4, (int) $order->id);
$history->addWithemail(true, $templateVars);
} 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);
}
$subjects = array(
1 => 'Package in transit',
2 => 'Livraison en cours',
3 => 'Pedido en tránsito',
);
Mail::Send(
intval($order->id_lang),
'in_transit',
$subjects[(int) $order->id_lang],
$templateVars,
$customer->email,
$customer->firstname.' '.$customer->lastname
);
} }
} }
} }
if(count($errors) > 0) { unset($orders_sent);
mail('marion@antadis.com', '[BBB] Erreurs integration envoi Philea', serialize($errors)); unset($orders_to_send);
foreach($orders_infos as $id_order => $parcels) {
$order = new Order($id_order);
$customer = new Customer((int) $order->id_customer);
foreach($parcels as $parcel) {
$products_sent = '';
$products_names = array();
foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order_detail`, d.`product_name`, SUM(p.`quantity`) AS `quantity`
FROM `'._DB_PREFIX_.'philea_parcel` p
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (p.`id_order_detail` = d.`id_order_detail`)
WHERE d.`id_order` = '.(int) $id_order.'
AND p.`shipping_number` = "'.pSQL($parcel[0]).'"
AND p.`date_add` = "'.pSQL($parcel[1]).'"
GROUP BY d.`id_order_detail`
') as $p) {
$products_sent .= '<br />'."\r\n".$p['quantity'].' x '.$p['product_name'];
}
$carrier = new Carrier($parcel[2], (int) $order->id_lang);
if((int) $order->id_lang == 3) {
if(preg_match('/colissimo/i', $carrier->name)) {
$carrier->url .= '&language=es_ES';
}
$content_html = '<strong>Contenido del paquete:</strong>';
$content_txt = 'Contenido del paquete:';
} else {
$content_html = '<strong>Contenu du colis :</strong>';
$content_txt = 'Contenu du colis :';
}
$templateVars = array(
'{followup}' => str_replace('@', $parcel[0], $carrier->url),
'{firstname}' => $customer->firstname,
'{lastname}' => $customer->lastname,
'{id_order}' => (int) $order->id,
'{product_list}' => !empty($products_sent)? $content_html.$products_sent: '',
'{product_list_txt}' => !empty($products_sent)? $content_txt.strip_tags($products_sent): '',
);
$order->shipping_number = $parcel[0];
$order->update();
if(in_array($order->id, $status_sent)) {
$history = new OrderHistory();
$history->id_order = (int) $order->id;
$history->changeIdOrderState(4, (int) $order->id);
$history->addWithemail(true, $templateVars);
} 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);
}
$subjects = array(
1 => 'Package in transit',
2 => 'Livraison en cours',
3 => 'Pedido en tránsito',
);
Mail::Send(
intval($order->id_lang),
'in_transit',
$subjects[(int) $order->id_lang],
$templateVars,
$customer->email,
$customer->firstname.' '.$customer->lastname
);
}
} }
mail('marion@antadis.com', '[BBB] Reception expe Philea', $datFile);
} }
mail('marion@antadis.com', '[BBB] Recept expe Philea', $datFile);
$repo_archive = './archives/IN/LIVRAISON/'; $repo_archive = './archives/IN/LIVRAISON/';
$repo_paths = array(date('Y'), date('m')); $repo_paths = array(date('Y'), date('m'));
foreach ($repo_paths as $repo_path) { foreach ($repo_paths as $repo_path) {

View File

@ -27,7 +27,7 @@
$format = $CRP; $format = $CRP;
if($magistorModule->active) { if($magistorModule->active) {
require_once('connection_ftp.php'); //require_once('connection_ftp.php');
@set_time_limit(0); @set_time_limit(0);
// Checking for ".bal" files with a "CRP" prefix that has an equivalent ".dat" file and process them... // Checking for ".bal" files with a "CRP" prefix that has an equivalent ".dat" file and process them...
@ -43,12 +43,13 @@
$datFile = $fileinfo->getPath() . '/' . preg_replace( '@BAL$@', 'DAT', $fileinfo->getFilename() ); $datFile = $fileinfo->getPath() . '/' . preg_replace( '@BAL$@', 'DAT', $fileinfo->getFilename() );
if( file_exists( $datFile ) ) { if( file_exists( $datFile ) ) {
$order_details = array();
$details = array();
$content = file_get_contents( $datFile ); $content = file_get_contents( $datFile );
$lines = preg_split( '@\n@', $content ); $lines = preg_split( '@\n@', $content );
// ANTADIS // ANTADIS
if( !empty($lines) ) { if( !empty($lines) ) {
$order_details = array();
foreach( $lines as $line ) { foreach( $lines as $line ) {
$data = array(); $data = array();
foreach($format as $field => $value) { foreach($format as $field => $value) {
@ -69,30 +70,54 @@
} else { } else {
$id_order = (int) $order; $id_order = (int) $order;
} }
if(!isset($details[(int)$id_order])) {
$details[(int)$id_order] = array();
}
// GET PRODUCT // GET PRODUCT DETAIL FROM FILE
$product = trim($data[7]); $product = trim($data[7]);
$product = explode('_', $product); $product = explode('_', $product);
$id_product = (int) $product[0]; $id_product = (int) $product[0];
$id_product_attribute = (isset($product[1]) ? (int) $product[1] : 0); $id_product_attribute = (isset($product[1]) ? (int) $product[1] : 0);
if(isset($details[(int)$id_order][$id_product.'_'.$id_product_attribute])) {
$details[(int)$id_order][$id_product.'_'.$id_product_attribute] += (int) trim($data[8]);
} else {
$details[(int)$id_order][$id_product.'_'.$id_product_attribute] = (int) trim($data[8]);
}
if($detail = Db::getInstance()->getRow(' }
SELECT `id_order_detail`, `product_quantity` - GREATEST(`product_quantity_return`, `product_quantity_refunded`) AS `quantity`
foreach ($details as $id_order => $detail) {
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` FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $id_order.' WHERE `id_order` = '.(int) $id_order.'
AND `product_id` = '.(int) $id_product.' ') as $key => $row) {
AND `product_attribute_id` = '.(int) $id_product_attribute.'
')) {
if ($id_sale && !isset($order_details[$id_sale])) { if ($id_sale && !isset($order_details[$id_sale])) {
$order_details[$id_sale] = array(); $order_details[$id_sale] = array();
} }
if ($id_sale && !isset($order_details[$id_sale][$id_order])) { if ($id_sale && !isset($order_details[$id_sale][$id_order])) {
$order_details[$id_sale][$id_order] = array(); $order_details[$id_sale][$id_order] = array();
} }
// GET QTY if (Pack::isPack((int) $row['product_id'])){
$qty = (int) trim($data[8]); $pack_items = Pack::getSimplePack((int) $row['product_id']);
$order_details[$id_sale][$id_order][$id_product.'|'.$id_product_attribute] = (int) $detail['quantity'] - $qty; foreach ($pack_items as $pack_item) {
$qty = (isset($details[(int)$id_order][$pack_item['id_product_item'].'_0']) ? $details[(int)$id_order][$pack_item['id_product_item'].'_0'] : 0);
if (isset($order_details[$id_sale][$id_order][$pack_item['id_product_item'].'|0'])) {
$order_details[$id_sale][$id_order][$pack_item['id_product_item'].'|0'] += ((int) $row['quantity'] * (int) $pack_item['quantity']);
} else {
$order_details[$id_sale][$id_order][$pack_item['id_product_item'].'|0'] = ((int) $row['quantity'] * (int) $pack_item['quantity']) - $qty;
}
}
} else {
$qty = (isset($details[(int)$id_order][$row['product_id'].'_'.$row['product_attribute_id']]) ? $details[(int)$id_order][$row['product_id'].'_'.$row['product_attribute_id']] : 0);
if(isset($order_details[$id_sale][$id_order][$row['product_id'].'|'.$row['product_attribute_id']])) {
$order_details[$id_sale][$id_order][$row['product_id'].'|'.$row['product_attribute_id']] += (int) $row['quantity'];
} else {
$order_details[$id_sale][$id_order][$row['product_id'].'|'.$row['product_attribute_id']] = (int) $row['quantity'] - $qty;
}
}
} }
} }
foreach ($order_details as $sale => $orders) { foreach ($order_details as $sale => $orders) {
@ -103,9 +128,9 @@
foreach ($products as $key => $qty) { foreach ($products as $key => $qty) {
$count += $qty; $count += $qty;
$product = explode('|', $key); $product = explode('|', $key);
$id_product = (int) $product[0];
$id_product_attribute = (isset($product[1]) ? (int) $product[1] : 0);
if ($qty>0) { if ($qty>0) {
$id_product = (int) $product[0];
$id_product_attribute = (isset($product[1]) ? (int) $product[1] : 0);
$errors .= "<li>".$qty." Produit #".$id_product.($id_product_attribute?" - attribute #".$id_product_attribute:"")." manquant</li>"; $errors .= "<li>".$qty." Produit #".$id_product.($id_product_attribute?" - attribute #".$id_product_attribute:"")." manquant</li>";
} }
} }

View File

@ -7,6 +7,9 @@ include(dirname(__FILE__) . '/../../../config/config.inc.php');
include( dirname(__FILE__) . '/../philea_magistor.php'); include( dirname(__FILE__) . '/../philea_magistor.php');
$id_sale = (int) $argv[1]; $id_sale = (int) $argv[1];
$_id_shipping = 1; // philea
if($id_sale == 0) { if($id_sale == 0) {
exit; exit;
} }
@ -83,8 +86,40 @@ if($magistorModule->active) {
$data = ''; $data = '';
/**
* @Override check pack items
*/
$product_ids = array_map(function($product){ return $product['id_product']; }, $products);
foreach(Db::getInstance()->executeS('
SELECT p.*, pl.*, s.*
FROM `'._DB_PREFIX_.'pack` pp
LEFT JOIN `'._DB_PREFIX_.'product` p ON (pp.`id_product_item` = p.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
ON (
p.`id_product` = pl.`id_product`
AND pl.`id_lang` = '.(int)(Configuration::get('PS_LANG_DEFAULT')).'
)
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c ON (c.`id_product` = pp.`id_product_pack`)
LEFT JOIN `'._DB_PREFIX_.'privatesale_shipping_sale` s ON (s.`id_sale` = c.`id_sale`)
WHERE s.`id_shipping` = '.(int) $_id_shipping.'
AND s.`id_sale` = '.(int) $id_sale.'
ORDER BY p.`id_product` ASC
') as $row){
// do not add product item it's in product list
if (!in_array($row['id_product'], $product_ids))
$products[] = $row;
}
foreach($products as $product) { foreach($products as $product) {
/**
* @Override check pack items
* Do not add pack item (only content items)
*/
if (isset($product['cache_is_pack']) && $product['cache_is_pack']) {
continue;
}
$link = new Link(); $link = new Link();
$cover = Db::getInstance()->getValue(' $cover = Db::getInstance()->getValue('
SELECT `id_image` SELECT `id_image`

View File

@ -10,7 +10,7 @@ ini_set('memory_limit', '4G');
$id_sale = (int) $argv[1]; $id_sale = (int) $argv[1];
//$_id_shipping = 4; // philea $_id_shipping = 1; // philea
if($id_sale == 0) { if($id_sale == 0) {
exit; exit;
@ -24,14 +24,15 @@ $id_lang = Configuration::get('PS_LANG_DEFAULT');
$tab_conversion_carrier = philea_magistor::getTabState(); $tab_conversion_carrier = philea_magistor::getTabState();
$socol_to_magistor = array( $socol_to_magistor = array(
'DOM' => 'SOCOLMDSS', // Livraison à domicile 'DOMINTER' => 'COLINT', // Livraison internationnale à domicile
'DOS' => 'SOCOLMDS', 'DOM' => 'SOCOLMDSS', // Livraison à domicile
'RDV' => 'SOCOLMRDV', // Livraison sur Rendez-vous 'DOS' => 'SOCOLMDS',
'CIT' => 'SOCOLCITY', // Livraison en Cityssimo 'RDV' => 'SOCOLMRDV', // Livraison sur Rendez-vous
'BPR' => 'SOCOLMBP', // Livraison en Bureau de Poste 'CIT' => 'SOCOLCITY', // Livraison en Cityssimo
'CDI' => 'SOCOLMBP', // Centre de distribution 'BPR' => 'SOCOLMBP', // Livraison en Bureau de Poste
'A2P' => 'SOCOLMC', // Livraison Commerce de proximité 'CDI' => 'SOCOLMBP', // Centre de distribution
'ACP' => 'SOCOLMBP', // Agence ColiPoste 'A2P' => 'SOCOLMC', // Livraison Commerce de proximité
'ACP' => 'SOCOLMBP', // Agence ColiPoste
); );
$mr_to_magistor = array( $mr_to_magistor = array(
@ -97,7 +98,7 @@ if($magistorModule->active) {
$orders = $db->ExecuteS(' $orders = $db->ExecuteS('
SELECT * FROM `'._DB_PREFIX_.'orders` SELECT * FROM `'._DB_PREFIX_.'orders`
WHERE `date_add` > "2016-08-30 00:00:00" WHERE `date_add` > "2016-09-30 00:00:00"
'.(count($exclude_orders) > 0? 'AND `id_order` NOT IN ('.implode(', ', $exclude_orders).')': '').' '.(count($exclude_orders) > 0? 'AND `id_order` NOT IN ('.implode(', ', $exclude_orders).')': '').'
'.(count($include_orders) > 0? 'AND `id_order` IN ('.implode(', ', $include_orders).')': '').' '.(count($include_orders) > 0? 'AND `id_order` IN ('.implode(', ', $include_orders).')': '').'
'); ');
@ -151,7 +152,6 @@ if($magistorModule->active) {
continue; continue;
} }
$products = $order->getProducts(); $products = $order->getProducts();
// ANTADIS // ANTADIS
$products_ids = array(); $products_ids = array();
@ -199,13 +199,21 @@ if($magistorModule->active) {
'); ');
if($delivery_info) { if($delivery_info) {
$carrier_value = $socol_to_magistor[$delivery_info['delivery_mode']]; if($delivery_info['cecountry'] != 'FR') {
$carrier_value = $socol_to_magistor['DOMINTER'];
} else {
$carrier_value = $socol_to_magistor[$delivery_info['delivery_mode']];
}
$prid = $delivery_info['prid']; $prid = $delivery_info['prid'];
} }
} }
if(!$carrier_value) { if(!$carrier_value) {
$carrier_value = $tab_conversion_carrier[$order->id_carrier.':']; if((int)$address_delivery->id_country == 8) {
$carrier_value = $tab_conversion_carrier[$order->id_carrier.':'];
} else {
$carrier_value = $socol_to_magistor['DOMINTER'];
}
} }
@ -306,6 +314,8 @@ if($magistorModule->active) {
$products = $order->getProducts(); $products = $order->getProducts();
$nb_ligne = 0; $nb_ligne = 0;
$product_packs = array();
$product_rows = array();
foreach($products as $product) foreach($products as $product)
{ {
if(!Db::getInstance()->getRow(' if(!Db::getInstance()->getRow('
@ -321,22 +331,72 @@ if($magistorModule->active) {
'); ');
$sales[(int)$other_sale_id] = (int)$other_sale_id; $sales[(int)$other_sale_id] = (int)$other_sale_id;
} }
/**
* @Override get pack items
*/
if(Pack::isPack((int)$product['product_id'])) {
$pack_items = Pack::getCompleteSimplePack((int) $product['product_id']);
foreach ($pack_items as $pack_item) {
$ean = !empty($pack_item['ean13'])? $pack_item['ean13']: $pack_item['supplier_reference'];
$ref = $pack_item['id_product'];
$p_key = $pack_item['id_product'];
if (!isset($product_rows[$p_key])) {
$product_rows[$p_key] = array(
str_replace(array("\r", "\n"), '', $ref),
0,
substr(utf8_decode(cleanChar($pack_item['name'])),0,50),
str_replace(array("\r", "\n"), "", $ean)
);
}
$product_rows[$p_key][1] += (max($product['product_quantity'] - max($product['product_quantity_return'], $product['product_quantity_refunded']), 0) * $pack_item['pack_quantity']);
}
} else {
$ean = !empty($product['product_ean13'])? $product['product_ean13']: $product['product_supplier_reference'];
$ref = ($product['product_attribute_id']?$product['product_id'].'_'.$product['product_attribute_id']:$product['product_id']);
$p_key = ($product['product_attribute_id']?$product['product_id'].'_'.$product['product_attribute_id']:$product['product_id']);
if (!isset($product_rows[$p_key])) {
$product_rows[$p_key] = array(
str_replace(array("\r", "\n"), '', $ref),
0,
substr(utf8_decode(cleanChar($product['product_name'])),0,50),
str_replace(array("\r", "\n"), "", $ean),
);
}
$product_rows[$p_key][1] += max($product['product_quantity'] - max($product['product_quantity_return'], $product['product_quantity_refunded']), 0);
}
}
// Add products to data
$nb_ligne = 0;
foreach ($product_rows as $p_key => $product) {
$nb_ligne++; $nb_ligne++;
$ean = !empty($product['product_ean13'])? $product['product_ean13']: $product['product_supplier_reference'];
$ref = ($product['product_attribute_id']?$product['product_id'].'_'.$product['product_attribute_id']:$product['product_id']);
$data .= str_pad('L01', 10, ' ', STR_PAD_RIGHT); $data .= str_pad('L01', 10, ' ', STR_PAD_RIGHT);
$data .= str_pad('OP'.(int) $id_sale.'-'.$order->id, 50, ' ', STR_PAD_RIGHT); $data .= str_pad('OP'.(int) $id_sale.'-'.$order->id, 50, ' ', STR_PAD_RIGHT);
$data .= str_pad($nb_ligne, 4, '0', STR_PAD_LEFT); $data .= str_pad($nb_ligne, 4, '0', STR_PAD_LEFT);
$data .= str_pad(str_replace(array("\r", "\n"), '', $ref), 50, ' ', STR_PAD_RIGHT); $data .= str_pad($product[0], 50, ' ', STR_PAD_RIGHT); // ref
$data .= str_pad(max($product['product_quantity'] - max($product['product_quantity_return'], $product['product_quantity_refunded']), 0), 8, '0', STR_PAD_LEFT); $data .= str_pad($product[1], 8, '0', STR_PAD_LEFT); // quantity
$data .= str_pad(substr(utf8_decode(cleanChar($product['product_name'])), 0, 50), 50, ' ', STR_PAD_RIGHT); $data .= str_pad($product[2], 50, ' ', STR_PAD_RIGHT); // product name
$data .= str_pad(str_replace(array("\r", "\n"), '', $ean), 14, ' ', STR_PAD_LEFT); $data .= str_pad($product[3], 14, ' ', STR_PAD_LEFT); // ean
$data .= PHP_EOL; $data .= PHP_EOL;
} }
// Add pack items to data
// foreach ($product_packs as $product) {
// $nb_ligne ++;
// $data .= str_pad( 'L01', 10, ' ', STR_PAD_RIGHT );
// $data .= str_pad( 'OP'.(int) $id_sale.'-'.$order->id, 50, ' ', STR_PAD_RIGHT );
// $data .= str_pad( $nb_ligne, 4, '0', STR_PAD_LEFT );
// $data .= str_pad( $product[0], 50, ' ', STR_PAD_RIGHT ); // ref
// $data .= str_pad( $product[1], 8, '0', STR_PAD_LEFT ); // quantity
// $data .= str_pad( $product[2], 50, ' ', STR_PAD_RIGHT ); // product name
// $data .= str_pad( $product[3], 14, ' ', STR_PAD_LEFT ); // ean
// $data .= PHP_EOL;
// }
foreach ($sales as $key => $sale_id) { foreach ($sales as $key => $sale_id) {
Db::getInstance()->ExecuteS(' Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'philea_sent` INSERT INTO `'._DB_PREFIX_.'philea_sent`
@ -350,7 +410,6 @@ if($magistorModule->active) {
if(count($sales)>1) { if(count($sales)>1) {
$multi[] = (int) $order->id; $multi[] = (int) $order->id;
} }
} //End if nbproducts } //End if nbproducts
}//End foreach }//End foreach

File diff suppressed because it is too large Load Diff

72
override/classes/Pack.php Normal file
View File

@ -0,0 +1,72 @@
<?php
class Pack extends PackCore
{
static $_cache_getSimplePack = NULL;
/**
* Get pack available quantity
*/
public static function getAvailableQuantity($id_product, $id_lang)
{
$items = self::getItems((int) $id_product, $id_lang);
$pack_quantity = Product::getQuantity($id_product, NULL, true);
if (!$pack_quantity) {
return 0;
}
foreach ($items AS $item){
if (!$item->isAvailableWhenOutOfStock((int) $item->out_of_stock) AND (floor( (int) $item->quantity / (int) $item->pack_quantity) < $pack_quantity)) {
$pack_quantity = floor( (int) $item->quantity / (int) $item->pack_quantity);
}
}
return $pack_quantity;
}
/**
* Get simple pack
*/
public static function getSimplePack($id_product_pack){
if (isset($_cache_getSimplePack[(int) $id_product_pack])) {
return $_cache_getSimplePack[(int) $id_product_pack];
}
$_cache_getSimplePack[(int) $id_product_pack] = Db::getInstance()->executeS('
SELECT *
FROM `' . _DB_PREFIX_ . 'pack`
WHERE `id_product_pack` = ' . (int) $id_product_pack . '
');
return $_cache_getSimplePack[(int) $id_product_pack];
}
/**
* Get complete simple pack
*/
public static function getCompleteSimplePack($id_product_pack){
if (isset($_cache_getSimplePack[(int) $id_product_pack])) {
return $_cache_getSimplePack[(int) $id_product_pack];
}
$_cache_getSimplePack[(int) $id_product_pack] = Db::getInstance()->executeS('
SELECT pp.`id_product_pack`, pp.`quantity` AS `pack_quantity`, p.*, pl.*
FROM `'._DB_PREFIX_.'pack` pp
LEFT JOIN `'._DB_PREFIX_.'product` p ON (pp.`id_product_item` = p.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
ON (
p.`id_product` = pl.`id_product`
AND pl.`id_lang` = '.(int)(Configuration::get('PS_LANG_DEFAULT')).'
)
WHERE pp.`id_product_pack` = ' . (int) $id_product_pack . '
');
return $_cache_getSimplePack[(int) $id_product_pack];
}
/**
* Get item pack
*/
public static function getPacks($id_product_item){
return Db::getInstance()->executeS('
SELECT `id_product_pack`, `quantity`
FROM `' . _DB_PREFIX_ . 'pack`
WHERE `id_product_item` = ' . (int) $id_product_item . '
');
}
}