Merge branch 'ticket-14716-PictoAppliAdminOrders' into develop

This commit is contained in:
Marion Muszynski 2017-12-07 11:13:05 +01:00
commit 620b003d23
3 changed files with 290 additions and 135 deletions

View File

@ -99,6 +99,7 @@ class AdminOrders extends AdminTab
//'mixed' => array('title' => $this->l('Mixed'), 'callback' => 'printMixedSale', 'orderby' => false, 'search' => false),
'id_pdf' => array('title' => $this->l('PDF'), 'callback' => 'printPDFIcons', 'orderby' => false, 'search' => false),
'id_country' => array('title' => $this->l('Pays'), 'callback' => 'printCountry', 'orderby' => false, 'type' => 'select', 'select' => $country_array, 'filter_key' => 'x!id_country', 'filter_type' => 'int', 'width' => 35,),
'appli' => array('title' => $this->l('Appli'), 'width' => 25, 'align' => 'center', 'type' => 'bool', 'filter_key' => 'appli', 'tmpTableFilter' => true, 'icon' => array(0 => 'disabled.gif', 1 => 'enabled.gif'), 'orderby' => false),
);
parent::__construct();
@ -1298,10 +1299,10 @@ class AdminOrders extends AdminTab
<div class="row">
<div class="col-md-6" style="padding-right:0;">
<div style="background:#efefef;padding:10px;">
'.($order->appli?'<p style="margin-bottom:0px;"><span class="anticon anticon-mobile"></span> '.$this->l('Commande faite via l\'appli').'</p>':'').'
'.($order->appli?'<p style="margin-bottom:0px;"><span class="anticon anticon-mobile"></span> '.$this->l('Commande faite via l\'appli').'</p>':'<p style="margin-bottom:0px;"><span class="anticon anticon-display"></span> '.$this->l('Commande faite via le site').'</p>').'
<p style="margin-bottom:0px;"><span class="anticon anticon-credit-card"></span> '.Tools::substr($order->payment, 0, 32).' '.($order->module ? '('.$order->module.')' : '').'</p>
<p><span class="anticon anticon-cart"></span> <a href="?tab=AdminCarts&id_cart='.$cart->id.'&viewcart&token='.Tools::getAdminToken('AdminCarts'.(int)(Tab::getIdFromClassName('AdminCarts')).(int)($cookie->id_employee)).'">'.$this->l('Cart #').sprintf('%06d', $cart->id).'</a></p>
<p style="margin-bottom:0px;"><span class="anticon anticon-cross '.($order->recyclable ? 'text-green-light' : 'text-rose').'"></span> '.$this->l('Recycled package').'</p>
<p style="margin-bottom:0px;"><span class="anticon anticon-'.($order->recyclable ? 'checkmark text-green-light' : 'cross text-rose').'"></span> '.$this->l('Recycled package').'</p>
<p><span class="anticon anticon-gift '.($order->gift ? 'text-green-light' : 'text-rose').'"></span> '.(!empty($order->gift_message) ? ' <a role="button" data-toggle="collapse" href="#collapseGiftMessage">'.$this->l('Gift wrapping').'</a>':$this->l('Gift wrapping')).'</p>
</div>
</div>
@ -1509,9 +1510,9 @@ class AdminOrders extends AdminTab
'.($order->hasBeenPaid() ? '<td style="vertical-align:middle;color:#444;" align="center" class="productQuantity"><span class="text-rose">'.(int)($product['product_quantity_refunded']).'</span> | <span class="text-rose">'.(int)($product['product_quantity_return']).'</span></td>' : '').'
<td style="vertical-align:middle;color:#444;" align="center" class="productQuantity">'.(int)$stock['quantity'].'</td>
<td style=" width:70px;vertical-align:middle;color:#444;" align="center">'.Tools::displayPrice(Tools::ps_round($product_price, 2) * ((int)($product['product_quantity']) - $product['customizationQuantityTotal']), $currency, false).'</td>
<td width="70" style="vertical-align:middle;color:#444;">
<input class="form-control input-quantity" type="number" data-ean="'.$product['product_ean13'].'" id="cancelQuantity_'.(int)($product['id_order_detail']).'" name="cancelQuantity['.(int)($product['id_order_detail']).']" min="0" max="'.((int)($product['product_quantity']) - (int)($product['product_quantity_return'] + $product['product_quantity_refunded'])).'" value="0" '.(((int)($product['product_quantity_return'] + $product['product_quantity_refunded']) >= (int)($product['product_quantity'])) ? 'disabled="disabled" ' : '').'/>
'.(((int)($product['product_quantity_return'] + $product['product_quantity_refunded']) >= (int)($product['product_quantity'])) ? '' : '<input class="form-control" type="hidden" id="id_order_detail_'.(int)($product['id_order_detail']).'" name="id_order_detail['.(int)($product['id_order_detail']).']" value="'.$product['id_order_detail'].'" />').'
<td width="100" style="vertical-align:middle;color:#444;">
<input style="width: 50px;display: inline;" class="form-control input-quantity" type="number" data-ean="'.$product['product_ean13'].'" onChange="changeCancelQuantity(this,'.(int)($product['id_order_detail']).','.(((int)($product['product_quantity_return'] + $product['product_quantity_refunded']) >= (int)($product['product_quantity'])) ?0:1).');" id="cancelQuantity_'.(int)($product['id_order_detail']).'" name="cancelQuantity['.(int)($product['id_order_detail']).']" min="0" max="'.((int)($product['product_quantity']) - (int)($product['product_quantity_return'] + $product['product_quantity_refunded'])).'" value="0" '.(((int)($product['product_quantity_return'] + $product['product_quantity_refunded']) >= (int)($product['product_quantity'])) ? 'disabled="disabled" ' : '').'/>
<span>('.((int)($product['product_quantity_return'] + $product['product_quantity_refunded'])).'/'.$quantity.')</span>
</td>
</tr>';
}
@ -1615,19 +1616,19 @@ class AdminOrders extends AdminTab
$html .= '<p class="text-center">Pas de remboursement</p>';
}
} elseif($order->module && $order->module=="paypal") {
$messages = Db::getInstance()->ExecuteS('
$paypal_messages = Db::getInstance()->ExecuteS('
SELECT `message`, `date_add`
FROM `ps_message`
WHERE `id_order` = '.$order->id.'
AND (`message` LIKE "%Refund operation%" || `message` LIKE "%Cancel products%")
ORDER BY `date_add` DESC
');
if($messages && !empty($messages)) {
foreach ($messages as $message) {
if($paypal_messages && !empty($paypal_message)) {
foreach ($paypal_message as $message) {
$html .= '<p>('.date('d/m/Y',strtotime($message['message'])).'):<br>'.$message['message'].'</p>';
}
}
if(empty($messages)){
if(empty($paypal_messages)){
$html .= '<p class="text-center">Pas de remboursement</p>';
}
@ -1653,7 +1654,7 @@ class AdminOrders extends AdminTab
<div class="clearfix"></div>
</div>
<div class="panel-content">
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&token='.$this->token.'" method="post" onsubmit="if (getE(\'visibility\').checked == true) return confirm(\''.$this->l('Do you want to send this message to the customer?', __CLASS__, true, false).'\');">
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post" onsubmit="if (getE(\'visibility\').checked == true) return confirm(\''.$this->l('Do you want to send this message to the customer?', __CLASS__, true, false).'\');">
<div id="message_m" style="display: '.(Tools::getValue('message') ? 'none' : 'block').'; overflow: auto;">
<a href="#" onclick="$(\'#message\').slideToggle();$(\'#message_m\').slideToggle();return false"><b>'.$this->l('Click here').'</b> '.$this->l('to add a comment or send a message to the customer').'</a>
</div>
@ -1721,8 +1722,7 @@ class AdminOrders extends AdminTab
<div class="panel-content">';
if (!sizeof($returns)){
$html.= '
<h5 style="background:#504D8B;color:#fff;padding:5px; text-align:center;cursor:pointer" data-toggle="collapse" href="#div_returns">'.$this->l('Create a product return').'</h5>
<div class="alert alert-info collapse" id="div_returns">'.$this->l('No merchandise return for this order.').'</div>';
<div class="alert alert-info">'.$this->l('No merchandise return for this order.').'</div>';
} else {
$html.='
<table class="table table-condensed th-grey" width="100%" >
@ -1756,114 +1756,114 @@ class AdminOrders extends AdminTab
}
$html.='</tbody>
</table>';
}
if(in_array($addressDelivery->id_country, array(3, 6, 8))) {
$returnable = array();
foreach ($products as $k => $product) {
$product['id_sale'] = $product_psale[(int) $product['product_id']];
$qty = OrderReturn::getOrderDetailReturnQty($product, $currentState->id);
if($qty > 0) {
$returnable[$product['id_order_detail']] = array($product['product_name'], $qty);
}
if(in_array($addressDelivery->id_country, array(3, 6, 8))) {
$returnable = array();
foreach ($products as $k => $product) {
$product['id_sale'] = $product_psale[(int) $product['product_id']];
$qty = OrderReturn::getOrderDetailReturnQty($product, $currentState->id);
if($qty > 0) {
$returnable[$product['id_order_detail']] = array($product['product_name'], $qty);
}
if(count($returnable) > 0) {
$instructions = array(
1 => 'Remboursement + Mise en stock',
2 => 'Échange',
3 => 'Défectueux',
4 => 'Commande à ré-expédier',
5 => 'Commande à rembourser',
);
$reasons = array(
// 1 => 'CLIENT : Annulation pré-envoi',
2 => 'CLIENT : Rétractation post-envoi',
11 => 'CLIENT : Annulation pour ré-achat',
4 => 'FEUR : Problème SAV',
5 => 'FEUR : Produit manquant',
3 => 'BBB : Erreur Achat / Prod',
6 => 'BBB : Erreur Logistique ',
8 => 'BBB : Pbme Site / Paiment',
12 => 'BBB : Suspicion de fraude',
9 => 'TRANS : Colis détruit',
10 => 'TRANS : Colis perdu',
7 => 'Autre'
);
}
if(count($returnable) > 0) {
$instructions = array(
1 => 'Remboursement + Mise en stock',
2 => 'Échange',
3 => 'Défectueux',
4 => 'Commande à ré-expédier',
5 => 'Commande à rembourser',
);
$reasons = array(
// 1 => 'CLIENT : Annulation pré-envoi',
2 => 'CLIENT : Rétractation post-envoi',
11 => 'CLIENT : Annulation pour ré-achat',
4 => 'FEUR : Problème SAV',
5 => 'FEUR : Produit manquant',
3 => 'BBB : Erreur Achat / Prod',
6 => 'BBB : Erreur Logistique ',
8 => 'BBB : Pbme Site / Paiment',
12 => 'BBB : Suspicion de fraude',
9 => 'TRANS : Colis détruit',
10 => 'TRANS : Colis perdu',
7 => 'Autre'
);
$helper->_js .= '<script type="text/javascript">
$(document).ready(function() {
$(".return_input").change(function() {
var id_order_detail = $(this).attr("data-order-detail");
var qty = parseInt($(this).val());
var max = parseInt($(this).attr("max"));
if(qty == 0) {
$(".return_" + id_order_detail).hide();
}
for(var j = 1; j <= max; j=j+1) {
var id = "#return_" + id_order_detail + "_" + j;
if(j <= qty) {
$(id).show();
} else {
$(id).hide();
}
}
});
$(".return_input").trigger("change");
});
</script>';
$html.= '
<div>
<h5 style="background:#504D8B;color:#fff;padding:5px; text-align:center;cursor:pointer" data-toggle="collapse" href="#new_product_return">'.$this->l('Create a product return').'</h5>
<form id="new_product_return" class="collapse" action="" method="post">
<ul style="list-style: outside none; margin: 0; padding: 0;">';
foreach($returnable as $id_order_detail => $product) {
$html.= '
<li style="padding: 5px; background: #eee;"><input data-order-detail="'.(int) $id_order_detail.'" class="return_input" style="width: 30px; text-align: right; border: 1px solid #E0D0B1; padding: 2px 4px;" type="number" name="return_product['.(int) $id_order_detail.']" value="0" autocomplete="off" step="1" max="'.(int) $product[1].'" min="0" /> x '.$product[0]. '</li>
<li id="reason_'.$id_order_detail.'">';
for($i = 1; $i <= $product[1]; $i++) {
$html.= '
<div id="return_'.(int) $id_order_detail.'_'.$i.'">
<label style="margin: 0px; padding: 0px; float: none; text-align: left; font-weight: normal; display: block; margin-bottom: 5px;">'.sprintf($this->l('Return reason product #%s'), $i).'</label>
<select class="form-control" autocomplete="off" name="return_reason_'.(int) $id_order_detail.'_'.$i.'">';
foreach($reasons as $id_reason => $label) {
$html.= '<option value="'.$id_reason.'">'.$label.'</option>';
}
$html.= '
</select>
<label style="margin: 0px; padding: 0px; float: none; text-align: left; font-weight: normal;display: block; margin-bottom: 5px;">'.sprintf($this->l('Return instruction product #%s'), $i).'</label>
<select class="form-control" autocomplete="off" name="return_instruction_'.(int) $id_order_detail.'_'.$i.'">';
foreach($instructions as $id_instruction => $label) {
$html.= '<option value="'.$id_instruction.'">'.$this->l($label).'</option>';
}
$html.= '
</select>
<div class="ln_solid"></div>
</div>';
}
$html.= '</li>';
$helper->_js .= '<script type="text/javascript">
$(document).ready(function() {
$(".return_input").change(function() {
var id_order_detail = $(this).attr("data-order-detail");
var qty = parseInt($(this).val());
var max = parseInt($(this).attr("max"));
if(qty == 0) {
$(".return_" + id_order_detail).hide();
}
$html.= '</ul>
<p>
<label for="return_option" style="margin: 0px; padding: 0px; float: none; text-align: left; font-weight: bold;">'.$this->l('This return will be').'</label>
<select class="form-control" autocomplete="off" name="return_option" id="return_option">
<!--option value="1">'.$this->l('paid by the customer').'</option-->
<option value="2">'.$this->l('free').'</option>
</select>
</p>
<p>
<label style="width: auto; margin-bottom: 5px;">'.$this->l('Insert a comment (optional):').'</label>
<textarea class="form-control" name="return_comment" rows="5" cols="50" style="resize: vertical"></textarea>
</p>
<div style="text-right">
<input type="submit" value="'.$this->l('Confirm').'" name="submitCreateReturn" class="btn btn-primary" />
</div>
</form>
</div>';
} else {
$html.= '
<h5 style="background:#504D8B;color:#fff;padding:5px; text-align:center;cursor:pointer" data-toggle="collapse" href="#div_returns">'.$this->l('Create a product return').'</h5>
<div class="alert alert-warning-light collapse" id="div_returns">'.$this->l('No product can currently be returned on this order').'</div>';
}
for(var j = 1; j <= max; j=j+1) {
var id = "#return_" + id_order_detail + "_" + j;
if(j <= qty) {
$(id).show();
} else {
$(id).hide();
}
}
});
$(".return_input").trigger("change");
});
</script>';
$html.= '
<div>
<h5 style="background:#504D8B;color:#fff;padding:5px; text-align:center;cursor:pointer" data-toggle="collapse" href="#new_product_return">'.$this->l('Create a product return').'</h5>
<form id="new_product_return" class="collapse" action="" method="post">
<ul style="list-style: outside none; margin: 0; padding: 0;">';
foreach($returnable as $id_order_detail => $product) {
$html.= '
<li style="padding: 5px; background: #eee;"><input data-order-detail="'.(int) $id_order_detail.'" class="return_input" style="width: 30px; text-align: right; border: 1px solid #E0D0B1; padding: 2px 4px;" type="number" name="return_product['.(int) $id_order_detail.']" value="0" autocomplete="off" step="1" max="'.(int) $product[1].'" min="0" /> x '.$product[0]. '</li>
<li id="reason_'.$id_order_detail.'">';
for($i = 1; $i <= $product[1]; $i++) {
$html.= '
<div id="return_'.(int) $id_order_detail.'_'.$i.'">
<label style="margin: 0px; padding: 0px; float: none; text-align: left; font-weight: normal; display: block; margin-bottom: 5px;">'.sprintf($this->l('Return reason product #%s'), $i).'</label>
<select class="form-control" autocomplete="off" name="return_reason_'.(int) $id_order_detail.'_'.$i.'">';
foreach($reasons as $id_reason => $label) {
$html.= '<option value="'.$id_reason.'">'.$label.'</option>';
}
$html.= '
</select>
<label style="margin: 0px; padding: 0px; float: none; text-align: left; font-weight: normal;display: block; margin-bottom: 5px;">'.sprintf($this->l('Return instruction product #%s'), $i).'</label>
<select class="form-control" autocomplete="off" name="return_instruction_'.(int) $id_order_detail.'_'.$i.'">';
foreach($instructions as $id_instruction => $label) {
$html.= '<option value="'.$id_instruction.'">'.$this->l($label).'</option>';
}
$html.= '
</select>
<div class="ln_solid"></div>
</div>';
}
$html.= '</li>';
}
$html.= '</ul>
<p>
<label for="return_option" style="margin: 0px; padding: 0px; float: none; text-align: left; font-weight: bold;">'.$this->l('This return will be').'</label>
<select class="form-control" autocomplete="off" name="return_option" id="return_option">
<!--option value="1">'.$this->l('paid by the customer').'</option-->
<option value="2">'.$this->l('free').'</option>
</select>
</p>
<p>
<label style="width: auto; margin-bottom: 5px;">'.$this->l('Insert a comment (optional):').'</label>
<textarea class="form-control" name="return_comment" rows="5" cols="50" style="resize: vertical"></textarea>
</p>
<div style="text-right">
<input type="submit" value="'.$this->l('Confirm').'" name="submitCreateReturn" class="btn btn-primary" />
</div>
</form>
</div>';
} else {
$html.= '
<h5 style="background:#504D8B;color:#fff;padding:5px; text-align:center;cursor:pointer" data-toggle="collapse" href="#div_returns">'.$this->l('Create a product return').'</h5>
<div class="alert alert-warning-light collapse" id="div_returns">'.$this->l('No product can currently be returned on this order').'</div>';
}
}
$html.= '</div>
@ -1953,6 +1953,21 @@ class AdminOrders extends AdminTab
$helper->_js .= '
<script type="text/javascript">
function changeCancelQuantity(el,id_order_detail,can_change){
console.log(can_change);
console.log($(el).val());
if(can_change == 1){
var input_html = \'\';
if($(el).val()>0){
if($("#id_order_detail_"+id_order_detail).length==0){
input_html+=\'<input class="form-control" type="hidden" id="id_order_detail_\'+id_order_detail+\'" name="id_order_detail[\'+id_order_detail+\']" value="\'+id_order_detail+\'" />\';
$(el).parent().append(input_html);
}
} else {
$("#id_order_detail_"+id_order_detail).remove();
}
}
}
$(function() {
$("#changeAddress").click(function(){
url = $(this).data("url");

View File

@ -137,19 +137,24 @@ class AdminAntWp extends AdminTab
$product_info = array();
$product_found = 0;
$ids = array();
$exclude_ids = $this->getBraderieProducts();
foreach (Db::getInstance()->executeS('
SELECT p.`id_product`, p.`id_tax_rules_group`, p.`id_category_default`, p.`ean13`, p.`price`, p.`wholesale_price`,
p.`reference`, p.`supplier_reference`, p.`weight`, p.`height`, p.`width`, p.`depth`, c.`position`, cu.`nc8`, cu.`id_country`
FROM
`'._DB_PREFIX_.'product` p
INNER JOIN (SELECT date_add, max(id_product) as maxid FROM `'._DB_PREFIX_.'product` GROUP BY ean13) as b
INNER JOIN (
SELECT date_add, max(id_product) as maxid
FROM `'._DB_PREFIX_.'product`
WHERE id_product NOT IN ('.implode(',',$exclude_ids).')
GROUP BY ean13
) as b
ON p.`id_product` = b.maxid
LEFT JOIN `'._DB_PREFIX_.'category_product` c
ON (b.maxid = c.`id_product` AND p.`id_category_default` = c.`id_category`)
LEFT JOIN `'._DB_PREFIX_.'product_customs` cu
ON (cu.`id_product` = p.`id_product`)
WHERE p.`ean13` IN ("'.implode('","',$eans).'")
'.(!empty($refs)?' OR p.`supplier_reference` IN ("'.implode('","',$refs).'")':'').'
AND p.`id_product` IS NOT NULL
ORDER BY c.`position`
') as $row) {
@ -157,7 +162,40 @@ class AdminAntWp extends AdminTab
$products[$row['ean13']] = array_merge($products[$row['ean13']], $row);
$product_found++;
$ids[] = (int)$row['id_product'];
} elseif($row['supplier_reference']!='' && isset($products[$row['supplier_reference']])){
}
// elseif($row['supplier_reference']!='' && isset($products[$row['supplier_reference']])){
// $products[$row['supplier_reference']] = array_merge($products[$row['supplier_reference']], $row);
// $product_found++;
// $ids[] = (int)$row['id_product'];
// }
}
foreach (Db::getInstance()->executeS('
SELECT p.`id_product`, p.`id_tax_rules_group`, p.`id_category_default`, p.`ean13`, p.`price`, p.`wholesale_price`,
p.`reference`, p.`supplier_reference`, p.`weight`, p.`height`, p.`width`, p.`depth`, c.`position`, cu.`nc8`, cu.`id_country`
FROM
`'._DB_PREFIX_.'product` p
INNER JOIN (
SELECT date_add, max(id_product) as maxid
FROM `'._DB_PREFIX_.'product`
WHERE id_product NOT IN ('.implode(',',$exclude_ids).')
GROUP BY supplier_reference
) as b
ON p.`id_product` = b.maxid
LEFT JOIN `'._DB_PREFIX_.'category_product` c
ON (b.maxid = c.`id_product` AND p.`id_category_default` = c.`id_category`)
LEFT JOIN `'._DB_PREFIX_.'product_customs` cu
ON (cu.`id_product` = p.`id_product`)
WHERE p.`supplier_reference` IN ("'.implode('","',$refs).'")
AND p.`id_product` IS NOT NULL
ORDER BY c.`position`
') as $row) {
// if($row['ean13']!='' && isset($products[$row['ean13']])){
// $products[$row['ean13']] = array_merge($products[$row['ean13']], $row);
// $product_found++;
// $ids[] = (int)$row['id_product'];
// } else
if($row['supplier_reference']!='' && isset($products[$row['supplier_reference']])){
$products[$row['supplier_reference']] = array_merge($products[$row['supplier_reference']], $row);
$product_found++;
$ids[] = (int)$row['id_product'];
@ -165,36 +203,95 @@ class AdminAntWp extends AdminTab
}
foreach (Db::getInstance()->executeS('
SELECT p.`id_product`, p.`id_tax_rules_group`, p.`id_category_default`, at.`ean13`, p.`price`, p.`wholesale_price`,
SELECT p.`id_product`, p.`id_tax_rules_group`, p.`id_category_default`, b.`id_product_attribute`, b.`ean13`, b.`supplier_reference` as at_ref, p.`price`, p.`wholesale_price`,
p.`reference`, p.`supplier_reference`, p.`weight`, p.`height`, p.`width`, p.`depth`, c.`position`, cu.`nc8`, cu.`id_country`,
al.`name` as attribute_name
FROM
`'._DB_PREFIX_.'product` p
INNER JOIN (SELECT date_add, max(id_product) as maxid FROM `'._DB_PREFIX_.'product` GROUP BY `supplier_reference`) as b
ON p.`id_product` = b.maxid
INNER JOIN (
SELECT max(id_product) as maxid, ean13, `supplier_reference`, `id_product_attribute`
FROM `'._DB_PREFIX_.'product_attribute`
WHERE id_product NOT IN ('.implode(',',$exclude_ids).')
GROUP BY ean13
) as b
ON p.`id_product`= b.maxid
LEFT JOIN `'._DB_PREFIX_.'category_product` c
ON (b.maxid = c.`id_product` AND p.`id_category_default` = c.`id_category`)
LEFT JOIN `'._DB_PREFIX_.'product_customs` cu
ON (cu.`id_product` = p.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'product_attribute` at
ON (at.`id_product` = p.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` ac
ON (ac.`id_product_attribute` = at.`id_product_attribute`)
ON (ac.`id_product_attribute` = b.`id_product_attribute`)
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al
ON (al.`id_attribute` = ac.`id_attribute` AND al.`id_lang` = 2)
WHERE at.`ean13` IN ("'.implode('","',$eans).'")
WHERE b.`ean13` IN ("'.implode('","',$eans).'")
AND p.`id_product` IS NOT NULL
ORDER BY c.`position`
') as $row) {
if($row['ean13']!='' && isset($products[$row['ean13']])){
$products[$row['ean13']] = array_merge($products[$row['ean13']], $row);
$product_found++;
if(!in_array((int)$row['id_product'],$ids)){
$ids[] = (int)$row['id_product'];
}
}
// elseif($row['supplier_reference']!='' && isset($products[$row['supplier_reference']])){
// $products[$row['supplier_reference']] = array_merge($products[$row['supplier_reference']], $row);
// $product_found++;
// if(!in_array((int)$row['id_product'],$ids)){
// $ids[] = (int)$row['id_product'];
// }
// } elseif($row['at_ref']!='' && isset($products[$row['at_ref']])){
// $products[$row['at_ref']] = array_merge($products[$row['at_ref']], $row);
// $product_found++;
// if(!in_array((int)$row['id_product'],$ids)){
// $ids[] = (int)$row['id_product'];
// }
// }
}
foreach (Db::getInstance()->executeS('
SELECT p.`id_product`, p.`id_tax_rules_group`, p.`id_category_default`,b.`id_product_attribute`, b.`ean13`, b.`supplier_reference` as at_ref, p.`price`, p.`wholesale_price`,
p.`reference`, p.`supplier_reference`, p.`weight`, p.`height`, p.`width`, p.`depth`, c.`position`, cu.`nc8`, cu.`id_country`,
al.`name` as attribute_name
FROM
`'._DB_PREFIX_.'product` p
INNER JOIN (
SELECT max(id_product) as maxid, ean13, `supplier_reference`, `id_product_attribute`
FROM `'._DB_PREFIX_.'product_attribute`
WHERE id_product NOT IN ('.implode(',',$exclude_ids).')
GROUP BY supplier_reference
) as b
ON p.`id_product`= b.maxid
LEFT JOIN `'._DB_PREFIX_.'category_product` c
ON (b.maxid = c.`id_product` AND p.`id_category_default` = c.`id_category`)
LEFT JOIN `'._DB_PREFIX_.'product_customs` cu
ON (cu.`id_product` = p.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` ac
ON (ac.`id_product_attribute` = b.`id_product_attribute`)
LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al
ON (al.`id_attribute` = ac.`id_attribute` AND al.`id_lang` = 2)
WHERE b.`supplier_reference` IN ("'.implode('","',$refs).'")
AND p.`id_product` IS NOT NULL
ORDER BY c.`position`
') as $row) {
// if($row['ean13']!='' && isset($products[$row['ean13']])){
// $products[$row['ean13']] = array_merge($products[$row['ean13']], $row);
// $product_found++;
// if(!in_array((int)$row['id_product'],$ids)){
// $ids[] = (int)$row['id_product'];
// }
// }
if($row['at_ref']!='' && isset($products[$row['at_ref']])){
$products[$row['at_ref']] = array_merge($products[$row['at_ref']], $row);
$product_found++;
if(!in_array((int)$row['id_product'],$ids)){
$ids[] = (int)$row['id_product'];
}
} elseif($row['supplier_reference']!='' && isset($products[$row['supplier_reference']])){
$products[$row['supplier_reference']] = array_merge($products[$row['supplier_reference']], $row);
$product_found++;
}
if(!in_array((int)$row['id_product'],$ids)){
$ids[] = (int)$row['id_product'];
if(!in_array((int)$row['id_product'],$ids)){
$ids[] = (int)$row['id_product'];
}
}
}
$new_products = count($products) - $product_found;
@ -225,7 +322,7 @@ class AdminAntWp extends AdminTab
}
foreach (Db::getInstance()->executeS('
SELECT at.`ean13`, p.`supplier_reference`, pl.*
SELECT at.`ean13`, at.`supplier_reference` as at_ref, p.`supplier_reference`, pl.*
FROM '._DB_PREFIX_.'product p
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.`id_product` = p.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'product_attribute` at ON (at.`id_product` = p.`id_product`)
@ -247,6 +344,13 @@ class AdminAntWp extends AdminTab
if(!isset($products[$row['supplier_reference']]['lang'][(int)$row['id_lang']])){
$products[$row['supplier_reference']]['lang'][(int)$row['id_lang']] = $row;
}
} elseif($row['at_ref']!='' && isset($products[$row['at_ref']])){
if(!isset($products[$row['at_ref']]['lang'])){
$products[$row['at_ref']]['lang'] = array();
}
if(!isset($products[$row['at_ref']]['lang'][(int)$row['id_lang']])){
$products[$row['at_ref']]['lang'][(int)$row['id_lang']] = $row;
}
}
}
}
@ -333,4 +437,17 @@ class AdminAntWp extends AdminTab
$this->helperForm->renderForm();
}
public function getBraderieProducts()
{
$products = array();
foreach(Db::getInstance()->executeS('
SELECT categ.id_product
FROM '._DB_PREFIX_.'category_product categ
INNER JOIN '._DB_PREFIX_.'category_lang lang ON (categ.id_category=lang.id_category AND lang.id_lang=2 AND lang.name LIKE "%braderie%")'
) as $row){
$products[] = (int)$row['id_product'];
}
return $products;
}
}

View File

@ -61,7 +61,7 @@ class GenerateWp
'AI' => 'Prix HA old',
'AJ' => 'Différence',
'AK' => 'PV 3BTK appliqué',
'AL' => 'Prix vente',
'AL' => 'Prix vente old',
'AM' => 'Remise membre',
'AN' => 'Marge',
'AO' => 'Photos',
@ -214,6 +214,7 @@ class GenerateWp
$i++;
$sales = array();
$order_states = explode(',', Configuration::get('PS_IT_OF_ORDER_STATES'));
foreach ($params['lines'] as $key => $row) {
if(isset($row['id_product'])){
$id_categories = array();
@ -261,6 +262,28 @@ class GenerateWp
$price = Product::getPriceStatic($row['id_product'],TRUE, NULL, 2, NULL, FALSE, FALSE);
$price2 = Product::getPriceStatic($row['id_product'],TRUE, NULL, 2);
if(isset($row['id_product_attribute'])){
$quantity_sold = (int) Db::getInstance()->getValue('
SELECT SUM(d.`product_quantity` - d.`product_quantity_reinjected`)
FROM `'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order`
lEFT JOIN `'._DB_PREFIX_.'order_state_current` sc ON sc.`id_order` = d.`id_order`
WHERE d.`product_id` = '.(int)$row['id_product'].'
AND d.`product_attribute_id` = '.(int)$row['id_product_attribute'].'
AND sc.id_order_state IN ("'.implode('","', $order_states).'")
');
} else {
$quantity_sold = (int) Db::getInstance()->getValue('
SELECT SUM(d.`product_quantity` - d.`product_quantity_reinjected`)
FROM `'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order`
lEFT JOIN `'._DB_PREFIX_.'order_state_current` sc ON sc.`id_order` = d.`id_order`
WHERE d.`product_id` = '.(int)$row['id_product'].'
AND d.`product_attribute_id` = 0
AND sc.id_order_state IN ("'.implode('","', $order_states).'")
');
}
$this->objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$i, (String)$row['ean'])
->setCellValue('C'.$i, (String)$row['supplier_reference'])
->setCellValue('D'.$i, '=IF(AND(E'.$i.'="",F'.$i.'="",G'.$i.'=""),"",E'.$i.'&" "&F'.$i.'&" - "&G'.$i.')')
@ -286,13 +309,13 @@ class GenerateWp
->setCellValue('X'.$i, $row['lang'][2]['videos'])
->setCellValue('Y'.$i, $row['lang'][2]['description_delivery'])
->setCellValue('Z'.$i, $row['weight'])
->setCellValue('AA'.$i, '')
->setCellValue('AB'.$i, '')
->setCellValue('AA'.$i, $quantity_sold)
->setCellValue('AB'.$i, Tools::ps_round(($quantity_sold * $row['wholesale_price']),2))
->setCellValue('AC'.$i, $row['quantity'])
->setCellValue('AD'.$i, $row['height'])
->setCellValue('AE'.$i, $row['id_tax_rules_group'])
->setCellValue('AF'.$i, $row['ppc'])
->setCellValue('AG'.$i, '')
->setCellValue('AG'.$i, Product::getPriceStatic($row['id_product'],TRUE, (int) $k, 2, NULL, FALSE, FALSE))
->setCellValue('AH'.$i, $row['prix_ha'])
->setCellValue('AI'.$i, Tools::ps_round($row['wholesale_price'], 2))
->setCellValue('AJ'.$i, '=IF(AI'.$i.'="","",IF((AH'.$i.'-AI'.$i.')>0,"ATTENTION",IF((AH'.$i.'-AI'.$i.')<0,"COOL",IF((AH'.$i.'-AI'.$i.')=0,"OK",""))))')
@ -310,7 +333,7 @@ class GenerateWp
$this->objPHPExcel->setActiveSheetIndex(1)->setCellValue('B'.$i, (String)$row['ean'])
->setCellValue('C'.$i, (String)$row['supplier_reference'])
->setCellValue('D'.$i, $row['id_product'])
->setCellValue('D'.$i, '')
->setCellValue('E'.$i, $row['lang'][3]['name'])
->setCellValue('F'.$i, $categories_title[3][0])
->setCellValue('G'.$i, $categories_title[3][1])