Merge branch 'ticket-printProductEan' into develop

This commit is contained in:
Marion Muszynski 2016-09-22 13:41:39 +02:00
commit 1a3ce467c5
5 changed files with 252 additions and 7 deletions

View File

@ -317,6 +317,8 @@ class AdminProducts extends AdminTab
Tools::redirectAdmin($currentIndex.(Tools::getValue('id_category') ? '&id_category='.Tools::getValue('id_category') : '').'&token='.($token ? $token : $this->token));
}
Module::hookExec('admin_product_postprocess', array());
if(Tools::isSubmit('cloneProduct')){
$products = Tools::getValue('productBox');
$id_category_clonage = Tools::getValue('id_category_clonage');
@ -2080,6 +2082,11 @@ class AdminProducts extends AdminTab
<div class="tab-page" id="step5"><h4 class="tab">5. '.$this->l('Features').'</h4></div>
<div class="tab-page" id="step6"><h4 class="tab">6. '.$this->l('Customization').'</h4></div>
<div class="tab-page" id="step7"><h4 class="tab">7. '.$this->l('Attachments').' ('.$countAttachments.')</h4></div>';
// @Antadis - display hook specified to this page : AdminProduct
if (($hookProductExtraTab = Module::hookExec('admin_product_extra', array('product' => $obj))) !== false) {
echo $hookProductExtraTab;
}
// @End Antadis
echo '<script type="text/javascript">
var toload = new Array();
toload[3] = true;

View File

@ -29,8 +29,8 @@ if($id_category && $p && $id_category > 1) {
if($cookie->isLogged() || !$cookie->isLogged() && $sale->pub == 1) {
$now = mktime();
$category = new Category($id_category, $cookie->id_lang);
$customer = new Customer((int) $cookie->id_customer);
$category = new Category($id_category, $cookie->id_lang);
$customer = new Customer((int) $cookie->id_customer);
if( ($sale !== NULL
&& $sale->enabled
@ -42,19 +42,19 @@ if($id_category && $p && $id_category > 1) {
$orderBy = $order[Configuration::get('PS_PRODUCTS_ORDER_BY', 1)];
$orderWay = (Configuration::get('PS_PRODUCTS_ORDER_WAY', 0) == 0? 'ASC': 'DESC');
if (!empty($f)){
if (!empty($f)){
$nbProducts = count($category->getProductsByAttributes($cookie->id_lang, $f, false, false));
}
else{
$nbProducts = $category->getProducts(NULL, NULL, NULL, $orderBy, $orderWay, true);
}
// if($p >= $nbProducts / $n) {
// if($p >= $nbProducts / $n) {
if($p >= $nbProducts / $n && !Tools::getValue('init')) {
$result['endreached'] = TRUE;
} else {
if (!empty($f)){
if (Tools::getValue('init')){
if (Tools::getValue('init')){
$cat_products = $category->getProductsByAttributes($cookie->id_lang, $f, $p, $n, $orderBy, $orderWay);
}
else{
@ -131,9 +131,10 @@ if($id_category && $p && $id_category > 1) {
}
$images[$img['id_product']][] = $img;
}
$smarty->assign('images', $images);
$smarty->assign('images', $images);
$smarty->assign('categoryProductAttributes', $attributes);
$smarty->assign('last_qties', (int)Configuration::get('PS_LAST_QTIES'));
$result['products'] = $smarty->fetch(file_exists(_PS_THEME_DIR_.'modules/categoryscroll/product-list.tpl')? '../../themes/'._THEME_NAME_.'/modules/categoryscroll/product-list.tpl': 'product-list.tpl', __FILE__);
}

View File

@ -384,6 +384,7 @@ class Paybox extends PaymentModule
if($cookie->profile == 1
|| $cookie->profile == 7
|| $cookie->profile == 14
|| $cookie->profile == 11) {
if(!$order->hasBeenPaid()) {
// mail('thibault@antadis.com', 'Erreur remboursement', 'Erreur de remboursement sur la commande ' . $order_detail->id_order . ' la commande n\'a pas été payée.');
@ -422,6 +423,7 @@ class Paybox extends PaymentModule
if (Tools::isSubmit('generateCreditSlip')) {
if($cookie->profile == 1
|| $cookie->profile == 7
|| $cookie->profile == 14
|| $cookie->profile == 11) {
$order = new Order($order_detail->id_order);

@ -0,0 +1 @@
Subproject commit b26d6103a62b0eff495b785ec15edf0ad7020ea8

View File

@ -0,0 +1,234 @@
<?php
class Print_Ean extends Module {
public function __construct() {
$this->name = 'print_ean';
$this->tab = 'administration';
$this->author = 'Antadis';
$this->version = '1';
parent::__construct();
$this->displayName = $this->l('Print Ean');
$this->description = $this->l('Allows to generate product ean and print it');
}
public function install() {
$langs = Db::getInstance()->ExecuteS('
SELECT `id_lang`, `iso_code`
FROM `'._DB_PREFIX_.'lang`
');
# Add custom hooks
$hooks = array(
'admin_product_extra' => array('Display Admin Product extra', 'Called on Admin product to show extra tabs'),
'admin_product_postprocess' => array('Admin Product Post Process', 'Called on PostProcess Admin Product'),
);
foreach($hooks as $k => $v) {
if(count(Db::getInstance()->ExecuteS('
SELECT `id_hook`
FROM `'._DB_PREFIX_.'hook`
WHERE `name` = "'.$k.'"
LIMIT 1
')) == 0) {
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'hook`
VALUES (DEFAULT, "'.$k.'", "'.$v[0].'", "'.$v[1].'", 0, 0)
');
}
}
# Register hooks
if(!parent::install()
|| !$this->registerHook('admin_product_extra')
|| !$this->registerHook('admin_product_postprocess')) {
return false;
}
return true;
}
public function uninstall() {
if(parent::uninstall() == false) {
return false;
}
return true;
}
public function hookAdmin_Product_Postprocess($params) {
if(Tools::isSubmit('generateEan') && Tools::getValue('id_product')){
global $cookie, $smarty, $currentIndex;
$product = new Product(Tools::getValue('id_product'));
$combinations = $product->getAttributeCombinaisons($cookie->id_lang);
if ($combinations) {
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']
);
} else {
$ean_generate = $combination['ean13'];
}
$this->printEAN13($ean_generate,1,Configuration::get('LOGISTICS_QUEUE_'.(int) $cookie->id_employee));
}
} 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
');
} 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'));
}
}
public function hookAdmin_Product_Extra($params) {
global $cookie, $smarty;
$product = new Product((int)$params['product']->id);
$combinations = $product->getAttributeCombinaisons((int)$cookie->id_lang);
$_html = '<style>
.table-ean {
text-align:center;
}
</style>';
$_html .= '<div class="tab-page" id="stepEAN">
<h4 class="tab">'.$this->l('EAN Management').'</h4>
<fieldset>
<legend>'.$this->l('Print & Generate EAN').'</legend>
<div>';
if($combinations){
$_html .= '<h4>'.$this->l('Le produit présente des attributs : ').'</h4>
<table border="0" cellpadding="0" cellspacing="0" class="table table-ean">
<tbody>
<tr>
<th>ID</th>
<th>Déclinaisons</th>
<th>EAN13</th>
</tr>';
foreach ($combinations as $key => $combination) {
$_html .= '<tr style="background-color:#D1EAEF">
<td>'.$combination['id_product_attribute'].'</td>
<td>'.$combination['attribute_name'].'</td>
<td>'.(!empty($combination['ean13'])?$combination['ean13']:$this->l('Pas encore d\'ean')).'</td>
</tr>';
}
$_html .= '</tbody></table>';
} else {
if(!empty($product->ean13)) {
$_html .= '
<h4>'.$this->l('Le produit présente déjà un code ean').' : <strong>'.$product->ean13.'</strong></h4>';
} else {
$_html .= '
<h4>'.$this->l('Le produit n\'a pas encore de code ean').'</h4>';
}
}
$_html .= '<div class="clear"></div>
</div>
<p><button class="button" type="submit" name="generateEan">'.$this->l('Lancer la génération/impression').'</button></p>
</fieldset>
</div>';
return $_html;
}
private function _getEanNumber() {
// min 1111111111
$number = Configuration::get('BARCODE_NUMBER') + 1;
Configuration::updateValue('BARCODE_NUMBER', $number);
return $number;
}
public function printEAN13($ean13, $quantity, $queue) {
if((string) $queue == '') {
return;
}
if($quantity > 30 || $quantity < 1) {
$quantity = 1;
}
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/OptionInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/AbstractOption.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Command/Processor/CommandProcessingInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Command/PrefixableCommandInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Command/CommandInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Command/AbstractCommand.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Command/PrefixableCommand.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Command/PubSubPublish.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Connection/ConnectionInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Connection/SingleConnectionInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Helpers.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/PredisException.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/CommunicationException.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Connection/ConnectionException.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Connection/AbstractConnection.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Connection/StreamConnection.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Connection/ConnectionParametersInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Connection/ConnectionParameters.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Connection/ConnectionFactoryInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Connection/ConnectionFactory.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Profile/ServerProfileInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Profile/ServerProfile.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Profile/ServerVersion26.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/ClientCluster.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/ClientPrefix.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/ClientExceptions.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/ClientReplication.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/ClientConnectionFactory.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/ClientProfile.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/ClientOptionsInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Option/ClientOptions.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/BasicClientInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/ClientInterface.php';
require_once dirname(__FILE__).'/libs/predis/lib/Predis/Client.php';
$redis = new Predis\Client();
$redis->publish(
$queue,
json_encode(array(
'data' => base64_encode(
chr(2).'m'."\n"
.chr(2).'O0100'."\n"
.chr(2).'L'."\n"
.'C0000'."\n"
.'D11'."\n"
.chr(2).'L'."\n"
.'1'.(strlen($ean13) == 12? 'B': 'F').'0000000150340'.$ean13."\n"
.'Q'.sprintf('%04d', $quantity)."\n"
.'E'."\n"
),
'queue' => $queue,
))
);
}
}