/**
  * creates of a dejala carrier corresponding to $dejalaProduct
  */
 public static function createDejalaCarrier($dejalaConfig, $dejalaProduct)
 {
     // MFR091130 - get id zone from the country used in the module (if the store zones were customized) - default is 1 (Europe)
     $id_zone = 1;
     $moduleCountryIsoCode = strtoupper($dejalaConfig->country);
     $countryID = Country::getByIso($moduleCountryIsoCode);
     if (intval($countryID)) {
         $id_zone = Country::getIdZone($countryID);
     }
     $vatRate = floatval($dejalaProduct['vat']);
     // MFR091130 - get or create the tax & attach it to our zone if needed
     $id_tax = Tax::getTaxIdByRate($vatRate);
     if (!$id_tax) {
         $tax = new Tax();
         $tax->rate = $vatRate;
         $defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
         $tax->name[$defaultLanguage] = $tax->rate . '%';
         $tax->add();
         $id_tax = Tax::getTaxIdByRate($vatRate);
     }
     if (!Tax::zoneHasTax($id_tax, $id_zone)) {
         // MFR : direct call because $tax->addZone($id_zone) causes errors when called
         Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'tax_zone` (`id_tax` , `id_zone`) VALUES (' . intval($id_tax) . ', ' . intval($id_zone) . ')');
     }
     $carrier = new Carrier();
     $carrier->name = 'dejala';
     $carrier->id_tax = $id_tax;
     $carrier->url = 'http://tracking.dejala.' . $dejalaConfig->country . '/tracker/@';
     $carrier->active = true;
     $carrier->deleted = 0;
     $carrier->shipping_handling = false;
     $carrier->range_behavior = 0;
     $carrier->is_module = 1;
     $languages = Language::getLanguages(true);
     foreach ($languages as $language) {
         if ($language['iso_code'] == 'fr') {
             $carrier->delay[$language['id_lang']] = utf8_encode('Quand vous voulez... Par coursier, ' . $dejalaProduct['timelimit'] . 'H');
         }
         if ($language['iso_code'] == 'en') {
             $carrier->delay[$language['id_lang']] = utf8_encode('When you want... Dispatch rider, ' . $dejalaProduct['timelimit'] . 'H range');
         }
         if ($language['iso_code'] == 'es') {
             $carrier->delay[$language['id_lang']] = utf8_encode('Cuando quiera... Por mensajero, ' . $dejalaProduct['timelimit'] . 'H');
         }
     }
     $carrier->add();
     $sql = 'INSERT INTO `' . _DB_PREFIX_ . 'carrier_zone` (`id_carrier` , `id_zone`) VALUES (' . intval($carrier->id) . ', ' . intval($id_zone) . ')';
     Db::getInstance()->Execute($sql);
     $rangeW = new RangeWeight();
     $rangeW->id_carrier = $carrier->id;
     $rangeW->delimiter1 = 0;
     $rangeW->delimiter2 = $dejalaProduct['max_weight'];
     $rangeW->add();
     $vat_factor = 1 + $dejalaProduct['vat'] / 100;
     $priceTTC = round($dejalaProduct['price'] * $vat_factor + $dejalaProduct['margin'], 2);
     $priceHT = round($priceTTC / $vat_factor, 2);
     $priceList = '(NULL' . ',' . $rangeW->id . ',' . $carrier->id . ',' . $id_zone . ',' . $priceHT . ')';
     $carrier->addDeliveryPrice($priceList);
     return new Carrier($carrier->id);
 }
 public function xdInstall()
 {
     foreach ($this->Options->getValue('carrierList') as $carrier_key => $carrier_name) {
         $carrierId = \Configuration::get($carrier_key);
         $deleted = false;
         if ($carrierId > 0) {
             $carrier = new \Carrier($carrierId);
             $deleted = $carrier->deleted;
         }
         if ($carrierId < 1 || $deleted) {
             // Create carrier
             $carrier = new \Carrier();
             $carrier->name = $carrier_name;
             $carrier->id_tax_rules_group = 0;
             $carrier->active = 1;
             $carrier->deleted = 0;
             foreach (\Language::getLanguages(true) as $language) {
                 // TODO Carrier delay
                 $carrier->delay[(int) $language['id_lang']] = ' ';
             }
             $carrier->shipping_handling = 0;
             $carrier->range_behavior = 1;
             $carrier->is_module = 1;
             $carrier->shipping_external = 1;
             $carrier->external_module_name = $this->moduleInstance->name;
             $carrier->need_range = 1;
             if (!$carrier->add()) {
                 return false;
             }
             // Associate carrier to all groups
             $groups = \Group::getGroups(true);
             foreach ($groups as $group) {
                 \Db::getInstance()->insert('carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']));
             }
             // Create price range
             $rangePrice = new \RangePrice();
             $rangePrice->id_carrier = $carrier->id;
             $rangePrice->delimiter1 = '0';
             $rangePrice->delimiter2 = '10000';
             $rangePrice->add();
             // Create weight range
             $rangeWeight = new \RangeWeight();
             $rangeWeight->id_carrier = $carrier->id;
             $rangeWeight->delimiter1 = '0';
             $rangeWeight->delimiter2 = '10000';
             $rangeWeight->add();
             // Associate carrier to all zones
             $zones = \Zone::getZones(true);
             foreach ($zones as $zone) {
                 \Db::getInstance()->insert('carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']));
                 \Db::getInstance()->insert('delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => null, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'));
                 \Db::getInstance()->insert('delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => null, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'));
             }
             copy(self::$instanceBaseDir . '/img/logo.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg');
             \Configuration::updateValue($carrier_key, $carrier->id);
         }
     }
     return true;
 }
 public function installExternalCarrier($config)
 {
     $carrier = new Carrier();
     $carrier->name = $config['name'];
     $carrier->id_tax_rules_group = $config['id_tax_rules_group'];
     $carrier->active = $config['active'];
     $carrier->deleted = $config['deleted'];
     $carrier->delay = $config['delay'];
     $carrier->shipping_handling = $config['shipping_handling'];
     $carrier->range_behavior = $config['range_behavior'];
     $carrier->is_module = $config['is_module'];
     $carrier->shipping_external = $config['shipping_external'];
     $carrier->external_module_name = $config['external_module_name'];
     $carrier->need_range = $config['need_range'];
     $languages = Context::getContext()->language->getLanguages(true);
     foreach ($languages as $language) {
         if ($language['iso_code'] == 'cs') {
             $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
         } else {
             $carrier->delay[(int) $language['id_lang']] = '2 days';
         }
     }
     if ($carrier->add()) {
         $groups = Group::getGroups(true);
         foreach ($groups as $group) {
             Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
         }
         $rangePrice = new RangePrice();
         $rangePrice->id_carrier = $carrier->id;
         $rangePrice->delimiter1 = '0';
         $rangePrice->delimiter2 = '1000000';
         $rangePrice->add();
         $rangeWeight = new RangeWeight();
         $rangeWeight->id_carrier = $carrier->id;
         $rangeWeight->delimiter1 = '0';
         $rangeWeight->delimiter2 = '10000';
         $rangeWeight->add();
         $sql = 'SELECT DISTINCT id_zone FROM ' . _DB_PREFIX_ . 'country WHERE iso_code="CZ" OR iso_code="SK"';
         $zones = Db::getInstance()->executeS($sql);
         if (is_array($zones)) {
             foreach ($zones as $zone) {
                 Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']), 'INSERT');
                 Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => NULL, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
                 Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => NULL, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
             }
         }
         $this->module->copyLogo($carrier->id);
         if (Configuration::get('PS_TAX')) {
             $carrier->setTaxRulesGroup(1, true);
         }
         return (int) $carrier->id;
     }
     $this->messages[] = 'Failed to create external carrier ' . $config['name'];
     return false;
 }
 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 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_weight') && !count($this->_errors) && ($ranges = RangeWeight::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();
 }
