From 85d5b6daed9a64205e4ef981fbb0f6a36b80ca5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Gaillard?= Date: Fri, 26 Jul 2013 17:20:55 +0200 Subject: [PATCH] // ranges --- .../helpers/form/form_ranges.tpl | 10 +- .../template/controllers/shipping/content.tpl | 105 ------------------ .../template/controllers/shipping/index.php | 35 ------ classes/Carrier.php | 2 +- .../admin/AdminCarrierWizardController.php | 74 ++++++++---- 5 files changed, 61 insertions(+), 165 deletions(-) delete mode 100644 admin-dev/themes/default/template/controllers/shipping/content.tpl delete mode 100644 admin-dev/themes/default/template/controllers/shipping/index.php 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 4cbfdca8e..4908e2448 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 @@ -4,18 +4,18 @@ >= {foreach from=$ranges key=r item=range} - + {foreachelse} - + {/foreach} < {foreach from=$ranges key=r item=range} - + {foreachelse} - + {/foreach} @@ -37,7 +37,7 @@ {$zone.name} {foreach from=$ranges key=r item=range} - + {/foreach} {/foreach} diff --git a/admin-dev/themes/default/template/controllers/shipping/content.tpl b/admin-dev/themes/default/template/controllers/shipping/content.tpl deleted file mode 100644 index 4ab2ff01a..000000000 --- a/admin-dev/themes/default/template/controllers/shipping/content.tpl +++ /dev/null @@ -1,105 +0,0 @@ -{* -* 2007-2013 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-2013 PrestaShop SA -* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*} - -{$content} -

-

{l s='Fees by carrier, geographical zone and ranges'}

