Merge branch 'ticket-10657-PhileaPacks' into develop

This commit is contained in:
Marion Muszynski 2016-11-23 12:57:51 +01:00
commit 6f2b7f8732
7 changed files with 1304 additions and 761 deletions

View File

@ -10,6 +10,11 @@ class AdminPhileaMagistor extends AdminTab {
public function postProcess() {
if(Tools::isSubmit('submitProductSaleCache')) {
$fileName = 'cron_sale_cache.php';
$output = shell_exec("ps -ax | grep $fileName | wc -l");
if($output > 2){
echo '<p class="error">'.$this->l('Association automatique en cours, réessayez plus tard').'</p><br />';
}
$hour = (int) date('H');
$min = (int) date('i');
if ($hour%3 == 0 && $min <= 20 && $min >= 10 ){
@ -51,7 +56,6 @@ class AdminPhileaMagistor extends AdminTab {
SELECT *
FROM `'._DB_PREFIX_.'philea_sync`
WHERE `id_sale` = '.(int) $id_sale.'
AND `status` = 0
')) {
Db::getInstance()->execute('
INSERT INTO `'._DB_PREFIX_.'philea_sync`
@ -131,7 +135,16 @@ class AdminPhileaMagistor extends AdminTab {
echo '<p class="conf">'.$this->l('CDC for this Sale added to queue successfully').'</p><br />';
} else {
echo '<p class="error">'.$this->l('CDC Sync already in progress for this sale').'</p><br />';
if(Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'philea_sync`
WHERE `id_sale` = '.(int) $id_sale.'
AND `status` = 0
')) {
echo '<p class="error">'.$this->l('Vous ne pouvez pas envoyer les commandes car la base produits de cette vente n\'a pas encore été envoyée').'</p><br />';
} else {
echo '<p class="error">'.$this->l('CDC Sync already in progress for this sale').'</p><br />';
}
}
} else {
echo '<p class="error">'.$this->l('Invalid sale id').'</p><br />';

View File

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

View File

@ -39,7 +39,9 @@ if(is_object($iterator) && count($iterator)) {
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 style="color:red;">[E]').' '.(string) $message['codeArticle'].' : </span>'.(string) $message;
if((string) $message['bloquant'] != 'False') {
$result[] = '<span style="color:red;">[E] '.(string) $message['codeArticle'].' : </span>'.(string) $message;
}
}
$result = nl2br(implode("\n", $result));

View File

@ -7,6 +7,9 @@ include(dirname(__FILE__) . '/../../../config/config.inc.php');
include( dirname(__FILE__) . '/../philea_magistor.php');
$id_sale = (int) $argv[1];
$_id_shipping = 1; // philea
if($id_sale == 0) {
exit;
}
@ -83,8 +86,40 @@ if($magistorModule->active) {
$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) {
/**
* @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();
$cover = Db::getInstance()->getValue('
SELECT `id_image`

View File

@ -10,7 +10,7 @@ ini_set('memory_limit', '4G');
$id_sale = (int) $argv[1];
//$_id_shipping = 4; // philea
$_id_shipping = 1; // philea
if($id_sale == 0) {
exit;
@ -96,7 +96,7 @@ if($magistorModule->active) {
$orders = $db->ExecuteS('
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($include_orders) > 0? 'AND `id_order` IN ('.implode(', ', $include_orders).')': '').'
');
@ -131,6 +131,31 @@ if($magistorModule->active) {
$fileArchive = $repo_archive . 'CDC02' . date('ymdHis');
/**
* @Override get pack items
*/
$pack_items = array();
foreach(Db::getInstance()->executeS('
SELECT pp.`id_product_pack`, pp.`quantity` AS `pack_quantity`, 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){
if (!isset($pack_items[$row['id_product_pack']])) {
$pack_items[$row['id_product_pack']] = array();
}
$pack_items[$row['id_product_pack']][] = $row;
}
$data = '';
foreach($orders as $o) {
$partialOrder = false;
@ -290,6 +315,8 @@ if($magistorModule->active) {
$products = $order->getProducts();
$nb_ligne = 0;
$product_packs = array();
$product_rows = array();
foreach($products as $product)
{
if(!Db::getInstance()->getRow('
@ -301,18 +328,106 @@ if($magistorModule->active) {
continue;
}
$nb_ligne++;
/**
* @Override get pack items
*/
if (isset($pack_items[$product['product_id']])
&& is_array($pack_items[$product['product_id']])
&& !empty($pack_items[$product['product_id']])
){
foreach ($pack_items[$product['product_id']] as $pack_item) {
$productObj = new Product($pack_item['id_product']);
$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']);
// ANTADIS
$product_shipping = (int) Db::getInstance()->getValue('
SELECT s.`id_shipping`
FROM `'._DB_PREFIX_.'product_ps_cache` c
LEFT JOIN `'._DB_PREFIX_.'privatesale_shipping_sale` s
ON s.`id_sale` = c.`id_sale`
WHERE c.`id_product` = '.(int) $productObj->id.'
AND s.`id_sale` = '.(int) $id_sale.'
');
//
if($product_shipping === $_id_shipping)
{
$nb_ligne++;
$ean = !empty($pack_item['ean13'])? $pack_item['ean13']: $pack_item['supplier_reference'];
$ref = $pack_item['id_product'];;
$p_key = (int) $pack_item['id_product'];
if (!isset($product_packs[$p_key])) {
$product_packs[$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_packs[$p_key][1] += max($product['product_quantity'] - max($product['product_quantity_return'], $product['product_quantity_refunded']), 0) * $pack_item['pack_quantity'];
}
else
$partialOrder = true;
}
} else {
$productObj = new Product($product['product_id']);
// ANTADIS
$product_shipping = (int) Db::getInstance()->getValue('
SELECT s.`id_shipping`
FROM `'._DB_PREFIX_.'product_ps_cache` c
LEFT JOIN `'._DB_PREFIX_.'privatesale_shipping_sale` s
ON s.`id_sale` = c.`id_sale`
WHERE c.`id_product` = '.(int) $productObj->id.'
AND s.`id_sale` = '.(int) $id_sale.'
');
//
if($product_shipping === $_id_shipping)
{
$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']);
$p_key = ($product['product_attribute_id']?$product['product_id'].'_'.$product['product_attribute_id']:$product['product_id']);
$product_rows[(int) $p_key] = array(
str_replace(array("\r", "\n"), '', $ref),
max($product['product_quantity'] - max($product['product_quantity_return'], $product['product_quantity_refunded']), 0),
substr(utf8_decode(cleanChar($product['product_name'])),0,50),
str_replace(array("\r", "\n"), "", $ean),
);
}
else
$partialOrder = true;
}
}
// Add products to data
$nb_ligne = 0;
foreach ($product_rows as $p_key => $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(str_replace(array("\r", "\n"), '', $ref), 50, ' ', STR_PAD_RIGHT);
$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(substr(utf8_decode(cleanChar($product['product_name'])), 0, 50), 50, ' ', STR_PAD_RIGHT);
$data .= str_pad(str_replace(array("\r", "\n"), '', $ean), 14, ' ', 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;
}
// 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;
}

File diff suppressed because it is too large Load Diff

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

@ -0,0 +1,52 @@
<?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 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 . '
');
}
}