/**
  * creates of a dejala carrier corresponding to $dejalaProduct
  */
 public static function createDejalaCarrier($dejalaConfig)
 {
     // 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 ((int) $countryID) {
         $id_zone = Country::getIdZone($countryID);
     }
     //TODO Will have to review this and apply proper code.
     $trg_id = 1;
     /*$vatRate = "19.6";
     		// MFR091130 - get or create the tax & attach it to our zone if needed
     		$id_tax = Tax::getTaxIdByRate((float)$vatRate);
     		$trg_id = 0;
     		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->id;
     
     			$trg = new TaxRulesGroup();
     			$trg->name = 'Dejala '.$tax->name[$defaultLanguage];
     			$trg->active = 1;
     			if ($trg->save())
     			{
     				$trg_id = $trg->id;
     
     				$tr = new TaxRule();
     				$tr->id_tax_rules_group = $trg_id;
     				$tr->id_country = (int) $countryID;
     				$tr->id_state = 0;
     				$tr->id_tax = (int)$tax->id;				
     				$tr->state_behavior = 0;
     				$tr->save();
     			}
     		}*/
     $carrier = new Carrier();
     $carrier->name = 'dejala';
     $carrier->id_tax_rules_group = (int) $trg_id;
     $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;
     $carrier->external_module_name = 'dejala';
     $carrier->shipping_external = 1;
     $carrier->need_range = 0;
     $languages = Language::getLanguages(true);
     foreach ($languages as $language) {
         $carrier->delay[$language['id_lang']] = 'Dejala';
     }
     $carrier->add();
     $carrier->addZone((int) $id_zone);
     /*$sql = 'INSERT INTO `'._DB_PREFIX_.'carrier_zone` (`id_carrier` , `id_zone`) VALUES ('.(int)($carrier->id).', ' . (int)($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 true;
 }
Exemple #2
0
 public static function install($carrier_type, $carrier_name)
 {
     $id_carrier = (int) Configuration::get($carrier_type);
     if (version_compare(_PS_VERSION_, '1.5', '<')) {
         $id_carrier = (int) DpdGroupCarrier::getIdCarrierByReference((int) $id_carrier);
         $carrier = new Carrier((int) $id_carrier);
     } else {
         $carrier = Carrier::getCarrierByReference($id_carrier);
     }
     if ($id_carrier && Validate::isLoadedObject($carrier)) {
         if (!$carrier->deleted) {
             return true;
         } else {
             $carrier->deleted = 0;
             return (bool) $carrier->save();
         }
     }
     $service = new DpdGroupService();
     $carrier = new Carrier();
     $carrier->name = $carrier_name;
     $carrier->active = 1;
     $carrier->is_free = 0;
     $carrier->shipping_handling = 1;
     $carrier->shipping_external = 1;
     $carrier->shipping_method = 1;
     $carrier->max_width = 0;
     $carrier->max_height = 0;
     $carrier->max_weight = 0;
     $carrier->grade = 0;
     $carrier->is_module = 1;
     $carrier->need_range = 1;
     $carrier->range_behavior = 1;
     $carrier->external_module_name = $service->module_instance->name;
     $carrier->url = _DPDGROUP_TRACKING_URL_;
     $delay = array();
     foreach (Language::getLanguages(false) as $language) {
         $delay[$language['id_lang']] = $carrier_name;
     }
     $carrier->delay = $delay;
     if (!$carrier->save()) {
         return false;
     }
     $dpdgroup_carrier = new DpdGroupCarrier();
     $dpdgroup_carrier->id_carrier = (int) $carrier->id;
     $dpdgroup_carrier->id_reference = (int) $carrier->id;
     if (!$dpdgroup_carrier->save()) {
         return false;
     }
     foreach ($service->continents as $continent => $value) {
         if ($value && !$carrier->addZone($continent)) {
             return false;
         }
     }
     $groups = array();
     foreach (Group::getGroups((int) Context::getContext()->language->id) as $group) {
         $groups[] = $group['id_group'];
     }
     if (version_compare(_PS_VERSION_, '1.5.5', '<')) {
         if (!self::setGroups14((int) $carrier->id, $groups)) {
             return false;
         }
     } else {
         if (!$carrier->setGroups($groups)) {
             return false;
         }
     }
     if (!Configuration::updateValue($carrier_type, (int) $carrier->id)) {
         return false;
     }
     return true;
 }
 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;
 }
Exemple #4
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;
 }