Closed harishkhant closed 1 year ago
Hi,
When Magento runs on PHP 8.2, it may be necessary to adjust the configuration to ensure that non-null data is passed to some functions that handle strings.
Could you please post here your configuration (at least the part using preg_match
)?
Best Regards, A.L.
we installed the below version on our magento 2.4.6. and we used php8.1 not 8.2 please note. https://nimb.ws/BFpULl
let me know if anything else.
// on récupère le nombre d'éléments dont le poids est nul $qteEltsDontPoidsNul = array_sum( array_map( function ($item) { return ($item->weight == 0)? $item->qty : 0; }, $request->all_items)); // on considère que chaque élément de poids nul pèse 1 kg $poidsDefautPourEltsPoidsNul = 1; // en kilos // calcul du poids total estimé pour les produits à poids nul $poidsTotalPourEltsDontPoidsNul = $qteEltsDontPoidsNul *$poidsDefautPourEltsPoidsNul; // nouveau poids du paquet $poidsColisEstimation = $request->package_weight + $poidsTotalPourEltsDontPoidsNul;
//application du barème pour les colis dont le poids estimé est inférieur à 30 kilos // condition de livraison : France métropolitaine ou Belgique ou Suisse
$taxeCorse = ($request->dest_country_id == 'FR' && preg_match('/^20/', $request->dest_postcode) )? 20 : 0;
if($poidsColisEstimation <= 30){ if( $request->dest_country_id == 'FR' && !preg_match('/^[0\s]9\s[78]/', $request->dest_postcode) ){ addMethod('id_013', [ 'title' => "Express", 'enabled' => ( $request->dest_country_id == 'FR' && !preg_match('/^[0\s]9\s[78]/', $request->dest_postcode) ), 'price'=> array_reduce([ [5.0, 12.95], [10.0, 16.95], [20.0, 22.95], [30.0, 26.95] ], function ($carry, $item) { global $request, $poidsColisEstimation, $taxeCorse; if (isset($carry)) return $carry; if (isset($item[0]) && ($poidsColisEstimation <= $item[0] || $item[0] == '*')) { $carry = $item[1] + $taxeCorse; } return $carry; }), ]); }
if(( in_array($request->dest_country_id, ['BE','LU']) ) ){
// 2e mode de livraison : la Belgique, le Luxembourg addMethod('id_014', [ 'title' => "Express Belgique et Luxembourg", 'enabled' => ( ( in_array($request->dest_country_id, ['BE','LU']) ) ), 'price'=> array_reduce([ [10.0, 29.95], [30.0, 65.00] ], function ($carry, $item) { global $request, $poidsColisEstimation; if (isset($carry)) return $carry; if (isset($item[0]) && ($poidsColisEstimation <= $item[0] || $item[0] == '*')) { $carry = $item[1]; } return $carry; }), ]); }
if(( in_array($request->dest_country_id, ['CH']) ) ){
// 3e mode de livraison : la Suisse addMethod('id_017', [ 'title' => "Express Suisse", 'enabled' => ( ( in_array($request->dest_country_id, ['CH']) ) ), 'price'=> array_reduce([ [5.0, 49.95], [9.0, 68.95], [10.0, 69.95], [30.0, 155.00] ], function ($carry, $item) { global $request, $poidsColisEstimation; if (isset($carry)) return $carry; if (isset($item[0]) && ($poidsColisEstimation <= $item[0] || $item[0] == '*')) { $carry = $item[1]; } return $carry; }), ]); }
if(( in_array($request->dest_country_id, ['GP','MQ','RE','MF','BL']) )){ // 4e mode de livraison : ZONING 8 CHRONOPOST - DOM addMethod('id_015', [ 'title' => "Express DOM", 'enabled' => ( ( in_array($request->dest_country_id, ['GP','MQ','RE','MF','BL']) ) ), 'price'=> array_reduce([ [1.0, 43.5], [2.0, 51.22], [4.0, 65.05], [8.0, 93.51], [10.0, 107.87], [20.0, 185.01], [30.0, 270.13] ], function ($carry, $item) { global $request, $poidsColisEstimation; if (isset($carry)) return $carry; if (isset($item[0]) && ($poidsColisEstimation <= $item[0] || $item[0] == '*')) { $carry = $item[1]; } return $carry; }), ]); }
if( ( in_array($request->dest_country_id, ['GF','YT','PM','PF','NC','WF','TF']) ) ){
// 5e mode de livraison : ZONING 9 CHRONOPOST - ULTRA MARIN / TOM addMethod('id_016', [ 'title' => "Express TOM", 'enabled' => ( ( in_array($request->dest_country_id, ['GF','YT','PM','PF','NC','WF','TF']) ) ), 'price'=> array_reduce([ [1.0, 59.06], [2.0, 71.17], [4.0, 93.64], [8.0, 136.74], [10.0, 158.02], [20.0, 275.06], [30.0, 405.04] ], function ($carry, $item) { global $request, $poidsColisEstimation; if (isset($carry)) return $carry; if (isset($item[0]) && ($poidsColisEstimation <= $item[0] || $item[0] == '*')) { $carry = $item[1]; } return $carry; }), ]); } }
if (count(getMethods(true)) == 0) { addError("Les frais de livraison ne peuvent malheureusement pas être calculés automatiquement. Veuillez nous contacter directement."); }
Hi,
You can replace preg_match('...', $request->dest_postcode)
by preg_match('...', $request->dest_postcode ?? '')
and $request->all_items
by $request->all_items ?? []
.
Best Regards, A.L.
// on récupère le nombre d'éléments dont le poids est nul $qteEltsDontPoidsNul = array_sum( array_map( function ($item) { return ($item->weight == 0)? $item->qty : 0; }, $request->all_items ?? [])); // on considère que chaque élément de poids nul pèse 1 kg $poidsDefautPourEltsPoidsNul = 1; // en kilos // calcul du poids total estimé pour les produits à poids nul $poidsTotalPourEltsDontPoidsNul = $qteEltsDontPoidsNul *$poidsDefautPourEltsPoidsNul; // nouveau poids du paquet $poidsColisEstimation = $request->package_weight + $poidsTotalPourEltsDontPoidsNul;
//application du barème pour les colis dont le poids estimé est inférieur à 30 kilos // condition de livraison : France métropolitaine ou Belgique ou Suisse
$taxeCorse = ($request->dest_country_id == 'FR' && preg_match('/^20/', $request->dest_postcode ?? '') )? 20 : 0;
if($poidsColisEstimation <= 30){ if( $request->dest_country_id == 'FR' && !preg_match('/^[0\s]9\s[78]/', $request->dest_postcode ?? '') ){ addMethod('id_013', [ 'title' => "Express", 'enabled' => ( $request->dest_country_id == 'FR' && !preg_match('/^[0\s]9\s[78]/', $request->dest_postcode ?? '') ), 'price'=> array_reduce([ [5.0, 12.95], [10.0, 16.95], [20.0, 22.95], [30.0, 26.95] ], function ($carry, $item) { global $request, $poidsColisEstimation, $taxeCorse; if (isset($carry)) return $carry; if (isset($item[0]) && ($poidsColisEstimation <= $item[0] || $item[0] == '*')) { $carry = $item[1] + $taxeCorse; } return $carry; }), ]); }
if(( in_array($request->dest_country_id, ['BE','LU']) ) ){
// 2e mode de livraison : la Belgique, le Luxembourg addMethod('id_014', [ 'title' => "Express Belgique et Luxembourg", 'enabled' => ( ( in_array($request->dest_country_id, ['BE','LU']) ) ), 'price'=> array_reduce([ [10.0, 29.95], [30.0, 65.00] ], function ($carry, $item) { global $request, $poidsColisEstimation; if (isset($carry)) return $carry; if (isset($item[0]) && ($poidsColisEstimation <= $item[0] || $item[0] == '*')) { $carry = $item[1]; } return $carry; }), ]); }
if(( in_array($request->dest_country_id, ['CH']) ) ){
// 3e mode de livraison : la Suisse addMethod('id_017', [ 'title' => "Express Suisse", 'enabled' => ( ( in_array($request->dest_country_id, ['CH']) ) ), 'price'=> array_reduce([ [5.0, 49.95], [9.0, 68.95], [10.0, 69.95], [30.0, 155.00] ], function ($carry, $item) { global $request, $poidsColisEstimation; if (isset($carry)) return $carry; if (isset($item[0]) && ($poidsColisEstimation <= $item[0] || $item[0] == '*')) { $carry = $item[1]; } return $carry; }), ]); }
if(( in_array($request->dest_country_id, ['GP','MQ','RE','MF','BL']) )){ // 4e mode de livraison : ZONING 8 CHRONOPOST - DOM addMethod('id_015', [ 'title' => "Express DOM", 'enabled' => ( ( in_array($request->dest_country_id, ['GP','MQ','RE','MF','BL']) ) ), 'price'=> array_reduce([ [1.0, 43.5], [2.0, 51.22], [4.0, 65.05], [8.0, 93.51], [10.0, 107.87], [20.0, 185.01], [30.0, 270.13] ], function ($carry, $item) { global $request, $poidsColisEstimation; if (isset($carry)) return $carry; if (isset($item[0]) && ($poidsColisEstimation <= $item[0] || $item[0] == '*')) { $carry = $item[1]; } return $carry; }), ]); }
if( ( in_array($request->dest_country_id, ['GF','YT','PM','PF','NC','WF','TF']) ) ){
// 5e mode de livraison : ZONING 9 CHRONOPOST - ULTRA MARIN / TOM addMethod('id_016', [ 'title' => "Express TOM", 'enabled' => ( ( in_array($request->dest_country_id, ['GF','YT','PM','PF','NC','WF','TF']) ) ), 'price'=> array_reduce([ [1.0, 59.06], [2.0, 71.17], [4.0, 93.64], [8.0, 136.74], [10.0, 158.02], [20.0, 275.06], [30.0, 405.04] ], function ($carry, $item) { global $request, $poidsColisEstimation; if (isset($carry)) return $carry; if (isset($item[0]) && ($poidsColisEstimation <= $item[0] || $item[0] == '*')) { $carry = $item[1]; } return $carry; }), ]); } }
if (count(getMethods(true)) == 0) { addError("Les frais de livraison ne peuvent malheureusement pas être calculés automatiquement. Veuillez nous contacter directement."); }
we added above it's correct?
Yes, it looks good to me. Do you still have an error?
solved. Thank you, team,
if I have used php8.1 in magento 2.4.5
then?
Curretly my shipping charges are not shown on the checkout page, after downgrade magento 2.4.5
Hi,
Thanks for the feedback. Do you have an error in Magento log files?
Best Regards, A.L.
Unfortunately, delivery costs cannot be calculated automatically. Please contact us directly.
owebia/magento2-module-advanced-shipping after installing this module we faced an error on the checkout page.
Error Deprecated Functionality: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in /home/dev_comartex/public_html/vendor/owebia/magento2-module-shared-php-config/Helper/Evaluator.php on line 1123