Пример #1
0
 public function postProcess()
 {
     if (isset($_POST['submitAdd' . $this->table])) {
         $delimiter1 = Tools::getValue('delimiter1');
         $delimiter2 = Tools::getValue('delimiter2');
         if ($delimiter1 >= $delimiter2) {
             $this->_errors[] = Tools::displayError('Invalid range, "From" must be lower than "To"');
         }
         /* Check that a similar range does not exist yet for this carrier */
         if (!Tools::isSubmit('id_range_price') && !count($this->_errors) && ($ranges = RangePrice::getRanges((int) Tools::getValue('id_carrier')))) {
             foreach ($ranges as $range) {
                 if (!($delimiter2 <= $range['delimiter1'] || $delimiter1 >= $range['delimiter2'])) {
                     $this->_errors[] = Tools::displayError('Invalid range, this range is overlapping an existing range');
                     break;
                 }
             }
         }
     }
     parent::postProcess();
 }
Пример #2
0
    /**
     * Add zone
     */
    public function addZone($id_zone)
    {
        if (Db::getInstance()->execute('
			INSERT INTO `' . _DB_PREFIX_ . 'carrier_zone` (`id_carrier` , `id_zone`)
			VALUES (' . (int) $this->id . ', ' . (int) $id_zone . ')
		')) {
            // Get all ranges for this carrier
            $ranges_price = RangePrice::getRanges($this->id);
            $ranges_weight = RangeWeight::getRanges($this->id);
            // Create row in ps_delivery table
            if (count($ranges_price) || count($ranges_weight)) {
                $sql = 'INSERT INTO `' . _DB_PREFIX_ . 'delivery` (`id_carrier`, `id_range_price`, `id_range_weight`, `id_zone`, `price`) VALUES ';
                if (count($ranges_price)) {
                    foreach ($ranges_price as $range) {
                        $sql .= '(' . (int) $this->id . ', ' . (int) $range['id_range_price'] . ', 0, ' . (int) $id_zone . ', 0),';
                    }
                }
                if (count($ranges_weight)) {
                    foreach ($ranges_weight as $range) {
                        $sql .= '(' . (int) $this->id . ', 0, ' . (int) $range['id_range_weight'] . ', ' . (int) $id_zone . ', 0),';
                    }
                }
                $sql = rtrim($sql, ',');
                return Db::getInstance()->execute($sql);
            }
            return true;
        }
        return false;
    }
Пример #3
0
 private function carrierCompatibility($carrier)
 {
     // fix a bug in Prestashop before version 1.4.4.0 classes/cart.php function isCarrierInRange() range behavior
     $rangePrices = RangePrice::getRanges($carrier->id);
     if (empty($rangePrices)) {
         $rangePrice = new RangePrice();
         $rangePrice->id_carrier = $carrier->id;
         $rangePrice->delimiter1 = 0.0;
         $rangePrice->delimiter2 = 1000000.0;
         if (!$rangePrice->add()) {
             $this->log('installation adding rangePrice failed', ShopgateLogger::LOGTYPE_ACCESS);
             return false;
         }
     } else {
         $rangePrice = new RangeWeight($rangePrices[0]['id_range_price']);
     }
     $rangeWeights = RangeWeight::getRanges($carrier->id);
     if (empty($rangeWeights)) {
         $rangeWeight = new RangeWeight();
         $rangeWeight->id_carrier = $carrier->id;
         $rangeWeight->delimiter1 = 0.0;
         $rangeWeight->delimiter2 = 1000000.0;
         if (!$rangeWeight->add()) {
             $this->log('installation adding rangeWeight failed', ShopgateLogger::LOGTYPE_ACCESS);
             return false;
         }
     } else {
         $rangeWeight = new RangeWeight($rangeWeights[0]['id_range_weight']);
     }
     // Zones
     $zones = Zone::getZones();
     foreach ($zones as $zone) {
         $carrier->addZone($zone['id_zone']);
     }
     // create for each zone delivery options
     foreach ($zones as $zone) {
         $deliveryRangeWeight = new Delivery();
         $deliveryRangeWeight->id_carrier = $carrier->id;
         $deliveryRangeWeight->id_range_weight = $rangeWeight->id;
         $deliveryRangeWeight->id_range_price = 0;
         $deliveryRangeWeight->price = 0;
         $deliveryRangeWeight->id_zone = $zone['id_zone'];
         if (!$deliveryRangeWeight->add(true, true)) {
             $this->log('installation adding deliveryRangeWeight failed', ShopgateLogger::LOGTYPE_ACCESS);
             return false;
         }
         $deliveryRangePrice = new Delivery();
         $deliveryRangePrice->id_carrier = $carrier->id;
         $deliveryRangePrice->id_range_price = $rangePrice->id;
         $deliveryRangePrice->id_range_weight = 0;
         $deliveryRangePrice->price = 0;
         $deliveryRangePrice->id_zone = $zone['id_zone'];
         if (!$deliveryRangePrice->add(true, true)) {
             $this->log('installation adding deliveryRangePrice failed', ShopgateLogger::LOGTYPE_ACCESS);
             return false;
         }
     }
 }