Skip to content

Commit

Permalink
PES-2328: carrier restrictions by product dimension (#693)
Browse files Browse the repository at this point in the history
  • Loading branch information
zemekoule authored Jan 2, 2025
2 parents fe55f60 + 4c1d8b3 commit 328d7d5
Show file tree
Hide file tree
Showing 18 changed files with 691 additions and 115 deletions.
2 changes: 1 addition & 1 deletion public/block/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wc-blocks-checkout', 'wc-blocks-components', 'wc-settings', 'wp-block-editor', 'wp-blocks', 'wp-data', 'wp-i18n'), 'version' => 'b0db576f57e6741cfcca');
<?php return array('dependencies' => array('react', 'wc-blocks-checkout', 'wc-blocks-components', 'wc-settings', 'wp-block-editor', 'wp-blocks', 'wp-data', 'wp-i18n'), 'version' => 'afbe8dfd18c9ee387d93');
2 changes: 1 addition & 1 deletion public/block/index.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions public/js/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,18 @@ var packeteryLoadCheckout = function( $, settings ) {
widgetOptions.livePickupPoint = true; // Pickup points with real person only.
}

if ( settings.biggestProductSize ) {
if ( settings.biggestProductSize.length ) {
widgetOptions.lenght = settings.biggestProductSize.length;
}
if ( settings.biggestProductSize.width ) {
widgetOptions.width = settings.biggestProductSize.width;
}
if ( settings.biggestProductSize.depth ) {
widgetOptions.depth = settings.biggestProductSize.depth;
}
}

console.log('Pickup point widget options: apiKey: ' + settings.packeteryApiKey + ', ' + stringifyOptions(widgetOptions));
Packeta.Widget.pick( settings.packeteryApiKey, function( pickupPoint ) {
if ( pickupPoint == null ) {
Expand Down
3 changes: 2 additions & 1 deletion src/PacketaWidget/useDynamicSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ export const useDynamicSettings = ( adminAjaxUrl ) => {
} )
.then( ( response ) => response.json() )
.then( ( data ) => {
const { isAgeVerificationRequired } = data;
const { isAgeVerificationRequired, biggestProductSize } = data;
setDynamicSettings( prevState => ( {
...prevState,
isAgeVerificationRequired,
biggestProductSize,
} ) );
} )
.catch( ( error ) => {
Expand Down
19 changes: 17 additions & 2 deletions src/PacketaWidget/useOnWidgetButtonClicked.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,23 @@ export const useOnWidgetButtonClicked = (
if ( carrierConfig[ rateId ].vendors ) {
widgetOptions.vendors = carrierConfig[ rateId ].vendors;
}
if ( dynamicSettings && dynamicSettings.isAgeVerificationRequired ) {
widgetOptions.livePickupPoint = true; // Pickup points with real person only.

if ( dynamicSettings ) {
if ( dynamicSettings.isAgeVerificationRequired ) {
widgetOptions.livePickupPoint = true; // Pickup points with real person only.
}

if ( dynamicSettings.biggestProductSize ) {
if ( dynamicSettings.biggestProductSize.length ) {
widgetOptions.lenght = dynamicSettings.biggestProductSize.length;
}
if ( dynamicSettings.biggestProductSize.width ) {
widgetOptions.width = dynamicSettings.biggestProductSize.width;
}
if ( dynamicSettings.biggestProductSize.depth ) {
widgetOptions.depth = dynamicSettings.biggestProductSize.depth;
}
}
}

console.log( 'Pickup point widget options: apiKey: ' + packeteryApiKey + ', ' + stringifyOptions( widgetOptions ) );
Expand Down
17 changes: 17 additions & 0 deletions src/Packetery/Core/CoreHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,21 @@ public function getStringFromDateTime( ?DateTimeImmutable $date, string $format
public function getDateTimeFromString( ?string $date ): ?DateTimeImmutable {
return $date !== null ? new DateTimeImmutable( $date ) : null;
}

public static function convertToCentimeters( float $value, string $fromUnit ): float {
$conversionFactors = [
'cm' => 1,
'm' => 100,
'mm' => 0.1,
'in' => 2.54,
'yd' => 91.44,
];

if ( ! isset( $conversionFactors[ $fromUnit ] ) ) {
// Do not convert unknown values.
return $value;
}

return $value * $conversionFactors[ $fromUnit ];
}
}
1 change: 1 addition & 0 deletions src/Packetery/Core/Entity/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Carrier {

public const INTERNAL_PICKUP_POINTS_ID = 'packeta';
public const VENDOR_GROUP_ZPOINT = 'zpoint';
public const VENDOR_GROUP_ZBOX = 'zbox';
public const ADDRESS_VALIDATION_COUNTRIES = [ 'cz', 'sk' ];
public const CAR_DELIVERY_CARRIERS = [ '25061' ];

Expand Down
11 changes: 11 additions & 0 deletions src/Packetery/Module/Carrier/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,15 @@ public function getPricingType(): string {
public function hasOptions(): bool {
return count( $this->options ) > 0;
}

public function getSizeRestrictions(): ?array {
if (
isset( $this->options['dimensions_restrictions']['active'] ) &&
$this->options['dimensions_restrictions']['active'] === true
) {
return $this->options['dimensions_restrictions'];
}

return null;
}
}
Loading

0 comments on commit 328d7d5

Please sign in to comment.