Skip to content

Commit

Permalink
Merge pull request #273 from Zasilkovna/PES-1487_button_hiding_fix
Browse files Browse the repository at this point in the history
PES-1487: widget button display fix
  • Loading branch information
zemekoule authored Jul 28, 2023
2 parents 9d88cc0 + c599e5b commit 5d91f8b
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 10 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Návod v češtině](#modul-pro-prestashop-17)

# Module for PrestaShop 1.7
# Module for PrestaShop 1.7, PrestaShop 8

### Download link
[Download the latest version](https://github.com/Zasilkovna/prestashop/releases/latest)
Expand Down Expand Up @@ -75,7 +75,7 @@ In the **Orders** tab you will find a list of all orders for which the Packeta s
- english

### Supported versions
- PrestaShop version 1.7.x.
- PrestaShop 1.7.x., PrestaShop 8
- If you have problems using the module, please contact us at [[email protected]](mailto:[email protected]).

### Provided functions
Expand All @@ -102,12 +102,12 @@ Packeta module may not work with another OPC module.
| Module version | Branch | PHP version |
|----------------|----------|-------------|
| `>= 2.1.18` | `master` | 5.6 - 8.2 |
| `>= 3.0` | `v3.0.0` | 5.6 - 8.2 |
| `>= 3.0` | `v3` | 5.6 - 8.2 |

### Further module limitations
- Module does not currently support multistore.

# Modul pro PrestaShop 1.7
# Modul pro PrestaShop 1.7, PrestaShop 8

### Stažení modulu
[Aktuální verze (Stáhnout »)](https://github.com/Zasilkovna/prestashop/releases/latest)
Expand Down Expand Up @@ -185,7 +185,7 @@ V záložce **objednávky** naleznete seznam všech objednávek u kterých byla
- angličtina

### Podporovaná verze
- PrestaShop verze 1.7.x.
- PrestaShop 1.7.x., PrestaShop 8
- Při problému s použitím modulu nás kontaktujte na adrese [[email protected]](mailto:[email protected]).

### Poskytované funkce
Expand All @@ -211,7 +211,7 @@ Modul Zásilkovny nemusí být s jiným OPC modulem funkční.
| Verze modulu | Větev | PHP verze |
|--------------|----------|-----------|
| `>= 2.1.18` | `master` | 5.6 - 8.2 |
| `>= 3.0` | `v3.0.0` | 5.6 - 8.2 |
| `>= 3.0` | `v3` | 5.6 - 8.2 |

### Další omezení modulu
- Modul v současné době nepodporuje multistore.
1 change: 1 addition & 0 deletions packetery/CHANGE_LOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
2.1.19 - Fixed: displaying the widget button and cart validation
2.1.18 - Updated: compatibility with PrestaShop 8 ensured
2.1.17 - Updated: sk "Is COD" translation update
- Updated: improvements to the display of widget button in the cart
Expand Down
48 changes: 48 additions & 0 deletions packetery/libs/Module/Helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Packetery\Module;

class Helper
{

/**
* @param mixed $value
*
* @return bool
*/
private static function isCastableToInt($value)
{
if (is_int($value)) {
return true;
}
if (is_string($value) && strlen((string)(float)$value) !== strlen($value)) {
return false;
}
if (is_float($value) || is_string($value)) {
if ($value <= PHP_INT_MAX && $value >= -PHP_INT_MAX) {
return (int)$value == $value;
}

return false;
}

return false;
}

/**
* @param array $array
*
* @return array
*/
public static function typeCastableArrayItemsAsInts(array $array)
{
foreach ($array as $key => $value) {
if (self::isCastableToInt($value)) {
$array[$key] = (int)$value;
}
}

return $array;
}

}
7 changes: 5 additions & 2 deletions packetery/packetery.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct()
{
$this->name = 'packetery';
$this->tab = 'shipping_logistics';
$this->version = '2.1.18';
$this->version = '2.1.19';
$this->author = 'Packeta s.r.o.';
$this->need_instance = 0;
$this->is_configurable = 1;
Expand Down Expand Up @@ -568,8 +568,11 @@ public function hookDisplayCarrierExtraContent($params)
);
if (!$zPointCarriers) {
$zPointCarriers = [];
} else {
$zPointCarriers = array_column($zPointCarriers, 'id_carrier');
$zPointCarriers = Packetery\Module\Helper::typeCastableArrayItemsAsInts($zPointCarriers);
}
$zPointCarriersIdsJSON = json_encode(array_column($zPointCarriers, 'id_carrier'));
$zPointCarriersIdsJSON = json_encode($zPointCarriers);
$this->context->smarty->assign('zpoint_carriers', $zPointCarriersIdsJSON);
$name_branch = '';
$currency_branch = '';
Expand Down
4 changes: 2 additions & 2 deletions packetery/views/js/front.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,10 @@ tools = {
}

if ($extra.find('#open-packeta-widget').length) {
var carrierId = String($extra.find('#carrier_id').val());
var carrierId = parseInt($extra.find('#carrier_id').val());
var zpointCarriers = $extra.find('#zpoint_carriers').val();
zpointCarriers = JSON.parse(zpointCarriers);
if (!zpointCarriers.includes(parseInt(carrierId))) {
if (!zpointCarriers.includes(carrierId)) {
$extra.find('#open-packeta-widget').hide();
$extra.find('#selected-branch').hide();
}
Expand Down

0 comments on commit 5d91f8b

Please sign in to comment.