Esempio n. 6
0
    public static function installExternalCarrier($config)
    {
        $carrier = new Carrier();
        $carrier->name = $config['name'];
        $carrier->id_tax = $config['id_tax'];
        $carrier->active = $config['active'];
        $carrier->deleted = $config['deleted'];
        $carrier->delay = $config['delay'];
        $carrier->shipping_handling = $config['shipping_handling'];
        $carrier->range_behavior = $config['range_behavior'];
        $carrier->is_module = $config['is_module'];
        $carrier->shipping_external = $config['shipping_external'];
        $carrier->external_module_name = $config['external_module_name'];
        $carrier->need_range = $config['need_range'];
        $languages = Language::getLanguages(true);
        foreach ($languages as $language) {
            if ($language['iso_code'] == 'fr') {
                $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
            }
            if ($language['iso_code'] == 'en') {
                $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
            }
            if ($language['iso_code'] == 'es') {
                $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
            }
        }
        if ($carrier->add()) {
            $groups = Group::getGroups(true);
            foreach ($groups as $group) {
                Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'carrier_group` VALUES (\'' . (int) $carrier->id . '\',\'' . (int) $group['id_group'] . '\')');
            }
            $rangePrice = new RangePrice();
            $rangePrice->id_carrier = $carrier->id;
            $rangePrice->delimiter1 = '0';
            $rangePrice->delimiter2 = '10000';
            $rangePrice->add();
            $rangeWeight = new RangeWeight();
            $rangeWeight->id_carrier = $carrier->id;
            $rangeWeight->delimiter1 = '0';
            $rangeWeight->delimiter2 = '15';
            $rangeWeight->add();
            $id_zone = Zone::getIdByName('Europe');
            Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'carrier_zone` VALUES (\'' . (int) $carrier->id . '\',\'' . (int) $id_zone . '\')');
            Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'delivery` (`id_carrier`, `id_range_price`, `id_range_weight`, `id_zone`, `price`)
				VALUES (\'' . (int) $carrier->id . '\',\'' . (int) $rangePrice->id . '\',NULL,\'' . (int) $id_zone . '\',\'' . (double) $config['price'] . '\'),
					   (\'' . (int) $carrier->id . '\',NULL,\'' . (int) $rangeWeight->id . '\',\'' . (int) $id_zone . '\',\'' . (double) $config['price'] . '\')');
            Configuration::updateValue('KIALASMALL_CARRIER_ID', (int) $carrier->id);
            //copy logo
            if (!copy(dirname(__FILE__) . '/carrier.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg')) {
                return false;
            }
            return true;
        } else {
            return false;
        }
    }
Esempio n. 7
0
 public static function installExternalCarrier($config)
 {
     $carrier = new Carrier();
     $carrier->name = $config['name'];
     $carrier->id_tax_rules_group = $config['id_tax_rules_group'];
     $carrier->id_zone = $config['id_zone'];
     $carrier->active = $config['active'];
     $carrier->deleted = $config['deleted'];
     $carrier->delay = $config['delay'];
     $carrier->shipping_handling = $config['shipping_handling'];
     $carrier->range_behavior = $config['range_behavior'];
     $carrier->is_module = $config['is_module'];
     $carrier->shipping_external = $config['shipping_external'];
     $carrier->external_module_name = $config['external_module_name'];
     $carrier->need_range = $config['need_range'];
     $languages = Language::getLanguages(true);
     foreach ($languages as $language) {
         if ($language['iso_code'] == 'fr') {
             $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
         }
         if ($language['iso_code'] == 'en') {
             $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
         }
         if ($language['iso_code'] == Language::getIsoById(Configuration::get('PS_LANG_DEFAULT'))) {
             $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
         }
     }
     if ($carrier->add()) {
         $groups = Group::getGroups(true);
         foreach ($groups as $group) {
             Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
         }
         $rangePrice = new RangePrice();
         $rangePrice->id_carrier = $carrier->id;
         $rangePrice->delimiter1 = '0';
         $rangePrice->delimiter2 = '10000';
         $rangePrice->add();
         $rangeWeight = new RangeWeight();
         $rangeWeight->id_carrier = $carrier->id;
         $rangeWeight->delimiter1 = '0';
         $rangeWeight->delimiter2 = '10000';
         $rangeWeight->add();
         $zones = Zone::getZones(true);
         foreach ($zones as $zone) {
             Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']), 'INSERT');
             Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => NULL, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
             Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => NULL, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
         }
         // Copy Logo
         if (!copy(dirname(__FILE__) . '/carrier.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg')) {
             return false;
         }
         // Return ID Carrier
         return (int) $carrier->id;
     }
     return false;
 }
