Skip to content

Commit 5d91f8b

Browse files
authored
Merge pull request #273 from Zasilkovna/PES-1487_button_hiding_fix
PES-1487: widget button display fix
2 parents 9d88cc0 + c599e5b commit 5d91f8b

File tree

5 files changed

+62
-10
lines changed

5 files changed

+62
-10
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[Návod v češtině](#modul-pro-prestashop-17)
22

3-
# Module for PrestaShop 1.7
3+
# Module for PrestaShop 1.7, PrestaShop 8
44

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

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

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

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

110-
# Modul pro PrestaShop 1.7
110+
# Modul pro PrestaShop 1.7, PrestaShop 8
111111

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

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

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

216216
### Další omezení modulu
217217
- Modul v současné době nepodporuje multistore.

packetery/CHANGE_LOG.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
2.1.19 - Fixed: displaying the widget button and cart validation
12
2.1.18 - Updated: compatibility with PrestaShop 8 ensured
23
2.1.17 - Updated: sk "Is COD" translation update
34
- Updated: improvements to the display of widget button in the cart

packetery/libs/Module/Helper.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Packetery\Module;
4+
5+
class Helper
6+
{
7+
8+
/**
9+
* @param mixed $value
10+
*
11+
* @return bool
12+
*/
13+
private static function isCastableToInt($value)
14+
{
15+
if (is_int($value)) {
16+
return true;
17+
}
18+
if (is_string($value) && strlen((string)(float)$value) !== strlen($value)) {
19+
return false;
20+
}
21+
if (is_float($value) || is_string($value)) {
22+
if ($value <= PHP_INT_MAX && $value >= -PHP_INT_MAX) {
23+
return (int)$value == $value;
24+
}
25+
26+
return false;
27+
}
28+
29+
return false;
30+
}
31+
32+
/**
33+
* @param array $array
34+
*
35+
* @return array
36+
*/
37+
public static function typeCastableArrayItemsAsInts(array $array)
38+
{
39+
foreach ($array as $key => $value) {
40+
if (self::isCastableToInt($value)) {
41+
$array[$key] = (int)$value;
42+
}
43+
}
44+
45+
return $array;
46+
}
47+
48+
}

packetery/packetery.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct()
6464
{
6565
$this->name = 'packetery';
6666
$this->tab = 'shipping_logistics';
67-
$this->version = '2.1.18';
67+
$this->version = '2.1.19';
6868
$this->author = 'Packeta s.r.o.';
6969
$this->need_instance = 0;
7070
$this->is_configurable = 1;
@@ -568,8 +568,11 @@ public function hookDisplayCarrierExtraContent($params)
568568
);
569569
if (!$zPointCarriers) {
570570
$zPointCarriers = [];
571+
} else {
572+
$zPointCarriers = array_column($zPointCarriers, 'id_carrier');
573+
$zPointCarriers = Packetery\Module\Helper::typeCastableArrayItemsAsInts($zPointCarriers);
571574
}
572-
$zPointCarriersIdsJSON = json_encode(array_column($zPointCarriers, 'id_carrier'));
575+
$zPointCarriersIdsJSON = json_encode($zPointCarriers);
573576
$this->context->smarty->assign('zpoint_carriers', $zPointCarriersIdsJSON);
574577
$name_branch = '';
575578
$currency_branch = '';

packetery/views/js/front.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,10 @@ tools = {
266266
}
267267

268268
if ($extra.find('#open-packeta-widget').length) {
269-
var carrierId = String($extra.find('#carrier_id').val());
269+
var carrierId = parseInt($extra.find('#carrier_id').val());
270270
var zpointCarriers = $extra.find('#zpoint_carriers').val();
271271
zpointCarriers = JSON.parse(zpointCarriers);
272-
if (!zpointCarriers.includes(parseInt(carrierId))) {
272+
if (!zpointCarriers.includes(carrierId)) {
273273
$extra.find('#open-packeta-widget').hide();
274274
$extra.find('#selected-branch').hide();
275275
}

0 commit comments

Comments
 (0)