Skip to content

Commit

Permalink
Version 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luigifab committed Feb 2, 2023
1 parent fc46b34 commit 2076b43
Show file tree
Hide file tree
Showing 76 changed files with 2,531 additions and 2,342 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ To display delivery times, you must edit your template with:

## Copyright and Credits

- Current version: 2.7.0 (01/01/2023)
- Current version: 3.0.0 (02/02/2023)
- Compatibility: OpenMage 19.x / 20.x / 21.x, PHP 7.2 / 7.3 / 7.4 / 8.0 / 8.1 / 8.2
- 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 Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created V/21/05/2021
* Updated M/06/12/2022
* Updated M/24/01/2023
*
* Copyright 2019-2023 | Fabrice Creuzot <fabrice~cellublue~com>
* Copyright 2019-2022 | Jérôme Siau <jerome~cellublue~com>
Expand All @@ -26,22 +26,27 @@ public function render(Varien_Data_Form_Element_Abstract $element) {

$html = [];
$help = $this->helper('shippingmax');
$code = (string) str_replace('carriers_', '', $element->getId()); // (yes)
$code = (string) str_replace('carriers_', '', $element->getHtmlId()); // (yes)

$storeId = $this->getStoreId();
$comment = $element->getComment();
$comment = empty($comment) ? '' : '<p>'.$comment.'</p>';
$maxAmounts = Mage::getStoreConfig('carriers/'.$code.'/max_amounts');
$maxWeight = Mage::getStoreConfig('carriers/'.$code.'/max_weight');

$defaultCountry = Mage::getStoreConfig('general/country/default', $storeId);
$allCountries = Mage::getStoreConfig('carriers/'.$code.'/allowedcountry');
$allCountries = empty($allCountries) ? [] : array_filter(explode(',', $allCountries)); // config.xml
$allCountries = empty($allCountries) ? [] : array_filter(explode(',', $allCountries));
$selCountries = $help->getCarrierCountries($code, $storeId);
//$euCountries = explode(',', Mage::getStoreConfig('general/country/eu_countries'));

// pays du mode de livraison
// fait la liste, si elle est vide, c'est que tous les pays sont autorisés
if ($selCountries != $allCountries) {
if (!empty($allCountries) && ($selCountries != $allCountries)) {

$html['all'][] = '<p><span>'.$this->__('Allowed countries (%d) for this method:', count($allCountries)).'</span></p>';
$html['all'][] = '<ul>';

$html['all'][] = $this->__('Allowed countries for this method:').' ';
foreach ($allCountries as $country) {

$name = Mage::getModel('directory/country')->loadByCode($country)->getName();
Expand All @@ -50,70 +55,91 @@ public function render(Varien_Data_Form_Element_Abstract $element) {
if (!empty($maxAmounts[$key]['amount'])) {
$max = $help->getNumber($maxAmounts[$key]['amount'], ['precision' => 2]);
if ($country == $defaultCountry)
$html['all'][] = '<u><span title="'.addslashes($this->__('Default Country')).' - '.$name.', max '.$max.' '.$maxAmounts[$key]['currency'].'">'.$country.'</span></u>';
$html['all'][$country] = '<li><strong title="'.addslashes($this->__('Default Country')).'">'.$this->getFlag($country).'&nbsp;'.$country.' - '.$name.'</strong> <em>(max '.$max.' '.$maxAmounts[$key]['currency'].')</em></li>';
else
$html['all'][] = '<span title="'.$name.', max '.$max.' '.$maxAmounts[$key]['currency'].'">'.$country.'</span>';
$html['all'][$country] = '<li>'.$this->getFlag($country).'&nbsp;'.$country.' - '.$name.' <em>(max '.$max.' '.$maxAmounts[$key]['currency'].')</em></li>';
}
else if ($country == $defaultCountry) {
$html['all'][] = '<u><span title="'.addslashes($this->__('Default Country')).' - '.$name.'">'.$country.'</span></u>';
$html['all'][$country] = '<li><strong title="'.addslashes($this->__('Default Country')).'">'.$this->getFlag($country).'&nbsp;'.$country.' - '.$name.'</strong></li>';
}
else {
$html['all'][] = '<span title="'.$name.'">'.$country.'</span>';
$html['all'][$country] = '<li>'.$this->getFlag($country).'&nbsp;'.$country.' - '.$name.'</li>';
}
}

if (empty($allCountries)) {
$html['all'][] = '<a href="'.$this->getUrl('*/*/*', ['section' => 'general', 'store' => $this->getRequest()->getParam('store'), 'website' => $this->getRequest()->getParam('website')]).'">'.$this->__('All Allowed Countries').'</a>';
//if (in_array($country, $euCountries)) {
// $key = count($html['all']) - 1;
//}
}

ksort($html['all'], SORT_NATURAL);
$html['all'][] = '</ul>';
}
else if (!empty($allCountries)) {
$html['all'][] = '<p><span>'.$this->__('Allowed countries (%d) for this method:', count($allCountries)).'</span> '.
'<img src="'.$this->getSkinUrl('images/sort-arrow-down.png').'" class="v-middle" /></p>';
}
else {
$defCountries = array_filter(explode(',', Mage::getStoreConfig('general/country/allow', $storeId)));
$html['all'][] = '<p><span>'.$this->__('Allowed countries (%d) for this method:', count($defCountries)).'</span>'.
' <a href="'.$this->getUrl('*/*/*', ['section' => 'general', 'store' => $this->getRequest()->getParam('store'), 'website' => $this->getRequest()->getParam('website')]).'">'.$this->__('All Allowed Countries').'</a>'.'</p>';
}

// pays possibles pour les clients
// fait la liste, si elle est vide, c'est qu'aucun pays n'est autorisé
$html['sel'][] = $this->__('Allowed countries for customers:').' ';
foreach ($selCountries as $country) {

$name = Mage::getModel('directory/country')->loadByCode($country)->getName();
$key = strtolower($country);

if (!empty($maxAmounts[$key]['amount'])) {
$max = $help->getNumber($maxAmounts[$key]['amount'], ['precision' => 2]);
if ($country == $defaultCountry)
$html['sel'][] = '<u title="'.addslashes($this->__('Default Country')).'"><strong>'.$country.'</strong>&nbsp;<em>('.$name.', max '.$max.'&nbsp;'.$maxAmounts[$key]['currency'].')</em></u>';
else
$html['sel'][] = '<strong>'.$country.'</strong>&nbsp;<em>('.$name.', max '.$max.'&nbsp;'.$maxAmounts[$key]['currency'].')</em>';
}
else if ($country == $defaultCountry) {
$html['sel'][] = '<u title="'.addslashes($this->__('Default Country')).'"><strong>'.$country.'</strong>&nbsp;<em>('.$name.')</em></u>';
}
else {
$html['sel'][] = '<strong>'.$country.'</strong>&nbsp;<em>('.$name.')</em>';
if (!empty($selCountries)) {

$html['sel'][] = '<p><span>'.$this->__('Allowed countries (%d) for customers:', count($selCountries)).'</span></p>';
$html['sel'][] = '<ul>';

foreach ($selCountries as $country) {

$name = Mage::getModel('directory/country')->loadByCode($country)->getName();
$key = strtolower($country);

if (!empty($maxAmounts[$key]['amount'])) {
$max = $help->getNumber($maxAmounts[$key]['amount'], ['precision' => 2]);
if ($country == $defaultCountry)
$html['sel'][$country] = '<li><strong title="'.addslashes($this->__('Default Country')).'">'.$this->getFlag($country).'&nbsp;'.$country.' - '.$name.'</strong> <em>(max '.$max.' '.$maxAmounts[$key]['currency'].')</em></li>';
else
$html['sel'][$country] = '<li>'.$this->getFlag($country).'&nbsp;'.$country.' - '.$name.' <em>(max '.$max.' '.$maxAmounts[$key]['currency'].')</em></li>';
}
else if ($country == $defaultCountry) {
$html['sel'][$country] = '<li><strong title="'.addslashes($this->__('Default Country')).'">'.$this->getFlag($country).'&nbsp;'.$country.' - '.$name.'</strong></li>';
}
else {
$html['sel'][$country] = '<li>'.$this->getFlag($country).'&nbsp;'.$country.' - '.$name.'</li>';
}

//if (in_array($country, $euCountries)) {
// $key = count($html['sel']) - 1;
//}
}
}

if (empty($selCountries)) {
$html['sel'][] = '<a href="'.$this->getUrl('*/*/*', ['section' => 'general', 'store' => $this->getRequest()->getParam('store'), 'website' => $this->getRequest()->getParam('website')]).'">'.$this->__('None').'</a>';
ksort($html['sel'], SORT_NATURAL);
$html['sel'][] = '</ul>';
}
else {
$html['sel'][] = '<p><span>'.$this->__('Allowed countries (%d) for customers:', 0).'</span>'.
' <a href="'.$this->getUrl('*/*/*', ['section' => 'general', 'store' => $this->getRequest()->getParam('store'), 'website' => $this->getRequest()->getParam('website')]).'">'.$this->__('None').'</a></p>';
}

// final
$this->_html = str_replace(': ,', ': ',
$this->_html =
'<div class="comment shippingmax">'.
(empty($svg = Mage::getStoreConfig('carriers/'.$code.'/img_backend')) ? '' : '<img src="'.$this->getSkinUrl('images/kyrena/shippingmax/'.$svg).'" alt="" class="shippingmax logo" />').
((($code == 'shippingmax_storelocator') || !str_contains($code, 'shippingmax_')) ? '' : '<p>'.$this->__('Maximum weight: %d kg.', empty($maxWeight) ? 30 : $maxWeight).'</p>').
(empty($html['all']) ? '' : '<p>'.implode(', ', $html['all']).'.</p>').
(empty($html['sel']) ? '' : '<p>'.implode(', ', $html['sel']).'.</p>').
'</div>');

// drapeau utf8
$flag = '';
if (preg_match('#^[A-Z]{2} - #', $element->getLegend()) === 1) {
$flag = substr($element->getLegend(), 0, 2);
$flag = mb_convert_encoding('&#'.(127397 + ord($flag[0])).';', 'UTF-8', 'HTML-ENTITIES').
mb_convert_encoding('&#'.(127397 + ord($flag[1])).';', 'UTF-8', 'HTML-ENTITIES').
' &nbsp;';
}

// marquage
$element->setLegend($flag.$element->getLegend().((in_array($defaultCountry, $selCountries) && Mage::getStoreConfigFlag('carriers/'.$code.'/active', $storeId)) ? ' *' : ''));
$comment.
((($code != 'shippingmax_storelocator') && str_contains($code, 'shippingmax_')) ? '<p>'.$this->__('Maximum weight: %d kg.', empty($maxWeight) ? 30 : $maxWeight).'</p>' : ''). // @see Kyrena_Shippingmax_Model_Carrier::checkMaxWeight
'<div class="countries">'.
(empty($html['all']) ? '' : implode($html['all'])).
(empty($html['sel']) ? '' : implode($html['sel'])).
'</div>'.
'</div>';

// drapeau et éventuel marquage
$legend = $element->getLegend();
$flag = (preg_match('#^[A-Z]{2} - #', $legend) === 1) ? $this->getFlag(substr($legend, 0, 2)).'&nbsp;&nbsp;' : '';
$element->setLegend($flag.$legend.
((in_array($defaultCountry, $selCountries) && Mage::getStoreConfigFlag('carriers/'.$code.'/active', $storeId)) ? ' *' : ''));

return parent::render($element);
}
Expand All @@ -122,6 +148,11 @@ protected function _getHeaderCommentHtml($element) {
return $this->_html ?? parent::_getHeaderCommentHtml($element);
}

protected function getFlag($code) {
return mb_convert_encoding('&#'.(127397 + ord($code[0])).';', 'UTF-8', 'HTML-ENTITIES').
mb_convert_encoding('&#'.(127397 + ord($code[1])).';', 'UTF-8', 'HTML-ENTITIES');
}

protected function getStoreId() {

$store = $this->getRequest()->getParam('store');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Created J/05/01/2023
* Updated M/24/01/2023
*
* Copyright 2019-2023 | Fabrice Creuzot <fabrice~cellublue~com>
* Copyright 2019-2022 | Jérôme Siau <jerome~cellublue~com>
* https://github.com/kyrena/openmage-shippingmax
*
* This program is free software, you can redistribute it or modify
* it under the terms of the GNU General Public License (GPL) as published
* by the free software foundation, either version 2 of the license, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but without any warranty, without even the implied warranty of
* merchantability or fitness for a particular purpose. See the
* GNU General Public License (GPL) for more details.
*/

class Kyrena_Shippingmax_Block_Adminhtml_Config_Countries extends Mage_Adminhtml_Block_System_Config_Form_Field {

protected $_options;

public function render(Varien_Data_Form_Element_Abstract $element) {

if (!$this->_options)
$this->_options = Mage::getResourceModel('directory/country_collection')->loadData()->toOptionArray(false);

$code = (string) str_replace(['carriers_', '_specificcountry'], '', $element->getHtmlId()); // (yes)
$countries = Mage::getStoreConfig('carriers/'.$code.'/allowedcountry');
$countries = empty($countries) ? [] : array_filter(explode(',', $countries));

$options = [];
foreach ($this->_options as $option) {
if (empty($countries) || in_array($option['value'], $countries))
$options[] = $option;
}

$element->setValues($options);
return parent::render($element);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created L/13/09/2021
* Updated L/13/09/2021
* Updated L/02/01/2023
*
* Copyright 2019-2023 | Fabrice Creuzot <fabrice~cellublue~com>
* Copyright 2019-2022 | Jérôme Siau <jerome~cellublue~com>
Expand All @@ -23,9 +23,21 @@ class Kyrena_Shippingmax_Block_Adminhtml_Config_Tooltip extends Mage_Adminhtml_B
public function render(Varien_Data_Form_Element_Abstract $element) {

if (!empty(Mage::getConfig()->getNode('modules/Owebia_Shipping2/lite')))
$element->setTooltip((empty($text = $element->getTooltip()) ? '' : $text.'<br /><br />').'<u>Only with Owebia/Shipping 2.6.10-<b>lite</b>:</u><br />label is optional<br />{config.x-y-z}<br />fees (default)<br />fees_eur (for stores in EUR)<br />conditons (default)<br />conditons_pln (for stores in PLN)');
$element->setTooltip(
(empty($text = $element->getTooltip()) ? '' : $text.'<br /><br />').
'<u>Only with Owebia/Shipping 2.6.10-<b>lite</b>:</u>'.
'<br />label is optional'.
'<br />{config.x-y-z}'.
'<br />fees (default)'.
'<br />fees_eur (for stores in EUR)'.
'<br />conditons (default)'.
'<br />conditons_pln (for stores in PLN)');

$element->setComment('<a href="https://owebia.com/os2/en/doc">owebia.com/os2/en/doc</a>'.(empty($text = $element->getComment()) ? '' : '<br />'.$text));
$element->setComment(
'<strong>'.str_replace('"eval"', '<a href="https://www.php.net/eval">eval</a>', $this->__('Never copy/paste unreliable data, because they are "eval" and they can destroy your website!')).'</strong>'.
'<br /><a href="https://owebia.com/os2/en/doc">owebia.com/os2/en/doc</a>'.
(empty($text = $element->getComment()) ? '' : '<br />'.$text)
);

return parent::render($element);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created V/26/04/2019
* Updated J/29/12/2022
* Updated S/14/01/2023
*
* Copyright 2019-2023 | Fabrice Creuzot <fabrice~cellublue~com>
* Copyright 2019-2022 | Jérôme Siau <jerome~cellublue~com>
Expand Down Expand Up @@ -86,7 +86,7 @@ public function getInfos(bool $showTitle = true, bool $showPrice = true, bool $s
$lnk2 = 'https://www.google.eu/maps/dir//'.$point['lat'].','.$point['lng'];
$html[] = '<div class="info" style="margin-top:10px;">'.
(empty($point['description']) ? '' : $help->formatDesc($point['description']).'<br />').
'<button type="button" class="slink" onclick="shippingmax.open(\''.$lnk1.'\');">'.$this->__('Show map').'</button> / <button type="button" class="slink" onclick="window.open(\''.$lnk2.'\');">'.$this->__('Go to the pick up station').'</button>'.
'<button type="button" class="slink" onclick="shippingmax.open(\''.$lnk1.'\');">'.$this->__('Show map').'</button> / <button type="button" class="slink" onclick="self.open(\''.$lnk2.'\');">'.$this->__('Go to the pick up station').'</button>'.
'</div>';
}
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Created V/26/04/2019
* Updated V/02/12/2022
* Updated S/14/01/2023
*
* Copyright 2019-2023 | Fabrice Creuzot <fabrice~cellublue~com>
* Copyright 2019-2022 | Jérôme Siau <jerome~cellublue~com>
Expand Down Expand Up @@ -65,7 +65,7 @@ public function getInfos(bool $showTitle = true, bool $showPrice = true, bool $s
$lnk2 = 'https://www.google.eu/maps/dir//'.$point['lat'].','.$point['lng'];
$html[] = '<span class="info">'.
'<br /><br />'.(empty($point['description']) ? '' : $help->formatDesc($point['description']).'<br /><br />').
'<button type="button" class="slink" onclick="shippingmax.open(\''.$lnk1.'\');">'.$this->__('Show map').'</button> / <button type="button" class="slink" onclick="window.open(\''.$lnk2.'\');">'.$this->__('Go to the pick up station').'</button>'.
'<button type="button" class="slink" onclick="shippingmax.open(\''.$lnk1.'\');">'.$this->__('Show map').'</button> / <button type="button" class="slink" onclick="self.open(\''.$lnk2.'\');">'.$this->__('Go to the pick up station').'</button>'.
'</span>';
}
else {
Expand Down
38 changes: 24 additions & 14 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/29/09/2022
* Updated J/29/12/2022
*
* Copyright 2019-2023 | Fabrice Creuzot <fabrice~cellublue~com>
* Copyright 2019-2022 | Jérôme Siau <jerome~cellublue~com>
Expand All @@ -28,26 +28,36 @@ public function getItem(string $code, $rate = null) {
$address = $object->getAddress();
$country = $address->getData('country_id');

// récupère le point relais sélectionné
// remplace Monaco par France (MC = FR)
$country = ($country == 'MC') ? 'FR' : $country;

// récupère l'éventuel point de livraison déjà sélectionné
$help = $this->helper('shippingmax');
$data = $help->getSession()->getData($code);

// récupère depuis les dernières commandes
if (empty($data['item']) && is_object($rate) && (empty($data['from_orders']) || ($data['from_orders'] != $country)))
$data = $help->getItemFromLastOrder($code, $country, $rate);
// s'il n'y a pas de point de livraison déjà sélectionné ou s'il n'est pas sur le bon pays
// récupère l'éventuel point de livraison depuis les dernières commandes par rapport au pays de l'adresse
if (is_object($rate) &&
(empty($data['item']['country_id']) || ($data['item']['country_id'] != $country)) &&
(empty($data['from_orders']) || ($data['from_orders'] != $country))
) {
$data = $help->getItemFromLastOrder($address, $rate, $code);
if (!empty($data['item']))
$data['item']['from_orders'] = $country;
$data['from_orders'] = $country;
$data['saved_at'] = date('c');
$data['saved_from'] = 'selected-block';
$help->getSession()->setData($code, $data);
}

if (empty($data['item']))
return false;
return new Varien_Object();

// n'autorise pas le changement de pays
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;
}
// n'autorise pas le changement de pays par rapport au pays de l'adresse
if ($data['item']['country_id'] != $country)
return new Varien_Object();

$countries = $help->getCarrierCountries($code);
return in_array($data['item']['country_id'], $countries) ? $data['item'] : false;
return new Varien_Object($data['item']);
}

public function getRateByCode(string $code) {
Expand Down
Loading

0 comments on commit 2076b43

Please sign in to comment.