Esempio n. 8
0
 protected function addRanges($carrier)
 {
     $range_price = new RangePrice();
     $range_price->id_carrier = $carrier->id;
     $range_price->delimiter1 = '0';
     $range_price->delimiter2 = '10000';
     $range_price->add();
     $range_weight = new RangeWeight();
     $range_weight->id_carrier = $carrier->id;
     $range_weight->delimiter1 = '0';
     $range_weight->delimiter2 = '10000';
     $range_weight->add();
 }
 public static function installExternalCarrier($config)
 {
     $carrier = new Carrier();
     $carrier->hydrate($config);
     $carrier->name = $config['name'];
     $carrier->id_zone = $config['id_zone'];
     $carrier->active = $config['active'];
     $carrier->deleted = $config['deleted'];
     $carrier->delay = $config['delay'];
     $carrier->shipping_handling = $config['shipping_handling'];
     $carrier->range_behavior = $config['range_behavior'];
     $carrier->is_module = $config['is_module'];
     $carrier->shipping_external = $config['shipping_external'];
     $carrier->external_module_name = $config['external_module_name'];
     $carrier->need_range = $config['need_range'];
     $carrier->setTaxRulesGroup($config['id_tax_rules_group'], true);
     $languages = Language::getLanguages(true);
     foreach ($languages as $language) {
         if ($language['iso_code'] == 'lv') {
             $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
         }
         if ($language['iso_code'] == 'lt') {
             $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
         }
         if ($language['iso_code'] == Language::getIsoById(Configuration::get('PS_LANG_DEFAULT'))) {
             $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
         }
     }
     if ($carrier->add()) {
         $groups = Group::getGroups(true);
         foreach ($groups as $group) {
             Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
         }
         // $range_price = new RangePrice();
         // $range_price->id_carrier = $carrier->id;
         // $range_price->delimiter1 = '0';
         // $range_price->delimiter2 = '10000';
         // $range_price->add();
         // $range_weight = new RangeWeight();
         // $range_weight->id_carrier = $carrier->id;
         // $range_weight->delimiter1 = '0';
         // $range_weight->delimiter2 = '10000';
         // $range_weight->add();
         // Add weight ranges to carrier
         $rangePrices = array();
         foreach ($config['ranges'] as $range) {
             $rangeWeight = new RangeWeight();
             $rangeWeight->hydrate(array('id_carrier' => $carrier->id, 'delimiter1' => (double) $range['delimiter1'], 'delimiter2' => (double) $range['delimiter2']));
             $rangeWeight->add();
             // Save range ID and price and set it after the Zones have been added
             $rangePrices[] = array('id_range_weight' => $rangeWeight->id, 'price' => $range['price']);
         }
         // Update prices in delivery table for each range (need IDs)
         foreach ($rangePrices as $rangePrice) {
             $data = array('price' => $rangePrice['price']);
             $where = 'id_range_weight = ' . $rangePrice['id_range_weight'];
             Db::getInstance()->update('delivery', $data, $where);
         }
         // Add Europe for EVERY carrier range
         // Automatically creates rows in delivery table, price is 0
         $id_zone_europe = Zone::getIdByName('Europe');
         $carrier->addZone($id_zone_europe ? $id_zone_europe : 1);
         // Copy Logo
         if (!Tools::copy(dirname(__FILE__) . '/logo.png', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.png')) {
             return false;
         }
         DpdCarrierOptions::setCarrierOptions((int) $carrier->id, (int) $carrier->id, $config['type']);
         // Return ID Carrier
         return (int) $carrier->id;
     }
     return false;
 }
 /**
  * create shopgate carrier
  */
 public function createShopgateCarrier()
 {
     /** @var CarrierCore $carrier */
     $carrier = new Carrier();
     $carrier->name = self::MODULE_CARRIER_NAME;
     $carrier->active = true;
     $carrier->deleted = true;
     $carrier->shipping_handling = false;
     $carrier->range_behavior = true;
     $carrier->delay[Configuration::get('PS_LANG_DEFAULT')] = self::MODULE_CARRIER_NAME;
     $carrier->shipping_external = true;
     $carrier->is_module = true;
     $carrier->external_module_name = self::DEFAULT_EXTERNAL_MODULE_CARRIER_NAME;
     $carrier->need_range = true;
     foreach (Language::getLanguages() as $language) {
         $carrier->delay[$language['id_lang']] = 'Depends on Shopgate selected carrier';
     }
     if ($carrier->add()) {
         $groups = Group::getGroups(true);
         foreach ($groups as $group) {
             Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
         }
         /** @var RangePriceCore $rangePrice */
         $rangePrice = new RangePrice();
         $rangePrice->id_carrier = $carrier->id;
         $rangePrice->delimiter1 = '0';
         $rangePrice->delimiter2 = '1000000';
         $rangePrice->add();
         /** @var RangeWeightCore $rangeWeight */
         $rangeWeight = new RangeWeight();
         $rangeWeight->id_carrier = $carrier->id;
         $rangeWeight->delimiter1 = '0';
         $rangeWeight->delimiter2 = '1000000';
         $rangeWeight->add();
         $zones = Zone::getZones(true);
         foreach ($zones as $zone) {
             /** @var $zone ZoneCore */
             Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']), 'INSERT');
             Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => null, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
             Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => null, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
         }
     }
     Configuration::updateValue('SG_CARRIER_ID', $carrier->id);
 }
Esempio n. 11
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;
         }
     }
 }
Esempio n. 12
0
 public static function createChronopostCarriers($carrierConfig)
 {
     if (Shop::isFeatureActive()) {
         Shop::setContext(Shop::CONTEXT_ALL);
     }
     // Create carriers from config
     foreach ($carrierConfig as $carrierName => $config) {
         $carrier = new Carrier();
         $carrier->name = $config['name'];
         $carrier->id_tax_rules_group = $config['id_tax_rules_group'];
         $carrier->url = $config['url'];
         $carrier->active = $config['active'];
         $carrier->deleted = $config['deleted'];
         $carrier->delay = $config['delay'];
         $carrier->shipping_handling = $config['shipping_handling'];
         $carrier->range_behavior = $config['range_behavior'];
         $carrier->is_module = $config['is_module'];
         $carrier->shipping_external = $config['shipping_external'];
         $carrier->external_module_name = $config['external_module_name'];
         $carrier->need_range = $config['need_range'];
         $languages = Language::getLanguages(true);
         foreach ($languages as $language) {
             if (array_key_exists($language['iso_code'], $config['delay'])) {
                 $carrier->delay[$language['id_lang']] = $config['delay'][$language['iso_code']];
             } else {
                 $carrier->delay[$language['id_lang']] = $config['delay']['fr'];
             }
         }
         if ($carrier->add()) {
             Configuration::updateValue($config['configuration_item'], (int) $carrier->id);
             // ASSIGN GROUPS
             $groups = Group::getgroups(true);
             foreach ($groups as $group) {
                 Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'carrier_group VALUE (\'' . (int) $carrier->id . '\',\'' . (int) $group['id_group'] . '\')');
             }
             // ASSIGN ZONES
             $zones = Zone::getZones();
             foreach ($zones as $zone) {
                 $carrier->addZone($zone['id_zone']);
             }
             // RANGE PRICE
             $rp = new RangePrice();
             $rp->id_carrier = $carrier->id;
             $rp->delimiter1 = 0;
             $rp->delimiter2 = 100000;
             $rp->add();
             $fp = fopen(_MYDIR_ . '/csv/' . $carrierName . '.csv', 'r');
             // insert prices per weight range
             while ($line = fgetcsv($fp)) {
                 $rangeWeight = new RangeWeight();
                 $rangeWeight->id_carrier = $carrier->id;
                 $rangeWeight->delimiter1 = $line[0];
                 $rangeWeight->delimiter2 = $line[1];
                 $rangeWeight->price_to_affect = $line[2];
                 $rangeWeight->add();
             }
             //copy logo
             if (!copy(dirname(__FILE__) . '/views/img/' . $config['logo_filename'] . '.jpg', _PS_SHIP_IMG_DIR_ . '/' . $carrier->id . '.jpg')) {
                 return false;
             }
         }
     }
     return true;
 }
 private function installCarrier($is_COD = 0)
 {
     $carrier = new Carrier();
     $carrier->name = 'Почта России';
     //Проверяем какого перевозчика создаем
     if ($is_COD) {
         $carrier->name .= ' (наложенный платеж)';
     }
     // @deprecated since 1.5.0
     //$carrier->id_tax_rules_group' = 0;
     // TODO: проверить -- это точно обязательно?
     //Способ доставки активен
     $carrier->active = true;
     // TODO: проверить -- это точно обязательно?
     //Не удален. При удалении способа доставки он не удаляется из
     //базы данных, а только помечается как удаленный
     $carrier->deleted = 0;
     // TODO: это может быть интересным -- стоимость упаковки и пр.
     //Доставка и обработка
     $carrier->shipping_handling = false;
     // Что делать, если Out Of Range. 0 -- считать, 1 -- не считать
     // Мы, ведь, сами определяем можем или не можем, настроек range
     // никаких не будет.
     //Исключения: применить наибольшую цену доставки
     $carrier->range_behavior = 0;
     // Тут зависимости от языка
     // TODO: по идее это время доставки, но для разных пунктов
     // оно может сильно отличасться. Посмотреть, можно-ли это как-то
     // динамически править
     $delay_str_list = array('ru' => 'Срок доставки зависит от удаленности', 'default' => 'Delivery time depens on distance');
     $languages = Language::getLanguages(false);
     foreach ($languages as $language) {
         //Проверяем есть ли текущий язык в списке предусмотренных языков
         if (!isset($delay_str_list[$language['iso_code']])) {
             //Если нет, то ставим фразу по умолчанию
             $carrier->delay[(int) $language['id_lang']] = $delay_str_list['default'];
         } else {
             //Иначе берем фразу из конфига
             $carrier->delay[(int) $language['id_lang']] = $delay_str_list[$language['iso_code']];
         }
     }
     // Этот перевозчик связан с модулем
     //Расчет производится из внешнего источника
     $carrier->shipping_external = true;
     //Признак того, что способ доставки принадлежит модулю
     $carrier->is_module = true;
     //Имя модуля, которому принадлежит способ доставки
     $carrier->external_module_name = 'russianpostcarrier';
     // Если я правильно понял, то заданные лимиты
     // нам не уперлись, у нас внутре свои лимиты задаются
     // UPD: Но оно в этом случае, похоже, не работает. Придется задавать лимиты
     $carrier->need_range = true;
     // TODO: еще полезные переменные, мы ими потом займемся,
     // надо понять, как оно считает
     // $carrier->max_width => 1;
     // $carrier->max_height => 1;
     // $carrier->max_depth => 1;
     // $carrier->max_weight => 1; // вот это вот особенно!
     if ($carrier->add()) {
         // Добавим нашего несчастного перевозчика всем группам
         $groups = Group::getGroups(true);
         foreach ($groups as $group) {
             Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
         }
         // Без указания пределов по весу и стоимости оно не заработало
         // Сделаем, хотя оно нам не надо
         $rangePrice = new RangePrice();
         $rangePrice->id_carrier = $carrier->id;
         $rangePrice->delimiter1 = '0';
         $rangePrice->delimiter2 = '100500';
         $rangePrice->add();
         $rangeWeight = new RangeWeight();
         $rangeWeight->id_carrier = $carrier->id;
         $rangeWeight->delimiter1 = '0';
         $rangeWeight->delimiter2 = '100500';
         //Предельные тяжеловесные посылки 20 кг
         $rangeWeight->add();
         $zones = Zone::getZones(true);
         foreach ($zones as $z) {
             Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $z['id_zone']), 'INSERT');
             Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => NULL, 'id_zone' => (int) $z['id_zone'], 'price' => '0'), 'INSERT');
             Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => NULL, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $z['id_zone'], 'price' => '0'), 'INSERT');
         }
         copy(dirname(__FILE__) . '/carrier.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg');
         return $carrier->id;
     }
     return false;
 }
