Merge branch 'ticket-printProductEan' into develop
This commit is contained in:
commit
e78e5098e3
@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
class Print_Ean extends Module {
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'print_ean';
|
||||
$this->tab = 'administration';
|
||||
$this->author = 'Antadis';
|
||||
@ -12,7 +13,8 @@ class Print_Ean extends Module {
|
||||
$this->description = $this->l('Allows to generate product ean and print it');
|
||||
}
|
||||
|
||||
public function install() {
|
||||
public function install()
|
||||
{
|
||||
|
||||
$langs = Db::getInstance()->ExecuteS('
|
||||
SELECT `id_lang`, `iso_code`
|
||||
@ -47,14 +49,16 @@ class Print_Ean extends Module {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function uninstall() {
|
||||
public function uninstall()
|
||||
{
|
||||
if(parent::uninstall() == false) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hookAdmin_Product_Postprocess($params) {
|
||||
public function hookAdmin_Product_Postprocess($params)
|
||||
{
|
||||
|
||||
if(Tools::isSubmit('generateEan') && Tools::getValue('id_product')){
|
||||
global $cookie, $smarty, $currentIndex;
|
||||
@ -65,20 +69,7 @@ class Print_Ean extends Module {
|
||||
foreach ($combinations as $key => $combination) {
|
||||
if (empty($combination['ean13'])) {
|
||||
$ean_generate = $this->_getEanNumber();
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE
|
||||
`'._DB_PREFIX_.'product_attribute`
|
||||
SET `ean13` = '. $ean_generate . '
|
||||
WHERE `id_product` = ' . (int)$product->id .'
|
||||
AND `id_product_attribute` = ' . (int)$combination['id_product_attribute']
|
||||
);
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE
|
||||
`'._DB_PREFIX_.'order_detail`
|
||||
SET `product_ean13` = "'. pSQL($ean_generate) .'"
|
||||
WHERE `product_id` = '. (int)$product->id .'
|
||||
AND `product_attribute_id` = '. (int)$combination['id_product_attribute']
|
||||
);
|
||||
$this->_updateAttributeEan($product->id, $combination['id_product_attribute'], $ean_generate);
|
||||
} else {
|
||||
$ean_generate = $combination['ean13'];
|
||||
}
|
||||
@ -87,40 +78,46 @@ class Print_Ean extends Module {
|
||||
} else {
|
||||
if (empty($product->ean13)) {
|
||||
$ean_generate = $this->_getEanNumber();
|
||||
Db::getInstance()->execute('
|
||||
UPDATE
|
||||
`'._DB_PREFIX_.'product`
|
||||
SET `ean13` = '. $ean_generate . '
|
||||
WHERE `id_product` = ' . (int)$product->id
|
||||
);
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE
|
||||
`'._DB_PREFIX_.'order_detail`
|
||||
SET `product_ean13` = "'. pSQL($ean_generate) .'"
|
||||
WHERE `product_id` = '. (int)$product->id .'
|
||||
AND `product_attribute_id` = 0
|
||||
');
|
||||
$this->_updateProductEan($product->id, $ean_generate);
|
||||
} else {
|
||||
$ean_generate = $product->ean13;
|
||||
}
|
||||
$this->printEAN13($ean_generate,1,Configuration::get('LOGISTICS_QUEUE_'.(int) $cookie->id_employee));
|
||||
}
|
||||
Tools::redirectAdmin($currentIndex.'&id_product='.(int)$product->id.'&id_category='.(!empty($_REQUEST['id_category'])?$_REQUEST['id_category']:'1').'&updateproduct&tabs=0'.'&token='.Tools::getAdminTokenLite('AdminCatalog'));
|
||||
Tools::redirectAdmin($currentIndex.'&id_product='.(int)$product->id.'&id_category='.(!empty($_REQUEST['id_category'])?$_REQUEST['id_category']:'1').'&updateproduct'.'tabs=7&&token='.Tools::getAdminTokenLite('AdminCatalog'));
|
||||
}
|
||||
|
||||
if (Tools::getValue('generateattrean') && Tools::getValue('id_product')) {
|
||||
global $cookie, $smarty, $currentIndex;
|
||||
$id_attribute = Tools::getValue('generateattrean');
|
||||
$product = new Product(Tools::getValue('id_product'));
|
||||
$combination = $this->_getAttributeCombination((int)$product->id, (int)$id_attribute);
|
||||
if ($combination) {
|
||||
if(empty($combination['ean13'])) {
|
||||
$ean_generate = $this->_getEanNumber();
|
||||
$this->_updateAttributeEan((int)$product->id, $id_attribute, $ean_generate);
|
||||
}
|
||||
$this->printEAN13($ean_generate,1,Configuration::get('LOGISTICS_QUEUE_'.(int) $cookie->id_employee));
|
||||
}
|
||||
|
||||
Tools::redirectAdmin($currentIndex.'&id_product='.(int)$product->id.'&id_category='.(!empty($_REQUEST['id_category'])?$_REQUEST['id_category']:'1').'&updateproduct'.'&tabs=7&token='.Tools::getAdminTokenLite('AdminCatalog'));
|
||||
}
|
||||
}
|
||||
|
||||
public function hookAdmin_Product_Extra($params) {
|
||||
global $cookie, $smarty;
|
||||
public function hookAdmin_Product_Extra($params)
|
||||
{
|
||||
global $cookie, $smarty, $currentIndex;
|
||||
$product = new Product((int)$params['product']->id);
|
||||
$combinations = $product->getAttributeCombinaisons((int)$cookie->id_lang);
|
||||
$_html = '<style>
|
||||
$_html .= '<style type="text/css">
|
||||
/**@import "'.__PS_BASE_URI__.'css/custom_admin.css";**/
|
||||
.table-ean {
|
||||
text-align:center;
|
||||
}
|
||||
</style>';
|
||||
|
||||
$_html .= '<div class="tab-page" id="stepEAN">
|
||||
<h4 class="tab">'.$this->l('EAN Management').'</h4>
|
||||
$_html .= '<div class="tab-page" id="step8">
|
||||
<h4 class="tab">8. '.$this->l('EAN Management').'</h4>
|
||||
<fieldset>
|
||||
<legend>'.$this->l('Print & Generate EAN').'</legend>
|
||||
<div>';
|
||||
@ -132,15 +129,30 @@ class Print_Ean extends Module {
|
||||
<th>ID</th>
|
||||
<th>Déclinaisons</th>
|
||||
<th>EAN13</th>
|
||||
<th>Action</th>
|
||||
</tr>';
|
||||
foreach ($combinations as $key => $combination) {
|
||||
$_html .= '<tr style="background-color:#D1EAEF">
|
||||
$_html .= '<tr style="background-color:#FFF">
|
||||
<td>'.$combination['id_product_attribute'].'</td>
|
||||
<td>'.$combination['attribute_name'].'</td>
|
||||
<td>'.(!empty($combination['ean13'])?$combination['ean13']:$this->l('Pas encore d\'ean')).'</td>
|
||||
<td><a class="generateEanAttr" href="#" data-id="'.$combination['id_product_attribute'].'">'
|
||||
.(!empty($combination['ean13'])?'<img src="../img/admin/printer.gif"/> '.$this->l('Imprimer'):'<img src="../img/admin/add.gif"/> '.$this->l('Généré/imprimer')).
|
||||
'</a></td>
|
||||
</tr>';
|
||||
}
|
||||
$_html .= '</tbody></table>';
|
||||
$_html .= '</tbody></table>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$(".generateEanAttr").click(function(e){
|
||||
e.preventDefault();
|
||||
id_attr = $(this).data("id");
|
||||
console.log(id_attr);
|
||||
window.location = "?tab=AdminCatalog&id_category='.(!empty($_REQUEST['id_category'])?$_REQUEST['id_category']:'1').'&updateproduct&id_product='.$product->id.'&generateattrean=" + id_attr + "&tabs=7&token='.Tools::getAdminTokenLite('AdminCatalog').'";
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
} else {
|
||||
if(!empty($product->ean13)) {
|
||||
@ -153,7 +165,7 @@ class Print_Ean extends Module {
|
||||
}
|
||||
$_html .= '<div class="clear"></div>
|
||||
</div>
|
||||
<p><button class="button" type="submit" name="generateEan">'.$this->l('Lancer la génération/impression').'</button></p>
|
||||
<p><button class="button" type="submit" name="generateEan">'.((!empty($product->ean13) && (!$combinations||empty($combinations)))?$this->l('Lancer l\'impression'):$this->l('Lancer la génération/impression')).'</button></p>
|
||||
</fieldset>
|
||||
|
||||
</div>';
|
||||
@ -167,6 +179,51 @@ class Print_Ean extends Module {
|
||||
return $number;
|
||||
}
|
||||
|
||||
public function _getAttributeCombination($id_product, $id_attribute)
|
||||
{
|
||||
return Db::getInstance()->getRow('
|
||||
SELECT pa.*
|
||||
FROM `'._DB_PREFIX_.'product_attribute` pa
|
||||
WHERE pa.`id_product` = ' . (int)$id_product .'
|
||||
AND pa.`id_product_attribute` = ' . (int)$id_attribute.'
|
||||
');
|
||||
}
|
||||
|
||||
public function _updateAttributeEan($id_product, $id_attribute, $ean)
|
||||
{
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE
|
||||
`'._DB_PREFIX_.'product_attribute`
|
||||
SET `ean13` = '. $ean . '
|
||||
WHERE `id_product` = ' . (int)$id_product .'
|
||||
AND `id_product_attribute` = ' . (int)$id_attribute
|
||||
);
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE
|
||||
`'._DB_PREFIX_.'order_detail`
|
||||
SET `product_ean13` = "'. pSQL($ean) .'"
|
||||
WHERE `product_id` = '. (int)$id_product .'
|
||||
AND `product_attribute_id` = '. (int)$id_attribute
|
||||
);
|
||||
}
|
||||
|
||||
public function _updateProductEan($id_product, $ean)
|
||||
{
|
||||
Db::getInstance()->execute('
|
||||
UPDATE
|
||||
`'._DB_PREFIX_.'product`
|
||||
SET `ean13` = '. $ean . '
|
||||
WHERE `id_product` = ' . (int)$id_product
|
||||
);
|
||||
Db::getInstance()->Execute('
|
||||
UPDATE
|
||||
`'._DB_PREFIX_.'order_detail`
|
||||
SET `product_ean13` = "'. pSQL($ean) .'"
|
||||
WHERE `product_id` = '. (int)$id_product .'
|
||||
AND `product_attribute_id` = 0
|
||||
');
|
||||
}
|
||||
|
||||
public function printEAN13($ean13, $quantity, $queue) {
|
||||
if((string) $queue == '') {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user