Merge branch 'ticket-12391-DiscountForNoneOrder' into develop

This commit is contained in:
Marion Muszynski 2017-02-20 12:59:06 +01:00
commit 27f059e40f
2 changed files with 145 additions and 1 deletions

View File

@ -141,6 +141,14 @@ class AdminAntConfigurations extends AdminTab
} else {
HelperFormBootstrap::echoError($this->l('Veuillez choisir une categorie'));
}
} elseif(Tools::isSubmit('submitExportDiscount')){
HelperFormBootstrap::echoError($this->l('L\'outils n\'est pas encore disponible'));
// $results = DB::getInstance()->ExecuteS('
// SELECT dh.`id_customer`, o.`id_order`, dh.`name`, o.`value`
// FROM `'._DB_PREFIX_.'ant_discount_history` dh
// LEFT JOIN `'._DB_PREFIX_.'order_discount` o ON (o.`id_discount` = dh.`id_discount`)
// WHERE 1
// ');
}
}
@ -238,12 +246,32 @@ class AdminAntConfigurations extends AdminTab
),
)
);
$helperForm->_forms[] = array(
'action' => $base_link,
'title' => $this->l('Outils'),
'icon' => '<span class="glyphicon glyphicon-cog"></span> ',
'class' => 'form-horizontal',
'class_div' => 'col-md-3',
'information' => 'Petit outils d\'exports utiles pour les suivis',
'sections' => array(
array(
'inputs' => array(
array(
'type' => 'submit',
'class' => 'btn-default',
'name' => 'submitExportDiscount',
'value' => $this->l('Exporter Suivi Code promo'),
),
),
),
),
);
$helperForm->_forms[] = array(
'action' => $base_link,
'title' => $this->l('Association categories/ventes'),
'icon' => '<span class="glyphicon glyphicon-cog"></span> ',
'class' => 'form-horizontal',
'class_div' => 'col-md-9',
'class_div' => 'col-md-6',
'sections' => array(
array(
'inputs' => array(

View File

@ -0,0 +1,116 @@
<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
/*
CREATE TABLE `ps_ant_discount_history` (
`id_discount_history` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_customer` int(10) unsigned NOT NULL,
`id_discount` int(10) unsigned NOT NULL,
`code` varchar(50) NOT NULL,
`used` int(4) NOT NULL DEFAULT '0',
`date_add` datetime NOT NULL,
PRIMARY KEY (`id_discount_history`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
*/
$_SERVER['HTTP_HOST'] = 'wwww.bebeboutik.dev';
$_SERVER['SERVER_NAME'] = 'www.bebeboutik.dev';
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
include dirname(__FILE__).'/../../config/config.inc.php';
// Create Discount
$customers = Db::getInstance()->ExecuteS('
SELECT c.`id_customer`
FROM `'._DB_PREFIX_.'customer` c
LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_customer` = c.`id_customer`)
LEFT JOIN `'._DB_PREFIX_.'ant_discount_history` dh ON (dh.`id_customer` = c.`id_customer`)
WHERE c.`date_add` < DATE_SUB(NOW(), INTERVAL 90 DAY)
AND o.`id_order` IS NULL
AND dh.`id_discount_history` IS NULL
ORDER BY c.id_customer DESC
');
foreach($customers as $customer){
if($discount = generateDiscount((int)$customer['id_customer'])) {
registerCustomer((int)$customer['id_customer'],$discount);
}
}
// Clean used Discount
$discounts = Db::getInstance()->ExecuteS('
SELECT dh.`id_discount_history`
FROM `'._DB_PREFIX_.'ant_discount_history` dh
LEFT JOIN `'._DB_PREFIX_.'order_discount` o ON (o.`id_discount` = dh.`id_discount`)
WHERE o.`id_order` IS NOT NULL
AND dh.`used` = 0
');
foreach ($discounts as $key => $discount) {
Db::getInstance()->Execute('
UPDATE `'._DB_PREFIX_.'ant_discount_history`
SET `used` = 1
WHERE `id_discount_history` ='.(int)$discount['id_discount_history'].'
');
}
function generateDiscount($id_customer)
{
$discount = new Discount();
$discount->id_customer = (int)$id_customer;
$discount->id_discount_type = 2;
$discount->behavior_not_exhausted = 1;
$discount->cumulable = 0;
$discount->cumulable_reduction = 1;
$discount->minimal = 10;
$discount->include_tax = 1;
$discount->cart_display = 0;
$discount->active = 1;
$discount->quantity = 1;
$discount->quantity_per_user = 1;
$discount->date_from = date('Y-m-d H:i:s');
$discount->date_to = (date('Y') + 1).date('-m-d H:i:s');
$name = 'KDO-'. Tools::passwdGen(8);
if(Discount::discountExists($name))
{
$name = 'KDO-'. Tools::passwdGen(8);
}
$discount->name = $name;
$languages = Language::getLanguages(TRUE);
$description = array(
1 => 'Welcome Gift',
2 => 'Cadeau de Bienvenue',
3 => 'Regalo de Bienvenida',
4 => 'Welcome Gift',
5 => 'Welcome Gift'
);
foreach ($languages as $language) {
$discount->description[$language['id_lang']] = $description[$language['id_lang']];
}
$discount->id_currency = 1;
$discount->value = 50;
if($discount->add(true, false, array(1)) ) {
return $discount;
} else {
return false;
}
}
function registerCustomer($id_customer,$discount) {
Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'ant_discount_history` (`id_discount_history`,`id_customer`,`id_discount`,`code`,`used`,`date_add`)
VALUES (
DEFAULT,
'.(int)$id_customer.',
'.(int)$discount->id.',
"'.pSQL($discount->name).'",
0,
NOW()
)
');
}