Esempio n. 14
0
 public static function createSoColissimoCarrier($config)
 {
     $carrier = new Carrier();
     $carrier->name = $config['name'];
     $carrier->id_tax_rules_group = $config['id_tax_rules_group'];
     $carrier->id_zone = $config['id_zone'];
     $carrier->url = $config['url'];
     $carrier->active = $config['active'];
     $carrier->deleted = $config['deleted'];
     $carrier->delay = $config['delay'];
     $carrier->shipping_handling = $config['shipping_handling'];
     $carrier->range_behavior = $config['range_behavior'];
     $carrier->is_module = $config['is_module'];
     $carrier->shipping_external = $config['shipping_external'];
     $carrier->external_module_name = $config['external_module_name'];
     $carrier->need_range = $config['need_range'];
     $languages = Language::getLanguages(true);
     foreach ($languages as $language) {
         if ($language['iso_code'] == 'fr') {
             $carrier->delay[$language['id_lang']] = $config['delay'][$language['iso_code']];
         }
         if ($language['iso_code'] == 'en') {
             $carrier->delay[$language['id_lang']] = $config['delay'][$language['iso_code']];
         }
     }
     if ($carrier->add()) {
         Configuration::updateValue('SOCOLISSIMO_CARRIER_ID', (int) $carrier->id);
         $groups = Group::getgroups(true);
         foreach ($groups as $group) {
             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'carrier_group VALUE (\'' . (int) $carrier->id . '\',\'' . (int) $group['id_group'] . '\')');
         }
         $rangePrice = new RangePrice();
         $rangePrice->id_carrier = $carrier->id;
         $rangePrice->delimiter1 = '0';
         $rangePrice->delimiter2 = '10000';
         $rangePrice->add();
         $rangeWeight = new RangeWeight();
         $rangeWeight->id_carrier = $carrier->id;
         $rangeWeight->delimiter1 = '0';
         $rangeWeight->delimiter2 = '10000';
         $rangeWeight->add();
         $zones = Zone::getZones(true);
         foreach ($zones as $zone) {
             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'carrier_zone VALUE (\'' . (int) $carrier->id . '\',\'' . (int) $zone['id_zone'] . '\')');
             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'delivery VALUE (\'\',\'' . (int) $carrier->id . '\',\'' . (int) $rangePrice->id . '\',NULL,\'' . (int) $zone['id_zone'] . '\',\'1\')');
             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'delivery VALUE (\'\',\'' . (int) $carrier->id . '\',NULL,\'' . (int) $rangeWeight->id . '\',\'' . (int) $zone['id_zone'] . '\',\'1\')');
         }
         //copy logo
         if (!copy(dirname(__FILE__) . '/socolissimo.jpg', _PS_SHIP_IMG_DIR_ . '/' . $carrier->id . '.jpg')) {
             return false;
         }
         return true;
     } else {
         return false;
     }
 }
