Skip to content

Commit d362e91

Browse files
authored
Merge pull request #84 from packlink-dev/fix/CS-7860
Release version 4.0.1
2 parents aafccfa + 45d61fe commit d362e91

14 files changed

+174
-21
lines changed
1.79 MB
Binary file not shown.

PluginInstallation/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
55

6+
## [v4.0.1](https://github.com/packlink-dev/woocommerce_module/compare/v4.0.0...v4.0.1) - 2026-03-19
7+
### Changed
8+
- Corrected service ID sent to the Packlink API
9+
- Improved postal code handling for AE
10+
- Improved drop-off button rendering
11+
- Fix send draft when manual sync is enabled
12+
- Added caching for shipping calculation parameters
13+
614
## [v4.0.0](https://github.com/packlink-dev/woocommerce_module/compare/v3.6.5...v4.0.0) - 2026-03-10
715
### Changed
816
**BREAKING CHANGES**

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "packlink/woocommerce-dev",
33
"description": "Packlink WooCommerce Integration",
4-
"version": "4.0.0",
4+
"version": "4.0.1",
55
"type": "library",
66
"require": {
77
"php": ">=7.0",

src/Components/Checkout/class-block-checkout-handler.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ public function initialize( array $payload ) {
115115
*/
116116
public function load_data() {
117117
if ( is_checkout() ) {
118-
include dirname( __DIR__ ) . '/../resources/views/block-checkout-shipping-method-drop-off.php';
119118
Script_Loader::load_js(
120119
array(
121120
'js/packlink-block-checkout.js',
@@ -131,6 +130,19 @@ public function load_data() {
131130
}
132131
}
133132

133+
/**
134+
* Renders drop-off for locations
135+
*
136+
* @return void
137+
*/
138+
public function render_drop_off_markup() {
139+
if ( ! is_checkout() ) {
140+
return;
141+
}
142+
143+
include dirname( __DIR__ ) . '/../resources/views/block-checkout-shipping-method-drop-off.php';
144+
}
145+
134146
/**
135147
* This hook is used to update drop-off point and order shipping address value.
136148
*

src/Components/Services/class-shipment-draft-service.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Packlink\WooCommerce\Components\Services;
99

1010
use Logeecom\Infrastructure\ServiceRegister;
11-
use MailPoetVendor\Doctrine\DBAL\Driver\PDO\Exception;
11+
use Logeecom\Infrastructure\TaskExecutor\Interfaces\TaskExecutorInterface;
1212
use Packlink\BusinessLogic\OrderShipmentDetails\OrderShipmentDetailsService;
1313
use Packlink\BusinessLogic\ShipmentDraft\ShipmentDraftService;
1414
use Packlink\BusinessLogic\Tasks\BusinessTasks\SendDraftBusinessTask;
@@ -46,7 +46,8 @@ public function enqueueCreateShipmentDraftTask( $orderId, $isDelayed = false, $d
4646
throw new \RuntimeException( 'Draft already exists' );
4747
}
4848

49-
( new SendDraftBusinessTask( $orderId ) )->execute();
49+
$taskExecutor = $this->get_task_executor();
50+
$taskExecutor->executeNow( new SendDraftBusinessTask( $orderId ) );
5051

5152
$translation = __(
5253
'Shipment draft for order %s created successfully',
@@ -110,4 +111,18 @@ private function get_order_shipment_details_service()
110111

111112
return $orderShipmentDetailsService;
112113
}
114+
115+
/**
116+
* Retrieves task executor service.
117+
*
118+
* @return TaskExecutorInterface
119+
*/
120+
private function get_task_executor()
121+
{
122+
/**@var TaskExecutorInterface $taskExecutor */
123+
$taskExecutor = ServiceRegister::getService( TaskExecutorInterface::CLASS_NAME );
124+
125+
return $taskExecutor;
126+
}
127+
113128
}

src/Components/Services/class-wordpress-task-executor.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,29 @@ public function executeTaskCallback( $args ) {
273273
// If not generator, task executed normally
274274
}
275275

276+
/**
277+
* @param BusinessTask $businessTask
278+
*
279+
* @return void
280+
*
281+
* @throws \Throwable
282+
*/
283+
public function executeNow( BusinessTask $businessTask )
284+
{
285+
try {
286+
$result = $businessTask->execute();
287+
288+
if ( $result instanceof \Generator ) {
289+
$this->executeWithProgressTracking( $result );
290+
}
291+
} catch ( \Throwable $e ) {
292+
Logger::logError( $e->getMessage(), 'Integration', [
293+
'task_class' => get_class($businessTask),
294+
] );
295+
throw $e;
296+
}
297+
}
298+
276299
/**
277300
* Execute generator with progress tracking.
278301
*

src/Components/ShippingMethod/class-packlink-shipping-method.php

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,15 @@ class Packlink_Shipping_Method extends \WC_Shipping_Method {
4040
* @var array
4141
*/
4242
private static $shipping_services = array();
43+
44+
4345
/**
44-
* Available shipping services loaded.
46+
* Last calculated parameters by cache key.
4547
*
46-
* @var bool
48+
* @var array
4749
*/
48-
private static $loaded = false;
50+
private static $last_shipping_params = array();
51+
4952
/**
5053
* Pricing policy.
5154
*
@@ -372,24 +375,93 @@ private function load_shipping_costs( array $package, ShippingMethod $shipping_m
372375
$id = $shipping_method->getId();
373376
$to_country = ! empty( $package['destination']['country'] ) ? $package['destination']['country'] : $warehouse->country;
374377
$to_zip = ! empty( $package['destination']['postcode'] ) ? $package['destination']['postcode'] : $warehouse->postalCode;
375-
if ( ! static::$loaded ) {
378+
$parcels = $this->build_parcels( $package, $default_parcel );
379+
380+
$new_params = $this->get_shipping_calculation_params(
381+
$package,
382+
$parcels,
383+
$warehouse->country,
384+
$warehouse->postalCode,
385+
$to_country,
386+
$to_zip,
387+
$cart_subtotal
388+
);
389+
390+
391+
if ( static::$last_shipping_params !== $new_params) {
376392
static::$shipping_services = ShippingCostCalculator::getShippingCosts(
377393
$this->shipping_method_service->getAllMethods(),
378394
$warehouse->country,
379395
$warehouse->postalCode,
380396
$to_country,
381397
$to_zip,
382-
$this->build_parcels( $package, $default_parcel ),
398+
$parcels,
383399
$cart_subtotal,
384400
System_Info_Service::SYSTEM_ID
385401
);
386402

387-
static::$loaded = true;
403+
static::$last_shipping_params = $new_params;
388404
}
389405

390406
return array_key_exists( $id, static::$shipping_services ) || ( - 1 === $id && ! empty( static::$shipping_services ) );
391407
}
392408

409+
/**
410+
* Builds normalized shipping calculation parameters.
411+
*
412+
* @param array $package Package.
413+
* @param array $parcels Parcels.
414+
* @param string $from_country Origin country.
415+
* @param string $from_zip Origin postal code.
416+
* @param string $to_country Destination country.
417+
* @param string $to_zip Destination postal code.
418+
* @param float $cart_subtotal Cart subtotal.
419+
*
420+
* @return array
421+
*/
422+
private function get_shipping_calculation_params(
423+
array $package,
424+
array $parcels,
425+
string $from_country,
426+
string $from_zip,
427+
string $to_country,
428+
string $to_zip,
429+
float $cart_subtotal
430+
) {
431+
$contents = array();
432+
433+
foreach ( $package['contents'] as $item ) {
434+
$contents[] = array(
435+
'product_id' => $item['product_id'] ?? null,
436+
'variation_id' => $item['variation_id'] ?? null,
437+
'quantity' => isset( $item['quantity'] ) ? (int) $item['quantity'] : 0,
438+
'line_total' => isset( $item['line_total'] ) ? (float) $item['line_total'] : 0.0,
439+
);
440+
}
441+
442+
$normalized_parcels = array_map(
443+
static function ( $parcel ) {
444+
return array(
445+
'weight' => isset( $parcel->weight ) ? (float) $parcel->weight : 0.0,
446+
'width' => isset( $parcel->width ) ? (float) $parcel->width : 0.0,
447+
'height' => isset( $parcel->height ) ? (float) $parcel->height : 0.0,
448+
'length' => isset( $parcel->length ) ? (float) $parcel->length : 0.0,
449+
);
450+
},
451+
$parcels
452+
);
453+
454+
return array(
455+
'from_country' => $from_country,
456+
'from_zip' => $from_zip,
457+
'to_country' => $to_country,
458+
'to_zip' => $to_zip,
459+
'cart_subtotal' => $cart_subtotal,
460+
'contents' => $contents,
461+
'parcels' => $normalized_parcels,
462+
);
463+
}
464+
393465
/**
394466
* Retrieves the cart subtotal to be used for shipping cost calculation.
395467
*

src/changelog.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
*** Packlink PRO Changelog ***
22

3+
2026-03-19 - version 4.0.1
4+
- Corrected service ID sent to the Packlink API
5+
- Improved postal code handling for AE
6+
- Improved drop-off button rendering
7+
- Fix send draft when manual sync is enabled
8+
- Added caching for shipping calculation parameters
9+
310
2026-03-10 - version 4.0.0
411
* Dropped support for PHP 5.6. Minimum supported PHP version is now PHP 7.0
512
* Migrated Packlink task execution to WooCommerce Action Scheduler

src/class-plugin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ private function checkout_hooks_and_actions() {
756756
add_action( 'woocommerce_store_api_checkout_update_order_from_request', [ $surcharge_handle, 'add_surcharge_block' ], 10, 2 );
757757

758758
add_action('woocommerce_blocks_checkout_enqueue_data', array ($block_handler, 'load_data'));
759+
add_action( 'wp_footer', array( $block_handler, 'render_drop_off_markup' ) );
759760
add_action('woocommerce_store_api_checkout_update_order_meta', array ($block_handler, 'checkout_update_drop_off'));
760761
}
761762

src/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "packlink/woocommerce",
33
"description": "Packlink WooCommerce Integration",
4-
"version": "4.0.0",
4+
"version": "4.0.1",
55
"type": "library",
66
"repositories": [
77
{
@@ -12,7 +12,7 @@
1212
],
1313
"require": {
1414
"php": ">=7.0",
15-
"packlink/integration-core": "v4.0.0",
15+
"packlink/integration-core": "v4.0.1",
1616
"ext-json": "*",
1717
"ext-curl": "*",
1818
"ext-zip": "*",

0 commit comments

Comments
 (0)