// ajax process off adminaccess is now in the controller
This commit is contained in:
@@ -996,85 +996,3 @@ if (Tools::isSubmit('ajaxUpdateTaxRule'))
|
|||||||
die(Tools::jsonEncode($output));
|
die(Tools::jsonEncode($output));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update Access Tabs */
|
|
||||||
if (Tools::isSubmit('submitAddAccess'))
|
|
||||||
{
|
|
||||||
$perm = Tools::getValue('perm');
|
|
||||||
if (!in_array($perm, array('view', 'add', 'edit', 'delete', 'all')))
|
|
||||||
throw new PrestashopException('permission not exists');
|
|
||||||
|
|
||||||
$enabled = (int)Tools::getValue('enabled');
|
|
||||||
$id_tab = (int)Tools::getValue('id_tab');
|
|
||||||
$id_profile = (int)Tools::getValue('id_profile');
|
|
||||||
$res = true;
|
|
||||||
|
|
||||||
if ($id_tab == -1 && $perm == 'all' && $enabled == 0)
|
|
||||||
$res &= Db::getInstance()->execute('
|
|
||||||
UPDATE `'._DB_PREFIX_.'access`
|
|
||||||
SET `view` = '.$enabled.', `add` = '.$enabled.', `edit` = '.$enabled.', `delete` = '.$enabled.'
|
|
||||||
WHERE `id_profile` = '.(int)$id_profile.' AND `id_tab` != 31
|
|
||||||
');
|
|
||||||
else if ($id_tab == -1 && $perm == 'all')
|
|
||||||
$res &= Db::getInstance()->execute('
|
|
||||||
UPDATE `'._DB_PREFIX_.'access`
|
|
||||||
SET `view` = '.$enabled.', `add` = '.$enabled.', `edit` = '.$enabled.', `delete` = '.$enabled.'
|
|
||||||
WHERE `id_profile` = '.(int)$id_profile
|
|
||||||
);
|
|
||||||
else if ($id_tab == -1)
|
|
||||||
$res &= Db::getInstance()->execute('
|
|
||||||
UPDATE `'._DB_PREFIX_.'access`
|
|
||||||
SET `'.pSQL($perm).'` = '.$enabled.'
|
|
||||||
WHERE `id_profile` = '.(int)$id_profile
|
|
||||||
);
|
|
||||||
else if ($perm == 'all')
|
|
||||||
$res &= Db::getInstance()->execute('
|
|
||||||
UPDATE `'._DB_PREFIX_.'access`
|
|
||||||
SET `view` = '.$enabled.', `add` = '.$enabled.', `edit` = '.$enabled.', `delete` = '.$enabled.'
|
|
||||||
WHERE `id_tab` = '.(int)$id_tab.'
|
|
||||||
AND `id_profile` = '.(int)$id_profile
|
|
||||||
);
|
|
||||||
else
|
|
||||||
$res &= Db::getInstance()->execute('
|
|
||||||
UPDATE `'._DB_PREFIX_.'access`
|
|
||||||
SET `'.pSQL($perm).'` = '.$enabled.'
|
|
||||||
WHERE `id_tab` = '.(int)$id_tab.'
|
|
||||||
AND `id_profile` = '.(int)$id_profile
|
|
||||||
);
|
|
||||||
$res = $res?'ok':'error';
|
|
||||||
die($res);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Update Access Modules */
|
|
||||||
if (Tools::isSubmit('changeModuleAccess'))
|
|
||||||
{
|
|
||||||
$perm = Tools::getValue('perm');
|
|
||||||
$enabled = (int)Tools::getValue('enabled');
|
|
||||||
$id_module = (int)Tools::getValue('id_module');
|
|
||||||
$id_profile = (int)Tools::getValue('id_profile');
|
|
||||||
$res = true;
|
|
||||||
|
|
||||||
if (!in_array($perm, array('view', 'configure')))
|
|
||||||
throw new PrestashopException('permission not exists');
|
|
||||||
|
|
||||||
if ($id_module == -1)
|
|
||||||
{
|
|
||||||
$res &= Db::getInstance()->execute('
|
|
||||||
UPDATE `'._DB_PREFIX_.'module_access`
|
|
||||||
SET `'.pSQL($perm).'` = '.(int)$enabled.'
|
|
||||||
WHERE `id_profile` = '.(int)$id_profile
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$res &= Db::getInstance()->execute('
|
|
||||||
UPDATE `'._DB_PREFIX_.'module_access`
|
|
||||||
SET `'.pSQL($perm).'` = '.(int)$enabled.'
|
|
||||||
WHERE `id_module` = '.(int)$id_module.'
|
|
||||||
AND `id_profile` = '.(int)$id_profile
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$res = $res?'ok':'error';
|
|
||||||
die($res);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@
|
|||||||
perfect_access_js_gestion(this, perm, id_tab, tabsize, tabnumber, table);
|
perfect_access_js_gestion(this, perm, id_tab, tabsize, tabnumber, table);
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "ajax.php",
|
url: "{$link->getAdminLink('AdminAccess')}",
|
||||||
cache: false,
|
cache: false,
|
||||||
data : {
|
data : {
|
||||||
ajaxMode : '1',
|
ajaxMode : '1',
|
||||||
@@ -59,7 +59,10 @@
|
|||||||
id_profile: id_profile,
|
id_profile: id_profile,
|
||||||
perm: perm,
|
perm: perm,
|
||||||
enabled: enabled,
|
enabled: enabled,
|
||||||
submitAddAccess: '1'
|
submitAddAccess: '1',
|
||||||
|
action: 'updateAccess',
|
||||||
|
ajax: '1',
|
||||||
|
token: '{getAdminToken tab='AdminAccess'}',
|
||||||
},
|
},
|
||||||
success : function(res,textStatus,jqXHR)
|
success : function(res,textStatus,jqXHR)
|
||||||
{
|
{
|
||||||
@@ -96,7 +99,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "ajax.php",
|
url: "{$link->getAdminLink('AdminAccess')}",
|
||||||
cache: false,
|
cache: false,
|
||||||
data : {
|
data : {
|
||||||
ajaxMode: '1',
|
ajaxMode: '1',
|
||||||
@@ -105,6 +108,9 @@
|
|||||||
enabled: enabled,
|
enabled: enabled,
|
||||||
id_profile: id_profile,
|
id_profile: id_profile,
|
||||||
changeModuleAccess: '1',
|
changeModuleAccess: '1',
|
||||||
|
action: 'updateModuleAccess',
|
||||||
|
ajax: '1',
|
||||||
|
token: '{getAdminToken tab='AdminAccess'}',
|
||||||
},
|
},
|
||||||
success : function(res,textStatus,jqXHR)
|
success : function(res,textStatus,jqXHR)
|
||||||
{
|
{
|
||||||
@@ -382,4 +388,4 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/foreach}
|
{/foreach}
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -69,7 +69,8 @@ class AdminAccessController extends AdminController
|
|||||||
'admin_profile' => (int)_PS_ADMIN_PROFILE_,
|
'admin_profile' => (int)_PS_ADMIN_PROFILE_,
|
||||||
'access_edit' => $this->tabAccess['edit'],
|
'access_edit' => $this->tabAccess['edit'],
|
||||||
'perms' => array('view', 'add', 'edit', 'delete'),
|
'perms' => array('view', 'add', 'edit', 'delete'),
|
||||||
'modules' => $modules
|
'modules' => $modules,
|
||||||
|
'link' => $this->context->link
|
||||||
);
|
);
|
||||||
|
|
||||||
return parent::initForm();
|
return parent::initForm();
|
||||||
@@ -97,6 +98,99 @@ class AdminAccessController extends AdminController
|
|||||||
'url_post' => self::$currentIndex.'&token='.$this->token,
|
'url_post' => self::$currentIndex.'&token='.$this->token,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function ajaxProcessUpdateAccess()
|
||||||
|
{
|
||||||
|
if ($this->tabAccess['edit'] != '1')
|
||||||
|
throw new PrestashopException(Tools::displayError('You do not have permission to edit here.'));
|
||||||
|
|
||||||
|
if (Tools::isSubmit('submitAddAccess'))
|
||||||
|
{
|
||||||
|
$perm = Tools::getValue('perm');
|
||||||
|
if (!in_array($perm, array('view', 'add', 'edit', 'delete', 'all')))
|
||||||
|
throw new PrestashopException('permission not exists');
|
||||||
|
|
||||||
|
$enabled = (int)Tools::getValue('enabled');
|
||||||
|
$id_tab = (int)Tools::getValue('id_tab');
|
||||||
|
$id_profile = (int)Tools::getValue('id_profile');
|
||||||
|
$res = true;
|
||||||
|
|
||||||
|
if ($id_tab == -1 && $perm == 'all' && $enabled == 0)
|
||||||
|
$res &= Db::getInstance()->execute('
|
||||||
|
UPDATE `'._DB_PREFIX_.'access`
|
||||||
|
SET `view` = '.(int)$enabled.', `add` = '.(int)$enabled.', `edit` = '.(int)$enabled.', `delete` = '.(int)$enabled.'
|
||||||
|
WHERE `id_profile` = '.(int)$id_profile.' AND `id_tab` != 31
|
||||||
|
');
|
||||||
|
else if ($id_tab == -1 && $perm == 'all')
|
||||||
|
$res &= Db::getInstance()->execute('
|
||||||
|
UPDATE `'._DB_PREFIX_.'access`
|
||||||
|
SET `view` = '.(int)$enabled.', `add` = '.(int)$enabled.', `edit` = '.(int)$enabled.', `delete` = '.(int)$enabled.'
|
||||||
|
WHERE `id_profile` = '.(int)$id_profile
|
||||||
|
);
|
||||||
|
else if ($id_tab == -1)
|
||||||
|
$res &= Db::getInstance()->execute('
|
||||||
|
UPDATE `'._DB_PREFIX_.'access`
|
||||||
|
SET `'.bqSQL($perm).'` = '.(int)$enabled.'
|
||||||
|
WHERE `id_profile` = '.(int)$id_profile
|
||||||
|
);
|
||||||
|
else if ($perm == 'all')
|
||||||
|
$res &= Db::getInstance()->execute('
|
||||||
|
UPDATE `'._DB_PREFIX_.'access`
|
||||||
|
SET `view` = '.(int)$enabled.', `add` = '.(int)$enabled.', `edit` = '.(int)$enabled.', `delete` = '.(int)$enabled.'
|
||||||
|
WHERE `id_tab` = '.(int)$id_tab.'
|
||||||
|
AND `id_profile` = '.(int)$id_profile
|
||||||
|
);
|
||||||
|
else
|
||||||
|
$res &= Db::getInstance()->execute('
|
||||||
|
UPDATE `'._DB_PREFIX_.'access`
|
||||||
|
SET `'.bqSQL($perm).'` = '.(int)$enabled.'
|
||||||
|
WHERE `id_tab` = '.(int)$id_tab.'
|
||||||
|
AND `id_profile` = '.(int)$id_profile
|
||||||
|
);
|
||||||
|
$res = $res?'ok':'error';
|
||||||
|
die($res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ajaxProcessUpdateModuleAccess()
|
||||||
|
{
|
||||||
|
if ($this->tabAccess['edit'] != '1')
|
||||||
|
throw new PrestashopException(Tools::displayError('You do not have permission to edit here.'));
|
||||||
|
/* Update Access Modules */
|
||||||
|
|
||||||
|
if (Tools::isSubmit('changeModuleAccess'))
|
||||||
|
{
|
||||||
|
$perm = Tools::getValue('perm');
|
||||||
|
$enabled = (int)Tools::getValue('enabled');
|
||||||
|
$id_module = (int)Tools::getValue('id_module');
|
||||||
|
$id_profile = (int)Tools::getValue('id_profile');
|
||||||
|
$res = true;
|
||||||
|
|
||||||
|
if (!in_array($perm, array('view', 'configure')))
|
||||||
|
throw new PrestashopException('permission not exists');
|
||||||
|
|
||||||
|
if ($id_module == -1)
|
||||||
|
{
|
||||||
|
$res &= Db::getInstance()->execute('
|
||||||
|
UPDATE `'._DB_PREFIX_.'module_access`
|
||||||
|
SET `'.bqSQL($perm).'` = '.(int)$enabled.'
|
||||||
|
WHERE `id_profile` = '.(int)$id_profile
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$res &= Db::getInstance()->execute('
|
||||||
|
UPDATE `'._DB_PREFIX_.'module_access`
|
||||||
|
SET `'.bqSQL($perm).'` = '.(int)$enabled.'
|
||||||
|
WHERE `id_module` = '.(int)$id_module.'
|
||||||
|
AND `id_profile` = '.(int)$id_profile
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$res = $res?'ok':'error';
|
||||||
|
die($res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current profile id
|
* Get the current profile id
|
||||||
@@ -107,4 +201,4 @@ class AdminAccessController extends AdminController
|
|||||||
{
|
{
|
||||||
return (isset($_GET['id_profile']) && !empty($_GET['id_profile']) && is_numeric($_GET['id_profile'])) ? (int)$_GET['id_profile'] : 1;
|
return (isset($_GET['id_profile']) && !empty($_GET['id_profile']) && is_numeric($_GET['id_profile'])) ? (int)$_GET['id_profile'] : 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,179 +183,207 @@ class AdminCartsController extends AdminController
|
|||||||
|
|
||||||
public function ajaxPreProcess()
|
public function ajaxPreProcess()
|
||||||
{
|
{
|
||||||
$id_customer = (int)Tools::getValue('id_customer');
|
if ($this->tabAccess['edit'] === '1')
|
||||||
$customer = new Customer((int)$id_customer);
|
{
|
||||||
$this->context->customer = $customer;
|
$id_customer = (int)Tools::getValue('id_customer');
|
||||||
$id_cart = (int)Tools::getValue('id_cart');
|
$customer = new Customer((int)$id_customer);
|
||||||
if (!$id_cart)
|
$this->context->customer = $customer;
|
||||||
$id_cart = $customer->getLastCart();
|
$id_cart = (int)Tools::getValue('id_cart');
|
||||||
$this->context->cart = new Cart((int)$id_cart);
|
if (!$id_cart)
|
||||||
if (!$this->context->cart->id_customer)
|
$id_cart = $customer->getLastCart();
|
||||||
$this->context->cart->id_customer = $id_customer;
|
$this->context->cart = new Cart((int)$id_cart);
|
||||||
if ($this->context->cart->OrderExists())
|
if (!$this->context->cart->id_customer)
|
||||||
return;
|
$this->context->cart->id_customer = $id_customer;
|
||||||
if (!$this->context->cart->id_shop)
|
if ($this->context->cart->OrderExists())
|
||||||
$this->context->cart->id_shop = (int)$this->context->shop->id;
|
return;
|
||||||
if (!$this->context->cart->id_lang)
|
if (!$this->context->cart->id_shop)
|
||||||
$this->context->cart->id_lang = (($id_lang = (int)Tools::getValue('id_lang')) ? $id_lang : Configuration::get('PS_LANG_DEFAULT'));
|
$this->context->cart->id_shop = (int)$this->context->shop->id;
|
||||||
if (!$this->context->cart->id_currency)
|
if (!$this->context->cart->id_lang)
|
||||||
$this->context->cart->id_currency = (($id_currency = (int)Tools::getValue('id_currency')) ? $id_currency : Configuration::get('PS_CURRENCY_DEFAULT'));
|
$this->context->cart->id_lang = (($id_lang = (int)Tools::getValue('id_lang')) ? $id_lang : Configuration::get('PS_LANG_DEFAULT'));
|
||||||
|
if (!$this->context->cart->id_currency)
|
||||||
|
$this->context->cart->id_currency = (($id_currency = (int)Tools::getValue('id_currency')) ? $id_currency : Configuration::get('PS_CURRENCY_DEFAULT'));
|
||||||
|
|
||||||
$addresses = $customer->getAddresses((int)$this->context->cart->id_lang);
|
$addresses = $customer->getAddresses((int)$this->context->cart->id_lang);
|
||||||
$id_address_delivery = (int)Tools::getValue('id_address_delivery');
|
$id_address_delivery = (int)Tools::getValue('id_address_delivery');
|
||||||
$id_address_invoice = (int)Tools::getValue('id_address_delivery');
|
$id_address_invoice = (int)Tools::getValue('id_address_delivery');
|
||||||
|
|
||||||
if (!$this->context->cart->id_address_invoice && isset($addresses[0]))
|
|
||||||
$this->context->cart->id_address_invoice = (int)$addresses[0]['id_address'];
|
|
||||||
else if ($id_address_invoice)
|
|
||||||
$this->context->cart->id_address_invoice = (int)$id_address_invoice;
|
|
||||||
if (!$this->context->cart->id_address_delivery && isset($addresses[0]))
|
|
||||||
$this->context->cart->id_address_delivery = $addresses[0]['id_address'];
|
|
||||||
else if ($id_address_delivery)
|
|
||||||
$this->context->cart->id_address_delivery = (int)$id_address_delivery;
|
|
||||||
$this->context->cart->save();
|
|
||||||
$currency = new Currency((int)$this->context->cart->id_currency);
|
|
||||||
$this->context->currency = $currency;
|
|
||||||
|
|
||||||
|
if (!$this->context->cart->id_address_invoice && isset($addresses[0]))
|
||||||
|
$this->context->cart->id_address_invoice = (int)$addresses[0]['id_address'];
|
||||||
|
else if ($id_address_invoice)
|
||||||
|
$this->context->cart->id_address_invoice = (int)$id_address_invoice;
|
||||||
|
if (!$this->context->cart->id_address_delivery && isset($addresses[0]))
|
||||||
|
$this->context->cart->id_address_delivery = $addresses[0]['id_address'];
|
||||||
|
else if ($id_address_delivery)
|
||||||
|
$this->context->cart->id_address_delivery = (int)$id_address_delivery;
|
||||||
|
$this->context->cart->save();
|
||||||
|
$currency = new Currency((int)$this->context->cart->id_currency);
|
||||||
|
$this->context->currency = $currency;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ajaxProcessDeleteProduct()
|
public function ajaxProcessDeleteProduct()
|
||||||
{
|
{
|
||||||
$errors = array();
|
if ($this->tabAccess['edit'] === '1')
|
||||||
if (!$id_product = (int)Tools::getValue('id_product') || !$id_product_attribute = (int)Tools::getValue('id_product_attribute'))
|
{
|
||||||
$errors[] = Tools::displayError('Invalid product');
|
$errors = array();
|
||||||
if (count($errors))
|
if (!$id_product = (int)Tools::getValue('id_product') || !$id_product_attribute = (int)Tools::getValue('id_product_attribute'))
|
||||||
die(Tools::jsonEncode($errors));
|
$errors[] = Tools::displayError('Invalid product');
|
||||||
|
if (count($errors))
|
||||||
|
die(Tools::jsonEncode($errors));
|
||||||
|
|
||||||
if ($this->context->cart->deleteProduct($id_product, $id_product_attribute))
|
if ($this->context->cart->deleteProduct($id_product, $id_product_attribute))
|
||||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ajaxProcessUpdateQty()
|
public function ajaxProcessUpdateQty()
|
||||||
{
|
{
|
||||||
$errors = array();
|
if ($this->tabAccess['edit'] === '1')
|
||||||
if (!$this->context->cart->id)
|
|
||||||
return;
|
|
||||||
if ($this->context->cart->OrderExists())
|
|
||||||
$errors[] = Tools::displayErrors('An order already placed with this cart');
|
|
||||||
else if (!$id_product = (int)Tools::getValue('id_product') OR (!$product = new Product((int)$id_product, true, $this->context->language->id)))
|
|
||||||
$errors[] = Tools::displayError('Invalid product');
|
|
||||||
else if (!$qty = Tools::getValue('qty') || $qty == 0)
|
|
||||||
$errors[] = Tools::displayError('Invalid quantity');
|
|
||||||
if (($id_product_attribute = Tools::getValue('id_product_attribute')) != 0)
|
|
||||||
{
|
{
|
||||||
if (!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !Attribute::checkAttributeQty((int)$id_product_attribute, (int)$qty))
|
$errors = array();
|
||||||
$errors[] = Tools::displayError('There is not enough product in stock');
|
if (!$this->context->cart->id)
|
||||||
}
|
return;
|
||||||
else
|
if ($this->context->cart->OrderExists())
|
||||||
if (!$product->checkQty((int)$qty))
|
$errors[] = Tools::displayErrors('An order already placed with this cart');
|
||||||
$errors[] = Tools::displayError('There is not enough product in stock');
|
else if (!$id_product = (int)Tools::getValue('id_product') OR (!$product = new Product((int)$id_product, true, $this->context->language->id)))
|
||||||
if (!$id_customization = (int)Tools::getValue('id_customization', 0) && !$product->hasAllRequiredCustomizableFields())
|
$errors[] = Tools::displayError('Invalid product');
|
||||||
$errors[] = Tools::displayError('Please fill in all required fields');
|
else if (!$qty = Tools::getValue('qty') || $qty == 0)
|
||||||
$this->context->cart->save();
|
$errors[] = Tools::displayError('Invalid quantity');
|
||||||
if (!count($errors))
|
if (($id_product_attribute = Tools::getValue('id_product_attribute')) != 0)
|
||||||
{
|
|
||||||
if ((int)$qty < 0)
|
|
||||||
{
|
{
|
||||||
$qty = str_replace('-', '', $qty);
|
if (!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !Attribute::checkAttributeQty((int)$id_product_attribute, (int)$qty))
|
||||||
$operator = 'down';
|
$errors[] = Tools::displayError('There is not enough product in stock');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$operator = 'up';
|
if (!$product->checkQty((int)$qty))
|
||||||
if (!($qty_upd = $this->context->cart->updateQty($qty, $id_product, (int)$id_product_attribute, (int)$id_customization, 0, $operator)))
|
$errors[] = Tools::displayError('There is not enough product in stock');
|
||||||
$errors[] = Tools::displayError('You already have the maximum quantity available for this product.');
|
if (!$id_customization = (int)Tools::getValue('id_customization', 0) && !$product->hasAllRequiredCustomizableFields())
|
||||||
|
$errors[] = Tools::displayError('Please fill in all required fields');
|
||||||
|
$this->context->cart->save();
|
||||||
|
if (!count($errors))
|
||||||
|
{
|
||||||
|
if ((int)$qty < 0)
|
||||||
|
{
|
||||||
|
$qty = str_replace('-', '', $qty);
|
||||||
|
$operator = 'down';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$operator = 'up';
|
||||||
|
if (!($qty_upd = $this->context->cart->updateQty($qty, $id_product, (int)$id_product_attribute, (int)$id_customization, 0, $operator)))
|
||||||
|
$errors[] = Tools::displayError('You already have the maximum quantity available for this product.');
|
||||||
|
}
|
||||||
|
|
||||||
|
echo Tools::jsonEncode(array_merge($this->ajaxReturnVars(), array('errors' => $errors)));
|
||||||
}
|
}
|
||||||
|
|
||||||
echo Tools::jsonEncode(array_merge($this->ajaxReturnVars(), array('errors' => $errors)));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ajaxProcessUpdateCarrier()
|
public function ajaxProcessUpdateCarrier()
|
||||||
{
|
{
|
||||||
if (Validate::isBool(($recyclable = (int)Tools::getValue('recyclable'))))
|
if ($this->tabAccess['edit'] === '1')
|
||||||
$this->context->cart->recyclable = $recyclable;
|
{
|
||||||
if (Validate::isBool(($gift = (int)Tools::getValue('gift'))))
|
if (Validate::isBool(($recyclable = (int)Tools::getValue('recyclable'))))
|
||||||
$this->context->cart->gift = $gift;
|
$this->context->cart->recyclable = $recyclable;
|
||||||
if (Validate::isMessage(($gift_message = pSQL(Tools::getValue('gift_message')))))
|
if (Validate::isBool(($gift = (int)Tools::getValue('gift'))))
|
||||||
$this->context->cart->gift_message = $gift_message;
|
$this->context->cart->gift = $gift;
|
||||||
$this->context->cart->save();
|
if (Validate::isMessage(($gift_message = pSQL(Tools::getValue('gift_message')))))
|
||||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
$this->context->cart->gift_message = $gift_message;
|
||||||
|
$this->context->cart->save();
|
||||||
|
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ajaxProcessUpdateCurrency()
|
public function ajaxProcessUpdateCurrency()
|
||||||
{
|
{
|
||||||
$currency = new Currency((int)Tools::getValue('id_currency'));
|
if ($this->tabAccess['edit'] === '1')
|
||||||
if (Validate::isLoadedObject($currency) && !$currency->deleted && $currency->active)
|
|
||||||
{
|
{
|
||||||
$this->context->cart->id_currency = (int)$currency->id;
|
$currency = new Currency((int)Tools::getValue('id_currency'));
|
||||||
$this->context->cart->save();
|
if (Validate::isLoadedObject($currency) && !$currency->deleted && $currency->active)
|
||||||
|
{
|
||||||
|
$this->context->cart->id_currency = (int)$currency->id;
|
||||||
|
$this->context->cart->save();
|
||||||
|
}
|
||||||
|
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||||
}
|
}
|
||||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
|
||||||
}
|
}
|
||||||
public function ajaxProcessUpdateLang()
|
public function ajaxProcessUpdateLang()
|
||||||
{
|
{
|
||||||
$lang = new Language((int)Tools::getValue('id_lang'));
|
if ($this->tabAccess['edit'] === '1')
|
||||||
if (Validate::isLoadedObject($lang) && $lang->active)
|
|
||||||
{
|
{
|
||||||
$this->context->cart->id_lang = (int)$lang->id;
|
$lang = new Language((int)Tools::getValue('id_lang'));
|
||||||
$this->context->cart->save();
|
if (Validate::isLoadedObject($lang) && $lang->active)
|
||||||
|
{
|
||||||
|
$this->context->cart->id_lang = (int)$lang->id;
|
||||||
|
$this->context->cart->save();
|
||||||
|
}
|
||||||
|
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||||
}
|
}
|
||||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
|
||||||
}
|
}
|
||||||
public function ajaxProcessDuplicateOrder()
|
public function ajaxProcessDuplicateOrder()
|
||||||
{
|
{
|
||||||
$errors = array();
|
if ($this->tabAccess['edit'] === '1')
|
||||||
if (!$id_order = Tools::getValue('id_order'))
|
|
||||||
$errors[] = Tools::displayErrors('Invalid order');
|
|
||||||
$cart = Cart::getCartByOrderId($id_order);
|
|
||||||
$new_cart = $cart->duplicate();
|
|
||||||
if (!$new_cart || !Validate::isLoadedObject($new_cart['cart']))
|
|
||||||
$errors[] = Tools::displayError('The order cannot be renewed');
|
|
||||||
else if (!$new_cart['success'])
|
|
||||||
$errors[] = Tools::displayError('The order cannot be renewed');
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
$this->context->cart = $new_cart['cart'];
|
$errors = array();
|
||||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
if (!$id_order = Tools::getValue('id_order'))
|
||||||
|
$errors[] = Tools::displayErrors('Invalid order');
|
||||||
|
$cart = Cart::getCartByOrderId($id_order);
|
||||||
|
$new_cart = $cart->duplicate();
|
||||||
|
if (!$new_cart || !Validate::isLoadedObject($new_cart['cart']))
|
||||||
|
$errors[] = Tools::displayError('The order cannot be renewed');
|
||||||
|
else if (!$new_cart['success'])
|
||||||
|
$errors[] = Tools::displayError('The order cannot be renewed');
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->context->cart = $new_cart['cart'];
|
||||||
|
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ajaxProcessDeleteVoucher()
|
public function ajaxProcessDeleteVoucher()
|
||||||
{
|
{
|
||||||
if ($this->context->cart->removeCartRule((int)Tools::getValue('id_cart_rule')))
|
if ($this->tabAccess['edit'] === '1')
|
||||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
{
|
||||||
|
if ($this->context->cart->removeCartRule((int)Tools::getValue('id_cart_rule')))
|
||||||
|
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ajaxProcessAddVoucher()
|
public function ajaxProcessAddVoucher()
|
||||||
{
|
{
|
||||||
$errors = array();
|
if ($this->tabAccess['edit'] === '1')
|
||||||
$customer = new Customer((int)$this->context->cart->id_customer);
|
{
|
||||||
|
$errors = array();
|
||||||
|
$customer = new Customer((int)$this->context->cart->id_customer);
|
||||||
|
|
||||||
if (!$id_cart_rule = Tools::getValue('id_cart_rule') OR !$cart_rule = new CartRule((int)$id_cart_rule))
|
if (!$id_cart_rule = Tools::getValue('id_cart_rule') OR !$cart_rule = new CartRule((int)$id_cart_rule))
|
||||||
$errors[] = Tools::displayError('Invalid voucher');
|
$errors[] = Tools::displayError('Invalid voucher');
|
||||||
else if ($err = $cart_rule->checkValidity($this->context))
|
else if ($err = $cart_rule->checkValidity($this->context))
|
||||||
$errors[] = $err;
|
$errors[] = $err;
|
||||||
if (!count($errors))
|
if (!count($errors))
|
||||||
if (!$this->context->cart->addCartRule((int)$cart_rule->id))
|
if (!$this->context->cart->addCartRule((int)$cart_rule->id))
|
||||||
$errors[] = Tools::displayError('Can\'t add the voucher');
|
$errors[] = Tools::displayError('Can\'t add the voucher');
|
||||||
echo Tools::jsonEncode(array_merge($this->ajaxReturnVars(), array('errors' => $errors)));
|
echo Tools::jsonEncode(array_merge($this->ajaxReturnVars(), array('errors' => $errors)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ajaxProcessUpdateAddresses()
|
public function ajaxProcessUpdateAddresses()
|
||||||
{
|
{
|
||||||
if (($id_address_delivery = (int)Tools::getValue('id_address_delivery')) &&
|
if ($this->tabAccess['edit'] === '1')
|
||||||
$address_delivery = new Address((int)$id_address_delivery) &&
|
{
|
||||||
$address_delivery->id_customer = $this->context->cart->id_customer)
|
if (($id_address_delivery = (int)Tools::getValue('id_address_delivery')) &&
|
||||||
$this->context->cart->id_address_delivery = (int)$address_delivery->id;
|
$address_delivery = new Address((int)$id_address_delivery) &&
|
||||||
|
$address_delivery->id_customer = $this->context->cart->id_customer)
|
||||||
|
$this->context->cart->id_address_delivery = (int)$address_delivery->id;
|
||||||
|
|
||||||
if (($id_address_invoice = (int)Tools::getValue('id_address_invoice')) &&
|
if (($id_address_invoice = (int)Tools::getValue('id_address_invoice')) &&
|
||||||
$address_invoice = new Address((int)$id_address_invoice) &&
|
$address_invoice = new Address((int)$id_address_invoice) &&
|
||||||
$address_invoice->id_customer = $this->context->cart->id_customer)
|
$address_invoice->id_customer = $this->context->cart->id_customer)
|
||||||
$this->context->cart->id_address_invoice = (int)$address_invoice->id;
|
$this->context->cart->id_address_invoice = (int)$address_invoice->id;
|
||||||
$this->context->cart->save();
|
$this->context->cart->save();
|
||||||
|
|
||||||
echo Tools::jsonEncode($this->ajaxReturnVars());
|
echo Tools::jsonEncode($this->ajaxReturnVars());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getCartSummary()
|
protected function getCartSummary()
|
||||||
|
|||||||
@@ -604,20 +604,23 @@ class AdminOrdersControllerCore extends AdminController
|
|||||||
|
|
||||||
public function ajaxProcessSendMailValidateOrder()
|
public function ajaxProcessSendMailValidateOrder()
|
||||||
{
|
{
|
||||||
$errors = array();
|
if ($this->tabAccess['edit'] === '1')
|
||||||
$cart = new Cart((int)Tools::getValue('id_cart'));
|
|
||||||
if (Validate::isLoadedObject($cart))
|
|
||||||
{
|
{
|
||||||
$customer = new Customer((int)$cart->id_customer);
|
$errors = array();
|
||||||
if (Validate::isLoadedObject($customer))
|
$cart = new Cart((int)Tools::getValue('id_cart'));
|
||||||
|
if (Validate::isLoadedObject($cart))
|
||||||
{
|
{
|
||||||
$mailVars = array('{order_link}' => Context::getContext()->link->getPageLink('order', false, (int)$cart->id_lang, 'step=3&recover_cart='.(int)$cart->id.'&token_cart='.md5(_COOKIE_KEY_.'recover_cart_'.(int)$cart->id)),
|
$customer = new Customer((int)$cart->id_customer);
|
||||||
'{firstname}' => $customer->firstname,
|
if (Validate::isLoadedObject($customer))
|
||||||
'{lastname}' => $customer->lastname,);
|
{
|
||||||
if (Mail::Send((int)$cart->id_lang, 'backoffice_order', Mail::l('Process the payment of your order'), $mailVars, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL,_PS_MAIL_DIR_, true))
|
$mailVars = array('{order_link}' => Context::getContext()->link->getPageLink('order', false, (int)$cart->id_lang, 'step=3&recover_cart='.(int)$cart->id.'&token_cart='.md5(_COOKIE_KEY_.'recover_cart_'.(int)$cart->id)),
|
||||||
die(Tools::jsonEncode(array('errors' => false, 'result' => $this->l('The mail was sent to your customer.'))));
|
'{firstname}' => $customer->firstname,
|
||||||
|
'{lastname}' => $customer->lastname,);
|
||||||
|
if (Mail::Send((int)$cart->id_lang, 'backoffice_order', Mail::l('Process the payment of your order'), $mailVars, $customer->email, $customer->firstname.' '.$customer->lastname, NULL, NULL, NULL, NULL,_PS_MAIL_DIR_, true))
|
||||||
|
die(Tools::jsonEncode(array('errors' => false, 'result' => $this->l('The mail was sent to your customer.'))));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
$this->content = Tools::jsonEncode(array('errors' => true, 'result' => $this->l('Error in sending the email to your customer.')));
|
||||||
}
|
}
|
||||||
$this->content = Tools::jsonEncode(array('errors' => true, 'result' => $this->l('Error in sending the email to your customer.')));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user