Esempio n. 15
0
 public function installCarriers()
 {
     $id_lang_default = Language::getIsoById(Configuration::get('PS_LANG_DEFAULT'));
     $carriers_list = array('MYMOD_CA_CLDE' => 'Classic delivery', 'MYMOD_CA_REPO' => 'Relay Point');
     foreach ($carriers_list as $carrier_key => $carrier_name) {
         if (Configuration::get($carrier_key) < 1) {
             // Create new carrier
             $carrier = new Carrier();
             $carrier->name = $carrier_name;
             $carrier->id_tax_rules_group = 0;
             $carrier->active = 1;
             $carrier->deleted = 0;
             foreach (Language::getLanguages(true) as $language) {
                 $carrier->delay[(int) $language['id_lang']] = 'Delay ' . $carrier_name;
             }
             $carrier->shipping_handling = false;
             $carrier->range_behavior = 0;
             $carrier->is_module = true;
             $carrier->shipping_external = true;
             $carrier->external_module_name = $this->name;
             $carrier->need_range = true;
             if (!$carrier->add()) {
                 return false;
             }
             // Associate carrier to all groups
             $groups = Group::getGroups(true);
             foreach ($groups as $group) {
                 Db::getInstance()->insert('carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']));
             }
             // Create price range
             $rangePrice = new RangePrice();
             $rangePrice->id_carrier = $carrier->id;
             $rangePrice->delimiter1 = '0';
             $rangePrice->delimiter2 = '10000';
             $rangePrice->add();
             // Create weight range
             $rangeWeight = new RangeWeight();
             $rangeWeight->id_carrier = $carrier->id;
             $rangeWeight->delimiter1 = '0';
             $rangeWeight->delimiter2 = '10000';
             $rangeWeight->add();
             // Associate carrier to all zones
             $zones = Zone::getZones(true);
             foreach ($zones as $zone) {
                 Db::getInstance()->insert('carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']));
                 Db::getInstance()->insert('delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => NULL, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'));
                 Db::getInstance()->insert('delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => NULL, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'));
             }
             // Copy the carrier logo
             copy(dirname(__FILE__) . '/views/img/' . $carrier_key . '.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg');
             // Save the carrier ID in the Configuration table
             Configuration::updateValue($carrier_key, $carrier->id);
         }
     }
     return true;
 }
 public static function createSoColissimoCarrierSeller($config)
 {
     $carrier = new Carrier();
     $carrier->name = $config['name'] . ' - Commerce de proximité';
     $carrier->id_tax_rules_group = $config['id_tax_rules_group'];
     $carrier->id_zone = $config['id_zone'];
     $carrier->url = $config['url'];
     $carrier->active = 0;
     $carrier->deleted = $config['deleted'];
     $carrier->delay = $config['delay'];
     $carrier->shipping_handling = $config['shipping_handling'];
     $carrier->range_behavior = $config['range_behavior'];
     $carrier->is_module = $config['is_module'];
     $carrier->shipping_external = $config['shipping_external'];
     $carrier->external_module_name = $config['external_module_name'];
     $carrier->need_range = $config['need_range'];
     $languages = Language::getLanguages(true);
     foreach ($languages as $language) {
         if ($language['iso_code'] == 'fr') {
             $carrier->delay[$language['id_lang']] = $config['delay_seller'][$language['iso_code']];
         }
         if ($language['iso_code'] == 'en') {
             $carrier->delay[$language['id_lang']] = $config['delay_seller'][$language['iso_code']];
         }
     }
     if ($carrier->add()) {
         if (!version_compare(_PS_VERSION_, '1.5', '<')) {
             if (Shop::isFeatureActive()) {
                 Shop::setContext(Shop::CONTEXT_ALL);
             }
         }
         Configuration::updateValue('SOCOLISSIMO_CARRIER_ID_SELLER', (int) $carrier->id);
         $groups = Group::getgroups(true);
         foreach ($groups as $group) {
             Db::getInstance()->execute('INSERT INTO ' . _DB_PREFIX_ . 'carrier_group VALUE (\'' . (int) $carrier->id . '\',\'' . (int) $group['id_group'] . '\')');
         }
         $range_price = new RangePrice();
         $range_price->id_carrier = $carrier->id;
         $range_price->delimiter1 = '0';
         $range_price->delimiter2 = '10000';
         $range_price->add();
         $range_weight = new RangeWeight();
         $range_weight->id_carrier = $carrier->id;
         $range_weight->delimiter1 = '0';
         $range_weight->delimiter2 = '10000';
         $range_weight->add();
         //copy logo
         if (!copy(dirname(__FILE__) . '/img/socolissimo.jpg', _PS_SHIP_IMG_DIR_ . '/' . $carrier->id . '.jpg')) {
             return false;
         }
         return true;
     }
     return false;
 }
Esempio n. 17
0
 public function cAddCarrierPost()
 {
     $db = Db::getInstance();
     if (!Tools::getIsset('packetery_add_carrier') || !Tools::getValue('packetery_add_carrier')) {
         return;
     }
     $carrier = new Carrier();
     $carrier->name = Tools::getValue('packetery_carrier_name');
     $carrier->active = true;
     $carrier->shipping_method = defined('Carrier::SHIPPING_METHOD_WEIGHT') ? Carrier::SHIPPING_METHOD_WEIGHT : 1;
     $carrier->deleted = 0;
     $carrier->range_behavior = true;
     // true disables this carrier if outside weight range
     $carrier->is_module = false;
     $carrier->external_module_name = "packetery";
     $carrier->need_range = true;
     foreach (Language::getLanguages(true) as $language) {
         if (Tools::getIsset('delay_' . $language['id_lang']) && Tools::getValue('delay_' . $language['id_lang'])) {
             $carrier->delay[$language['id_lang']] = Tools::getValue('delay_' . $language['id_lang']);
         }
     }
     if (!$carrier->add()) {
         return false;
     }
     $country = "";
     $countries = Tools::getValue('packetery_carrier_country');
     foreach ($countries as $key => $countryCode) {
         $country .= $countryCode;
         if ($key != count($countries) - 1) {
             $country .= ',';
         }
     }
     $db->execute('insert into `' . _DB_PREFIX_ . 'packetery_carrier` set id_carrier=' . (int) $carrier->id . ', country="' . pSQL($country ? $country : 'cz,sk') . '", list_type=' . (int) Tools::getValue('packetery_carrier_list_type') . ', is_cod=' . (Tools::getIsset('packetery_carrier_is_cod') ? (int) Tools::getValue('packetery_carrier_is_cod') : 0));
     foreach (Group::getGroups(true) as $group) {
         $db->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
     }
     $rangeWeight = new RangeWeight();
     $rangeWeight->id_carrier = $carrier->id;
     $rangeWeight->delimiter1 = '0';
     $rangeWeight->delimiter2 = '5';
     $rangeWeight->add();
     $rangePrice = new RangePrice();
     $rangePrice->id_carrier = $carrier->id;
     $rangePrice->delimiter1 = '0';
     $rangePrice->delimiter2 = '1000000';
     $rangePrice->add();
     $zones = Zone::getZones(true);
     foreach ($zones as $zone) {
         $db->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']), 'INSERT');
         $db->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => null, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
         $db->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => null, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
     }
     if (Tools::getIsset('packetery_carrier_logo') && Tools::strlen(Tools::getValue('packetery_carrier_logo')) == 2) {
         copy(dirname(__FILE__) . '/logo-' . Tools::getValue('packetery_carrier_logo') . '.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg');
     }
 }
