correct code style, update L4/commandes-perso with module
This commit is contained in:
parent
6912a92b97
commit
d267225d5c
@ -13,6 +13,33 @@ $dayNOW=date('Y-m-d');
|
||||
$dayNOW_INF=date('Y-m-d', strtotime("-10 day"))." 00:00:00";
|
||||
$dayNOW_SUP=date('Y-m-d')." 23:59:59";
|
||||
|
||||
|
||||
//----------------------------------------------
|
||||
// MODULE 'antadis product pack'
|
||||
//----------------------------------------------
|
||||
$id_lang = 1;
|
||||
$id_products_to_replace = array();
|
||||
|
||||
$sql = 'SELECT COUNT(*) AS nb_module FROM `ps_module` WHERE `name` = \'antadis_productpack\'';
|
||||
$res = mysql_query($sql, $conn);
|
||||
$row = mysql_fetch_array($res);
|
||||
if ($row['nb_module'] == 1) {
|
||||
$sql = 'SELECT pa.`id_product_root`, ppa.`id_product_associated`
|
||||
FROM `ps_productpack` pa
|
||||
JOIN `ps_productpack_association` ppa ON ppa.`id_productpack` = pa.`id_productpack`
|
||||
ORDER BY pa.`id_product_root`';
|
||||
$res = mysql_query($sql, $conn);
|
||||
$id_products_to_replace = array();
|
||||
|
||||
while ($row = mysql_fetch_array($res)) {
|
||||
$id_products_to_replace[$row['id_product_root']][] = $row['id_product_associated'];
|
||||
}
|
||||
}
|
||||
//----------------------------------------------
|
||||
// MODULE 'antadis product pack' END
|
||||
//----------------------------------------------
|
||||
|
||||
|
||||
$sql = "SELECT o.*,c.name as carrier_name
|
||||
from ps_orders o
|
||||
left join ps_carrier c on (o.id_carrier=c.id_carrier)
|
||||
@ -208,18 +235,48 @@ foreach($results as $row){
|
||||
continue;
|
||||
}
|
||||
|
||||
$ligne++;
|
||||
$product_reference=$rowProd['product_reference'];
|
||||
$product_name=utf8_encode($rowProd['product_name']);
|
||||
$product_name=str_replace('&','&',$product_name);
|
||||
$qty=$rowProd['product_quantity'];
|
||||
$txt.='
|
||||
<LIGNE>
|
||||
<IDLIGNE>'.$ligne.'</IDLIGNE>
|
||||
<CODARTI>'.$product_reference.'</CODARTI>
|
||||
<QTTECDE>'.$qty.'</QTTECDE>
|
||||
<DESLANG>'.$product_name.'</DESLANG>
|
||||
</LIGNE>';
|
||||
if (isset($id_products_to_replace[$rowProd['product_id']]) &&
|
||||
is_array($id_products_to_replace[$rowProd['product_id']])){
|
||||
|
||||
foreach($id_products_to_replace[$rowProd['product_id']] as $id_product) {
|
||||
$sql = 'SELECT pl.`name`, p.`reference`
|
||||
FROM `ps_product` p
|
||||
JOIN `ps_product_lang` pl
|
||||
ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = '.(int)$id_lang.')
|
||||
WHERE p.`id_product` = '.(int)$id_product;
|
||||
|
||||
$resultProductOfPack = mysql_query($sql, $conn);
|
||||
$rowProdOfPack = mysql_fetch_array($resultProductOfPack);
|
||||
|
||||
$ligne++;
|
||||
$product_reference=$rowProdOfPack['reference'];
|
||||
$product_name=utf8_encode($rowProdOfPack['name']);
|
||||
$product_name=str_replace('&','&',$product_name);
|
||||
$qty=$rowProd['product_quantity'];
|
||||
$txt.='
|
||||
<LIGNE>
|
||||
<IDLIGNE>'.$ligne.'</IDLIGNE>
|
||||
<CODARTI>'.$product_reference.'</CODARTI>
|
||||
<QTTECDE>'.$qty.'</QTTECDE>
|
||||
<DESLANG>'.$product_name.'</DESLANG>
|
||||
</LIGNE>';
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
$ligne++;
|
||||
$product_reference=$rowProd['product_reference'];
|
||||
$product_name=utf8_encode($rowProd['product_name']);
|
||||
$product_name=str_replace('&','&',$product_name);
|
||||
$qty=$rowProd['product_quantity'];
|
||||
$txt.='
|
||||
<LIGNE>
|
||||
<IDLIGNE>'.$ligne.'</IDLIGNE>
|
||||
<CODARTI>'.$product_reference.'</CODARTI>
|
||||
<QTTECDE>'.$qty.'</QTTECDE>
|
||||
<DESLANG>'.$product_name.'</DESLANG>
|
||||
</LIGNE>';
|
||||
}
|
||||
}
|
||||
}
|
||||
$txt.="
|
||||
|
@ -2,7 +2,7 @@
|
||||
if (!defined('_CAN_LOAD_FILES_'))
|
||||
exit;
|
||||
|
||||
include_once(_PS_MODULE_DIR_.'antadis_productpack/controllers/admin/AdminProductPack.php');
|
||||
include_once _PS_MODULE_DIR_.'antadis_productpack/controllers/admin/AdminProductPack.php';
|
||||
|
||||
class Antadis_ProductPack extends Module
|
||||
{
|
||||
@ -25,11 +25,13 @@ class Antadis_ProductPack extends Module
|
||||
|
||||
public function install()
|
||||
{
|
||||
if (Shop::isFeatureActive())
|
||||
Shop::setContext(Shop::CONTEXT_ALL);
|
||||
if (Shop::isFeatureActive()) {
|
||||
Shop::setContext(Shop::CONTEXT_ALL);
|
||||
}
|
||||
|
||||
if (!parent::install())
|
||||
if (!parent::install()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$new_tab = new Tab();
|
||||
$new_tab->class_name = 'AdminProductPack';
|
||||
@ -39,27 +41,24 @@ class Antadis_ProductPack extends Module
|
||||
foreach ($languages as $language) {
|
||||
$new_tab->name[$language['id_lang']] = $this->l('Packs produits');
|
||||
}
|
||||
|
||||
$result = $new_tab->add();
|
||||
|
||||
$sql = "CREATE TABLE `"._DB_PREFIX_."productpack` (
|
||||
$sql = 'CREATE TABLE `'._DB_PREFIX_.'productpack` (
|
||||
`id_productpack` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`id_product_root` INTEGER UNSIGNED NOT NULL,
|
||||
PRIMARY KEY (`id_productpack`)
|
||||
)";
|
||||
)';
|
||||
$result = Db::getInstance()->execute($sql);
|
||||
|
||||
if (!$result) {
|
||||
$this->uninstallTab();
|
||||
}
|
||||
|
||||
$sql = "CREATE TABLE `"._DB_PREFIX_."productpack_association` (
|
||||
$sql = 'CREATE TABLE `'._DB_PREFIX_.'productpack_association` (
|
||||
`id_productpack` INTEGER UNSIGNED NOT NULL,
|
||||
`id_product_associated` INTEGER UNSIGNED NOT NULL,
|
||||
INDEX `index_productpack_association` (`id_productpack`, `id_product_associated`)
|
||||
)";
|
||||
)';
|
||||
$result = Db::getInstance()->execute($sql);
|
||||
|
||||
if (!$result) {
|
||||
$this->uninstallTab();
|
||||
}
|
||||
@ -69,10 +68,10 @@ class Antadis_ProductPack extends Module
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
$sql = "DROP TABLE IF EXISTS `"._DB_PREFIX_."productpack_association`";
|
||||
$sql = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'productpack_association`';
|
||||
Db::getInstance()->execute($sql);
|
||||
|
||||
$sql = "DROP TABLE IF EXISTS `"._DB_PREFIX_."productpack`";
|
||||
$sql = 'DROP TABLE IF EXISTS `'._DB_PREFIX_.'productpack`';
|
||||
Db::getInstance()->execute($sql);
|
||||
|
||||
$this->uninstallTab();
|
||||
@ -89,7 +88,8 @@ class Antadis_ProductPack extends Module
|
||||
}
|
||||
}
|
||||
|
||||
public function getContent(){
|
||||
public function getContent()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Description of AdminCartRuleProductPackController
|
||||
*
|
||||
* @company Antadis
|
||||
*/
|
||||
include_once(_PS_MODULE_DIR_.'antadis_productpack/models/ProductPack.php');
|
||||
|
||||
class AdminProductPackController extends ModuleAdminController {
|
||||
include_once _PS_MODULE_DIR_.'antadis_productpack/models/ProductPack.php';
|
||||
|
||||
class AdminProductPackController extends ModuleAdminController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->bootstrap = true;
|
||||
@ -24,9 +22,11 @@ class AdminProductPackController extends ModuleAdminController {
|
||||
$this->_select .= 'a.`id_product_root`, pl.`name`, p.`reference` product_ref, count(pa.`id_product_associated`) nb_products';
|
||||
|
||||
$this->_join .= '
|
||||
JOIN `'._DB_PREFIX_.'product` p ON (a.`id_product_root` = p.`id_product`)
|
||||
JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.$this->context->language->id.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'productpack_association` pa ON (a.`id_productpack` = pa.`id_productpack`)';
|
||||
JOIN `'._DB_PREFIX_.'product` p
|
||||
ON (a.`id_product_root` = p.`id_product`)
|
||||
JOIN `'._DB_PREFIX_.'product_lang` pl
|
||||
ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int) $this->context->language->id.')
|
||||
LEFT JOIN `'._DB_PREFIX_.'productpack_association` pa ON (a.`id_productpack` = pa.`id_productpack`)';
|
||||
|
||||
$this->_group .= 'GROUP BY a.`id_product_root`, pl.`name`, product_ref';
|
||||
|
||||
@ -63,21 +63,9 @@ class AdminProductPackController extends ModuleAdminController {
|
||||
return parent::renderList();
|
||||
}
|
||||
|
||||
public function processDelete()
|
||||
{
|
||||
$object = $this->loadObject();
|
||||
|
||||
if (Validate::isLoadedObject($object)) {
|
||||
$object->deleteAssociations();
|
||||
}
|
||||
|
||||
return parent::processDelete();
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
if ($this->display == 'edit' || $this->display == 'add')
|
||||
{
|
||||
if ($this->display == 'edit' || $this->display == 'add') {
|
||||
$this->addjQueryPlugin(array(
|
||||
'autocomplete',
|
||||
'tablednd'
|
||||
@ -128,7 +116,7 @@ class AdminProductPackController extends ModuleAdminController {
|
||||
if(Validate::isLoadedObject($this->object)) {
|
||||
$productpack = $this->object;
|
||||
}
|
||||
else{
|
||||
else {
|
||||
$productpack = new ProductPack();
|
||||
$productpack->id_product_root = Tools::getValue('id_product_root');
|
||||
$productpack->add();
|
||||
@ -142,15 +130,12 @@ class AdminProductPackController extends ModuleAdminController {
|
||||
public function updateProductAssociations($productpack)
|
||||
{
|
||||
$productpack->deleteAssociations();
|
||||
if ($product_associations = Tools::getValue('inputProducts'))
|
||||
{
|
||||
if ($product_associations = Tools::getValue('inputProducts')) {
|
||||
$product_id = array_unique(explode('-', $product_associations));
|
||||
if (count($product_id))
|
||||
{
|
||||
if (count($product_id)) {
|
||||
array_pop($product_id);
|
||||
$productpack->changeAssociations($product_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -16,16 +16,13 @@ class ProductPack extends ObjectModel {
|
||||
|
||||
public static function getIdProductsToReplace()
|
||||
{
|
||||
// get all products in productpack module but the product root
|
||||
$id_products_to_replace = array();
|
||||
|
||||
$sql = 'SELECT pa.`id_product_root`, ppa.`id_product_associated`
|
||||
FROM `'._DB_PREFIX_.'productpack` pa
|
||||
JOIN `'._DB_PREFIX_.'productpack_association` ppa ON ppa.`id_productpack` = pa.`id_productpack`
|
||||
ORDER BY pa.`id_product_root`';
|
||||
$result = DB::getInstance()->executeS($sql);
|
||||
|
||||
$id_product_root = '';
|
||||
$id_products_to_replace = array();
|
||||
foreach ($result as $row) {
|
||||
$id_products_to_replace[$row['id_product_root']][] = $row['id_product_associated'];
|
||||
}
|
||||
@ -33,6 +30,12 @@ class ProductPack extends ObjectModel {
|
||||
return $id_products_to_replace;
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$this->deleteAssociations();
|
||||
return parent::delete();
|
||||
}
|
||||
|
||||
public function deleteAssociations()
|
||||
{
|
||||
if (Validate::isLoadedObject($this)) {
|
||||
@ -57,12 +60,12 @@ class ProductPack extends ObjectModel {
|
||||
{
|
||||
if (Validate::isLoadedObject($this)) {
|
||||
$sql = 'SELECT p.`id_product`, p.`reference`, pl.`name`
|
||||
FROM `'._DB_PREFIX_.'productpack_association` pa
|
||||
JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = pa.`id_product_associated`
|
||||
JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = '.(int)$id_lang.')
|
||||
WHERE pa.`id_productpack` = '.(int)$this->id;
|
||||
FROM `'._DB_PREFIX_.'productpack_association` pa
|
||||
JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = pa.`id_product_associated`
|
||||
JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = '.(int)$id_lang.')
|
||||
WHERE pa.`id_productpack` = '.(int)$this->id;
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
return [];
|
||||
return array();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user