From fe7dfe0460bec1295151fb69b4b6f9e3f6c6d1f8 Mon Sep 17 00:00:00 2001 From: rGaillard Date: Wed, 2 Nov 2011 19:19:03 +0000 Subject: [PATCH] // Some improvements on BackOffice orders git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9810 b9a71923-0436-4b27-9f14-aed3839534dd --- .../themes/template/form_submit_ajax.tpl | 8 +- admin-dev/themes/template/orders/form.tpl | 103 ++++++++++++------ classes/AdminController.php | 11 +- classes/CartRule.php | 8 ++ classes/Discount.php | 8 -- .../admin/AdminCartRulesController.php | 10 ++ controllers/admin/AdminCartsController.php | 13 ++- img/bg_loader.png | Bin 0 -> 109 bytes 8 files changed, 105 insertions(+), 56 deletions(-) create mode 100644 img/bg_loader.png diff --git a/admin-dev/themes/template/form_submit_ajax.tpl b/admin-dev/themes/template/form_submit_ajax.tpl index 88a28fbc8..7937bae24 100644 --- a/admin-dev/themes/template/form_submit_ajax.tpl +++ b/admin-dev/themes/template/form_submit_ajax.tpl @@ -26,7 +26,8 @@ diff --git a/admin-dev/themes/template/orders/form.tpl b/admin-dev/themes/template/orders/form.tpl index 2bf887e1f..2c20b75d3 100755 --- a/admin-dev/themes/template/orders/form.tpl +++ b/admin-dev/themes/template/orders/form.tpl @@ -84,7 +84,7 @@ }); $('#show_old_carts').click(); $.ajaxSetup({ type:"post" }); - $("#voucher").autocomplete('{$link->getAdminLink('AdminDiscounts')}', { + $("#voucher").autocomplete('{$link->getAdminLink('AdminCartRules')}', { minChars: 3, max: 15, width: 250, @@ -106,9 +106,9 @@ }, extraParams: { ajax: "1", - token: "{getAdminToken tab='AdminDiscounts'}", - tab: "AdminDiscounts", - action: "searchVouchers" + token: "{getAdminToken tab='AdminCartRules'}", + tab: "AdminCartRules", + action: "searchCartRuleVouchers" } } ) @@ -124,7 +124,7 @@ token: "{getAdminToken tab='AdminCarts'}", tab: "AdminCarts", action: "addVoucher", - id_voucher: data.id_discount, + id_cart_rule: data.id_cart_rule, id_cart: id_cart }, success : function(res) @@ -148,54 +148,87 @@ setupCustomer('{$cart->id_customer}'); useCart('{$cart->id}'); {/if} - $('#loader, #loader_container').ajaxStart(function() { - $(this).fadeIn(); - }); - resetBind(); - }); - - function resetBind() - { - $(".fancybox").fancybox(); - /*$("#new_address").fancybox({ - onClosed: useCart(id_cart) - });*/ - $(".delete_product").unbind('click').click(function() { + + $('.delete_product').live('click', function(e) { + e.preventDefault(); var to_delete = $(this).attr('rel').split('_'); deleteProduct(to_delete[1], to_delete[2]); }); - $('.delete_discount').unbind('click').click(function() { - deleteDiscount($(this).attr('rel')); + $('.delete_discount').live('click', function(e) { + e.preventDefault(); + deleteVoucher($(this).attr('rel')); }); - $(".use_cart").unbind('click').click(function() { + $('.use_cart').live('click', function(e) { + e.preventDefault(); useCart($(this).attr('rel')); }); - $('#loader, #loader_container').ajaxStart(function() { - $(this).fadeIn(); - }); - $('#loader, #loader_container').ajaxComplete(function() { - $(this).fadeOut(); - }); - $(".duplicate_order").unbind('click').click(function() { + + $('.duplicate_order').live('click', function(e) { + e.preventDefault(); duplicateOrder($(this).attr('rel')); }); - $('.cart_quantity').change(function() { + $('.cart_quantity').live('change', function(e) { + e.preventDefault(); if ($(this).val() != cart_quantity[$(this).attr('rel')]) { var product = $(this).attr('rel').split('_'); updateQty(product[0], product[1], $(this).val() - cart_quantity[$(this).attr('rel')]); } }); - $('.increaseqty_product,.decreaseqty_product').unbind('click').click(function() { + $('.increaseqty_product,.decreaseqty_product').live('click', function(e) { + e.preventDefault(); var product = $(this).attr('rel').split('_'); var sign = ''; if ($(this).hasClass('decreaseqty_product')) sign = '-'; updateQty(product[0], product[1], sign+1); }); - $('#id_product, .id_product_attribute').unbind('change').change(function() { + $('#id_product, .id_product_attribute').live('change', function(e) { + e.preventDefault(); displayQtyInStock(this.id); }); + $('.product_unit_price').live('change', function(e) { + e.preventDefault(); + var product = $(this).attr('rel').split('_'); + updateProductPrice(product[0], product[1], $(this).val()); + }); + /*$('.fancybox').live('click', function(e) { + $(this).fancybox().trigger('click'); + return false; + });*/ + resetBind(); + }); + + function resetBind() + { + $('.fancybox').fancybox(); + /*$("#new_address").fancybox({ + onClosed: useCart(id_cart) + });*/ + } + + function updateProductPrice(id_product, id_product_attribute, new_price) + { + $.ajax({ + type:"POST", + url: "{$link->getAdminLink('AdminCarts')}", + async: true, + dataType: "json", + data : { + ajax: "1", + token: "{getAdminToken tab='AdminCarts'}", + tab: "AdminCarts", + action: "updateProductPrice", + id_cart: id_cart, + id_product: id_product, + id_product_attribute: id_product_attribute, + price: new_price + }, + success : function(res) + { + displaySummary(res); + } + }); } function displayQtyInStock(id) @@ -233,6 +266,7 @@ { id_cart = id_new_cart; $('#id_cart').val(id_cart); + $('#id_cart').val(id_cart); $.ajax({ type:"POST", url: "{$link->getAdminLink('AdminCarts')}", @@ -252,7 +286,7 @@ }); } - function deleteDiscount(id_voucher) + function deleteVoucher(id_cart_rule) { $.ajax({ type:"POST", @@ -263,8 +297,8 @@ ajax: "1", token: "{getAdminToken tab='AdminCarts'}", tab: "AdminCarts", - action: "deleteDiscount", - id_voucher: id_voucher, + action: "deleteVoucher", + id_voucher: id_cart_rule, id_cart: id_cart, }, success : function(res) @@ -387,6 +421,7 @@ if (res.id_cart) { id_cart = res.id_cart; + $('#id_cart').val(id_cart); } displaySummary(res); resetBind(); diff --git a/classes/AdminController.php b/classes/AdminController.php index 7c8be6dac..fb7f8c63b 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -1028,9 +1028,6 @@ class AdminControllerCore extends Controller 'token_admin_messages' => Tools::getAdminTokenLite('AdminMessages'), 'token_admin_employees' => Tools::getAdminTokenLite('AdminEmployees'), 'token_admin_search' => Tools::getAdminTokenLite('AdminSearch'), - 'table' => $this->table, - 'current' => self::$currentIndex, - 'token' => $this->token, 'first_name' => Tools::substr($this->context->employee->firstname, 0, 1), 'last_name' => htmlentities($this->context->employee->lastname, ENT_COMPAT, 'UTF-8'), 'base_url' => $this->context->shop->getBaseURL(), @@ -1104,9 +1101,6 @@ class AdminControllerCore extends Controller } $this->context->smarty->assign(array( - 'table' => $this->table, - 'current' => self::$currentIndex, - 'token' => $this->token, 'content' => $this->content, 'url_post' => self::$currentIndex.'&token='.$this->token, )); @@ -1522,6 +1516,11 @@ class AdminControllerCore extends Controller } if ($this->ajax && method_exists($this, 'ajaxPreprocess')) $this->ajaxPreProcess(); + $this->context->smarty->assign(array( + 'table' => $this->table, + 'current' => self::$currentIndex, + 'token' => $this->token, + )); } /** diff --git a/classes/CartRule.php b/classes/CartRule.php index 17b8ef107..e2ff28bb3 100644 --- a/classes/CartRule.php +++ b/classes/CartRule.php @@ -685,4 +685,12 @@ class CartRuleCore extends ObjectModel { return (bool)Configuration::get('PS_CART_RULE_FEATURE_ACTIVE'); } + + public static function getCartsRuleByCode($name, $id_lang) + { + return Db::getInstance()->ExecuteS('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).'%\''); + } } \ No newline at end of file diff --git a/classes/Discount.php b/classes/Discount.php index 80207d792..a0a6848d1 100644 --- a/classes/Discount.php +++ b/classes/Discount.php @@ -252,12 +252,4 @@ class DiscountCore extends CartRule return $voucher; } - - public static function getVoucherByName($name, $id_lang) - { - return Db::getInstance()->ExecuteS('SELECT d.*, dl.* - FROM '._DB_PREFIX_.'discount d - LEFT JOIN '._DB_PREFIX_.'discount_lang dl ON (d.id_discount = dl.id_discount AND dl.id_lang='.(int)$id_lang.') - WHERE name LIKE \'%'.pSQL($name).'%\''); - } } \ No newline at end of file diff --git a/controllers/admin/AdminCartRulesController.php b/controllers/admin/AdminCartRulesController.php index 62f9b7ae0..591175d48 100644 --- a/controllers/admin/AdminCartRulesController.php +++ b/controllers/admin/AdminCartRulesController.php @@ -323,4 +323,14 @@ class AdminCartRulesControllerCore extends AdminController return parent::initForm(); } + + public function displayAjaxSearchCartRuleVouchers() + { + if ($vouchers = CartRule::getCartsRuleByCode(Tools::getValue('q'), (int)Context::getContext()->cookie->id_lang)) + $found = true; + else + $found = false; + echo Tools::jsonEncode(array('found' => $found, 'vouchers' => $vouchers)); + } + } \ No newline at end of file diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index 3a9b0b634..85e4df489 100755 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -306,9 +306,9 @@ class AdminCartsController extends AdminController } - public function ajaxProcessDeleteDiscount() + public function ajaxProcessDeleteVoucher() { - if ($this->context->cart->deleteDiscount((int)Tools::getValue('id_voucher'))) + if ($this->context->cart->removeCartRule((int)Tools::getValue('id_cart_rule'))) echo Tools::jsonEncode($this->ajaxReturnVars()); } @@ -317,9 +317,9 @@ class AdminCartsController extends AdminController $errors = array(); $customer = new Customer((int)$this->context->cart->id_customer); - if (!$id_cart_rule = Tools::getValue('id_voucher') OR !$cartRule = new CartRule((int)$id_cart_rule)) + if (!$id_cart_rule = Tools::getValue('id_cart_rule') OR !$cartRule = new CartRule((int)$id_cart_rule)) $errors[] = Tools::displayError('Invalid voucher'); - elseif ($err = $this->context->cart->checkDiscountValidity($cartRule, $this->context->cart->getDiscounts(), $this->context->cart->getOrderTotal(), $this->context->cart->getProducts(), true, $customer)) + elseif ($err = $cartRule->checkValidity($this->context)) $errors[] = $err; if (!sizeof($errors)) if (!$this->context->cart->addCartRule((int)$cartRule->id)) @@ -419,6 +419,11 @@ class AdminCartsController extends AdminController echo Tools::jsonEncode($this->ajaxReturnVars()); } + public function ajaxProcessUpdateProductPrice() + { + + } + public static function getOrderTotalUsingTaxCalculationMethod($id_cart) { return Cart::getTotalCart($id_cart, true); diff --git a/img/bg_loader.png b/img/bg_loader.png new file mode 100644 index 0000000000000000000000000000000000000000..f9da304b50c7a75870fead62ff4acbf2aa283add GIT binary patch literal 109 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1|;Q0k8}bl$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWw1G{GKk3Ar-fhHk5q0!y}Nu!1Ru>Y?;lXhd?O?Pgg&ebxsLQ E09i906#xJL literal 0 HcmV?d00001