Esempio n. 18
0
 private static function createDefaultRanges()
 {
     $ids_ranges_seur = array();
     $ids_ranges_pos = array();
     $ids_ranges_canarias_48 = array();
     $ids_ranges_canarias_m = array();
     if (self::$carrier_seur->id != self::$carrier_pos->id && self::$carrier_seur->id != self::$carrier_canarias_48->id && self::$carrier_seur->id != self::$carrier_canarias_m->id) {
         foreach (self::$ranges as $from => $to) {
             $range_seur = new RangeWeight();
             $range_seur->id_carrier = self::$carrier_seur->id;
             $range_seur->delimiter1 = $from;
             $range_seur->delimiter2 = $to;
             $range_seur->save();
             $ids_ranges_seur[$from] = $range_seur->id;
         }
     }
     if (self::$carrier_pos->id != self::$carrier_seur->id && self::$carrier_pos->id != self::$carrier_canarias_48->id && self::$carrier_pos->id != self::$carrier_canarias_m->id) {
         foreach (self::$ranges as $from => $to) {
             $range_pos = new RangeWeight();
             $range_pos->id_carrier = self::$carrier_pos->id;
             $range_pos->delimiter1 = $from;
             $range_pos->delimiter2 = $to;
             $range_pos->save();
             $ids_ranges_pos[$from] = $range_pos->id;
         }
     }
     if (self::$carrier_canarias_48->id != self::$carrier_seur->id && self::$carrier_canarias_48->id != self::$carrier_pos->id && self::$carrier_canarias_48->id != self::$carrier_canarias_m->id) {
         foreach (self::$ranges as $from => $to) {
             $range_canarias_48 = new RangeWeight();
             $range_canarias_48->id_carrier = self::$carrier_canarias_48->id;
             $range_canarias_48->delimiter1 = $from;
             $range_canarias_48->delimiter2 = $to;
             $range_canarias_48->save();
             $ids_ranges_canarias_48[$from] = $range_canarias_48->id;
         }
     }
     if (self::$carrier_canarias_m->id != self::$carrier_seur->id && self::$carrier_canarias_m->id != self::$carrier_pos->id && self::$carrier_canarias_m->id != self::$carrier_canarias_48->id) {
         foreach (self::$ranges as $from => $to) {
             $range_canarias_m = new RangeWeight();
             $range_canarias_m->id_carrier = self::$carrier_canarias_m->id;
             $range_canarias_m->delimiter1 = $from;
             $range_canarias_m->delimiter2 = $to;
             $range_canarias_m->save();
             $ids_ranges_canarias_m[$from] = $range_canarias_m->id;
         }
     }
     $range_table_seur = self::$carrier_seur->getRangeTable();
     $range_table_pos = self::$carrier_pos->getRangeTable();
     $range_table_48 = self::$carrier_canarias_48->getRangeTable();
     $range_table_m = self::$carrier_canarias_m->getRangeTable();
     self::$carrier_seur->deleteDeliveryPrice($range_table_seur);
     self::$carrier_pos->deleteDeliveryPrice($range_table_pos);
     self::$carrier_canarias_48->deleteDeliveryPrice($range_table_48);
     self::$carrier_canarias_m->deleteDeliveryPrice($range_table_m);
     if (version_compare(_PS_VERSION_, '1.5', '>=')) {
         $priceListSeur = array();
         $priceListPos = array();
         $priceListC_48 = array();
         $priceListSeurC_M = array();
         foreach (self::$ranges as $from => $to) {
             /*
              * carrier_seur
              */
             $priceListSeur[] = array('id_range_price' => 'NULL', 'id_range_weight' => (int) $ids_ranges_seur[$from], 'id_carrier' => (int) self::$carrier_seur->id, 'id_zone' => (int) self::$provincia->id, 'price' => 0);
             $priceListSeur[] = array('id_range_price' => 'NULL', 'id_range_weight' => (int) $ids_ranges_seur[$from], 'id_carrier' => (int) self::$carrier_seur->id, 'id_zone' => (int) self::$peninsula->id, 'price' => 0);
             $priceListSeur[] = array('id_range_price' => 'NULL', 'id_range_weight' => (int) $ids_ranges_seur[$from], 'id_carrier' => (int) self::$carrier_seur->id, 'id_zone' => (int) self::$portugal->id, 'price' => 0);
             $priceListSeur[] = array('id_range_price' => 'NULL', 'id_range_weight' => (int) $ids_ranges_seur[$from], 'id_carrier' => (int) self::$carrier_seur->id, 'id_zone' => (int) self::$baleares->id, 'price' => 0);
             $priceListSeur[] = array('id_range_price' => 'NULL', 'id_range_weight' => (int) $ids_ranges_seur[$from], 'id_carrier' => (int) self::$carrier_seur->id, 'id_zone' => (int) self::$ceuta_melilla->id, 'price' => 0);
             /*
              * carrier_pos
              */
             if (self::$carrier_seur->id != self::$carrier_pos->id) {
                 $priceListPos[] = array('id_range_price' => 'NULL', 'id_range_weight' => (int) $ids_ranges_seur[$from], 'id_carrier' => (int) self::$carrier_pos->id, 'id_zone' => (int) self::$provincia->id, 'price' => 0);
                 $priceListPos[] = array('id_range_price' => 'NULL', 'id_range_weight' => (int) $ids_ranges_seur[$from], 'id_carrier' => (int) self::$carrier_pos->id, 'id_zone' => (int) self::$peninsula->id, 'price' => 0);
                 $priceListPos[] = array('id_range_price' => 'NULL', 'id_range_weight' => (int) $ids_ranges_seur[$from], 'id_carrier' => (int) self::$carrier_pos->id, 'id_zone' => (int) self::$portugal->id, 'price' => 0);
                 $priceListPos[] = array('id_range_price' => 'NULL', 'id_range_weight' => (int) $ids_ranges_seur[$from], 'id_carrier' => (int) self::$carrier_pos->id, 'id_zone' => (int) self::$baleares->id, 'price' => 0);
                 $priceListPos[] = array('id_range_price' => 'NULL', 'id_range_weight' => (int) $ids_ranges_seur[$from], 'id_carrier' => (int) self::$carrier_pos->id, 'id_zone' => (int) self::$ceuta_melilla->id, 'price' => 0);
             }
             /*
              * carrier_canarias_48
              */
             $priceListC_48[] = array('id_range_price' => 'NULL', 'id_range_weight' => (int) $ids_ranges_seur[$from], 'id_carrier' => (int) self::$carrier_canarias_48->id, 'id_zone' => (int) self::$canarias->id, 'price' => 0);
             /*
              * carrier_canarias_m
              */
             if (self::$carrier_canarias_48->id != self::$carrier_canarias_m->id) {
                 $priceListSeurC_M[] = array('id_range_price' => 'NULL', 'id_range_weight' => (int) $ids_ranges_seur[$from], 'id_carrier' => (int) self::$carrier_canarias_m->id, 'id_zone' => (int) self::$canarias->id, 'price' => 0);
             }
         }
         self::$carrier_seur->addDeliveryPrice($priceListSeur);
         if (self::$carrier_seur->id != self::$carrier_pos->id) {
             self::$carrier_pos->addDeliveryPrice($priceListPos);
         }
         self::$carrier_canarias_48->addDeliveryPrice($priceListC_48);
         if (self::$carrier_canarias_48->id != self::$carrier_canarias_m->id) {
             self::$carrier_canarias_m->addDeliveryPrice($priceListSeurC_M);
         }
     } else {
         foreach (self::$ranges as $from => $to) {
             /*
              * self::$carrier_seur
              */
             self::$carrier_seur->addDeliveryPrice('(NULL, ' . (int) $ids_ranges_seur[$from] . ', ' . (int) self::$carrier_seur->id . ', ' . (int) self::$provincia->id . ', 0)');
             self::$carrier_seur->addDeliveryPrice('(NULL, ' . (int) $ids_ranges_seur[$from] . ', ' . (int) self::$carrier_seur->id . ', ' . (int) self::$peninsula->id . ', 0)');
             self::$carrier_seur->addDeliveryPrice('(NULL, ' . (int) $ids_ranges_seur[$from] . ', ' . (int) self::$carrier_seur->id . ', ' . (int) self::$portugal->id . ', 0)');
             self::$carrier_seur->addDeliveryPrice('(NULL, ' . (int) $ids_ranges_seur[$from] . ', ' . (int) self::$carrier_seur->id . ', ' . (int) self::$baleares->id . ', 0)');
             self::$carrier_seur->addDeliveryPrice('(NULL, ' . (int) $ids_ranges_seur[$from] . ', ' . (int) self::$carrier_seur->id . ', ' . (int) self::$ceuta_melilla->id . ', 0)');
             /*
              * self::$carrier_pos
              */
             if (self::$carrier_seur->id != self::$carrier_pos->id) {
                 self::$carrier_pos->addDeliveryPrice('(NULL, ' . (int) $ids_ranges_pos[$from] . ', ' . (int) self::$carrier_pos->id . ', ' . (int) self::$provincia->id . ', 0)');
                 self::$carrier_pos->addDeliveryPrice('(NULL, ' . (int) $ids_ranges_pos[$from] . ', ' . (int) self::$carrier_pos->id . ', ' . (int) self::$peninsula->id . ', 0)');
                 self::$carrier_pos->addDeliveryPrice('(NULL, ' . (int) $ids_ranges_pos[$from] . ', ' . (int) self::$carrier_pos->id . ', ' . (int) self::$portugal->id . ', 0)');
                 self::$carrier_pos->addDeliveryPrice('(NULL, ' . (int) $ids_ranges_pos[$from] . ', ' . (int) self::$carrier_pos->id . ', ' . (int) self::$baleares->id . ', 0)');
                 self::$carrier_pos->addDeliveryPrice('(NULL, ' . (int) $ids_ranges_pos[$from] . ', ' . (int) self::$carrier_pos->id . ', ' . (int) self::$ceuta_melilla->id . ', 0)');
             }
             /*
              * self::$carrier_canarias_48
              */
             self::$carrier_canarias_48->addDeliveryPrice('(NULL, ' . (int) $ids_ranges_canarias_48[$from] . ', ' . (int) self::$carrier_canarias_48->id . ', ' . (int) self::$canarias->id . ', 0)');
             /*
              * self::$carrier_canarias_m
              */
             if (self::$carrier_canarias_48->id != self::$carrier_canarias_m->id) {
                 self::$carrier_canarias_m->addDeliveryPrice('(NULL, ' . (int) $ids_ranges_canarias_m[$from] . ', ' . (int) self::$carrier_canarias_m->id . ', ' . (int) self::$canarias->id . ', 0)');
             }
         }
     }
     return true;
 }
 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;
 }
