export cat nw
This commit is contained in:
parent
7b5b3bd48e
commit
224e53ece4
41
migrations/20151016135600_newsletter_migration.php
Normal file
41
migrations/20151016135600_newsletter_migration.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
class NewsletterMigration extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$this->execute('CREATE TABLE `ps_newsletter_cmsps` (
|
||||
`id_newsletter` int(11) NOT NULL,
|
||||
`id_category` int(11) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;');
|
||||
|
||||
$this->execute('ALTER TABLE `ps_newsletter_cmsps`
|
||||
ADD UNIQUE KEY `id_newsletter` (`id_newsletter`,`id_category`)');
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
36
migrations/20151016142247_newsletter_cms_ps_migration.php
Normal file
36
migrations/20151016142247_newsletter_cms_ps_migration.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
class NewsletterCmsPsMigration extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Change Method.
|
||||
*
|
||||
* Write your reversible migrations using this method.
|
||||
*
|
||||
* More information on writing migrations is available here:
|
||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
||||
*
|
||||
* The following commands can be used in this method and Phinx will
|
||||
* automatically reverse them when rolling back:
|
||||
*
|
||||
* createTable
|
||||
* renameTable
|
||||
* addColumn
|
||||
* renameColumn
|
||||
* addIndex
|
||||
* addForeignKey
|
||||
*
|
||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
||||
* with the Table class.
|
||||
*/
|
||||
public function change()
|
||||
{
|
||||
$this->execute('ALTER TABLE `ps_newsletter_cmsps`
|
||||
ADD `id_customer` INT(11) NULL,
|
||||
MODIFY `id_newsletter` INT(11) NULL,
|
||||
ADD UNIQUE KEY `id_customer` (`id_customer`,`id_category`)');
|
||||
|
||||
}
|
||||
}
|
@ -68,6 +68,55 @@ class AdminCmsPsCategoriesController extends ModuleAdminController {
|
||||
}
|
||||
}
|
||||
|
||||
public function initContent(){
|
||||
parent::initContent();
|
||||
if (Tools::getIsset('export'.$this->table)){
|
||||
|
||||
$this->display = 'export';
|
||||
$this->action = 'export';
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public function processExport($delimiter=';'){
|
||||
|
||||
$items = $this->getCatNewsletterSubscriber(Tools::getValue('id_category'));
|
||||
$filename = $this->table.'_'.date('Y-m-d_His').'.csv';
|
||||
|
||||
header('Content-Type: application/force-download; charset=UTF-8');
|
||||
header('Content-disposition: attachment; filename="'.$filename.'"');
|
||||
|
||||
$this->exportCsv($items, $filename);
|
||||
die();
|
||||
}
|
||||
|
||||
public function exportCsv($items, $filename){
|
||||
$row_definition = array(
|
||||
'email' => 'email',
|
||||
'is_customer' => 'is_customer'
|
||||
);
|
||||
|
||||
//open file pointer to standard output
|
||||
$fp = fopen("php://output", 'w+');
|
||||
$delim = ';';
|
||||
|
||||
// first row
|
||||
$data=array();
|
||||
foreach ($row_definition as $col => $index)
|
||||
$data[]=$col;
|
||||
fputcsv ($fp,$data,$delim);
|
||||
|
||||
foreach ($items as $item) {
|
||||
$data = array();
|
||||
foreach ($row_definition as $index)
|
||||
$data[] = (isset($item[$index]) ? $item[$index] : '');
|
||||
fputcsv ($fp,array_map('utf8_decode',array_values($data)),$delim);
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
public function renderForm() {
|
||||
if (!($obj = $this->loadObject(TRUE)))
|
||||
return;
|
||||
@ -199,6 +248,25 @@ class AdminCmsPsCategoriesController extends ModuleAdminController {
|
||||
}
|
||||
}
|
||||
|
||||
public function renderList(){
|
||||
$this->addRowAction('export');
|
||||
return parent::renderList();
|
||||
}
|
||||
|
||||
public function displayExportLink($token = null, $id, $name = null) {
|
||||
$tpl = $this->createTemplate('helpers/list/list_action_edit.tpl');
|
||||
if (!array_key_exists('Export', self::$cache_lang))
|
||||
self::$cache_lang['Export'] = $this->l('Export', 'Helper');
|
||||
|
||||
$tpl->assign(array(
|
||||
'href' => self::$currentIndex.'&'.$this->identifier.'='.$id.'&export'.$this->table.'&token='.($token != null ? $token : $this->token),
|
||||
'action' => self::$cache_lang['Export'],
|
||||
'id' => $id
|
||||
));
|
||||
|
||||
return $tpl->fetch();
|
||||
}
|
||||
|
||||
public function getParentPossibility() {
|
||||
$categories_list = CmsPsCategory::getParentPossibility($this->context->language->id, $this->context->shop->id, $this->object->id_category);
|
||||
$categories = array(
|
||||
@ -216,6 +284,28 @@ class AdminCmsPsCategoriesController extends ModuleAdminController {
|
||||
return $categories;
|
||||
}
|
||||
|
||||
public function getCatNewsletterSubscriber($id_category){
|
||||
|
||||
$sqlCustomer = 'SELECT c.`email`, ("oui") as is_customer
|
||||
FROM '._DB_PREFIX_.'customer c
|
||||
LEFT JOIN '._DB_PREFIX_.'newsletter_cmsps nc ON (nc.`id_customer` = c.`id_customer`)
|
||||
WHERE nc.`id_category` = '.(int)$id_category.'
|
||||
AND c.`newsletter` = 1
|
||||
AND nc.`id_customer` IS NOT NULL
|
||||
AND c.`id_shop` = '.$this->context->shop->id;
|
||||
|
||||
$sqlGuest = 'SELECT n.`email`, ("non") as is_customer
|
||||
FROM '._DB_PREFIX_.'newsletter n
|
||||
LEFT JOIN '._DB_PREFIX_.'newsletter_cmsps nc ON (nc.`id_newsletter` = n.`id`)
|
||||
WHERE nc.`id_category` = '.(int)$id_category.'
|
||||
AND nc.`id_newsletter` IS NOT NULL
|
||||
AND n.`id_shop` = '.$this->context->shop->id;
|
||||
|
||||
return Db::getInstance()->ExecuteS('('.$sqlCustomer.') UNION ('.$sqlGuest.')');
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function copyFromPost(&$object, $table) {
|
||||
parent::copyFromPost($object, $table);
|
||||
}
|
||||
|
@ -8,25 +8,15 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
public function install() {
|
||||
if (!parent::install() || !$this->registerHook('displayNewsletterFooter')|| !$this->registerHook('displayleftPostCms'))
|
||||
return false;
|
||||
/*return Db::getInstance()->execute('
|
||||
CREATE TABLE IF NOT EXISTS `'._DB_PREFIX_.'newsletter_cmsps` (
|
||||
`id_customer` int(11) NULL ,
|
||||
`id_newsletter` int(11) NULL,
|
||||
`id_category` int(11) NOT NULL
|
||||
) ENGINE='._MYSQL_ENGINE_.' default CHARSET=utf8');*/
|
||||
}
|
||||
|
||||
public function ajaxCall($email, $action = 0, $page, $id_post = false){
|
||||
/*$_POST['email'] = $email;
|
||||
$_POST['action'] = $action;
|
||||
$_POST['page'] = $page;
|
||||
if($id_post)
|
||||
$_POST['id_post'] = $id_post;
|
||||
$result = $this->newsletterRegistration();
|
||||
if($result && $this->error != '')
|
||||
die(Tools::jsonEncode(array(
|
||||
'has_error' => true,
|
||||
'message' => $this->error
|
||||
)));
|
||||
elseif($result && $this->valid!='')
|
||||
die(Tools::jsonEncode(array(
|
||||
'has_error' => false,
|
||||
'message' => $this->valid
|
||||
)));*/
|
||||
|
||||
if (empty($email) || !Validate::isEmail($email))
|
||||
return array(
|
||||
@ -117,9 +107,8 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
$register_status = $this->isNewsletterRegistered($_POST['email']);
|
||||
$email = pSQL($_POST['email']);
|
||||
if ($register_status > 0){
|
||||
|
||||
// Pas d'enregistrement mais envoie du pdf
|
||||
if (Configuration::get('NW_CONFIRMATION_EMAIL') && $cmsCategory){
|
||||
if (Configuration::get('NW_CONFIRMATION_EMAIL') && $cmsCategory && $this->isNewsletterCmsPsRegistered($email, $cmsCategory['id_category'], $register_status)){
|
||||
// enregistrement pour la categorie si pas enregistré pour
|
||||
$this->valid = $this->l('You will recieve your PDF.');
|
||||
$this->sendConfirmationEmail($email, $cmsCategory);
|
||||
}
|
||||
@ -156,7 +145,7 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
|
||||
if ($code = Configuration::get('NW_VOUCHER_CODE') && !$cmsCategory && !$genericPdf)
|
||||
$this->sendVoucher($email, Configuration::get('NW_VOUCHER_CODE'));
|
||||
elseif (Configuration::get('NW_CONFIRMATION_EMAIL') && $cmsCategory)
|
||||
elseif (Configuration::get('NW_CONFIRMATION_EMAIL') && $cmsCategory && $this->isNewsletterCmsPsRegistered($email, $cmsCategory['id_category'], $register_status))
|
||||
$this->sendConfirmationEmail($email, $cmsCategory);
|
||||
elseif (Configuration::get('NW_CONFIRMATION_EMAIL') && $genericPdf)
|
||||
$this->sendConfirmationEmail($email, false, $genericPdf);
|
||||
@ -194,6 +183,66 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
|
||||
}
|
||||
|
||||
protected function isNewsletterCmsPsRegistered($email, $id_category, $register_status)
|
||||
{
|
||||
if($register_status == self::GUEST_REGISTERED)
|
||||
$sql = 'SELECT n.`id`
|
||||
FROM '._DB_PREFIX_.'newsletter n
|
||||
LEFT JOIN '._DB_PREFIX_.'newsletter_cmsps nc ON (nc.`id_newsletter` = n.`id`)
|
||||
WHERE n.`email` = \''.pSQL($email).'\'
|
||||
AND n.`id_shop` = '.$this->context->shop->id.'
|
||||
AND nc.`id_category`='.(int)$id_category;
|
||||
elseif($register_status == self::CUSTOMER_REGISTERED)
|
||||
$sql = 'SELECT c.`id_customer`
|
||||
FROM '._DB_PREFIX_.'customer c
|
||||
LEFT JOIN '._DB_PREFIX_.'newsletter_cmsps nc ON (nc.`id_customer` = c.`id_customer`)
|
||||
WHERE c.`email` = \''.pSQL($email).'\'
|
||||
AND c.`newsletter` = 1
|
||||
AND nc.`id_customer` IS NOT NULL
|
||||
AND c.`id_shop` = '.$this->context->shop->id;
|
||||
else
|
||||
return false;
|
||||
|
||||
if ($test = Db::getInstance()->getRow($sql)){
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return $this->registerNewsletterCmsPs($email, $id_category, $register_status);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function registerNewsletterCmsPs($email, $id_category, $register_status)
|
||||
{
|
||||
if($register_status == self::GUEST_REGISTERED)
|
||||
$sql = 'INSERT INTO '._DB_PREFIX_.'newsletter_cmsps (id_newsletter, id_category)
|
||||
VALUES
|
||||
(
|
||||
(
|
||||
SELECT n.`id`
|
||||
FROM '._DB_PREFIX_.'newsletter n
|
||||
WHERE n.`email` = \''.pSQL($email).'\'
|
||||
),
|
||||
'.(int)$id_category.'
|
||||
)';
|
||||
elseif($register_status == self::CUSTOMER_REGISTERED)
|
||||
$sql = 'INSERT INTO '._DB_PREFIX_.'newsletter_cmsps (id_category, id_customer)
|
||||
VALUES
|
||||
(
|
||||
'.(int)$id_category.',
|
||||
(
|
||||
SELECT c.`id_customer`
|
||||
FROM '._DB_PREFIX_.'customer c
|
||||
WHERE c.`email` = \''.pSQL($email).'\'
|
||||
AND c.`newsletter` = \'1\'
|
||||
)
|
||||
)';
|
||||
|
||||
//echo "<pre>";var_dump($sql);echo "</pre>";die();
|
||||
|
||||
return Db::getInstance()->execute($sql);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Override
|
||||
@ -204,6 +253,7 @@ class BlockNewsletterOverride extends BlockNewsletter
|
||||
$fileAttachment = array();
|
||||
if($cmsCategory){
|
||||
if(glob(_CMS_CAT_IMG_DIR_.'pdf/Tout-pratique-'.$cmsCategory['slug'].'.pdf')){
|
||||
echo "<pre>";var_dump('in pdf cat');echo "</pre>";die();
|
||||
$fileAttachment['content'] = _CMS_CAT_IMG_DIR_.'pdf/Tout-pratique-'.$cmsCategory['slug'].'.pdf';
|
||||
$fileAttachment['name'] = 'Tout-pratique-'.$cmsCategory['slug'].'.pdf';
|
||||
$fileAttachment['mime'] = "application/pdf";
|
||||
|
Loading…
Reference in New Issue
Block a user