Sauvegarde configuration et mail
This commit is contained in:
parent
60b2508d1f
commit
533ede92cf
58
www/modules/antadisconfigurator/ajax.php
Normal file
58
www/modules/antadisconfigurator/ajax.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__).'../../../config/config.inc.php');
|
||||
require_once(dirname(__FILE__).'../../../init.php');
|
||||
|
||||
$module = new AntadisConfigurator();
|
||||
|
||||
switch (Tools::getValue('action')) {
|
||||
case 'backup' :
|
||||
$email = Tools::getValue('config-email');
|
||||
if (empty($email)) {
|
||||
$return = array(
|
||||
'hasError' => true,
|
||||
'errors' => $module->l("No email given."),
|
||||
);
|
||||
} else {
|
||||
$id_product = Tools::getValue('id_product');
|
||||
$id_configurator = Tools::getValue('configurator');
|
||||
$id_configurator = ConfiguratorStorage::backupConfigurator($id_configurator, $id_product);
|
||||
if ($id_configurator == 0) {
|
||||
$return = array(
|
||||
'hasError' => true,
|
||||
'errors' => $module->l("Error configuration not save."),
|
||||
);
|
||||
} else {
|
||||
$ctx = Context::getContext();
|
||||
|
||||
$product = new Product($id_product);
|
||||
$category = new Category($product->id_category_default);
|
||||
$link = new Link();
|
||||
|
||||
$vars = array(
|
||||
'{product_name}' => $product->name,
|
||||
'{configurator_link}' => $link->getProductLink($product, null, $category->link_rewrite[$ctx->language->id]).
|
||||
'?id_configurator='.$id_configurator,
|
||||
);
|
||||
|
||||
$isMailSent = Mail::Send($ctx->language->id, 'configurator_backup', "Votre simulation", $vars, $email);
|
||||
if ($isMailSent) {
|
||||
$return = array(
|
||||
'hasError' => false,
|
||||
'id' => $id_configurator,
|
||||
'msg' => $module->l("Configuration enregistré."),
|
||||
);
|
||||
} else {
|
||||
$return = array(
|
||||
'hasError' => true,
|
||||
'errors' => $module->l("Error configuration not save."),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
die(Tools::jsonEncode($return));
|
||||
break;
|
||||
default:
|
||||
exit;
|
||||
}
|
||||
|
||||
exit;
|
@ -245,6 +245,88 @@ class ConfiguratorStorage extends ObjectModel
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public static function backupConfigurator($id_configurator, $id_product)
|
||||
{
|
||||
$detectOptGroup = 'optgroup-';
|
||||
$postValues = Tools::getAllValues();
|
||||
|
||||
if (count($postValues) > 0) {
|
||||
$sqlValues = array();
|
||||
foreach($postValues as $p => $v) {
|
||||
if (!empty($v)) {
|
||||
if (substr($p, 0, strlen($detectOptGroup)) === $detectOptGroup) {
|
||||
$ids = explode('-', substr($p, strlen($detectOptGroup)));
|
||||
$id_configurator_opt_group = $ids[0];
|
||||
$id_configurator_opt = $v;
|
||||
|
||||
$optValue = '';
|
||||
if (isset($ids[1])) {
|
||||
$id_configurator_opt = $ids[1];
|
||||
$optValue = $v;
|
||||
}
|
||||
|
||||
if (is_array($id_configurator_opt) && count($id_configurator_opt) > 0) {
|
||||
foreach ($id_configurator_opt as $item) {
|
||||
$price = Db::getInstance()->getValue('SELECT pcoi.`price` FROM `'._DB_PREFIX_.'configurator_opt` co,
|
||||
`'._DB_PREFIX_.'product_configurator_opt_impact` pcoi
|
||||
WHERE co.`id_configurator_opt` = pcoi.`id_configurator_opt` AND co.`id_configurator_opt` = '.(int)$item);
|
||||
$sqlValues[] = '(@id_configurator, '.$id_product.', '.(int)$id_configurator_opt_group.', '.pSQL($item).', \''.pSQL($optValue).'\', '.$price.')';
|
||||
}
|
||||
} else {
|
||||
if (is_array($optValue)) {
|
||||
foreach($optValue as $v) {
|
||||
$price = Db::getInstance()->getValue('SELECT pcoi.`price` FROM `'._DB_PREFIX_.'configurator_opt` co,
|
||||
`'._DB_PREFIX_.'product_configurator_opt_impact` pcoi
|
||||
WHERE co.`id_configurator_opt` = pcoi.`id_configurator_opt` AND co.`id_configurator_opt` = '.(int)$id_configurator_opt);
|
||||
$sqlValues[] = '(@id_configurator, '.$id_product.', '.(int)$id_configurator_opt_group.', '.(int)$id_configurator_opt.', \''.pSQL($v).'\', '.$price.')';
|
||||
}
|
||||
} else {
|
||||
$price = Db::getInstance()->getValue('SELECT pcoi.`price` FROM `'._DB_PREFIX_.'configurator_opt` co,
|
||||
`'._DB_PREFIX_.'product_configurator_opt_impact` pcoi
|
||||
WHERE co.`id_configurator_opt` = pcoi.`id_configurator_opt` AND co.`id_configurator_opt` = '.(int)$id_configurator_opt);
|
||||
$sqlValues[] = '(@id_configurator, '.$id_product.', '.(int)$id_configurator_opt_group.', '.(int)$id_configurator_opt.', \''.pSQL($optValue).'\', '.$price.')';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count($sqlValues) > 0) {
|
||||
if ($id_configurator === null) {
|
||||
$id_configurator = 0;
|
||||
}
|
||||
|
||||
if ($id_configurator == 0) {
|
||||
// Get id_configurator max
|
||||
$cmaxSql = 'SELECT IF(MAX(cp.id_configurator) IS NULL, 0, MAX(cp.id_configurator)) AS maxCp,
|
||||
IF(MAX(cs.id_configurator) IS NULL, 0, MAX(cs.id_configurator)) AS maxCs
|
||||
FROM `'._DB_PREFIX_.'configurator_storage` cs, `'._DB_PREFIX_.'cart_product` cp';
|
||||
$max = Db::getInstance()->getRow($cmaxSql);
|
||||
$id_configurator = ($max['maxCp'] > $max['maxCs'] ? $max['maxCp'] : $max['maxCs']) + 1;
|
||||
}
|
||||
// Delete
|
||||
else {
|
||||
Db::getInstance()->delete('configurator_storage', 'id_configurator = '.(int)$id_configurator);
|
||||
}
|
||||
|
||||
// Insert configuration
|
||||
$insertSql = 'SET @id_configurator = '.$id_configurator.';
|
||||
INSERT INTO `'._DB_PREFIX_.'configurator_storage`
|
||||
(`id_configurator`, `id_product`, `id_configurator_opt_group`, `id_configurator_opt`, `opt_value`, `price`)
|
||||
VALUES '.implode(',', $sqlValues);
|
||||
if (!Db::getInstance()->execute($insertSql)){
|
||||
$id_configurator = 0;
|
||||
}
|
||||
|
||||
return $id_configurator;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if fields are required
|
||||
* @param int $id_product
|
||||
|
@ -9024,10 +9024,6 @@ table.resume td.delivery_option_logo_tnt > img.order_carrier_logo {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#extra_address_data {max-width: 50%;}
|
||||
.fancybox-inner #extra_address_data {
|
||||
padding: 20px;
|
||||
@ -9039,4 +9035,14 @@ table.resume td.delivery_option_logo_tnt > img.order_carrier_logo {
|
||||
|
||||
#manufacturer .ctn.account > div {
|
||||
padding: 30px;
|
||||
}
|
||||
}
|
||||
|
||||
#config-backup {
|
||||
text-transform: none;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
#config-backup-result {
|
||||
display:block;
|
||||
margin-top:15px;
|
||||
}
|
||||
|
@ -129,4 +129,23 @@ $(function(){
|
||||
return returnValidation;
|
||||
});
|
||||
|
||||
$('#config-backup').on('click', function(e){
|
||||
e.preventDefault();
|
||||
var formValues = $('#buy_block').serialize()+'&ajax&action=backup';
|
||||
var id_configurator = $(this).data('configurator');
|
||||
if (id_configurator != '') {
|
||||
formValues = formValues+'&configurator='+id_configurator;
|
||||
}
|
||||
$('#config-backup-result').attr('class', '');
|
||||
$.post(baseDir+'modules/antadisconfigurator/ajax.php', formValues, function(data){
|
||||
if (data.hasError == true) {
|
||||
$('#config-backup-result').addClass('alert alert-danger').text(data.errors);
|
||||
} else {
|
||||
$('#config-backup-result').addClass('alert alert-success').text(data.msg);
|
||||
$('#config-backup').data('configurator', data.id);
|
||||
}
|
||||
}, 'json').fail(function() {
|
||||
$('#config-backup-result').addClass('alert alert-danger').text("Error");
|
||||
});
|
||||
});
|
||||
});
|
@ -3,8 +3,6 @@
|
||||
{/if}
|
||||
|
||||
{if $nbOptGroupList > 0}
|
||||
{*<h3 class="page-product-heading" id="antadisconfigurator-content-tab">{l s='Options' mod='antadisconfigurator'}</h3>*}
|
||||
<input type="hidden" name="id_product" value="{$product->id}" />
|
||||
|
||||
{foreach item=optGroup from=$optGroupList}
|
||||
{if $optGroup['type'] == 'label' && $optGroup['reference'] == 'BIG-TITLE'}
|
||||
|
@ -264,6 +264,17 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="config-backup">
|
||||
<div class="form-control-ctn">
|
||||
<input type="text" name="config-email" class="form-control" value="" placeholder="{l s='Email'}"/>
|
||||
</div>
|
||||
<button type="button" id="config-backup" name="configBackup" class="btn btn2 btn-full-width">
|
||||
<span>{l s='Backup your configuration' mod='antadisconfigurator'}</span>
|
||||
</button>
|
||||
<span id="config-backup-result"></span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{hook h="displayReinsurranceProduct"}
|
||||
{hook h='displayBottomColumnProduct'}
|
||||
|
Loading…
Reference in New Issue
Block a user