public function initContent() { $array_carrier = array(); $carriers = Carrier::getCarriers($this->context->language->id, true, false, false, null, Carrier::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE); foreach ($carriers as $key => $carrier) { if ($carrier['is_free']) { unset($carriers[$key]); } else { $array_carrier[] = $carrier['id_carrier']; } } $id_carrier = (int) Tools::getValue('id_carrier'); if (count($carriers) && isset($array_carrier[0])) { if (!$id_carrier) { $id_carrier = (int) $array_carrier[0]; } $carrierSelected = new Carrier((int) $id_carrier); } else { $carrierSelected = new Carrier((int) $id_carrier); } $currency = $this->context->currency; $rangeObj = $carrierSelected->getRangeObject(); $rangeTable = $carrierSelected->getRangeTable(); $suffix = $carrierSelected->getRangeSuffix(); $rangeIdentifier = 'id_' . $rangeTable; $ranges = $rangeObj->getRanges($id_carrier); $delivery = Carrier::getDeliveryPriceByRanges($rangeTable, $id_carrier); $deliveryArray = array(); foreach ($delivery as $deliv) { $deliveryArray[$deliv['id_zone']][$deliv['id_carrier']][$deliv[$rangeIdentifier]] = $deliv['price']; } $this->context->smarty->assign(array('zones' => $carrierSelected->getZones(), 'carriers' => $carriers, 'ranges' => $ranges, 'currency' => $currency, 'deliveryArray' => $deliveryArray, 'carrierSelected' => $carrierSelected, 'id_carrier' => $id_carrier, 'suffix' => $suffix, 'rangeIdentifier' => $rangeIdentifier, 'action_fees' => self::$currentIndex . '&token=' . $this->token)); parent::initContent(); }
public function displayFormFees() { global $currentIndex; $carrierArray = array(); $id_carrier = Tools::getValue('id_carrier'); $carriers = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, false, NULL, Carrier::PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE); foreach ($carriers as $carrier) { if (!$carrier['is_free']) { $carrierArray[] = array('id' => $carrier['id_carrier'], 'display' => '<option value="' . (int) $carrier['id_carrier'] . '"' . ($carrier['id_carrier'] == $id_carrier ? ' selected="selected"' : '') . '>' . $carrier['name'] . '</option>'); } } if (count($carrierArray)) { if (!$id_carrier) { $id_carrier = (int) $carrierArray[0]['id']; } $carrierSelected = new Carrier($id_carrier); } echo '<br /><br /> <h2>' . $this->l('Fees by carrier, geographical zone, and ranges') . '</h2> <form action="' . $currentIndex . '&token=' . $this->token . '" id="fees" name="fees" method="post"> <fieldset> <legend><img src="../img/admin/delivery.gif" />' . $this->l('Fees') . '</legend>'; if (!count($carrierArray)) { echo $this->l('You only have free carriers, there is no need to configure your delivery prices.'); } else { echo '<b>' . $this->l('Carrier:') . ' </b> <select name="id_carrier2" onchange="document.fees.submit();">'; foreach ($carrierArray as $carrierOption) { echo $carrierOption['display']; } echo ' </select><br /> <table class="table space" cellpadding="0" cellspacing="0"> <tr> <th>' . $this->l('Zone / Range') . '</th>'; $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $rangeObj = $carrierSelected->getRangeObject(); $rangeTable = $carrierSelected->getRangeTable(); $suffix = $carrierSelected->getRangeSuffix(); $rangeIdentifier = 'id_' . $rangeTable; $ranges = $rangeObj->getRanges($id_carrier); $delivery = Carrier::getDeliveryPriceByRanges($rangeTable, $id_carrier); foreach ($delivery as $deliv) { $deliveryArray[$deliv['id_zone']][$deliv['id_carrier']][$deliv[$rangeIdentifier]] = $deliv['price']; } if (!$carrierSelected->is_free) { foreach ($ranges as $range) { echo '<th style="font-size: 11px;">' . (double) $range['delimiter1'] . $suffix . ' ' . $this->l('to') . ' ' . (double) $range['delimiter2'] . $suffix . '</th>'; } } echo '</tr>'; $zones = $carrierSelected->getZones(); if (sizeof($ranges) && !$carrierSelected->is_free) { if (sizeof($zones) > 1) { echo ' <tr> <th style="height: 30px;">' . $this->l('All') . '</th>'; foreach ($ranges as $range) { echo '<td class="center">' . $currency->getSign('left') . '<input type="text" id="fees_all_' . $range[$rangeIdentifier] . '" onchange="this.value = this.value.replace(/,/g, \'.\');" onkeyup="if ((event.keyCode||event.which) != 9){ spreadFees(' . $range[$rangeIdentifier] . ') }" style="width: 45px;" />' . $currency->getSign('right') . '</td>'; } echo '</tr>'; } foreach ($zones as $zone) { echo ' <tr> <th style="height: 30px;">' . $zone['name'] . '</th>'; 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'; } echo '<td class="center">' . $currency->getSign('left') . '<input type="text" class="fees_' . $range[$rangeIdentifier] . '" onchange="this.value = this.value.replace(/,/g, \'.\');" name="fees_' . $zone['id_zone'] . '_' . $range[$rangeIdentifier] . '" onkeyup="clearAllFees(' . $range[$rangeIdentifier] . ')" value="' . $price . '" style="width: 45px;" />' . $currency->getSign('right') . '</td>'; } echo ' </tr>'; } } echo '<tr> <td colspan="' . (sizeof($ranges) + 1) . '" class="center" style="border-bottom: none; height: 40px;"> <input type="hidden" name="submitFees' . $this->table . '" value="1" />'; if (sizeof($ranges) && !$carrierSelected->is_free) { echo ' <input type="submit" value="' . $this->l(' Save ') . '" class="button" />'; } elseif ($carrierSelected->is_free) { echo $this->l('This is a free carrier'); } else { echo $this->l('No ranges set for this carrier'); } echo ' </td> </tr>'; echo ' </table> <p>' . $this->l('Prices do not include tax.') . '</p>'; } echo ' </fieldset> <input type="hidden" name="id_carrier" value="' . $id_carrier . '" /> </form>'; }