Skip to content

Commit

Permalink
Version 2.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifab committed Oct 10, 2022
1 parent 5cb7afa commit db7f7d0
Show file tree
Hide file tree
Showing 36 changed files with 415 additions and 277 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<br>source of data: a TSV file |
| **Store locator** | | [online demo](https://cellu.blue/h9dhKJ)<br>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

Expand Down Expand Up @@ -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)
Expand All @@ -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`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created V/21/05/2021
* Updated M/05/07/2022
* Updated D/11/09/2022
*
* Copyright 2019-2022 | Fabrice Creuzot <fabrice~cellublue~com>
* Copyright 2019-2022 | Jérôme Siau <jerome~cellublue~com>
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created J/04/06/2020
* Updated V/20/05/2022
* Updated D/11/09/2022
*
* Copyright 2019-2022 | Fabrice Creuzot <fabrice~cellublue~com>
* Copyright 2019-2022 | Jérôme Siau <jerome~cellublue~com>
Expand All @@ -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;

Expand Down Expand Up @@ -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}');
Expand All @@ -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);
Expand All @@ -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'),
Expand Down
10 changes: 6 additions & 4 deletions src/app/code/community/Kyrena/Shippingmax/Block/Selected.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created V/12/04/2019
* Updated J/23/12/2021
* Updated J/29/09/2022
*
* Copyright 2019-2022 | Fabrice Creuzot <fabrice~cellublue~com>
* Copyright 2019-2022 | Jérôme Siau <jerome~cellublue~com>
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 11 additions & 12 deletions src/app/code/community/Kyrena/Shippingmax/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created V/12/04/2019
* Updated V/24/06/2022
* Updated D/11/09/2022
*
* Copyright 2019-2022 | Fabrice Creuzot <fabrice~cellublue~com>
* Copyright 2019-2022 | Jérôme Siau <jerome~cellublue~com>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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 = [];

Expand All @@ -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) {

Expand All @@ -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,
Expand All @@ -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);
}
Expand Down
9 changes: 5 additions & 4 deletions src/app/code/community/Kyrena/Shippingmax/Model/Carrier.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created V/12/04/2019
* Updated L/08/08/2022
* Updated D/18/09/2022
*
* Copyright 2019-2022 | Fabrice Creuzot <fabrice~cellublue~com>
* Copyright 2019-2022 | Jérôme Siau <jerome~cellublue~com>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit db7f7d0

Please sign in to comment.