-
-
- {l s='Fees'} - {if empty($carriers)} - {l s='If you only have free carriers, there\'s no need to configure delivery prices.'} - {else} - {l s='Carrier:'} -
- - - - - {if !$carrierSelected->is_free} - {foreach $ranges AS $range} - - {/foreach} - {/if} - - {if sizeof($ranges) && !$carrierSelected->is_free} - {if sizeof($zones) > 1} - - - {foreach $ranges AS $range} - - {/foreach} - - {/if} - - {foreach $zones AS $zone} - - - {foreach $ranges AS $range} - {if isset($deliveryArray[$zone['id_zone']][$id_carrier][$range[$rangeIdentifier]])} - {$price = $deliveryArray[$zone['id_zone']][$id_carrier][$range[$rangeIdentifier]]} - {else} - {$price = '0.00'} - {/if} - - {/foreach} - - {/foreach} - {/if} - - - -
{l s='Zone / Range'}{$range['delimiter1']|floatval}{$suffix} {l s='to'} {$range['delimiter2']|floatval}{$suffix}
{l s='All'} - {$currency->getSign('left')} - - {$currency->getSign('right')} {l s='(tax excl.)'} -
{$zone['name']} - {$currency->getSign('left')} - - {$currency->getSign('right')} {l s='(tax excl.)'} -
- - {if sizeof($ranges) && !$carrierSelected->is_free} - - {else if $carrierSelected->is_free} - {l s='This is a free carrier'} - {else} - {l s='No ranges is set for this carrier'} - {/if} -
- {/if} - -
-
diff --git a/admin-dev/themes/default/template/controllers/shipping/index.php b/admin-dev/themes/default/template/controllers/shipping/index.php deleted file mode 100644 index fcb7f5c2b..000000000 --- a/admin-dev/themes/default/template/controllers/shipping/index.php +++ /dev/null @@ -1,35 +0,0 @@ - -* @copyright 2007-2013 PrestaShop SA -* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); -header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); - -header('Cache-Control: no-store, no-cache, must-revalidate'); -header('Cache-Control: post-check=0, pre-check=0', false); -header('Pragma: no-cache'); - -header('Location: ../../../../../../'); -exit; \ No newline at end of file diff --git a/classes/Carrier.php b/classes/Carrier.php index 4343d754a..928418647 100644 --- a/classes/Carrier.php +++ b/classes/Carrier.php @@ -735,7 +735,7 @@ class CarrierCore extends ObjectModel */ public function deleteDeliveryPrice($range_table) { - $where = '`id_carrier` = '.(int)$this->id.' AND (`id_'.$range_table.'` IS NOT NULL OR `id_'.$range_table.'` = 0) '; + $where = '`id_carrier` = '.(int)$this->id.' AND (`id_'.bqSQL($range_table).'` IS NOT NULL OR `id_'.bqSQL($range_table).'` = 0) '; if (Shop::getContext() == Shop::CONTEXT_ALL) $where .= 'AND id_shop IS NULL AND id_shop_group IS NULL'; diff --git a/controllers/admin/AdminCarrierWizardController.php b/controllers/admin/AdminCarrierWizardController.php index 1070661e4..795623a30 100644 --- a/controllers/admin/AdminCarrierWizardController.php +++ b/controllers/admin/AdminCarrierWizardController.php @@ -358,7 +358,7 @@ class AdminCarrierWizardControllerCore extends AdminController // init blank range if (!count($tpl_vars['ranges'])) - $tpl_vars['ranges'][] = array('id_range' => -1, 'delimiter1' => 0, 'delimiter2' => 5); + $tpl_vars['ranges'][] = array('id_range' => -1, 'delimiter1' => 0, 'delimiter2' => 100000); } public function renderStepFour($carrier) @@ -529,10 +529,12 @@ class AdminCarrierWizardControllerCore extends AdminController $tpl_vars = array(); $fields_value = $this->getStepThreeFieldsValues($carrier); $this->getTplRangesVarsAndValues($carrier, &$tpl_vars, &$fields_value); + $template = $this->createTemplate('controllers/carrier_wizard/helpers/form/form_ranges.tpl'); $template->assign($tpl_vars); $template->assign('fields_value', $fields_value); $template->assign('input', array('type' => 'zone', 'name' => 'zones' )); + die ($template->fetch()); } @@ -566,33 +568,61 @@ class AdminCarrierWizardControllerCore extends AdminController die(Tools::jsonEncode($return)); } - public function processRange() + public function processRanges($id_carrier) { - if ((Validate::isLoadedObject($this->object) && !$this->wizard_access['edit']) || !$this->wizard_access['add']) + if (!$this->wizard_access['edit'] || !$this->wizard_access['add']) { $this->errors[] = Tools::displayError('You do not have permission to use this wizard.'); return; } + $carrier = new Carrier((int)$id_carrier); + if (!Validate::isLoadedObject($carrier)) + return false; + $range_inf = Tools::getValue('range_inf'); $range_sup = Tools::getValue('range_sup'); $range_type = Tools::getValue('shipping_method'); + + $fees = Tools::getValue('fees'); + + $carrier->deleteDeliveryPrice($carrier->getRangeTable()); if ($range_type != Carrier::SHIPPING_METHOD_FREE) { - foreach ($range_inf as $key => $range) - { + foreach ($range_inf as $key => $delimiter1) + { + if (!isset($range_sup[$key])) + continue; + if ($range_type == Carrier::SHIPPING_METHOD_WEIGHT) - $new_range = new RangeWeight(); - + $range = new RangeWeight((int)$key); if ($range_type == Carrier::SHIPPING_METHOD_PRICE) - $new_range = new RangePrice(); - - - /* $this-> */ - - - } + $range = new RangePrice((int)$key); + + $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(); + foreach ($fees as $id_zone => $fee) + $price_list[] = array( + 'id_range_price' => ($range_type == Carrier::SHIPPING_METHOD_PRICE ? (int)$range->id : null), + 'id_range_weight' => ($range_type == Carrier::SHIPPING_METHOD_WEIGHT ? (int)$range->id : null), + 'id_carrier' => (int)$carrier->id, + 'id_zone' => (int)$id_zone, + 'price' => (float)$fee[$key] + ); + + if (!$carrier->addDeliveryPrice($price_list)) + return false; + } } + + return true; } public function ajaxProcessUploadLogo() @@ -666,25 +696,31 @@ class AdminCarrierWizardControllerCore extends AdminController $return['has_error'] = true; $return['errors'][] = $this->l('An error occurred while saving carrier groups.'); } - + if (!$this->changeZones((int)$carrier->id)) { $return['has_error'] = true; $return['errors'][] = $this->l('An error occurred while saving carrier zones.'); } - + + if (!$this->processRanges((int)$carrier->id)) + { + $return['has_error'] = true; + $return['errors'][] = $this->l('An error occurred while saving carrier ranges.'); + } + if (Shop::isFeatureActive() && !$this->updateAssoShop((int)$carrier->id)) { $return['has_error'] = true; $return['errors'][] = $this->l('An error occurred while saving associations of shops.'); } - + if (!$carrier->setTaxRulesGroup((int)Tools::getValue('id_tax_rules_group'))) { $return['has_error'] = true; $return['errors'][] = $this->l('An error occurred while saving the tax rules group.'); } - + if (Tools::getValue('logo')) { if (Tools::getValue('logo') == 'null' && file_exists(_PS_SHIP_IMG_DIR_.$carrier->id.'.jpg')) @@ -780,4 +816,4 @@ class AdminCarrierWizardControllerCore extends AdminController { return $field; } -} \ No newline at end of file +}