Esempio n. 20
0
 /**
  * 
  * @param type $config
  * @return boolean
  */
 public function installExternalCarrier($config)
 {
     $check = Db::getInstance()->executeS("SELECT id_carrier FROM " . _DB_PREFIX_ . "carrier WHERE name = '" . $config['name'] . "' ");
     if (is_array($check) && !empty($check)) {
         return Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier', array('deleted' => 0), 'UPDATE', ' name = "' . $config['name'] . '" ');
     }
     $carrier = new Carrier();
     $carrier->name = $config['name'];
     $carrier->url = $config['url'];
     $carrier->id_tax_rules_group = $config['id_tax_rules_group'];
     $carrier->id_zone = $config['id_zone'];
     $carrier->active = $config['active'];
     $carrier->deleted = $config['deleted'];
     $carrier->delay = $config['delay'];
     $carrier->shipping_handling = $config['shipping_handling'];
     $carrier->range_behavior = $config['range_behavior'];
     $carrier->is_module = $config['is_module'];
     $carrier->shipping_external = $config['shipping_external'];
     $carrier->external_module_name = $config['external_module_name'];
     $carrier->need_range = $config['need_range'];
     $languages = Language::getLanguages(true);
     foreach ($languages as $language) {
         $carrier->delay[(int) $language['id_lang']] = $config['delay']['br'];
     }
     if ($carrier->add()) {
         $groups = Group::getGroups(true);
         foreach ($groups as $group) {
             Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
         }
         $rangePrice = new RangePrice();
         $rangePrice->id_carrier = $carrier->id;
         $rangePrice->delimiter1 = '0';
         $rangePrice->delimiter2 = '0';
         $rangePrice->add();
         $rangeWeight = new RangeWeight();
         $rangeWeight->id_carrier = $carrier->id;
         $rangeWeight->delimiter1 = '0';
         $rangeWeight->delimiter2 = '30';
         $rangeWeight->add();
         $zones = Zone::getZones(true);
         foreach ($zones as $zone) {
             Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']), 'INSERT');
             Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => NULL, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
             Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => NULL, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'), 'INSERT');
         }
         Configuration::updateValue("PS_CORREIOS_CARRIER_{$carrier->id}", $config['cod_servico']);
         // Copy Logo
         if (!copy(dirname(__FILE__) . '/logos/' . $config['cod_servico'] . '.png', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg')) {
             return false;
         }
         // Return ID Carrier
         return (int) $carrier->id;
     }
     return false;
 }
Esempio n. 21
0
 private function createCarrier($config, $product_id, $name, $debug_mode = false, &$debug_info = array())
 {
     $carrier = new Carrier();
     if ($debug_mode) {
         array_push($debug_info, "Trying to create carrier " . $product_id . " with name " . $name);
     }
     $carrier->name = $name;
     $carrier->id_zone = $config['id_zone'];
     $carrier->url = $config['url'];
     $carrier->active = $config['active'];
     $carrier->deleted = $config['deleted'];
     $carrier->shipping_handling = $config['shipping_handling'];
     $carrier->range_behaviour = $config['range_behaviour'];
     $carrier->is_module = $config['is_module'];
     $carrier->shipping_external = $config['shipping_external'];
     $carrier->external_module_name = $config['external_module_name'];
     $carrier->need_range = $config['need_range'];
     $languages = Language::getLanguages(true);
     foreach ($languages as $language) {
         if ($language['iso_code'] == 'en') {
             $carrier->delay[$language['id_lang']] = $config['delay'][$language['iso_code']];
         }
         if ($language['iso_code'] == 'no') {
             $carrier->delay[$language['id_lang']] = $config['delay'][$language['iso_code']];
         }
     }
     if ($debug_mode) {
         array_push($debug_info, "Adding carrier");
     }
     if ($carrier->add()) {
         if ($debug_mode) {
             array_push($debug_info, "Carrier added, setting up associations");
         }
         $carriers_str = Configuration::get('FRAKTGUIDE_CREATED_CARRIER_IDS');
         $carriers = $carriers_str ? explode(';', Configuration::get('FRAKTGUIDE_CREATED_CARRIER_IDS')) : array();
         $carriers[] = $carrier->id;
         Configuration::updateValue('FRAKTGUIDE_CREATED_CARRIER_IDS', implode(';', $carriers));
         $zones = Zone::getZones(true);
         foreach ($zones as $zone) {
             Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'carrier_zone VALUE(\'' . (int) $carrier->id . '\', \'' . (int) $zone['id_zone'] . '\')');
         }
         $groups = Group::getgroups(true);
         foreach ($groups as $group) {
             Db::getInstance()->execute('INSERT INTO ' . _DB_PREFIX_ . 'carrier_group VALUE (\'' . (int) $carrier->id . '\',\'' . (int) $group['id_group'] . '\')');
         }
         $rangePrice = new RangePrice();
         $rangePrice->id_carrier = $carrier->id;
         $rangePrice->delimiter1 = '0';
         $rangePrice->delimiter2 = '10000';
         $rangePrice->add();
         $rangeWeight = new RangeWeight();
         $rangeWeight->id_carrier = $carrier->id;
         $rangeWeight->delimiter1 = '0';
         $rangeWeight->delimiter2 = '10000';
         $rangeWeight->add();
         if ($debug_mode) {
             array_push($debug_info, "Trying to update product name table");
         }
         if (!Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'fraktguide_product_names`(`id_carrier`, `product_id`) VALUES(' . $carrier->id . ', \'' . $product_id . '\')')) {
             return false;
         }
         if (!copy(dirname(__FILE__) . '/img/logo.png', _PS_SHIP_IMG_DIR_ . '/' . $carrier->id . '.jpg')) {
             return false;
         }
         if ($debug_mode) {
             array_push($debug_info, "Success");
         }
         // Link to correct tax group (ps_carrier_tax_rules_group_shop aparently...)
         if (!Db::getInstance()->insert('carrier_tax_rules_group_shop', array('id_carrier' => $carrier->id, 'id_tax_rules_group' => Configuration::get('FRAKTGUIDE_ID_TAX_RULES_GROUP'), 'id_shop' => Context::getContext()->shop->id))) {
             return false;
         }
         return true;
     } else {
         Tools::dieOrLog("Error creating carrier " . $product_id);
         return false;
     }
 }
