update for bip ean

This commit is contained in:
Marion Muszynski 2016-03-31 12:47:51 +02:00
parent 4905fc1e86
commit bfa1328547
2 changed files with 50 additions and 30 deletions

View File

@ -101,6 +101,7 @@ class AdminBraderie extends AdminTab
dataType: \'json\',
data: { ean: $(this).val() },
success: function(response) {
console.log(response);
if (response.name == null) {
$("#error").empty().append("'.$this->l('Aucun produit n\'a été trouvé. Vérifier le code EAN').'");
$("#ean_from_product").empty();
@ -176,6 +177,7 @@ class AdminBraderie extends AdminTab
success: function(response) {
$("#error").empty().append(response);
$("#input_ean, #input_storage").val("");
$("#ean_from_product").empty();
},
error: function(xhr) {
$("#error").empty().append(JSON.parse(xhr.responseText));
@ -193,6 +195,7 @@ class AdminBraderie extends AdminTab
window.open("?tab=AdminCatalog&viewcategory&id_category=" + $category + "&token=" + $token, "_blank");
return false;
});
});
</script>';
echo $this->_html;
@ -218,27 +221,26 @@ class AdminBraderie extends AdminTab
} else {
$html .= '<p class="margin-form" id="error">'.$this->error.'</p>';
}
$html .= '<form action="?tab=AdminBraderie&token='.$token.'" method="POST">
<div class="margin-form">
<label>'.$this->l('Ventes').' : </label>
<select class="chosen-select" id="sale" name="sale">
<option value=""></option>';
$html .= '<div class="margin-form">
<label>'.$this->l('Ventes').' : </label>
<select class="chosen-select" id="sale" name="sale">
<option value=""></option>';
foreach ($categories as $key => $value) {
$html .= '<option value="'.$value['id_category'].'">'.$value['id_category'].' - '.$value['name'].(!empty($small_titles[(int)$value['id_category']])?' - '.$small_titles[(int)$value['id_category']]:'').'</option>';
}
$html .= ' </select>
</div>
<hr id="divider" style="display: none;">
<div class="margin-form" id="category_input_group" style="display: none;">
<label>'.$this->l('Catégories').' : </label>
<select class="chosen-select" id="category" name="category">
<option value=""></option>
</select>
<input type="submit" class="button" id="show_current_category_button" value="'.$this->l('Voir cette catégorie').'" style="margin-left: 20px; display: none">
</div>
foreach ($categories as $key => $value) {
$html .= '<option value="'.$value['id_category'].'">'.$value['id_category'].' - '.$value['name'].(!empty($small_titles[(int)$value['id_category']])?' - '.$small_titles[(int)$value['id_category']]:'').'</option>';
}
$html .= ' </select>
</div>
<hr id="divider" style="display: none;">
<div class="margin-form" id="category_input_group" style="display: none;">
<label>'.$this->l('Catégories').' : </label>
<select class="chosen-select" id="category" name="category">
<option value=""></option>
</select>
<input type="submit" class="button" id="show_current_category_button" value="'.$this->l('Voir cette catégorie').'" style="margin-left: 20px; display: none">
</div>
<form id="formBraderie" action="?tab=AdminBraderie&token='.$token.'" method="POST">
<div class="margin-form" id="ean_input_group" style="display: none;">
<label>'.$this->l('Code EAN').' : </label>
<input type="text" name="ean" id="input_ean">

View File

@ -61,22 +61,40 @@ function getProductId()
return Tools::displayError('Code EAN invalide');
}
$db = Db::getInstance();
$sql = 'SELECT `'._DB_PREFIX_.'product_lang`.`id_product`, `'._DB_PREFIX_.'product_lang`.`name` FROM `'._DB_PREFIX_.'product` LEFT JOIN `'._DB_PREFIX_.'product_lang` ON `'._DB_PREFIX_.'product`.id_product = `'._DB_PREFIX_.'product_lang`.id_product WHERE `ean13` = '.$ean.' AND `id_lang` = '.(int)$cookie->id_lang.' ORDER BY `date_add` DESC LIMIT 1';
$result = $db->ExecuteS($sql);
//$db = Db::getInstance();
//$sql = 'SELECT `'._DB_PREFIX_.'product_lang`.`id_product`, `'._DB_PREFIX_.'product_lang`.`name` FROM `'._DB_PREFIX_.'product` LEFT JOIN `'._DB_PREFIX_.'product_lang` ON `'._DB_PREFIX_.'product`.id_product = `'._DB_PREFIX_.'product_lang`.id_product WHERE `ean13` = '.$ean.' AND `id_lang` = '.(int)$cookie->id_lang.' ORDER BY `date_add` DESC LIMIT 1';
$result = Db::getInstance()->getRow('
SELECT p.`id_product`, p.`reference`, pl.`name`
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product`)
WHERE p.`ean13` = '.pSQL($ean).'
AND pl.`id_lang` = '.(int)$cookie->id_lang.'
ORDER BY `date_add` DESC
');
if (!$result) {
$sql = 'SELECT * FROM `'._DB_PREFIX_.'product_attribute` WHERE `ean13` = '.pSQL($ean).' ORDER BY `id_product_attribute` DESC LIMIT 1';
$result = $db->ExecuteS($sql);
$sql = 'SELECT * FROM `'._DB_PREFIX_.'product_lang` WHERE `id_product` = '.(int)($result[0]['id_product']).' LIMIT 1';
if (empty($result)) {
//$sql = 'SELECT * FROM `'._DB_PREFIX_.'product_attribute` WHERE `ean13` = '.pSQL($ean).' ORDER BY `id_product_attribute` DESC LIMIT 1';
/*$sql = 'SELECT * FROM `'._DB_PREFIX_.'product_lang` WHERE `id_product` = '.(int)($result[0]['id_product']).' LIMIT 1';
$tmp = $db->ExecuteS($sql)[0];
$result[0]['name'] = $tmp['name'];
$result[0]['reference'] = ($result[0]['reference']) ? $result[0]['reference'] : $tmp['reference'];
$result[0]['reference'] = ($result[0]['reference']) ? $result[0]['reference'] : $tmp['reference'];*/
$result = Db::getInstance()->getRow('
SELECT pa.*, pl.`name`, p.`reference` as product_reference
FROM `'._DB_PREFIX_.'product_attribute` pa
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = pa.`id_product`)
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product`)
WHERE pa.`ean13` = '.pSQL($ean).'
AND pl.`id_lang` = '.(int)$cookie->id_lang.'
ORDER BY pa.`id_product_attribute`
DESC'
);
$result['reference'] = (!empty($result['reference'])) ? $result['reference'] : $result['product_reference'];
}
if ($result) {
return $result[0];
if (!empty($result)) {
return $result;
} else {
http_response_code(500);
return Tools::displayError('Aucun produit trouvé');