From 5a88dc0f8bfc889bf8dd8a8fd4d5355f27642e2b Mon Sep 17 00:00:00 2001 From: Vincent Augagneur Date: Mon, 5 Aug 2013 14:06:50 +0200 Subject: [PATCH] //fixed bug on carrier wizard when edit carrier --- .../helpers/form/form_ranges.tpl | 6 +- .../admin/AdminCarrierWizardController.php | 62 ++++++++++++++----- css/admin.css | 5 +- js/admin_carrier_wizard.js | 9 +++ 4 files changed, 62 insertions(+), 20 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/form_ranges.tpl b/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/form_ranges.tpl index 0f1dbafa2..2fa54471c 100644 --- a/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/form_ranges.tpl +++ b/admin-dev/themes/default/template/controllers/carrier_wizard/helpers/form/form_ranges.tpl @@ -14,7 +14,7 @@ < {foreach from=$ranges key=r item=range} - *  {$PS_WEIGHT_UNIT}  {$currency_sign} + *  {$PS_WEIGHT_UNIT}  {$currency_sign} {foreachelse} *  {$PS_WEIGHT_UNIT}  {$currency_sign} {/foreach} @@ -23,8 +23,8 @@ All {foreach from=$ranges key=r item=range} - - + + {foreachelse} diff --git a/controllers/admin/AdminCarrierWizardController.php b/controllers/admin/AdminCarrierWizardController.php index 98cdc1ad1..70f79d11c 100644 --- a/controllers/admin/AdminCarrierWizardController.php +++ b/controllers/admin/AdminCarrierWizardController.php @@ -454,7 +454,7 @@ class AdminCarrierWizardControllerCore extends AdminController // init blank range if (!count($tpl_vars['ranges'])) - $tpl_vars['ranges'][] = array('id_range' => -1, 'delimiter1' => 0, 'delimiter2' => 0); + $tpl_vars['ranges'][] = array('id_range' => 0, 'delimiter1' => 0, 'delimiter2' => 0); } public function renderGenericForm($fields_form, $fields_value, $tpl_vars = array()) @@ -607,17 +607,36 @@ class AdminCarrierWizardControllerCore extends AdminController { if (!isset($range_sup[$key])) continue; - + $add_range = true; if ($range_type == Carrier::SHIPPING_METHOD_WEIGHT) - $range = new RangeWeight((int)$key); + { + if (!RangeWeight::rangeExist((int)$carrier->id, (float)$delimiter1, (float)$range_sup[$key])) + $range = new RangeWeight(); + else + { + $range = new RangeWeight((int)$key); + $add_range = false; + } + } + if ($range_type == Carrier::SHIPPING_METHOD_PRICE) - $range = new RangePrice((int)$key); - - $range->id_carrier = (int)$carrier->id; - $range->delimiter1 = (float)$delimiter1; - $range->delimiter2 = (float)$range_sup[$key]; - $range->save(); - + { + if (!RangePrice::rangeExist((int)$carrier->id, (float)$delimiter1, (float)$range_sup[$key])) + $range = new RangePrice(); + else + { + $range = new RangePrice((int)$key); + $add_range = false; + } + } + if ($add_range) + { + $range->id_carrier = (int)$carrier->id; + $range->delimiter1 = (float)$delimiter1; + $range->delimiter2 = (float)$range_sup[$key]; + $range->save(); + } + if (!Validate::isLoadedObject($range)) return false; $price_list = array(); @@ -632,7 +651,7 @@ class AdminCarrierWizardControllerCore extends AdminController 'price' => (float)$fee[$key] ); } - + if (count($price_list) && !$carrier->addDeliveryPrice($price_list, true)) return false; } @@ -692,9 +711,9 @@ class AdminCarrierWizardControllerCore extends AdminController $new_carrier->position = $current_carrier->position; $new_carrier->update(); - $this->updateAssoShop($new_carrier->id); - $new_carrier->copyCarrierData((int)$current_carrier->id); - $this->changeGroups($new_carrier->id); + $this->updateAssoShop((int)$new_carrier->id); + $this->duplicateLogo((int)$new_carrier->id, (int)$current_carrier->id); + $this->changeGroups((int)$new_carrier->id); // Call of hooks Hook::exec('actionCarrierUpdate', array( 'id_carrier' => (int)$current_carrier->id, @@ -848,4 +867,19 @@ class AdminCarrierWizardControllerCore extends AdminController { return $field; } + + public function duplicateLogo($new_id, $old_id) + { + $old_logo = _PS_SHIP_IMG_DIR_.'/'.(int)$old_id.'.jpg'; + if (file_exists($old_logo)) + copy($old_logo, _PS_SHIP_IMG_DIR_.'/'.(int)$new_id.'.jpg'); + + $old_tmp_logo = _PS_TMP_IMG_DIR_.'/carrier_mini_'.(int)$old_id.'.jpg'; + if (file_exists($old_tmp_logo)) + { + if (!isset($_FILES['logo'])) + copy($old_tmp_logo, _PS_TMP_IMG_DIR_.'/carrier_mini_'.$new_id.'.jpg'); + unlink($old_tmp_logo); + } + } } diff --git a/css/admin.css b/css/admin.css index 1e885be5e..f02fcd24b 100644 --- a/css/admin.css +++ b/css/admin.css @@ -2593,7 +2593,6 @@ margin-bottom:7px; padding:5px; border: 1px solid #FFD700; background-color: #FFFFDD; - font: normal 12px Verdana, Arial, Helvetica, sans-serif; color:#5A5655; -moz-border-radius : 5px; -webkit-border-radius: 5px; @@ -2625,9 +2624,9 @@ margin-bottom:7px; #carrier_wizard .border_left {border-left:solid 1px #C0C0C0;} #carrier_wizard .border_right {border-right:solid 1px #C0C0C0;} #carrier_wizard .border_all {border:solid 1px #C0C0C0;} -#carrier_wizard input.field_error {border : solid 1px red; background-color:#FFCCCCheight: 1px;} +#carrier_wizard input.field_error {border : solid 1px red; background-color:#FFCCCC;} #carrier_wizard table td.center {text-align: center} -#carrier_wizard .new_range {float: left; margin: 20px 0 0 10px; width: 130px;} +#carrier_wizard .new_range, #carrier_wizard .validate_range {float: left; margin: 20px 0 0 10px; width: 130px;} #carrier_wizard tr.fees_all { background: #CCCCCC} #carrier_wizard #zones_table input[type=text] {width: 45px;} #carrier_wizard #fieldset_form { min-height: 190px} diff --git a/js/admin_carrier_wizard.js b/js/admin_carrier_wizard.js index 83f9c8698..520fe2df8 100644 --- a/js/admin_carrier_wizard.js +++ b/js/admin_carrier_wizard.js @@ -94,6 +94,9 @@ function onFinishCallback(obj, context) } else window.location.href = carrierlist_url; + }, + error: function(XMLHttpRequest, textStatus, errorThrown) { + jAlert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); } }); } @@ -202,6 +205,9 @@ function validateSteps(step_number) displayError(datas.errors, step_number); resizeWizard(); } + }, + error: function(XMLHttpRequest, textStatus, errorThrown) { + jAlert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); } }); return is_ok; @@ -315,6 +321,9 @@ function bind_inputs() $('#zone_ranges').replaceWith(data); displayRangeType(); bind_inputs(); + }, + error: function(XMLHttpRequest, textStatus, errorThrown) { + jAlert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); } }); });