Exemplo n.º 1
0
 public function postProcess()
 {
     $id = (int) Tools::getValue('id_' . $this->table);
     if (Tools::getValue('submitAdd' . $this->table)) {
         if (Tools::getValue('delimiter1') >= Tools::getValue('delimiter2')) {
             $this->errors[] = Tools::displayError('Invalid range');
         } elseif (!$id && RangeWeight::rangeExist((int) Tools::getValue('id_carrier'), (double) Tools::getValue('delimiter1'), (double) Tools::getValue('delimiter2'))) {
             $this->errors[] = Tools::displayError('The range already exists');
         } elseif (RangeWeight::isOverlapping((int) Tools::getValue('id_carrier'), (double) Tools::getValue('delimiter1'), (double) Tools::getValue('delimiter2'), $id ? (int) $id : null)) {
             $this->errors[] = Tools::displayError('Error: Ranges are overlapping');
         } elseif (!count($this->errors)) {
             parent::postProcess();
         }
     } else {
         parent::postProcess();
     }
 }
 public function processRanges($id_carrier)
 {
     if (!$this->access('edit') || !$this->access('add')) {
         $this->errors[] = $this->trans('You do not have permission to use this wizard.', array(), 'Admin.Shipping.Notification');
         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 => $delimiter1) {
             if (!isset($range_sup[$key])) {
                 continue;
             }
             $add_range = true;
             if ($range_type == Carrier::SHIPPING_METHOD_WEIGHT) {
                 if (!RangeWeight::rangeExist(null, (double) $delimiter1, (double) $range_sup[$key], $carrier->id_reference)) {
                     $range = new RangeWeight();
                 } else {
                     $range = new RangeWeight((int) $key);
                     $range->id_carrier = (int) $carrier->id;
                     $range->save();
                     $add_range = false;
                 }
             }
             if ($range_type == Carrier::SHIPPING_METHOD_PRICE) {
                 if (!RangePrice::rangeExist(null, (double) $delimiter1, (double) $range_sup[$key], $carrier->id_reference)) {
                     $range = new RangePrice();
                 } else {
                     $range = new RangePrice((int) $key);
                     $range->id_carrier = (int) $carrier->id;
                     $range->save();
                     $add_range = false;
                 }
             }
             if ($add_range) {
                 $range->id_carrier = (int) $carrier->id;
                 $range->delimiter1 = (double) $delimiter1;
                 $range->delimiter2 = (double) $range_sup[$key];
                 $range->save();
             }
             if (!Validate::isLoadedObject($range)) {
                 return false;
             }
             $price_list = array();
             if (is_array($fees) && count($fees)) {
                 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' => isset($fee[$key]) ? (double) str_replace(',', '.', $fee[$key]) : 0);
                 }
             }
             if (count($price_list) && !$carrier->addDeliveryPrice($price_list, true)) {
                 return false;
             }
         }
     }
     return true;
 }