getWebsites(); } public function getDefaultWebsite() { $website = null; $websites = $this->getWebsites(); if (count($websites)) $website = array_shift($websites); return $website; } public function getServiceOptions() { $options = array(); // DK $options['PDK332'] = "Post Danmark Business Priority (Samsending)"; $options['PDK330'] = "Post Danmark Business Priority (Single)"; //$options['P24DK'] = "Post Danmark Privatpakke Retur"; $options['PDKEP'] = "Post Danmark Erhvervspakke"; $options['P19DK'] = "Post Danmark MyPack Collect"; $options['P19DKNO'] = "Post Danmark MyPack Collect (Norge)"; $options['P19DKBP'] = "Post Danmark MyPack Collect Samsending"; $options['P19DKDPD'] = "Post Danmark MyPack Collect udenfor Norden"; $options['PDK17'] = "Post Danmark MyPack Home"; $options['PDK17BP'] = "Post Danmark MyPack Home Samsending"; $options['P19DKDPDHOME'] = "Post Danmark MyPack Home udenfor Norden"; $options['P52DK'] = "Post Danmark Pallet"; //$options['P52DKR'] = "Post Danmark Pallet Return"; $options['PDK359'] = "Post Danmark Parcel Economy"; $options['PDK340'] = "Post Danmark Private Priority"; $options['PDKWAY'] = "Post Danmark Waybill"; $options['PDKLASTMILE'] = "Post Danmark Last Mile"; $options['PDKBREVI'] = "Post Danmark Varebrev til udlandet"; $options['PDKBREVISL'] = "Post Danmark Varebrev til udlandet Følgeseddel"; // DPD $options['DPDDK'] = "DPD Classic"; if(Mage::getStoreConfig('pacsoft/settings/use_swedish_services')) { // SE VAREBREVE $options['PAF'] = "PostNord - Brevpostförskott"; $options['BEXPD'] = "PostNord - Express (domestic)"; $options['BEXPI'] = "PostNord - Priority+"; $options['BREKD'] = "PostNord - Rek (domestic)"; $options['BREKI'] = "PostNord - Rek (international)"; $options['PUA'] = "PostNord - Varubrev 1:a klass"; $options['PUE'] = "PostNord - Varubrev Ekonomi"; $options['PBM'] = "PostNord - Varubrev Retur"; $options['BVAL'] = "PostNord - Värde"; $options['EMSD2'] = "PostNord EMS (brev/dokument)"; $options['EMSP2'] = "PostNord EMS (paket/varor)"; // SE PAKKER $options['P15'] = "PostNord DPD Företagspaket"; $options['P31'] = "PostNord DPD Företagspaket 09.00"; $options['P14'] = "PostNord DPD Företagspaket 12.00"; $options['DPD'] = "PostNord DPD Utrikes"; $options['P42'] = "PostNord Express - Expresspaket"; $options['P32'] = "PostNord Hempaket"; $options['P91'] = "PostNord International Parcel"; $options['P19'] = "PostNord MyPack"; $options['P24'] = "PostNord MyPack return (Sweden)"; $options['P52'] = "PostNord PALL.ETT (Sweden)"; } return $options; } private function __getServiceAddonMapping() { $service_addon_mapping = array('PDK332' => array('COD','DLVFLEX','INSU'), 'PDK330' => array('COD','INSU'), 'PDK331' => array(), 'PDKEP' => array('NOTEMAIL','DLVFLEX','POD','NOTSMS','VALUE','DNG','DLVT10','GREEN','INSU'), 'PDKEPR' => array('RETPUP','RETCAR'), 'PDKLASTMILE' => array('DLVFLEX','DLVT10','NOTEMAIL','NOTSMS','DLVFLEX','GREEN','INSU'), 'P52DK' => array('DNG','DLVIN','NOTPHONE','DLVFLEX','DLVT'), 'P52DKR' => array('DNG'), 'PDK359' => array('COD','INSU'), 'PDK340' => array('INSU','VALUE'), 'P24DK' => array(), 'P19DK' => array('NOTLTR','NOTEMAIL','DLVFLEX','AIR','DLV','GREEN','COD','NOTSMS','PUPOPT','VALUE','SPXL','INSU','FDNG'), 'P19DKNO' => array('INSU'), 'P19DKBP' => array('NOTLTR','NOTEMAIL','COD','INSU','VALUE','BSPLIT','AIR','NOTSMS','PUPOPT'), 'P19DKDPD' => array('NOTEMAIL','NOTSMS','FDNG','INSU','PUPOPT'), 'PDK17' => array('NOTEMAIL','FDNG','DLVFLEX','GREEN','NOTSMS','INSU','VALUE'), 'PDK17BP' => array('BSPLIT','NOTEMAIL','FDNG','DLVFLEX','GREEN','NOTSMS','INSU'), 'PDK19DPDHOME' => array('NOTEMAIL','FDNG','DLV','GREEN','NOTSMS','INSU'), 'PDKWAY' => array(), 'PDKBREVI' => array('ENOT'), 'PDKBREVISL' => array('ENOT'), 'DPDDK' => array(), // SE VAREBREVE 'PAF' => array('NOTEMAIL','NOTSMS','COD'), 'BEXPD' => array(), 'BEXPI' => array(), 'BREKD' => array('PORC','NOTEMAIL','NOTSMS','PERS','COD'), 'BREKI' => array('PORC','INSU','NOINSU'), 'PUA' => array('NOTEMAIL','NOTLTR','NOTSMS','PRENOT','SPBAG'), 'PUE' => array('NOTEMAIL','NOTLTR','NOTSMS','PRENOT','SPBAG'), 'PBM' => array('EMAILRECEIPT','NOTEMAIL','NOTLTR','NOTSMS'), 'BVAL' => array('NOTEMAIL','NOTSMS','PERS'), 'EMSD2' => array('LNKPRTN'), 'EMSP2' => array('LNKPRTN'), // SE PAKKER 'P15' => array('PODNOT','RPAY','DLVNOT','DLVNOPOD','DNG','PRENOT','CRR'), 'P31' => array('PODNOT','RPAY','DLVNOT','DLVNOPOD','DNG','PRENOT','CRR'), 'P14' => array('PODNOT','RPAY','DLVNOT','DLVNOPOD','DNG','PRENOT','CRR'), 'DPD' => array('CRR','DLVNOT'), 'P42' => array('RPAY','DLVNOPOD','PUPDEP','NOTSMS','PRENOT'), 'P32' => array('PODNOT','DLVNOT','DLVNOPOD'), 'P91' => array('ENOT','LNKPRTN'), 'P19' => array('COD','RETNEXT','DLV','NOTEMAIL','NOTLTR','NOTSMS','PUPOPT','PRENOT','RETN'), 'P24' => array('PODNOT'), 'P52' => array('PODNOT','RPAY','ULOAD','DLVNOT','DLVNOPOD','DNG','NOTPHONE','PRENOT','CRR'), ); return $service_addon_mapping; } private function __getAllAddons() { $addons = array(); $addons['NOTLTR'] = array('value' => "NOTLTR", 'label' => "Brevadvisering"); $addons['NOTEMAIL'] = array('value' => "NOTEMAIL", 'label' => "Email-advisering"); $addons['DLVFLEX'] = array('value' => "DLVFLEX", 'label' => "Flexlevering"); $addons['AIR'] = array('value' => "AIR", 'label' => "Fly"); $addons['DLV'] = array('value' => "DLV", 'label' => "Omdeling"); $addons['GREEN'] = array('value' => "GREEN", 'label' => "Pakke med omtanke"); $addons['COD'] = array('value' => "COD", 'label' => "Postopkrævning"); $addons['NOTSMS'] = array('value' => "NOTSMS", 'label' => "SMS-advisering"); $addons['INSU'] = array('value' => "INSU", 'label' => "Transportforsikring"); $addons['PUPOPT'] = array('value' => "PUPOPT", 'label' => "Valgfrit afhentningssted"); $addons['VALUE'] = array('value' => "VALUE", 'label' => "Værdi"); $addons['SPXL'] = array('value' => "SPXL", 'label' => "XL-omdeling"); $addons['POD'] = array('value' => "POD", 'label' => "Modtagerkvittering"); $addons['DNG'] = array('value' => "DNG", 'label' => "Farligt Indhold"); $addons['DLVT10'] = array('value' => "DLVT10", 'label' => "Levering før 10"); $addons['RETPUP'] = array('value' => "RETPUP", 'label' => "Returpakke afh. Erhverv"); $addons['RETCAR'] = array('value' => "RETCAR", 'label' => "Returpakkelabel udskrives af PDK"); $addons['DLVIN'] = array('value' => "DLVIN", 'label' => "Indbæring"); $addons['NOTPHONE'] = array('value' => "NOTPHONE", 'label' => "Tlf. varsel"); $addons['DLVT'] = array('value' => "DLVT", 'label' => "Tidsbestemt levering"); $addons['BSPLIT'] = array('value' => "BSPLIT", 'label' => "BulkSplit"); $addons['FDNG'] = array('value' => "FDNG", 'label' => "Farligt indhold i begrænset mængde"); $addons['ENOT'] = array('value' => "ENOT", 'label' => "Prenotification (Email)"); $addons['LNKPRTN'] = array('value' => "LNKPRTN", 'label' => "Link to print (normal)"); // SE SPECIFIKKE $addons['PORC'] = array('value' => "PORC", 'label' => "Mottagningsbevis"); $addons['PERS'] = array('value' => "PERS", 'label' => "Personlig Utlämning"); $addons['NOINSU'] = array('value' => "NOINSU", 'label' => "REK 2000"); $addons['PRENOT'] = array('value' => "PRENOT", 'label' => "Pre-advice"); $addons['SPBAG'] = array('value' => "SPBAG", 'label' => "Påse på dörren"); $addons['EMAILRECEIPT'] = array('value' => "EMAILRECEIPT", 'label' => "Email Receipt "); $addons['PODNOT'] = array('value' => "PODNOT", 'label' => "Confirmation of Delivery "); $addons['RPAY'] = array('value' => "RPAY", 'label' => "Consignee Paid Freight"); $addons['DLVNOT'] = array('value' => "DLVNOT", 'label' => "Delivery Notification"); $addons['DLVNOPOD'] = array('value' => "DLVNOPOD", 'label' => "Delivery without P.O.D."); $addons['DNG'] = array('value' => "DNG", 'label' => "Limited Quantities of Dangerous Goods "); $addons['CRR'] = array('value' => "CRR", 'label' => "Returuppdrag"); $addons['PUPDEP'] = array('value' => "PUPDEP", 'label' => "Mottagaren hämtar"); $addons['RETNEXT'] = array('value' => "RETNEXT", 'label' => "Förlängd liggetid"); $addons['RETN'] = array('value' => "RETN", 'label' => "Förkortad liggetid"); $addons['ULOAD'] = array('value' => "ULOAD", 'label' => "Behållarhyra"); return $addons; } public function getPosibleAddons() { $res = array(); $service_addon_mapping = $this->__getServiceAddonMapping(); $all_addons = $this->__getAllAddons(); foreach($this->getServiceOptions() as $service => $label) { $avil_addons_for_service = isset($service_addon_mapping[$service]) ? $service_addon_mapping[$service] : array(); if(empty($avil_addons_for_service)){ continue; } $options = array(); $optionsvalues = array(); foreach($avil_addons_for_service as $addon) { if(isset($all_addons[$addon])) { $optionsvalues[] = $all_addons[$addon]; } else { $optionsvalues[] = array('value' => $addon, 'label' => $addon); } } $options['label'] = $label; $options['value'] = $optionsvalues; $res[] = $options; } return $res; } public function getWebsite() { $website = null; $websiteId = (int) Mage::app()->getFrontController()->getRequest()->getParam('website', 0); if ($websiteId) $website = Mage::app()->getWebsite($websiteId); if (!$website) $website = $this->getDefaultWebsite(); return $website; } public function getWebsiteId($website = null) { if (is_null($website)) $website = $this->getWebsite(); return ($website) ? $website->getId() : null; } public function getCountries() { if (is_null($this->_countries)) { $countries = array(); $countryCollection = Mage::getResourceModel('directory/country_collection'); foreach ($countryCollection as $country) { $countries[$country->getId()] = $country; } $this->_countries = $countries; } return $this->_countries; } public function getCountry($countryId) { $countries = $this->getCountries(); if (isset($countries[$countryId])) return $countries[$countryId]; else return null; } public function getRegions() { if (is_null($this->_regions)) { $regions = array(); $regionCollection = Mage::getResourceModel('directory/region_collection'); foreach ($regionCollection as $region) { $regions[$region->getId()] = $region; } $this->_regions = $regions; } return $this->_regions; } public function getRegion($regionId) { $regions = $this->getRegions(); if (isset($regions[$regionId])) return $regions[$regionId]; else return null; } protected function _loadCountriesCodes() { if (is_null($this->_countriesISO2Codes) || is_null($this->_countriesISO3Codes)) { $this->_countriesISO2Codes = $this->_countriesISO3Codes = array(); foreach ($this->getCountries() as $country) { $this->_countriesISO2Codes[$country->getId()] = $country->getIso2Code(); $this->_countriesISO3Codes[$country->getId()] = $country->getIso3Code(); } } return $this; } protected function _loadRegionsCodes() { if (is_null($this->_regionsCodes)) { $this->_regionsCodes = array(); foreach ($this->getRegions() as $region) { $this->_regionsCodes[$region->getCountryId()][$region->getRegionId()] = $region->getCode(); } } return $this; } public function getCountriesISO2Codes() { if (is_null($this->_countriesISO2Codes)) $this->_loadCountriesCodes(); return $this->_countriesISO2Codes; } public function getCountriesISO3Codes() { if (is_null($this->_countriesISO3Codes)) $this->_loadCountriesCodes(); return $this->_countriesISO3Codes; } public function getRegionsCodes($countryId = null) { if (is_null($this->_regionsCodes)) $this->_loadRegionsCodes(); return ($countryId && isset($this->_regionsCodes[$countryId])) ? $this->_regionsCodes[$countryId] : array(); } public function getReturnService() { return $this->_returnService; } public function getServiceAndAddons($shipping_method, $returnlabel = false, $type, $country, $storeid = 0,$incrementId = "") { $nordicCountries = array('DK','SE','FI','IS','FO','GL'); // Norge er speciel if($type == 'private'){ if(in_array($country,$nordicCountries)){ $array['service'] = array(Mage::getStoreConfig('pacsoft/standard_labels/private_service',$storeid)); $array['addons'] = array_unique(explode(",",Mage::getStoreConfig('pacsoft/standard_labels/private_addons',$storeid))); } else{ $array['service'] = array(Mage::getStoreConfig('pacsoft/standard_labels_abroad/private_service',$storeid)); $array['addons'] = array(); } } elseif($type == 'business'){ if(in_array($country,$nordicCountries)){ $array['service'] = array(Mage::getStoreConfig('pacsoft/standard_labels/business_service',$storeid)); $array['addons'] = array_unique(explode(",",Mage::getStoreConfig('pacsoft/standard_labels/business_addons',$storeid))); } else{ $array['service'] = array(Mage::getStoreConfig('pacsoft/standard_labels_abroad/business_service',$storeid)); $array['addons'] = array(); } } else{ $id = explode("_",$shipping_method); $id = $id[count($id)-1]; $resource = Mage::getSingleton('core/resource'); $read = $resource->getConnection('core_read'); $table = $resource->getTableName('postdk_shipping/rate'); $select = $read->select()->from($table); $select->where('pk=?', $id); $row = $read->fetchAll($select); $array = array(); if (!empty($row) && !$returnlabel) { $row = $row[0]; $array['service'] = $this->__getArrayData($row['service']); $array['addons'] = $this->__getArrayData($row['addons']); } else { if($returnlabel){ $array['service'] = array($this->getReturnService()); } else{ throw new Exception($this->__("Ordren %s er ikke lagt med en Pacsoft leveringsmetode. Benyt i stedet 'Lav standard privatlabel' eller 'Lav standard erhvervslabel'",$incrementId)); $array['service'] = array(); } $array['addons'] = array(); } } return $array; } private function __getArrayData($data) { $data = explode(",",$data); $array = array(); foreach($data as $d) { $value = trim($d); if($value != "") { $array[] = $value; } } return $array; } }