// Fix backOffice order cart rules management

This commit is contained in:
rGaillard
2012-03-15 14:42:57 +00:00
parent 356f6f4360
commit 3be00c8e6f
6 changed files with 83 additions and 34 deletions
@@ -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 <contact@prestashop.com>
* @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}
<script type="text/javascript">
$('#voucher', window.parent.document).val('{$new_cart_rule->code|escape:htmlall}');
parent.add_cart_rule({$new_cart_rule->id|intval});
parent.$.fancybox.close();
</script>
{/if}
{/block}
@@ -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+'<br/>';
});
$('#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+'<br/>';
});
$('#vouchers_err').html(errors).show();
}
else
$('#vouchers_err').hide();
}
});
}
function updateProductPrice(id_product, id_product_attribute, new_price)
{
+1 -1
View File
@@ -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).'%\'
');
}
}
+1 -1
View File
@@ -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();
@@ -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)
{
+2 -2
View File
@@ -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))