Esempio n. 22
0
 protected function createCarriers($eta)
 {
     // Sameday(ETA: 18:00)
     foreach ($this->carriers as $key => $value) {
         //Create new carrier
         $carrier = new Carrier();
         $carrier->name = $key;
         $carrier->active = true;
         $carrier->deleted = 0;
         $carrier->shipping_handling = false;
         $carrier->range_behavior = 0;
         $carrier->delay[Configuration::get('PS_LANG_DEFAULT')] = $eta;
         $carrier->shipping_external = true;
         $carrier->is_module = true;
         $carrier->external_module_name = $this->name;
         $carrier->need_range = true;
         $carrier->url = 'https://send24.com/track?@';
         if ($carrier->add()) {
             $groups = Group::getGroups(true);
             foreach ($groups as $group) {
                 Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT');
             }
             $rangePrice = new RangePrice();
             $rangePrice->id_carrier = $carrier->id;
             $rangePrice->delimiter1 = '0';
             $rangePrice->delimiter2 = '5';
             $rangePrice->add();
             $rangeWeight = new RangeWeight();
             $rangeWeight->id_carrier = $carrier->id;
             $rangeWeight->delimiter1 = '0';
             $rangeWeight->delimiter2 = '5';
             $rangeWeight->add();
             $zones = Zone::getZones(true);
             foreach ($zones as $z) {
                 if ($z['name'] == 'Europe') {
                     Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $z['id_zone']), 'INSERT');
                     Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => null, 'id_zone' => (int) $z['id_zone'], 'price' => '0'), 'INSERT');
                     Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => $carrier->id, 'id_range_price' => null, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $z['id_zone'], 'price' => '0'), 'INSERT');
                 }
             }
             copy(dirname(__FILE__) . '/views/img/send24.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg');
             Configuration::updateValue(self::PREFIX . $value, $carrier->id);
             Configuration::updateValue(self::PREFIX . $value . '_reference', $carrier->id);
         }
     }
     return true;
 }
 /**
  * @return bool
  * @throws Exception
  * @throws PrestaShopDatabaseException
  *
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since ${VERSION}
  */
 public function installCarriers()
 {
     foreach (\acsws\classes\ACSWSOptions::getInstance()->getValue('carrierList') as $carrier_key => $carrier_name) {
         $carrierId = Configuration::get($carrier_key);
         if ($carrierId < 1) {
             // Create carrier
             $carrier = new Carrier();
             $carrier->name = $carrier_name;
             $carrier->id_tax_rules_group = 0;
             $carrier->active = 1;
             $carrier->deleted = 0;
             foreach (Language::getLanguages(true) as $language) {
                 // TODO Carrier delay
                 $carrier->delay[(int) $language['id_lang']] = '' . $carrier_name;
             }
             $carrier->shipping_handling = 1;
             $carrier->range_behavior = 0;
             $carrier->is_module = 1;
             $carrier->shipping_external = 1;
             $carrier->external_module_name = $this->name;
             $carrier->need_range = 1;
             if (!$carrier->add()) {
                 return false;
             }
             // Associate carrier to all groups
             $groups = Group::getGroups(true);
             foreach ($groups as $group) {
                 Db::getInstance()->insert('carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']));
             }
             // Create price range
             $rangePrice = new RangePrice();
             $rangePrice->id_carrier = $carrier->id;
             $rangePrice->delimiter1 = '0';
             $rangePrice->delimiter2 = '10000';
             $rangePrice->add();
             // Create weight range
             $rangeWeight = new RangeWeight();
             $rangeWeight->id_carrier = $carrier->id;
             $rangeWeight->delimiter1 = '0';
             $rangeWeight->delimiter2 = '10000';
             $rangeWeight->add();
             // Associate carrier to all zones
             $zones = Zone::getZones(true);
             foreach ($zones as $zone) {
                 Db::getInstance()->insert('carrier_zone', array('id_carrier' => (int) $carrier->id, 'id_zone' => (int) $zone['id_zone']));
                 Db::getInstance()->insert('delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => (int) $rangePrice->id, 'id_range_weight' => null, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'));
                 Db::getInstance()->insert('delivery', array('id_carrier' => (int) $carrier->id, 'id_range_price' => null, 'id_range_weight' => (int) $rangeWeight->id, 'id_zone' => (int) $zone['id_zone'], 'price' => '0'));
             }
             copy(dirname(__FILE__) . '/img/logo.png', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg');
             Configuration::updateValue($carrier_key, $carrier->id);
         }
     }
     return true;
 }
Esempio n. 24
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;
    }
 protected function importCarriers()
 {
     $this->truncateTables(array('carrier', 'carrier_group', 'carrier_lang', 'carrier_shop', 'carrier_tax_rules_group_shop', 'carrier_zone', 'range_weight', 'range_price'));
     $handle = $this->openCsvFile('carriers.csv');
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) {
         $res = false;
         $fields = $this->filterFields('Carrier', $this->carriers_fields, $line);
         if (!isset($fields['id'])) {
             $carrier = new Carrier((int) $line[0]);
             $carrier->id = $line[0];
         } else {
             $carrier = new Carrier((int) $fields['id']);
         }
         foreach ($fields as $key => $field) {
             if ($key == 'delay') {
                 $carrier->{$key} = $this->multilFild($field);
             } else {
                 $carrier->{$key} = $field;
             }
         }
         if (!Tools::isEmpty($line[2])) {
             $values = array('id_carrier' => (int) $line[0], 'id_tax_rules_group' => (int) $line[2], 'id_shop' => (int) Context::getContext()->shop->id);
             Cache::clean('carrier_id_tax_rules_group_' . (int) $line[0] . '_' . (int) Context::getContext()->shop->id);
             Db::getInstance()->insert('carrier_tax_rules_group_shop', $values);
         }
         if (trim($line[22])) {
             $groups = explode(',', $line[22]);
             foreach ($groups as $group) {
                 $values = array('id_carrier' => (int) $line[0], 'id_group' => (int) $group);
                 Db::getInstance()->insert('carrier_group', $values);
             }
         }
         if (trim($line[23])) {
             $zones = explode(',', $line[23]);
             foreach ($zones as $zone) {
                 $values = array('id_carrier' => (int) $line[0], 'id_zone' => (int) $zone);
                 Db::getInstance()->insert('carrier_zone', $values);
             }
         }
         if (trim($line[24])) {
             $range_line = explode(',', $line[24]);
             foreach ($range_line as $range) {
                 $rp_res = false;
                 $values = explode('-', $range);
                 $rp = new RangePrice();
                 $rp->id_carrier = (int) $line[0];
                 $rp->delimiter1 = $values[0];
                 $rp->delimiter2 = $values[1];
                 if (!$rp_res) {
                     $rp->add();
                 }
             }
         }
         if (trim($line[25])) {
             $range_line = explode(',', $line[25]);
             foreach ($range_line as $range) {
                 $rw_res = false;
                 $values = explode('-', $range);
                 $rw = new RangeWeight();
                 $rw->id_carrier = (int) $line[0];
                 $rw->delimiter1 = $values[0];
                 $rw->delimiter2 = $values[1];
                 if (!$rw_res) {
                     $rw->add();
                 }
             }
         }
         $carrier->force_id = true;
         if (!$res) {
             $carrier->add();
         }
     }
     $this->closeCsvFile($handle);
     return true;
 }