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; }