// small changes

This commit is contained in:
Rémi Gaillard
2013-07-26 10:31:58 +02:00
parent 0e0200e71c
commit f361b2fcbe
5 changed files with 28 additions and 34 deletions
@@ -27,6 +27,9 @@
{block name="field"} {block name="field"}
{if $input.name == 'zones'} {if $input.name == 'zones'}
{include file='controllers/carrier_wizard/helpers/form/form_ranges.tpl'} {include file='controllers/carrier_wizard/helpers/form/form_ranges.tpl'}
<div class="new_range">
<a href="#" onclick="add_new_range();return false;" class="button" id="add_new_range">{l s="Add new range"}<img src="../img/admin/add.gif"/></a>
</div>
{/if} {/if}
{$smarty.block.parent} {$smarty.block.parent}
{/block} {/block}
@@ -54,6 +54,3 @@
</tr> </tr>
</table> </table>
</div> </div>
<div class="new_range">
<a href="#" onclick="add_new_range();return false;" class="button" id="add_new_range">{l s="Add new range"}<img src="../img/admin/add.gif"/></a>
</div>
+7 -8
View File
@@ -378,13 +378,12 @@ class CarrierCore extends ObjectModel
*/ */
public static function getDeliveryPriceByRanges($range_table, $id_carrier) public static function getDeliveryPriceByRanges($range_table, $id_carrier)
{ {
$range_table = pSQL($range_table); $sql = 'SELECT d.`id_'.bqSQL($range_table).'`, d.id_carrier, d.id_zone, d.price
$sql = 'SELECT d.id_'.$range_table.', d.id_carrier, d.id_zone, d.price
FROM '._DB_PREFIX_.'delivery d FROM '._DB_PREFIX_.'delivery d
LEFT JOIN '._DB_PREFIX_.$range_table.' r ON r.id_'.$range_table.' = d.id_'.$range_table.' LEFT JOIN `'._DB_PREFIX_.bqSQL($range_table).'` r ON r.`id_'.bqSQL($range_table).'` = d.`id_'.bqSQL($range_table).'`
WHERE d.id_carrier = '.(int)$id_carrier.' WHERE d.id_carrier = '.(int)$id_carrier.'
AND d.id_'.$range_table.' IS NOT NULL AND d.`id_'.bqSQL($range_table).'` IS NOT NULL
AND d.id_'.$range_table.' != 0 AND d.`id_'.bqSQL($range_table).'` != 0
'.Carrier::sqlDeliveryRangeShop($range_table).' '.Carrier::sqlDeliveryRangeShop($range_table).'
ORDER BY r.delimiter1'; ORDER BY r.delimiter1';
return Db::getInstance()->executeS($sql); return Db::getInstance()->executeS($sql);
@@ -1059,9 +1058,9 @@ class CarrierCore extends ObjectModel
$sql = 'AND '.$alias.'.id_delivery = ( $sql = 'AND '.$alias.'.id_delivery = (
SELECT d2.id_delivery SELECT d2.id_delivery
FROM '._DB_PREFIX_.'delivery d2 FROM '._DB_PREFIX_.'delivery d2
WHERE d2.id_carrier = '.$alias.'.id_carrier WHERE d2.id_carrier = `'.bqSQL($alias).'`.id_carrier
AND d2.id_zone = '.$alias.'.id_zone AND d2.id_zone = `'.bqSQL($alias).'`.id_zone
AND d2.id_'.$range_table.' = '.$alias.'.id_'.$range_table.' AND d2.`id_'.bqSQL($range_table).'` = `'.bqSQL($alias).'`.`id_'.bqSQL($range_table).'`
'.$where.' '.$where.'
ORDER BY d2.id_shop DESC, d2.id_shop_group DESC ORDER BY d2.id_shop DESC, d2.id_shop_group DESC
LIMIT 1 LIMIT 1
@@ -310,7 +310,6 @@ class AdminCarrierWizardControllerCore extends AdminController
$fields_value = $this->getStepThreeFieldsValues($carrier); $fields_value = $this->getStepThreeFieldsValues($carrier);
$this->getTplRangesVarsAndValues($carrier, &$tpl_vars, &$fields_value); $this->getTplRangesVarsAndValues($carrier, &$tpl_vars, &$fields_value);
return $this->renderGenericForm(array('form' => $this->fields_form), $fields_value, $tpl_vars); return $this->renderGenericForm(array('form' => $this->fields_form), $fields_value, $tpl_vars);
} }
@@ -323,9 +322,6 @@ class AdminCarrierWizardControllerCore extends AdminController
foreach ($carrier_zones as $carrier_zone) foreach ($carrier_zones as $carrier_zone)
$carrier_zones_ids[] = $carrier_zone['id_zone']; $carrier_zones_ids[] = $carrier_zone['id_zone'];
$zones = Zone::getZones(false);
foreach ($zones as $zone)
$fields_value['zones'][$zone['id_zone']] = Tools::getValue('zone_'.$zone['id_zone'], (in_array($zone['id_zone'], $carrier_zones_ids)));
$shipping_method = $carrier->getShippingMethod(); $shipping_method = $carrier->getShippingMethod();
if ($shipping_method == Carrier::SHIPPING_METHOD_FREE) if ($shipping_method == Carrier::SHIPPING_METHOD_FREE)
@@ -339,6 +335,14 @@ class AdminCarrierWizardControllerCore extends AdminController
$range_table = $carrier->getRangeTable(); $range_table = $carrier->getRangeTable();
$range_obj = $carrier->getRangeObject(); $range_obj = $carrier->getRangeObject();
$price_by_range = Carrier::getDeliveryPriceByRanges($range_table, (int)$carrier->id); $price_by_range = Carrier::getDeliveryPriceByRanges($range_table, (int)$carrier->id);
}
$zones = Zone::getZones(false);
foreach ($zones as $zone)
{
$fields_value['zones'][$zone['id_zone']] = Tools::getValue('zone_'.$zone['id_zone'], (in_array($zone['id_zone'], $carrier_zones_ids)));
if (!count($price_by_range))
;
} }
foreach ($price_by_range as $price) foreach ($price_by_range as $price)
@@ -523,7 +527,8 @@ class AdminCarrierWizardControllerCore extends AdminController
$this->getTplRangesVarsAndValues($carrier, &$tpl_vars, &$fields_value); $this->getTplRangesVarsAndValues($carrier, &$tpl_vars, &$fields_value);
$template = $this->createTemplate('controllers/carrier_wizard/helpers/form/form_ranges.tpl'); $template = $this->createTemplate('controllers/carrier_wizard/helpers/form/form_ranges.tpl');
$template->assign($tpl_vars); $template->assign($tpl_vars);
$template->assign($fields_value); $template->assign('fields_value', $fields_value);
$template->assign('input', array('type' => 'zone', 'name' => 'zones' ));
die ($template->fetch()); die ($template->fetch());
} }
@@ -568,19 +573,10 @@ class AdminCarrierWizardControllerCore extends AdminController
$range_inf = Tools::getValue('range_inf'); $range_inf = Tools::getValue('range_inf');
$range_sup = Tools::getValue('range_sup'); $range_sup = Tools::getValue('range_sup');
$range_type = Tools::getValue('shipping_method'); $range_type = Tools::getValue('shipping_method');
if ($range_type != Carrier::SHIPPING_METHOD_FREE) if ($range_type != Carrier::SHIPPING_METHOD_FREE)
{ {
foreach ($range_inf as $key => $range) foreach ($range_inf as $key => $range)
{ {
if ($range_type == Carrier::SHIPPING_METHOD_DEFAULT)
{
if (!Configuration::get('PS_SHIPPING_METHOD'))
$range_type = Carrier::SHIPPING_METHOD_PRICE;
else
$range_type = Carrier::SHIPPING_METHOD_WEIGHT;
}
if ($range_type == Carrier::SHIPPING_METHOD_WEIGHT) if ($range_type == Carrier::SHIPPING_METHOD_WEIGHT)
$new_range = new RangeWeight(); $new_range = new RangeWeight();
@@ -659,7 +655,6 @@ class AdminCarrierWizardControllerCore extends AdminController
$return['errors'][] = $this->l('An error occurred while saving this carrier.'); $return['errors'][] = $this->l('An error occurred while saving this carrier.');
} }
} }
if (Validate::isLoadedObject($carrier)) if (Validate::isLoadedObject($carrier))
{ {
if (!$this->changeGroups((int)$carrier->id)) if (!$this->changeGroups((int)$carrier->id))
@@ -735,6 +730,7 @@ class AdminCarrierWizardControllerCore extends AdminController
else else
if (isset($_POST['zone_'.$zone['id_zone']]) && $_POST['zone_'.$zone['id_zone']]) if (isset($_POST['zone_'.$zone['id_zone']]) && $_POST['zone_'.$zone['id_zone']])
$return &= $carrier->addZone($zone['id_zone']); $return &= $carrier->addZone($zone['id_zone']);
return $return; return $return;
} }
+2 -3
View File
@@ -286,15 +286,14 @@ function bind_inputs()
$('input[name="is_free"]:checked').click(); $('input[name="is_free"]:checked').click();
$('input[name="shipping_method"]').on('click', function() { $('input[name="shipping_method"]').on('click', function() {
console.log('in');
$.ajax({ $.ajax({
type:"POST", type:"POST",
url : validate_url, url : validate_url,
async: false, async: false,
dataType: 'json', dataType: 'html',
data : 'id_carrier='+parseInt($('#id_carrier').val())+'&shipping_method='+parseInt($(this).val())+'&action=changeRanges&ajax=1', data : 'id_carrier='+parseInt($('#id_carrier').val())+'&shipping_method='+parseInt($(this).val())+'&action=changeRanges&ajax=1',
success : function(data) { success : function(data) {
$('#zone_ranges').replaceWith(data);
} }
}); });
}); });