diff --git a/admin-dev/themes/default/template/controllers/cart_rules/helpers/list/list_header.tpl b/admin-dev/themes/default/template/controllers/cart_rules/helpers/list/list_header.tpl new file mode 100644 index 000000000..ce7f479bf --- /dev/null +++ b/admin-dev/themes/default/template/controllers/cart_rules/helpers/list/list_header.tpl @@ -0,0 +1,35 @@ +{* +* 2007-2012 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2012 PrestaShop SA +* @version Release: $Revision: 10891 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} +{extends file="helpers/list/list_header.tpl"} +{block name='override_header'} +{if $submit_form_ajax} + +{/if} +{/block} diff --git a/admin-dev/themes/default/template/controllers/orders/form.tpl b/admin-dev/themes/default/template/controllers/orders/form.tpl index d3e0c6015..1147dd469 100755 --- a/admin-dev/themes/default/template/controllers/orders/form.tpl +++ b/admin-dev/themes/default/template/controllers/orders/form.tpl @@ -116,36 +116,7 @@ ) .result(function(event, data, formatted) { $('#voucher').val(data.name); - $.ajax({ - type:"POST", - url: "{$link->getAdminLink('AdminCarts')}", - async: true, - dataType: "json", - data : { - ajax: "1", - token: "{getAdminToken tab='AdminCarts'}", - tab: "AdminCarts", - action: "addVoucher", - id_cart_rule: data.id_cart_rule, - id_cart: id_cart, - id_customer: id_customer - }, - success : function(res) - { - displaySummary(res); - $('#voucher').val(''); - var errors = ''; - if (res.errors.length > 0) - { - $.each(res.errors, function() { - errors += this+'
'; - }); - $('#vouchers_err').html(errors).show(); - } - else - $('#vouchers_err').hide(); - } - }); + add_cart_rule(data.id_cart_rule); }); {if $cart->id} setupCustomer('{$cart->id_customer}'); @@ -244,6 +215,40 @@ onClosed: useCart(id_cart) });*/ } + + function add_cart_rule(id_cart_rule) + { + $.ajax({ + type:"POST", + url: "{$link->getAdminLink('AdminCarts')}", + async: true, + dataType: "json", + data : { + ajax: "1", + token: "{getAdminToken tab='AdminCarts'}", + tab: "AdminCarts", + action: "addVoucher", + id_cart_rule: id_cart_rule, + id_cart: id_cart, + id_customer: id_customer + }, + success : function(res) + { + displaySummary(res); + $('#voucher').val(''); + var errors = ''; + if (res.errors.length > 0) + { + $.each(res.errors, function() { + errors += this+'
'; + }); + $('#vouchers_err').html(errors).show(); + } + else + $('#vouchers_err').hide(); + } + }); + } function updateProductPrice(id_product, id_product_attribute, new_price) { diff --git a/classes/CartRule.php b/classes/CartRule.php index d56719bdc..a695fd323 100644 --- a/classes/CartRule.php +++ b/classes/CartRule.php @@ -1000,7 +1000,7 @@ class CartRuleCore extends ObjectModel SELECT cr.*, crl.* FROM '._DB_PREFIX_.'cart_rule cr LEFT JOIN '._DB_PREFIX_.'cart_rule_lang crl ON (cr.id_cart_rule = crl.id_cart_rule AND crl.id_lang = '.(int)$id_lang.') - WHERE name LIKE \'%'.pSQL($name).'%\' + WHERE code LIKE \'%'.pSQL($name).'%\' '); } } diff --git a/classes/controller/Controller.php b/classes/controller/Controller.php index e6f521c12..fe00fe88b 100644 --- a/classes/controller/Controller.php +++ b/classes/controller/Controller.php @@ -152,7 +152,7 @@ abstract class ControllerCore { if (!$this->content_only && ($this->display_header || (isset($this->className) && $this->className))) $this->setMedia(); - + // postProcess handles ajaxProcess $this->postProcess(); diff --git a/controllers/admin/AdminCartRulesController.php b/controllers/admin/AdminCartRulesController.php index daac0a581..fbf2a108e 100644 --- a/controllers/admin/AdminCartRulesController.php +++ b/controllers/admin/AdminCartRulesController.php @@ -89,6 +89,15 @@ class AdminCartRulesControllerCore extends AdminController $this->afterAdd($current_object); } + public function processAdd($token) + { + if ($cart_rule = parent::processAdd($token)) + $this->context->smarty->assign('new_cart_rule', $cart_rule); + if (Tools::getValue('submitFormAjax')) + $this->redirect_after = false; + + return $cart_rule; + } /* @TODO Move this function into CartRule */ protected function afterAdd($currentObject) { diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index 0109e3447..588665ea2 100755 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -388,9 +388,9 @@ class AdminCartsControllerCore extends AdminController if ($this->tabAccess['edit'] === '1') { $errors = array(); - if (!$id_cart_rule = Tools::getValue('id_cart_rule') || !$cart_rule = new CartRule((int)$id_cart_rule)) + if (!($id_cart_rule = Tools::getValue('id_cart_rule')) || !$cart_rule = new CartRule((int)$id_cart_rule)) $errors[] = Tools::displayError('Invalid voucher'); - else if ($err = $cart_rule->checkValidity($this->context)) + elseif ($err = $cart_rule->checkValidity($this->context)) $errors[] = $err; if (!count($errors)) if (!$this->context->cart->addCartRule((int)$cart_rule->id))