From 89c1909c66e5850c93317c2f4a4a6f18b11242c0 Mon Sep 17 00:00:00 2001 From: tDidierjean Date: Thu, 16 Feb 2012 09:45:47 +0000 Subject: [PATCH] // Upgrade specific price deletion git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@13378 b9a71923-0436-4b27-9f14-aed3839534dd --- .../template/controllers/products/prices.tpl | 2 +- controllers/admin/AdminProductsController.php | 38 ++++++++++++------ js/admin-products.js | 39 +++++++++++++++++++ 3 files changed, 67 insertions(+), 12 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/products/prices.tpl b/admin-dev/themes/default/template/controllers/products/prices.tpl index b2ddff30d..325623d63 100644 --- a/admin-dev/themes/default/template/controllers/products/prices.tpl +++ b/admin-dev/themes/default/template/controllers/products/prices.tpl @@ -351,7 +351,7 @@ jQuery(document).ready(Customer.init); - +
diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index a01063dac..712450d6f 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -777,19 +777,35 @@ class AdminProductsControllerCore extends AdminController } } - public function processDeleteSpecificPrice($token) + public function ajaxProcessDeleteSpecificPrice() { - if (!($obj = $this->loadObject())) - return; - $id_specific_price = (int)Tools::getValue('id_specific_price'); - if (!$id_specific_price || !Validate::isUnsignedId($id_specific_price)) - $this->errors[] = Tools::displayError('Invalid specific price ID'); - else + if ($this->tabAccess['delete'] === '1') { - $specificPrice = new SpecificPrice((int)$id_specific_price); - if (!$specificPrice->delete()) - $this->errors[] = Tools::displayError('An error occurred while deleting the specific price'); + $id_specific_price = (int)Tools::getValue('id_specific_price'); + if (!$id_specific_price || !Validate::isUnsignedId($id_specific_price)) + $error = Tools::displayError('Invalid specific price ID'); + else + { + $specificPrice = new SpecificPrice((int)$id_specific_price); + if (!$specificPrice->delete()) + $error = Tools::displayError('An error occurred while deleting the specific price'); + } } + else + $error = Tools::displayError('You do not have permission to delete here.'); + + if (isset($error)) + $json = array( + 'status' => 'error', + 'message'=> $error + ); + else + $json = array( + 'status' => 'ok', + 'message'=> $this->_conf[1] + ); + + die(Tools::jsonEncode($json)); } public function processSpecificPricePriorities($token) @@ -2815,7 +2831,7 @@ class AdminProductsControllerCore extends AdminController - + '; $i++; unset($customer_full_name); diff --git a/js/admin-products.js b/js/admin-products.js index b6e2d1ce7..526abda16 100644 --- a/js/admin-products.js +++ b/js/admin-products.js @@ -368,6 +368,36 @@ function toggleSpecificPrice() }); } +/** + * Ajax call to delete a specific price + * + * @param ids + * @param token + * @param parent + */ +function deleteSpecificPrice(url, parent) +{ + $.ajax({ + url: url, + data: { + ajax: true + }, + context: document.body, + dataType: 'json', + context: this, + async: false, + success: function(data) { + if (data.status == 'ok') + { + showSuccessMessage(data.message); + parent.remove(); + } + else + showErrorMessage(data.message); + } + }); +} + /** * Execute a callback function when a specific tab has finished loading or right now if the tab is already loaded * @@ -402,5 +432,14 @@ $(document).ready(function() { // Enable writing of the product name when the friendly url field in tab SEO is loaded onTabLoad('Seo', enableProductName); + // Bind to show/hide new specific price form onTabLoad('Prices', toggleSpecificPrice); + + // Bind to delete specific price link + onTabLoad('Prices', function(){ + $('#specific_prices_list').delegate('a[name="delete_link"]', 'click', function(){ + deleteSpecificPrice(this.href, $(this).parents('tr')); + return false; + }) + }); });
{l s='Rule'}'.$period.' '.$specific_price['from_quantity'].' '.Tools::displayPrice(Tools::ps_round((float)($this->_getFinalPrice($specific_price, (float)($obj->price), $taxRate)), 2), $current_specific_currency).''.(!$rule->id ? ''.$this->l('Delete').'': '').''.(!$rule->id ? ''.$this->l('Delete').'': '').'