diff --git a/README.md b/README.md index b4917fe..a8d1073 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Composer dependencies: Included dependencies: * [owebia/shipping](https://github.com/owebia/magento1-module-advanced-shipping) (2.6.10-lite) -* [leaflet](https://leafletjs.com/) (1.8.0) +* [leaflet](https://leafletjs.com/) (1.9.2) External services: * [Nominatim](https://nominatim.org/): addresses geocoding (results are stored in database) @@ -59,7 +59,7 @@ Demo links may not work, don't panic, it's not a bug. | **Store delivery** | | [online demo](https://cellu.blue/OmRX8p): 07200, Aubenas, FR
source of data: a TSV file | | **Store locator** | | [online demo](https://cellu.blue/h9dhKJ)
source of data: a TSV file | -Do you want more? Contact us, perhaps we can work together to add new methods! For example: Colissimo, Relais Colis, Swiss Post... +Do you want more? Contact us, perhaps we can work together to add new methods! For example: Colissimo, Relais Colis, Swiss Post, GLS, UPS... ## Customization @@ -95,7 +95,7 @@ To display delivery times, you must edit your template with: ## Copyright and Credits -- Current version: 2.4.1 (08/08/2022) +- Current version: 2.5.0 (10/10/2022) - Compatibility: OpenMage 19.x / 20.x / 21.x, PHP 7.2 / 7.3 / 7.4 / 8.0 / 8.1 - Client compatibility: Firefox 36+, Chrome 32+, Opera 19+, Edge 16+, Safari 9+ - Translations: English (en), French (fr-FR/fr-CA), German (de), Italian (it), Portuguese (pt-PT/pt-BR), Spanish (es) / Chinese (zh), Czech (cs), Dutch (nl), Greek (el), Hungarian (hu), Japanese (ja), Polish (pl), Romanian (ro), Russian (ru), Slovak (sk), Turkish (tr), Ukrainian (uk) @@ -105,9 +105,7 @@ If you like, take some of your time to improve the translations, go to https://b ## Installation -Warning: there are two packages, one that contains a lite and modified version (without jquery/editor/phpparser/doc) of owebia/shipping ([kyrena/openmage-shippingmax](https://github.com/kyrena/openmage-shippingmax)), and another one without owebia/shipping ([kyrena/openmage-shippingmax-alone](https://github.com/kyrena/openmage-shippingmax-alone)). - -#### For kyrena/openmage-shippingmax +Warning: it contains a lite and modified version (without jquery/editor/phpparser/doc) of owebia/shipping ([kyrena/openmage-shippingmax](https://github.com/kyrena/openmage-shippingmax)). With composer: - `composer remove owebia/magento1-module-advanced-shipping` diff --git a/src/app/code/community/Kyrena/Shippingmax/Block/Adminhtml/Config/Comment.php b/src/app/code/community/Kyrena/Shippingmax/Block/Adminhtml/Config/Comment.php index b388f43..b543247 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Block/Adminhtml/Config/Comment.php +++ b/src/app/code/community/Kyrena/Shippingmax/Block/Adminhtml/Config/Comment.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -31,7 +31,8 @@ public function render(Varien_Data_Form_Element_Abstract $element) { $maxWeight = Mage::getStoreConfig('carriers/'.$code.'/max_weight'); $defaultCountry = Mage::getStoreConfig('general/country/default', $storeId); - $allCountries = array_filter(explode(',', Mage::getStoreConfig('carriers/'.$code.'/allowedcountry'))); // config.xml + $allCountries = Mage::getStoreConfig('carriers/'.$code.'/allowedcountry'); + $allCountries = empty($allCountries) ? [] : array_filter(explode(',', $allCountries)); // config.xml $selCountries = $help->getCarrierCountries($code, $storeId); // pays du mode de livraison diff --git a/src/app/code/community/Kyrena/Shippingmax/Block/Rewrite/Renderer.php b/src/app/code/community/Kyrena/Shippingmax/Block/Rewrite/Renderer.php index 59bb298..df3f3fa 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Block/Rewrite/Renderer.php +++ b/src/app/code/community/Kyrena/Shippingmax/Block/Rewrite/Renderer.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -20,76 +20,88 @@ class Kyrena_Shippingmax_Block_Rewrite_Renderer extends Mage_Customer_Block_Address_Renderer_Default { + protected $_translate; + protected $_formatter; + protected function _construct() { $this->setModuleName('Mage_Customer'); + $this->_translate = Mage::getSingleton('core/locale'); + $this->_formatter = []; } public function render(Mage_Customer_Model_Address_Abstract $address, $output = null) { - $translate = Mage::getSingleton('core/locale'); - // traitement spécial pour France + DROM/COM + Monaco - $code = strtoupper($address->getData('country_id')); - $country = $translate->getCountryTranslation($code); + $code = strtoupper($address->getData('country_id')); + $country = $this->_translate->getCountryTranslation($code); + $postcode = $address->getData('postcode'); - if (in_array($code, $this->helper('shippingmax')->getFranceDromCom())) { + if (!empty($postcode) && in_array($code, $this->helper('shippingmax')->getFranceDromCom())) { - $post4 = mb_substr($address->getData('postcode'), 0, 4); + $post4 = mb_substr($postcode, 0, 4); $post3 = mb_substr($post4, 0, 3); $post2 = mb_substr($post4, 0, 2); if ($post2 == '97') { - $france = $translate->getCountryTranslation($code = 'FR'); + $france = $this->_translate->getCountryTranslation($code = 'FR'); // BL 97133 Saint-Barthélemy (977 Antilles) - if ($address->getData('postcode') == '97133') - $country = $france.' ('.$translate->getCountryTranslation($code = 'BL').')'; + if ($postcode == '97133') + $country = $france.' ('.$this->_translate->getCountryTranslation($code = 'BL').')'; // MF 97150 Saint-Martin (978 Antilles) else if ($post4 == '9715') - $country = $france.' ('.str_replace(' (partie française)', '', $translate->getCountryTranslation($code = 'MF')).')'; + $country = $france.' ('.str_replace(' (partie française)', '', $this->_translate->getCountryTranslation($code = 'MF')).')'; // GP 971XX Guadeloupe else if ($post3 == '971') - $country = $france.' ('.$translate->getCountryTranslation($code = 'GP').')'; + $country = $france.' ('.$this->_translate->getCountryTranslation($code = 'GP').')'; // MQ 972XX Martinique else if ($post3 == '972') - $country = $france.' ('.$translate->getCountryTranslation($code = 'MQ').')'; + $country = $france.' ('.$this->_translate->getCountryTranslation($code = 'MQ').')'; // GF 973XX Guyane else if ($post3 == '973') - $country = $france.' ('.$translate->getCountryTranslation($code = 'GF').')'; + $country = $france.' ('.$this->_translate->getCountryTranslation($code = 'GF').')'; // RE 974XX La Réunion else if ($post3 == '974') - $country = $france.' ('.$translate->getCountryTranslation($code = 'RE').')'; + $country = $france.' ('.$this->_translate->getCountryTranslation($code = 'RE').')'; // PM 975XX Saint-Pierre-et-Miquelon else if ($post3 == '975') - $country = $france.' ('.$translate->getCountryTranslation($code = 'PM').')'; + $country = $france.' ('.$this->_translate->getCountryTranslation($code = 'PM').')'; // YT 976XX Mayotte else if ($post3 == '976') - $country = $france.' ('.$translate->getCountryTranslation($code = 'YT').')'; + $country = $france.' ('.$this->_translate->getCountryTranslation($code = 'YT').')'; } else if ($post2 == '98') { - $france = $translate->getCountryTranslation($code = 'FR'); + $france = $this->_translate->getCountryTranslation($code = 'FR'); // WF 986XX Wallis-et-Futuna if ($post3 == '986') - $country = $france.' ('.$translate->getCountryTranslation($code = 'WF').')'; + $country = $france.' ('.$this->_translate->getCountryTranslation($code = 'WF').')'; // PF 987XX Polynésie Française else if ($post3 == '987') - $country = $france.' ('.$translate->getCountryTranslation($code = 'PF').')'; + $country = $france.' ('.$this->_translate->getCountryTranslation($code = 'PF').')'; // NC 988XX Nouvelle-Calédonie else if ($post3 == '988') - $country = $france.' ('.$translate->getCountryTranslation($code = 'NC').')'; + $country = $france.' ('.$this->_translate->getCountryTranslation($code = 'NC').')'; // TF 984XX Terres australes françaises else if ($post3 == '984') - $country = $france.' ('.$translate->getCountryTranslation($code = 'TF').')'; + $country = $france.' ('.$this->_translate->getCountryTranslation($code = 'TF').')'; // MC 980XX Monaco else if ($post3 == '980') - $country = $translate->getCountryTranslation($code = 'MC'); + $country = $this->_translate->getCountryTranslation($code = 'MC'); } } if ($output == 'country') return $code; - if (mb_stripos(__FILE__, 'vendor/kyrena') === false) - return ($output == 'telephone') ? $address->getData('telephone') : parent::render($address, $output); + if (stripos(__FILE__, 'vendor/kyrena') === false) { + + if ($output == 'telephone') + return $address->getData('telephone'); + + if (!$this->getType()) + $this->setType(new Varien_Object()); + + return parent::render($address, $output); + } $code = empty($code) ? Mage::getStoreConfig('general/country/default') : $code; @@ -124,14 +136,20 @@ public function render(Mage_Customer_Model_Address_Abstract $address, $output = // génération du template de l'adresse // https://github.com/adamlc/address-format - $formatter = new \Adamlc\AddressFormat\Format(); - try { - $formatter->setLocale($code); + if (array_key_exists($code, $this->_formatter)) { + $this->_formatter[$code]->clearAttributes(); } - catch (Throwable $t) { - $formatter->setLocale('US'); + else { + $this->_formatter[$code] = new \Adamlc\AddressFormat\Format(); + try { + $this->_formatter[$code]->setLocale($code); + } + catch (Throwable $t) { + $this->_formatter[$code]->setLocale('US'); + } } + $formatter = $this->_formatter[$code]; $formatter->setAttribute('ORGANIZATION', '#{company}'); $formatter->setAttribute('RECIPIENT', '#{name}'); $formatter->setAttribute('STREET_ADDRESS', '#{street}'); @@ -141,7 +159,7 @@ public function render(Mage_Customer_Model_Address_Abstract $address, $output = $formatter->setAttribute('ADMIN_AREA', '#{region}'); $template = $formatter->formatAddress()."\n#{country}\n#{telephone}\n#{fax}\n#{vat_id}"; - $output = $this->getType()->getCode(); + $output = $this->getType() ? $this->getType()->getCode() : $output; if ($output == 'js_template') return str_replace(['#{name}', '#{street}'], ['#{prefix} #{firstname} #{middlename} #{lastname} #{suffix}', "#{street0}\n#{street1}\n#{street2}\n#{street3}"], $template); @@ -159,8 +177,8 @@ public function render(Mage_Customer_Model_Address_Abstract $address, $output = '#{vat_id}' ], [ $address->getData('company'), - $address->getName(), - implode("\n", $address->getStreet()), + empty(Mage::registry('address_ignore_name')) ? $address->getName() : '', + method_exists($address, 'getStreet') ? implode("\n", $address->getStreet()) : $address->getData('street'), $address->getData('postcode'), $address->getData('city'), $address->getData('region'), diff --git a/src/app/code/community/Kyrena/Shippingmax/Block/Selected.php b/src/app/code/community/Kyrena/Shippingmax/Block/Selected.php index 51d0792..6b88261 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Block/Selected.php +++ b/src/app/code/community/Kyrena/Shippingmax/Block/Selected.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -40,9 +40,11 @@ public function getItem(string $code, $rate = null) { return false; // n'autorise pas le changement de pays - // sauf pour Monaco qui est considéré comment France avec Mondial Relay - if (($data['item']['country_id'] != $country) && !(($code == 'shippingmax_mondialrelay') && ($data['item']['country_id'] == 'FR') && ($country == 'MC'))) - return false; + if ($data['item']['country_id'] != $country) { + // sauf si le pays change de FR à MC ou inversement + if (!(in_array($data['item']['country_id'], ['FR', 'MC']) && in_array($country, ['FR', 'MC']))) + return false; + } $countries = $help->getCarrierCountries($code); return in_array($data['item']['country_id'], $countries) ? $data['item'] : false; diff --git a/src/app/code/community/Kyrena/Shippingmax/Helper/Data.php b/src/app/code/community/Kyrena/Shippingmax/Helper/Data.php index fc29eff..b144405 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Helper/Data.php +++ b/src/app/code/community/Kyrena/Shippingmax/Helper/Data.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -168,10 +168,8 @@ public function getShippingDate(string $code, bool $days = false, $country = nul } // recherche du vrai pays surtout pour la France et ses DROM/COM - // Mage::getBlockSingleton('shippingmax/rewrite_renderer') - // Mage::app()->getLayout()->getBlockSingleton('shippingmax/rewrite_renderer') $fake = Mage::getModel('customer/address')->setData('country_id', $country)->setData('postcode', $postcode); - $country = Mage::getBlockSingleton('shippingmax/rewrite_renderer')->setType(new Varien_Object())->render($fake, 'country'); + $country = Mage::getBlockSingleton('shippingmax/rewrite_renderer')->render($fake, 'country'); $storeId = is_null($storeId) ? Mage::app()->getStore()->getId() : $storeId; // recherche des délais @@ -284,7 +282,7 @@ public function getShippingDate(string $code, bool $days = false, $country = nul public function isClosedDay(object $date, string $country, $postcode = null) { - if (mb_stripos(__FILE__, 'vendor/kyrena') === false) + if (stripos(__FILE__, 'vendor/kyrena') === false) return false; // https://github.com/azuyalabs/yasumi @@ -316,7 +314,8 @@ public function getCarrierCountries(string $code, $storeId = null) { $countries = array_filter(explode(',', Mage::getStoreConfig('general/country/allow', $storeId))); // filtre sur la config des pays possibles sur le mode de livrais - $selCountries = array_filter(explode(',', Mage::getStoreConfig('carriers/'.$code.'/allowedcountry'))); // config.xml + $selCountries = Mage::getStoreConfig('carriers/'.$code.'/allowedcountry'); + $selCountries = empty($selCountries) ? [] : array_filter(explode(',', $selCountries)); // config.xml if (!empty($selCountries)) $countries = array_intersect($countries, $selCountries); @@ -441,7 +440,7 @@ public function formatDesc(string $data) { if (substr_count($data, '#') > 5) { - $lines = explode("\n", $data); + $lines = explode('~', str_replace("\n", '~', $data)); // 'saut de ligne' ou '~' $since = ''; $desc = []; @@ -450,7 +449,7 @@ public function formatDesc(string $data) { if (str_contains($line, '#') && is_numeric($line[0])) { $line = explode('#', $line); - $day = isset($line[0][0]) ? (int) $line[0][0] : 0; + $day = isset($line[0][0]) ? (int) $line[0][0] : 0; // '1 Monday' ou '1' if ($day > 0) { @@ -469,8 +468,8 @@ public function formatDesc(string $data) { $since = ''; } - // 1 Monday#09#30#12#00#12#00#19#00 - // 1 Monday#09#30#12#00#14#30#19#00 + // 1#09#30#12#00#12#00#19#00 + // 1#09#30#12#00#14#30#19#00 if (count($line) >= 9) { if (($line[3] == $line[5]) && ($line[4] == $line[6])) { $desc[] = $this->__('%s: %s:%s - %s:%s', $day, @@ -485,13 +484,13 @@ public function formatDesc(string $data) { str_pad($line[7], 2, '0', STR_PAD_LEFT), str_pad($line[8], 2, '0', STR_PAD_LEFT)); } } - // 1 Monday#15#00#19#00 + // 1#15#00#19#00 else if (count($line) >= 5) { $desc[] = $this->__('%s: %s:%s - %s:%s', $day, str_pad($line[1], 2, '0', STR_PAD_LEFT), str_pad($line[2], 2, '0', STR_PAD_LEFT), str_pad($line[3], 2, '0', STR_PAD_LEFT), str_pad($line[4], 2, '0', STR_PAD_LEFT)); } - // 1 Monday#closed + // 1#closed else if (count($line) >= 2) { $desc[] = $this->__('%s: closed', $day); } diff --git a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier.php b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier.php index 772b8ee..3f7fee4 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier.php +++ b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -102,7 +102,7 @@ public function loadItemsFromCache(object $address, bool $dataOnly = false) { $app = Mage::app(); $str = mb_strtolower(trim($address->getData('postcode').' '.$address->getData('city').', '.$address->getData('country_id'))); - if (mb_strlen($str) < 6) // géolocalisation + if (!empty($address->getData('lat')) && (mb_strlen($str) < 6)) // géolocalisation $str = trim(round($address->getData('lat'), 6).'/'.round($address->getData('lng'), 6)); $skey = $this->_code.'_'.md5($str); // clef pour le cache des résultats de la recherche actuelle @@ -155,8 +155,9 @@ public function loadItemsFromCache(object $address, bool $dataOnly = false) { if (!empty($items) && is_array($items)) { - array_walk_recursive($items, static function (&$item) { - $item = trim(Mage::helper('shippingmax')->escapeEntities(strip_tags($item))); + $help = Mage::helper('shippingmax'); + array_walk_recursive($items, static function (&$item) use ($help) { + $item = (is_bool($item) || empty($item)) ? $item : trim($help->escapeEntities(strip_tags($item))); }); // sauvegarde dans le cache fichier et dans le cache openmage diff --git a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Boxberry.php b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Boxberry.php index 38575ce..ac99057 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Boxberry.php +++ b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Boxberry.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -93,15 +93,7 @@ protected function createDesc($data) { // lundi à dimanche en russe abrégé $abbrs = ['пн', 'вт', 'ср', 'чт', 'пт', 'сб', 'вс']; - $days = [ - '1 Monday' => '', - '2 Tuesday' => '', - '3 Wednesday' => '', - '4 Thursday' => '', - '5 Friday' => '', - '6 Saturday' => '', - '7 Sunday' => '' - ]; + $days = [1 => '', 2 => '', 3 => '', 4 => '', 5 => '', 6 => '', 7 => '']; $positionToDay = array_keys($days); $pos = mb_stripos($data, 'обед'); @@ -148,8 +140,8 @@ protected function createDesc($data) { if (count($days) != 7) return ''; - // Array ( [1 Monday] => 09.00-19.00 ) - // Array ( [1 Monday] => 09.00-19.00/14.00-14.30 ) + // Array ( [1] => 09.00-19.00 ) + // Array ( [1] => 09.00-19.00/14.00-14.30 ) $always = array_unique(array_values($days)); if ((count($always) == 1) && in_array($always[0], ['00.00-23.59', '00.01-23.59'])) return '24/7'; @@ -186,6 +178,12 @@ protected function createDesc($data) { } } - return implode("\n", $html); + foreach ($days as $day => $str) { + if (!array_key_exists($day, $html)) + $html[$day] = $day.'#closed'; + } + + ksort($html); + return implode('~', $html); } } \ No newline at end of file diff --git a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Chronorelais.php b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Chronorelais.php index 1ff46e2..2a35b9f 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Chronorelais.php +++ b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Chronorelais.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -97,15 +97,18 @@ public function loadItemsFromApi(object $address) { protected function createDesc($data) { + if (empty($data->listeHoraireOuverture)) + return ''; + $html = []; $days = [ - '1 Monday' => ['0000', '0000', '0000', '0000'], - '2 Tuesday' => ['0000', '0000', '0000', '0000'], - '3 Wednesday' => ['0000', '0000', '0000', '0000'], - '4 Thursday' => ['0000', '0000', '0000', '0000'], - '5 Friday' => ['0000', '0000', '0000', '0000'], - '6 Saturday' => ['0000', '0000', '0000', '0000'], - '7 Sunday' => ['0000', '0000', '0000', '0000'], + 1 => ['0000', '0000', '0000', '0000'], + 2 => ['0000', '0000', '0000', '0000'], + 3 => ['0000', '0000', '0000', '0000'], + 4 => ['0000', '0000', '0000', '0000'], + 5 => ['0000', '0000', '0000', '0000'], + 6 => ['0000', '0000', '0000', '0000'], + 7 => ['0000', '0000', '0000', '0000'], ]; foreach ($data->listeHoraireOuverture as $info) { @@ -126,10 +129,10 @@ protected function createDesc($data) { } } - // Array ( [1 Monday] => Array ( [0] => 0930 [1] => 1200 [2] => 1400 [3] => 1800 ) - // Array ( [1 Monday] => Array ( [0] => 0930 [1] => 2300 [2] => 0000 [3] => 0000 ) + // Array ( [0] => 0000 [1] => 2359 [2] => 0000 [3] => 0000 ) + // Array ( [0] => 0001 [1] => 2359 [2] => 0000 [3] => 0000 ) $always = array_unique(array_values(array_map('implode', $days))); - if ((count($always) == 1) && in_array($always[0], ['0000235900000000', '0100235900000000'])) + if ((count($always) == 1) && in_array($always[0], ['0000235900000000', '0001235900000000'])) return '24/7'; foreach ($days as $day => $str) { @@ -154,6 +157,12 @@ protected function createDesc($data) { } } - return implode("\n", $html); + foreach ($days as $day => $str) { + if (!array_key_exists($day, $html)) + $html[$day] = $day.'#closed'; + } + + ksort($html); + return implode('~', $html); } } \ No newline at end of file diff --git a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Colisprivpts.php b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Colisprivpts.php index 326dba1..6de09ab 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Colisprivpts.php +++ b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Colisprivpts.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -140,9 +140,10 @@ public function loadItemsFromApi(object $address) { protected function checkIfAvailable(object $request) { // France (sans la Corse, sans Monaco, sans les DROM/COM) - if (in_array($request->getData('dest_country_id'), Mage::helper('shippingmax')->getFranceDromCom())) { + $postcode = $request->getData('dest_postcode'); + if (!empty($postcode) && in_array($request->getData('dest_country_id'), Mage::helper('shippingmax')->getFranceDromCom())) { - $postcode = trim($request->getData('dest_postcode')); + $postcode = trim($postcode); // FR France // FR 20XXX Corse // MC 980XX Monaco @@ -176,13 +177,13 @@ protected function createDescCurl($values) { $html = []; $days = [ - '1 Monday' => 'LUNDI;DEBUT_LU;FIN_LU', - '2 Tuesday' => 'MARDI;DEBUT_MA;FIN_MA', - '3 Wednesday' => 'MERCREDI;DEBUT_ME;FIN_ME', - '4 Thursday' => 'JEUDI;DEBUT_JE;FIN_JE', - '5 Friday' => 'VENDREDI;DEBUT_VE;FIN_VE', - '6 Saturday' => 'SAMEDI;DEBUT_SA;FIN_SA', - '7 Sunday' => 'DIMANCHE;DEBUT_DI;FIN_DI' + 1 => 'LUNDI;DEBUT_LU;FIN_LU', + 2 => 'MARDI;DEBUT_MA;FIN_MA', + 3 => 'MERCREDI;DEBUT_ME;FIN_ME', + 4 => 'JEUDI;DEBUT_JE;FIN_JE', + 5 => 'VENDREDI;DEBUT_VE;FIN_VE', + 6 => 'SAMEDI;DEBUT_SA;FIN_SA', + 7 => 'DIMANCHE;DEBUT_DI;FIN_DI', ]; foreach ($days as $day => $str) { @@ -208,13 +209,13 @@ protected function createDescApi($values) { $html = []; $days = [ - '1 Monday' => 'MON', - '2 Tuesday' => 'TUE', - '3 Wednesday' => 'WED', - '4 Thursday' => 'THU', - '5 Friday' => 'FRI', - '6 Saturday' => 'SAT', - '7 Sunday' => 'SUN' + 1 => 'MON', + 2 => 'TUE', + 3 => 'WED', + 4 => 'THU', + 5 => 'FRI', + 6 => 'SAT', + 7 => 'SUN', ]; foreach ($days as $day => $str) { diff --git a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Dpdfrrelais.php b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Dpdfrrelais.php index a524a5d..5a0af34 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Dpdfrrelais.php +++ b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Dpdfrrelais.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -26,6 +26,10 @@ class Kyrena_Shippingmax_Model_Carrier_Dpdfrrelais extends Kyrena_Shippingmax_Mo public function loadItemsFromApi(object $address) { + // pour la configuration des prix (cf module dpdfrance 5.2.0 pour magento 1.9) + // zones de montage : FR(04120, 04130, 04140, 04160, 04170, 04200, 04240, 04260, 04300, 04310, 04330, 04360, 04370, 04400, 04510, 04530, 04600, 04700, 04850, 05100, 05110, 05120, 05130, 05150, 05160, 05170, 05200, 05220, 05240, 05250, 05260, 05290, 05300, 05310, 05320, 05330, 05340, 05350, 05400, 05460, 05470, 05500, 05560, 05600, 05700, 05800, 06140, 06380, 06390, 06410, 06420, 06430, 06450, 06470, 06530, 06540, 06620, 06710, 06750, 06910, 09110, 09140, 09300, 09460, 25120, 25140, 25240, 25370, 25450, 25500, 25650, 30570, 31110, 38112, 38114, 38142, 38190, 38250, 38350, 38380, 38410, 38580, 38660, 38700, 38750, 38860, 38880, 39220, 39310, 39400, 63113, 63210, 63240, 63610, 63660, 63690, 63840, 63850, 64440, 64490, 64560, 64570, 65110, 65120, 65170, 65200, 65240, 65400, 65510, 65710, 66210, 66760, 66800, 68140, 68610, 68650, 73110, 73120, 73130, 73140, 73150, 73160, 73170, 73190, 73210, 73220, 73230, 73250, 73260, 73270, 73300, 73320, 73340, 73350, 73390, 73400, 73440, 73450, 73460, 73470, 73500, 73530, 73550, 73590, 73600, 73620, 73630, 73640, 73710, 73720, 73870, 74110, 74120, 74170, 74220, 74230, 74260, 74310, 74340, 74350, 74360, 74390, 74400, 74420, 74430, 74440, 74450, 74470, 74480, 74660, 74740, 74920, 83111, 83440, 83530, 83560, 83630, 83690, 83830, 83840, 84390, 88310, 88340, 88370, 88400, 90200) + // iles et corse : FR(20*, 17111, 17123, 17190, 17310, 17370, 17410, 17480, 17550, 17580, 17590, 17630, 17650, 17670, 17740, 17840, 17880, 17940, 22870, 29242, 29253, 29259, 29980, 29990, 56360, 56590, 56780, 56840, 85350) + $items = []; ini_set('default_socket_timeout', 20); @@ -40,7 +44,7 @@ public function loadItemsFromApi(object $address) { 'latitude' => round($address->getData('lat'), 11), 'longitude' => round($address->getData('lng'), 11), 'max_distance_search' => $this->getConfigData('dst_search'), - 'max_pudo_number' => $this->getConfigData('max_points'), + 'max_pudo_number' => min(25, $this->getConfigData('max_points')), 'date_from' => date('d/m/Y'), 'requestID' => '1234', // toujours à 1234, cf module dpdfrance 5.2.0 pour magento 1.9 (ligne 79) 'request_id' => '1234', // toujours à 1234, cf module dpdfrance 5.2.0 pour magento 1.9 (ligne 80) @@ -50,7 +54,8 @@ public function loadItemsFromApi(object $address) { // https://mypudo.pickup-services.com/mypudo/mypudo.asmx?op=GetPudoList // https://mypudo.pickup-services.com/mypudo/mypudo.asmx?op=GetPudoListByLongLat - // SoapFault exception: [soap:Server] Le serveur n'a pas pu traiter la demande. ---> La référence d'objet n'est pas définie à une instance d'un objet. + // SoapFault exception: [soap:Server] Le serveur n'a pas pu traiter la demande. + // ---> La référence d'objet n'est pas définie à une instance d'un objet. //if (empty($params['latitude']) || empty($params['longitude'])) $results = $client->getPudoList($params); //else @@ -98,13 +103,13 @@ protected function createDesc($data) { $html = []; $days = [ - '1 Monday' => ['0000', '0000', '0000', '0000'], - '2 Tuesday' => ['0000', '0000', '0000', '0000'], - '3 Wednesday' => ['0000', '0000', '0000', '0000'], - '4 Thursday' => ['0000', '0000', '0000', '0000'], - '5 Friday' => ['0000', '0000', '0000', '0000'], - '6 Saturday' => ['0000', '0000', '0000', '0000'], - '7 Sunday' => ['0000', '0000', '0000', '0000'], + 1 => ['0000', '0000', '0000', '0000'], + 2 => ['0000', '0000', '0000', '0000'], + 3 => ['0000', '0000', '0000', '0000'], + 4 => ['0000', '0000', '0000', '0000'], + 5 => ['0000', '0000', '0000', '0000'], + 6 => ['0000', '0000', '0000', '0000'], + 7 => ['0000', '0000', '0000', '0000'], ]; foreach ($data->OPENING_HOURS_ITEMS->OPENING_HOURS_ITEM as $info) { @@ -130,10 +135,10 @@ protected function createDesc($data) { } } - // Array ( [1 Monday] => Array ( [0] => 0930 [1] => 1200 [2] => 1400 [3] => 1800 ) - // Array ( [1 Monday] => Array ( [0] => 0930 [1] => 2300 [2] => 0000 [3] => 0000 ) + // Array ( [0] => 0000 [1] => 2359 [2] => 0000 [3] => 0000 ) + // Array ( [0] => 0001 [1] => 2359 [2] => 0000 [3] => 0000 ) $always = array_unique(array_values(array_map('implode', $days))); - if ((count($always) == 1) && in_array($always[0], ['0000235900000000', '0100235900000000'])) + if ((count($always) == 1) && in_array($always[0], ['0000235900000000', '0001235900000000'])) return '24/7'; foreach ($days as $day => $str) { @@ -160,6 +165,12 @@ protected function createDesc($data) { } } - return implode("\n", $html); + foreach ($days as $day => $str) { + if (!array_key_exists($day, $html)) + $html[$day] = $day.'#closed'; + } + + ksort($html); + return implode('~', $html); } } \ No newline at end of file diff --git a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Fivepost.php b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Fivepost.php index 5903a8d..c2bafab 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Fivepost.php +++ b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Fivepost.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -36,7 +36,7 @@ public function loadItemsFromApi(object $address) { curl_setopt($ch, CURLOPT_URL, trim($this->getConfigData('api_url'), '/').'/jwt-generate-claims/rs256/1?apikey='.$this->getConfigData('api_password', true)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json', - 'Content-Type: application/x-www-form-urlencoded' + 'Content-Type: application/x-www-form-urlencoded', ]); curl_setopt($ch, CURLOPT_POSTFIELDS, 'subject=OpenAPI&audience=A122019!'); $results = $this->runCurl($ch, true); @@ -50,13 +50,13 @@ public function loadItemsFromApi(object $address) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_URL, trim($this->getConfigData('api_url'), '/').'/api/v1/pickuppoints/query'). curl_setopt($ch, CURLOPT_HTTPHEADER, [ - 'Accept: application/json', + 'Accept: application/json', 'Content-Type: application/json; charset="utf-8"', - 'Authorization: "Bearer '.$jwt.'"' + 'Authorization: "Bearer '.$jwt.'"', ]); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ 'pageSize' => 1000, - 'pageNumber' => $page + 'pageNumber' => $page, ])); $results = $this->runCurl($ch, true); diff --git a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Inpospaczk.php b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Inpospaczk.php index b60284f..93dcaaa 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Inpospaczk.php +++ b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Inpospaczk.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -60,7 +60,7 @@ public function loadItemsFromApi(object $address) { 'city' => $result['address']['city'], 'region' => $result['address']['province'], 'country_id' => $this->_country, - 'description' => $result['operating_hours'], + 'description' => $this->createDesc($result['operating_hours']), ]; } } @@ -87,11 +87,58 @@ public function loadItemsFromApi(object $address) { 'city' => $result['address_details']['city'], 'region' => $result['address_details']['province'], 'country_id' => $this->_country, - 'description' => $result['opening_hours'], + 'description' => $this->createDesc($result['opening_hours']), ]; } } return $items; } + + protected function createDesc($data) { + + if ($data == '24/7') + return '24/7'; + if (empty($data)) + return ''; + + $data = explode(';', $data); + $days = [1 => 'MON', 2 => 'TUE', 3 => 'WED', 4 => 'THU', 5 => 'FRI', 6 => 'SAT', 7 => 'SUN']; + $html = []; + + foreach ($days as $day => $str) { + + foreach ($data as $hours) { + + $hours = array_filter(explode('|', str_replace('-', '|', $hours))); + if (empty($hours) || ($hours[0] != $str)) + continue; + + // ouvert non stop ou fermé le matin ou fermé l'après midi + if (count($hours) == 3) { + $html[$day] = $day.'#'. + str_replace(':', '#', $hours[1]).'#'. + str_replace(':', '#', $hours[2]); + } + // fermé à midi + else if (count($hours) == 5) { + $html[$day] = $day.'#'. + str_replace(':', '#', $hours[1]).'#'. + str_replace(':', '#', $hours[2]).'#'. + str_replace(':', '#', $hours[3]).'#'. + str_replace(':', '#', $hours[4]); + } + + break; + } + } + + foreach ($days as $day => $str) { + if (!array_key_exists($day, $html)) + $html[$day] = $day.'#closed'; + } + + ksort($html); + return implode('~', $html); + } } \ No newline at end of file diff --git a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Mondialrelay.php b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Mondialrelay.php index 33f38e0..b407a52 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Mondialrelay.php +++ b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Mondialrelay.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -99,9 +99,10 @@ protected function checkIfAvailable(object $request) { // France (avec la Corse et Monaco - sans les DROM/COM) // 05/2019 https://www.mondialrelay.fr/faq/envoyer-un-colis/faites-vous-des-livraisons-dans-les-dom-tom-/ - if (in_array($request->getData('dest_country_id'), Mage::helper('shippingmax')->getFranceDromCom())) { + $postcode = $request->getData('dest_postcode'); + if (!empty($postcode) && in_array($request->getData('dest_country_id'), Mage::helper('shippingmax')->getFranceDromCom())) { - $postcode = trim($request->getData('dest_postcode')); + $postcode = trim($postcode); // FR France // FR 20XXX Corse // MC 980XX Monaco @@ -127,9 +128,9 @@ protected function checkIfAvailable(object $request) { } // Espagne (avec les Îles Baléares - sans les Îles Canaries, Ceuta et Melilla) // 05/2019 https://www.puntopack.es/preguntas-frecuentes/enviar-un-paquete/entregas-en-las-islas-o-enclaves/ - else if ($request->getData('dest_country_id') == 'ES') { + else if (!empty($postcode) && ($request->getData('dest_country_id') == 'ES')) { - $postcode = trim($request->getData('dest_postcode')); + $postcode = trim($postcode); // ES 07XXX Baleares (AUTORISÉ) // ES 35XXX Las Palmas (Canaries) // ES 38XXX Santa Cruz de Tenerife (Canaries) @@ -152,21 +153,22 @@ protected function createDesc($data) { $html = []; $days = [ - '1 Monday' => $data->Horaires_Lundi->string, - '2 Tuesday' => $data->Horaires_Mardi->string, - '3 Wednesday' => $data->Horaires_Mercredi->string, - '4 Thursday' => $data->Horaires_Jeudi->string, - '5 Friday' => $data->Horaires_Vendredi->string, - '6 Saturday' => $data->Horaires_Samedi->string, - '7 Sunday' => $data->Horaires_Dimanche->string + 1 => $data->Horaires_Lundi->string, + 2 => $data->Horaires_Mardi->string, + 3 => $data->Horaires_Mercredi->string, + 4 => $data->Horaires_Jeudi->string, + 5 => $data->Horaires_Vendredi->string, + 6 => $data->Horaires_Samedi->string, + 7 => $data->Horaires_Dimanche->string, ]; - foreach ($days as $day => $str) { + // Array ( [0] => 0000 [1] => 2359 ) + // Array ( [0] => 0001 [1] => 2359 [2] => 0000 [3] => 0000 ) + $always = array_unique(array_values(array_map('implode', $days))); + if ((count($always) == 1) && in_array($always[0], ['00002359', '00012359', '0000235900000000', '0001235900000000'])) + return '24/7'; - // if (($str[0] == '0000') && ($str[2] == '0000')) - // else if (($str[0] == '0000') && ($str[2] != '0000')) - // else if (($str[0] != '0000') && ($str[2] == '0000')) - // else + foreach ($days as $day => $str) { if ($str[0] == '0000') { // fermé toute la journée @@ -196,6 +198,12 @@ protected function createDesc($data) { } } - return implode("\n", $html); + foreach ($days as $day => $str) { + if (!array_key_exists($day, $html)) + $html[$day] = $day.'#closed'; + } + + ksort($html); + return implode('~', $html); } } \ No newline at end of file diff --git a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Pickpoint.php b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Pickpoint.php index 93db8a7..03a2455 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Pickpoint.php +++ b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Pickpoint.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -33,7 +33,7 @@ public function loadItemsFromApi(object $address) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json', - 'Content-Type: application/json; charset="utf-8"' + 'Content-Type: application/json; charset="utf-8"', ]); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ 'Login' => $this->getConfigData('api_username'), @@ -49,7 +49,7 @@ public function loadItemsFromApi(object $address) { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json', - 'Content-Type: application/json; charset="utf-8"' + 'Content-Type: application/json; charset="utf-8"', ]); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ 'SessionId' => $results['SessionId'], @@ -128,17 +128,17 @@ protected function createDesc($data) { $html = []; $days = [ - '1 Monday' => $data[0], - '2 Tuesday' => $data[1], - '3 Wednesday' => $data[2], - '4 Thursday' => $data[3], - '5 Friday' => $data[4], - '6 Saturday' => $data[5], - '7 Sunday' => $data[6], + 1 => $data[0], + 2 => $data[1], + 3 => $data[2], + 4 => $data[3], + 5 => $data[4], + 6 => $data[5], + 7 => $data[6], ]; - // Array ( [1 Monday] => 09:00-19:00 ) - // Array ( [1 Monday] => 09:00-19:00/14:00-14:30 ) + // Array ( [1] => 09:00-19:00 ) + // Array ( [1] => 09:00-19:00/14:00-14:30 ) $always = array_unique(array_values($days)); if ((count($always) == 1) && in_array($always[0], ['00:00-23:59', '00:01-23:59'])) return '24/7'; @@ -175,6 +175,12 @@ protected function createDesc($data) { } } - return implode("\n", $html); + foreach ($days as $day => $str) { + if (!array_key_exists($day, $html)) + $html[$day] = $day.'#closed'; + } + + ksort($html); + return implode('~', $html); } } \ No newline at end of file diff --git a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Pocztk48Op.php b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Pocztk48Op.php index 2190544..d582aa5 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Pocztk48Op.php +++ b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Pocztk48Op.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -33,12 +33,12 @@ public function loadItemsFromApi(object $address) { curl_setopt($ch, CURLOPT_URL, $this->getConfigData('api_url')); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json', - 'Content-Type: application/json; charset="utf-8"' + 'Content-Type: application/json; charset="utf-8"', ]); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ 'latitude' => $address->getData('lat'), 'longitude' => $address->getData('lng'), - 'type' => explode(',', $this->getConfigData('allowed_methods')) + 'type' => explode(',', $this->getConfigData('allowed_methods')), ])); $items = []; diff --git a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Przesodbpk.php b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Przesodbpk.php index 1cae55f..ca66359 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Przesodbpk.php +++ b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Przesodbpk.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -65,19 +65,19 @@ protected function createDesc($data) { $html = []; $days = [ - '1 Monday' => is_array($data['monday']) ? $data['monday'] : explode('–', str_replace([':', ', '], ['', '–'], $data['monday'])), - '2 Tuesday' => is_array($data['tuesday']) ? $data['tuesday'] : explode('–', str_replace([':', ', '], ['', '–'], $data['tuesday'])), - '3 Wednesday' => is_array($data['wednesday']) ? $data['wednesday'] : explode('–', str_replace([':', ', '], ['', '–'], $data['wednesday'])), - '4 Thursday' => is_array($data['thursday']) ? $data['thursday'] : explode('–', str_replace([':', ', '], ['', '–'], $data['thursday'])), - '5 Friday' => is_array($data['friday']) ? $data['friday'] : explode('–', str_replace([':', ', '], ['', '–'], $data['friday'])), - '6 Saturday' => is_array($data['saturday']) ? $data['saturday'] : explode('–', str_replace([':', ', '], ['', '–'], $data['saturday'])), - '7 Sunday' => is_array($data['sunday']) ? $data['sunday'] : explode('–', str_replace([':', ', '], ['', '–'], $data['sunday'])) + 1 => is_array($data['monday']) ? $data['monday'] : explode('–', str_replace([':', ', '], ['', '–'], $data['monday'])), + 2 => is_array($data['tuesday']) ? $data['tuesday'] : explode('–', str_replace([':', ', '], ['', '–'], $data['tuesday'])), + 3 => is_array($data['wednesday']) ? $data['wednesday'] : explode('–', str_replace([':', ', '], ['', '–'], $data['wednesday'])), + 4 => is_array($data['thursday']) ? $data['thursday'] : explode('–', str_replace([':', ', '], ['', '–'], $data['thursday'])), + 5 => is_array($data['friday']) ? $data['friday'] : explode('–', str_replace([':', ', '], ['', '–'], $data['friday'])), + 6 => is_array($data['saturday']) ? $data['saturday'] : explode('–', str_replace([':', ', '], ['', '–'], $data['saturday'])), + 7 => is_array($data['sunday']) ? $data['sunday'] : explode('–', str_replace([':', ', '], ['', '–'], $data['sunday'])) ]; - // Array ( [1 Monday] => Array ( [0] => 0830 [1] => 1830 ) ) - // Array ( [1 Monday] => Array ( [0] => 0830 [1] => 1230, [2] => 1530 [3] => 1830 ) ) + // Array ( [0] => 0000 [1] => 2359 ) + // Array ( [0] => 0001 [1] => 2359 [2] => 0000 [3] => 0000 ) $always = array_unique(array_values(array_map('implode', $days))); - if ((count($always) == 1) && in_array($always[0], ['00002359', '00012359'])) + if ((count($always) == 1) && in_array($always[0], ['00002359', '00012359', '0000235900000000', '0001235900000000'])) return '24/7'; foreach ($days as $day => $str) { @@ -104,6 +104,12 @@ protected function createDesc($data) { } } - return implode("\n", $html); + foreach ($days as $day => $str) { + if (!array_key_exists($day, $html)) + $html[$day] = $day.'#closed'; + } + + ksort($html); + return implode('~', $html); } } \ No newline at end of file diff --git a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Shiptor.php b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Shiptor.php index d0ecd75..93c11e6 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Shiptor.php +++ b/src/app/code/community/Kyrena/Shippingmax/Model/Carrier/Shiptor.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -36,7 +36,7 @@ public function loadItemsFromApi(object $address) { curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Accept: application/json', 'Content-Type: application/json; charset="utf-8"', - 'X-Authorization-Token: ваш_API_ключ' + 'X-Authorization-Token: ваш_API_ключ', ]); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ 'id' => 'JsonRpcClient.js', @@ -101,13 +101,13 @@ protected function createDesc($data) { foreach ($data['work_shedule_obj']['schedule'] as $str) { if (!empty($str['workTime'])) { $days = [ - '1 Monday' => $data['work_shedule_obj']['schedule'][1], - '2 Tuesday' => $data['work_shedule_obj']['schedule'][2], - '3 Wednesday' => $data['work_shedule_obj']['schedule'][3], - '4 Thursday' => $data['work_shedule_obj']['schedule'][4], - '5 Friday' => $data['work_shedule_obj']['schedule'][5], - '6 Saturday' => $data['work_shedule_obj']['schedule'][6], - '7 Sunday' => $data['work_shedule_obj']['schedule'][0], + 1 => $data['work_shedule_obj']['schedule'][1], + 2 => $data['work_shedule_obj']['schedule'][2], + 3 => $data['work_shedule_obj']['schedule'][3], + 4 => $data['work_shedule_obj']['schedule'][4], + 5 => $data['work_shedule_obj']['schedule'][5], + 6 => $data['work_shedule_obj']['schedule'][6], + 7 => $data['work_shedule_obj']['schedule'][0], ]; break; } @@ -118,13 +118,13 @@ protected function createDesc($data) { $data = explode(';', $data['work_schedule']); if (count($data) == 7) { $days = [ - '1 Monday' => $data[0], - '2 Tuesday' => $data[1], - '3 Wednesday' => $data[2], - '4 Thursday' => $data[3], - '5 Friday' => $data[4], - '6 Saturday' => $data[5], - '7 Sunday' => $data[6], + 1 => $data[0], + 2 => $data[1], + 3 => $data[2], + 4 => $data[3], + 5 => $data[4], + 6 => $data[5], + 7 => $data[6], ]; } } @@ -132,6 +132,11 @@ protected function createDesc($data) { if (empty($days)) return ''; + // Array ( [0] => 1#09#00#22#00 ) + $always = array_unique(array_map(static function ($v) { return substr($v, strpos($v, '#')); }, $html)); + if ((count($always) == 1) && in_array($always[0], ['#00#00#23#59', '#00#01#23#59'])) + return '24/7'; + $html = []; foreach ($days as $day => $str) { @@ -177,11 +182,12 @@ protected function createDesc($data) { } } - // Array ( [0] => 1 Monday#09#00#22#00 ) - $always = array_unique(array_map(static function ($v) { return substr($v, strpos($v, '#')); }, $html)); - if ((count($always) == 1) && in_array($always[0], ['#00#00#23#59', '#00#01#23#59'])) - return '24/7'; + foreach ($days as $day => $str) { + if (!array_key_exists($day, $html)) + $html[$day] = $day.'#closed'; + } - return implode("\n", $html); + ksort($html); + return implode('~', $html); } } \ No newline at end of file diff --git a/src/app/code/community/Kyrena/Shippingmax/Model/Configparser.php b/src/app/code/community/Kyrena/Shippingmax/Model/Configparser.php index 0322d70..f36953a 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Model/Configparser.php +++ b/src/app/code/community/Kyrena/Shippingmax/Model/Configparser.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -27,7 +27,7 @@ public function extractAllPostcodes(string $country) { foreach ($rows as $code => $row) { $shipto = $this->getRowProperty($row, 'shipto'); - if (str_contains($shipto, $country.'(')) { + if (!empty($shipto) && str_contains($shipto, $country.'(')) { $search = []; preg_match('#'.$country.'\(([^)]+)\)#', $shipto, $search); if (!empty($search[1])) diff --git a/src/app/code/community/Kyrena/Shippingmax/Model/Coords.php b/src/app/code/community/Kyrena/Shippingmax/Model/Coords.php index 5705398..2ee18e4 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Model/Coords.php +++ b/src/app/code/community/Kyrena/Shippingmax/Model/Coords.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -96,9 +96,9 @@ public function getApiUrl($city, $postcode, $country) { public function setAddressCoords(object $address, bool $withCity = true) { - $city = trim($address->getData('city')); - $postcode = trim($address->getData('postcode')); - $country = trim($address->getData('country_id')); + $city = trim((string) $address->getData('city')); + $postcode = trim((string) $address->getData('postcode')); + $country = trim((string) $address->getData('country_id')); if (empty($city) || empty($postcode) || empty($country)) return $this; diff --git a/src/app/code/community/Kyrena/Shippingmax/Model/Observer.php b/src/app/code/community/Kyrena/Shippingmax/Model/Observer.php index 1ddfc00..70939c7 100644 --- a/src/app/code/community/Kyrena/Shippingmax/Model/Observer.php +++ b/src/app/code/community/Kyrena/Shippingmax/Model/Observer.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -306,7 +306,7 @@ public function updateFullFiles($cron = null) { if (is_object($cron)) $cron->setData('messages', implode("\n", $msg))->save(); - // global + // global (ignore les autres stores) continue 2; } @@ -329,7 +329,6 @@ public function updateFullFiles($cron = null) { return $msg; } - // recherche l'id de la région // recherche uniquement si la configuration indique que l'état est obligatoire public function searchRegionId(string $country, $postcode = null, $name = null) { diff --git a/src/app/code/community/Kyrena/Shippingmax/controllers/MapController.php b/src/app/code/community/Kyrena/Shippingmax/controllers/MapController.php index 6c4802e..3701522 100644 --- a/src/app/code/community/Kyrena/Shippingmax/controllers/MapController.php +++ b/src/app/code/community/Kyrena/Shippingmax/controllers/MapController.php @@ -1,7 +1,7 @@ * Copyright 2019-2022 | Jérôme Siau @@ -22,6 +22,7 @@ class Kyrena_Shippingmax_MapController extends Mage_Core_Controller_Front_Action protected function loadItems(object $address, string $code, $session = null) { + Mage::register('address_ignore_name', true, true); $this->_countries = Mage::helper('shippingmax')->getCarrierCountries($code); // récupère l'adresse mémorisée et met à jour l'adresse de livraison @@ -147,6 +148,8 @@ protected function getShippingAddress() { if (empty($address->getData('country_id'))) $address->setData('country_id', Mage::getStoreConfig('general/country/default')); + else if ($address->getData('country_id') == 'MC') + $address->setData('country_id', 'FR'); return $address; } @@ -268,12 +271,13 @@ public function updateAction() { $session = $this->getSession(); $address = $this->getShippingAddress(); - $code = $this->getRequest()->getParam('code'); - $city = $this->getRequest()->getPost('city'); - $postcode = $this->getRequest()->getPost('postcode'); - $country = $this->getRequest()->getPost('country'); - $lat = $this->getRequest()->getPost('lat'); - $lng = $this->getRequest()->getPost('lng'); + $request = $this->getRequest(); + $code = $request->getParam('code'); + $city = $request->getPost('city'); + $postcode = $request->getPost('postcode'); + $country = $request->getPost('country'); + $lat = $request->getPost('lat'); + $lng = $request->getPost('lng'); if (($country == 'RU') && Mage::getStoreConfigFlag('carriers/shippingmax/search_by_street')) { $message = $this->__('Please enter your street (or your postal code) and city.'); @@ -294,7 +298,7 @@ public function updateAction() { $data['city'] = $city; $data['postcode'] = $postcode; $data['country_id'] = $country; - $data['geoloc'] = !empty($this->getRequest()->getPost('geoloc')); + $data['geoloc'] = !empty($request->getPost('geoloc')); if (!empty($lat)) $data['lat'] = $lat; if (!empty($lng)) $data['lng'] = $lng; $session->setData($code, $data); @@ -313,6 +317,7 @@ public function updateAction() { // réponse if ($this->isAjax()) { + $this->loadLayout(); $this->initOurLayoutMessages(); $html = $this->getLayout()->getBlock('maplist') @@ -323,27 +328,31 @@ public function updateAction() { ->setData('geoloc', $data['geoloc']) ->toHtml(); - $this->getResponse()->setHeader('Content-Type', 'application/json', true); - $this->getResponse()->setHeader('Cache-Control', 'no-cache, must-revalidate', true); - $this->getResponse()->setBody(json_encode([ - 'status' => true, - 'city' => $address->getData('city'), - 'postcode' => $address->getData('postcode'), - 'country' => $address->getData('country_id'), - 'lat' => (float) $address->getData('lat'), - 'lng' => (float) $address->getData('lng'), - 'maplist' => trim(preg_replace("#\s{2,}#", ' ', $html)), // pour le html - 'items' => $items // pour le JavaScript - ])); + $this->getResponse() + ->setHttpResponseCode(200) + ->setHeader('Content-Type', 'application/json', true) + ->setHeader('Cache-Control', 'no-cache, must-revalidate', true) + ->setBody(json_encode([ + 'status' => true, + 'city' => $address->getData('city'), + 'postcode' => $address->getData('postcode'), + 'country' => $address->getData('country_id'), + 'lat' => (float) $address->getData('lat'), + 'lng' => (float) $address->getData('lng'), + 'maplist' => trim(preg_replace("#\s{2,}#", ' ', $html)), // pour le html + 'items' => $items, // pour le JavaScript + ])); } else { $this->_redirect('*/*/index', ['code' => $code]); } } else if ($this->isAjax()) { - $this->getResponse()->setHeader('Content-Type', 'application/json', true); - $this->getResponse()->setHeader('Cache-Control', 'no-cache, must-revalidate', true); - $this->getResponse()->setBody(json_encode(['status' => false, 'error' => $message])); + $this->getResponse() + ->setHttpResponseCode(200) + ->setHeader('Content-Type', 'application/json', true) + ->setHeader('Cache-Control', 'no-cache, must-revalidate', true) + ->setBody(json_encode(['status' => false, 'error' => $message])); } else { $session->addError($message); @@ -379,28 +388,40 @@ public function saveAction() { $html = trim(preg_replace("#\s{2,}#", ' ', $this->getLayout()->getBlock('shippingmax_selected')->setData('code', $code)->toHtml())); if ($this->isAjax()) { - $this->getResponse()->setHeader('Content-Type', 'application/json', true); - $this->getResponse()->setHeader('Cache-Control', 'no-cache, must-revalidate', true); - $this->getResponse()->setBody(json_encode([ - 'status' => true, - 'code' => $code, - 'id' => $id, - 'html' => $html - ])); + $this->getResponse() + ->setHttpResponseCode(200) + ->setHeader('Content-Type', 'application/json', true) + ->setHeader('Cache-Control', 'no-cache, must-revalidate', true) + ->setBody(json_encode([ + 'status' => true, + 'code' => $code, + 'id' => $id, + 'html' => $html, + ])); } else { - $this->getResponse()->setBody(''); + $this->getResponse() + ->setHttpResponseCode(200) + ->setHeader('Content-Type', 'text/html; charset=utf-8', true) + ->setHeader('Cache-Control', 'no-cache, must-revalidate', true) + ->setBody('shippingmax'. + ''. + ''. + '' + ); } } else if ($this->isAjax()) { - $this->getResponse()->setHeader('Content-Type', 'application/json', true); - $this->getResponse()->setHeader('Cache-Control', 'no-cache, must-revalidate', true); - $this->getResponse()->setBody(json_encode(['status' => false, 'error' => 'refresh'])); + $this->getResponse() + ->setHttpResponseCode(200) + ->setHeader('Content-Type', 'application/json', true) + ->setHeader('Cache-Control', 'no-cache, must-revalidate', true) + ->setBody(json_encode(['status' => false, 'error' => 'refresh'])); } else { $this->_redirect('*/*/index', ['code' => $code]); @@ -466,12 +487,16 @@ public function debugAction() { '
cache:keys/count: '.print_r($cache, true); } - $this->getResponse()->setBody( - 'shippingmax'. - ''. - '
'.
-			date('c').$link.'

'.$text. - '
'); + $this->getResponse() + ->setHttpResponseCode(200) + ->setHeader('Content-Type', 'text/html; charset=utf-8', true) + ->setHeader('Cache-Control', 'no-cache, must-revalidate', true) + ->setBody( + 'shippingmax'. + ''. + ''. + '
'.date('c').$link.'

'.$text.'
' + ); } public function debugclearcacheAction() { diff --git a/src/app/code/community/Kyrena/Shippingmax/etc/config.xml b/src/app/code/community/Kyrena/Shippingmax/etc/config.xml index f721545..ad8aa54 100644 --- a/src/app/code/community/Kyrena/Shippingmax/etc/config.xml +++ b/src/app/code/community/Kyrena/Shippingmax/etc/config.xml @@ -1,7 +1,7 @@