// 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

View File

@@ -27,6 +27,9 @@
{block name="field"}
{if $input.name == 'zones'}
{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}
{$smarty.block.parent}
{/block}

View File

@@ -54,6 +54,3 @@
</tr>
</table>
</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>

View File

@@ -378,13 +378,12 @@ class CarrierCore extends ObjectModel
*/
public static function getDeliveryPriceByRanges($range_table, $id_carrier)
{
$range_table = pSQL($range_table);
$sql = 'SELECT d.id_'.$range_table.', d.id_carrier, d.id_zone, d.price
$sql = 'SELECT d.`id_'.bqSQL($range_table).'`, d.id_carrier, d.id_zone, d.price
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.'
AND d.id_'.$range_table.' IS NOT NULL
AND d.id_'.$range_table.' != 0
AND d.`id_'.bqSQL($range_table).'` IS NOT NULL
AND d.`id_'.bqSQL($range_table).'` != 0
'.Carrier::sqlDeliveryRangeShop($range_table).'
ORDER BY r.delimiter1';
return Db::getInstance()->executeS($sql);
@@ -1059,9 +1058,9 @@ class CarrierCore extends ObjectModel
$sql = 'AND '.$alias.'.id_delivery = (
SELECT d2.id_delivery
FROM '._DB_PREFIX_.'delivery d2
WHERE d2.id_carrier = '.$alias.'.id_carrier
AND d2.id_zone = '.$alias.'.id_zone
AND d2.id_'.$range_table.' = '.$alias.'.id_'.$range_table.'
WHERE d2.id_carrier = `'.bqSQL($alias).'`.id_carrier
AND d2.id_zone = `'.bqSQL($alias).'`.id_zone
AND d2.`id_'.bqSQL($range_table).'` = `'.bqSQL($alias).'`.`id_'.bqSQL($range_table).'`
'.$where.'
ORDER BY d2.id_shop DESC, d2.id_shop_group DESC
LIMIT 1

View File

@@ -308,9 +308,8 @@ class AdminCarrierWizardControllerCore extends AdminController
$tpl_vars = array();
$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);
}
@@ -323,9 +322,6 @@ class AdminCarrierWizardControllerCore extends AdminController
foreach ($carrier_zones as $carrier_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();
if ($shipping_method == Carrier::SHIPPING_METHOD_FREE)
@@ -339,8 +335,16 @@ class AdminCarrierWizardControllerCore extends AdminController
$range_table = $carrier->getRangeTable();
$range_obj = $carrier->getRangeObject();
$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)
$tpl_vars['price_by_range'][$price['id_'.$range_table]][$price['id_zone']] = $price['price'];
@@ -517,13 +521,14 @@ class AdminCarrierWizardControllerCore extends AdminController
if (!(int)$shipping_method = (Tools::getValue('shipping_method')) || !in_array($shipping_method, array(CARRIER::SHIPPING_METHOD_PRICE, CARRIER::SHIPPING_METHOD_WEIGHT)))
return ;
$carrier = $this->loadObject(true);
$carrier = $this->loadObject(true);
$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);
$template->assign('fields_value', $fields_value);
$template->assign('input', array('type' => 'zone', 'name' => 'zones' ));
die ($template->fetch());
}
@@ -568,19 +573,10 @@ class AdminCarrierWizardControllerCore extends AdminController
$range_inf = Tools::getValue('range_inf');
$range_sup = Tools::getValue('range_sup');
$range_type = Tools::getValue('shipping_method');
if ($range_type != Carrier::SHIPPING_METHOD_FREE)
{
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)
$new_range = new RangeWeight();
@@ -659,7 +655,6 @@ class AdminCarrierWizardControllerCore extends AdminController
$return['errors'][] = $this->l('An error occurred while saving this carrier.');
}
}
if (Validate::isLoadedObject($carrier))
{
if (!$this->changeGroups((int)$carrier->id))
@@ -735,6 +730,7 @@ class AdminCarrierWizardControllerCore extends AdminController
else
if (isset($_POST['zone_'.$zone['id_zone']]) && $_POST['zone_'.$zone['id_zone']])
$return &= $carrier->addZone($zone['id_zone']);
return $return;
}

View File

@@ -286,15 +286,14 @@ function bind_inputs()
$('input[name="is_free"]:checked').click();
$('input[name="shipping_method"]').on('click', function() {
console.log('in');
$.ajax({
type:"POST",
url : validate_url,
async: false,
dataType: 'json',
dataType: 'html',
data : 'id_carrier='+parseInt($('#id_carrier').val())+'&shipping_method='+parseInt($(this).val())+'&action=changeRanges&ajax=1',
success : function(data) {
$('#zone_ranges').replaceWith(data);
}
});
});