-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c6c2c9
commit 1641c56
Showing
6 changed files
with
132 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
/** | ||
* ActivityBridge. | ||
* | ||
* @package Packetery | ||
*/ | ||
|
||
namespace Packetery\Module\Carrier; | ||
|
||
use Packetery\Module\Carrier; | ||
use Packetery\Module\Options; | ||
use Packetery\Module\ShippingMethod; | ||
use WC_Shipping_Zones; | ||
|
||
/** | ||
* ActivityBridge. | ||
* | ||
* @package Packetery | ||
*/ | ||
class ActivityBridge { | ||
|
||
/** | ||
* Options provider. | ||
* | ||
* @var Options\Provider | ||
*/ | ||
private $optionsProvider; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param Options\Provider $optionsProvider Options provider. | ||
*/ | ||
public function __construct( Options\Provider $optionsProvider ) { | ||
$this->optionsProvider = $optionsProvider; | ||
} | ||
|
||
/** | ||
* Gets active carrier ids. | ||
* | ||
* @return array | ||
*/ | ||
private function getActiveCarrierIds(): array { | ||
$activeMethods = []; | ||
$shippingZones = WC_Shipping_Zones::get_zones(); | ||
|
||
foreach ( $shippingZones as $shippingZone ) { | ||
$shippingMethods = $shippingZone['shipping_methods']; | ||
|
||
foreach ( $shippingMethods as $shippingMethod ) { | ||
if ( | ||
$shippingMethod instanceof ShippingMethod && | ||
'yes' === $shippingMethod->enabled && | ||
! empty( $shippingMethod->get_option( 'carrier_id' ) ) | ||
) { | ||
$activeMethods[] = $shippingMethod->get_option( 'carrier_id' ); | ||
} | ||
} | ||
} | ||
|
||
return $activeMethods; | ||
} | ||
|
||
/** | ||
* Tells if carrier is active. | ||
* | ||
* @param string $carrierId Carrier id. | ||
* @param \Packetery\Module\Carrier\Options $carrierOptions Carrier options. | ||
* | ||
* @return bool | ||
*/ | ||
public function isActive( string $carrierId, Carrier\Options $carrierOptions ): bool { | ||
if ( $this->optionsProvider->isWcCarrierConfigEnabled() ) { | ||
return in_array( $carrierId, $this->getActiveCarrierIds(), true ); | ||
} | ||
|
||
return $carrierOptions->isActive(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters