Skip to content

Commit

Permalink
PES-2537: carrier may be unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
J7F authored and J7F committed Mar 3, 2025
1 parent 5b53903 commit d2c4811
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
16 changes: 5 additions & 11 deletions src/Packetery/Module/Carrier/CountryListingPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,20 +278,14 @@ public function render(): void {
* @return array Data.
*/
private function getActiveCountries(): array {
$countries = $this->carrierRepository->getCountries();
$countries = $this->carrierRepository->getCountriesWithUnavailable();

$internalCountries = $this->pickupPointsConfig->getInternalCountries();
$countries = array_unique( array_merge( $internalCountries, $countries ) );

$countriesFinal = [];
foreach ( $countries as $country ) {
$allCarriers = $this->getCarriersDataByCountry( $country );
$activeCarriers = array_filter(
$allCarriers,
static function ( array $carrierData ): bool {
return $carrierData['isActive'];
}
);
$allCarriers = $this->getCarriersDataByCountry( $country, true );
$wcCountries = \WC()->countries->get_countries();
$countriesFinal[] = [
self::DATA_KEY_COUNTRY_CODE => $country,
Expand All @@ -303,7 +297,6 @@ static function ( array $carrierData ): bool {
],
get_admin_url( null, 'admin.php' )
),
'activeCarriers' => $activeCarriers,
'allCarriers' => $allCarriers,
'flag' => $this->urlBuilder->buildAssetUrl( sprintf( 'public/images/flags/%s.png', $country ) ),
];
Expand Down Expand Up @@ -384,13 +377,14 @@ public function getCarriersForOptionsExport(): array {
* Gets array of carriers data by country code.
*
* @param string $countryCode Country code.
* @param bool $includeUnavailable Include unavailable carriers.
*
* @return array
*/
private function getCarriersDataByCountry( string $countryCode ): array {
private function getCarriersDataByCountry( string $countryCode, bool $includeUnavailable = false ): array {
$carriersData = [];
$keyword = $this->httpRequest->getQuery( self::PARAM_CARRIER_FILTER ) ?? '';
$countryCarriers = $this->carrierEntityRepository->getByCountryIncludingNonFeed( $countryCode );
$countryCarriers = $this->carrierEntityRepository->getByCountryIncludingNonFeed( $countryCode, $includeUnavailable );
foreach ( $countryCarriers as $carrier ) {
if ( $carrier->isCarDelivery() && $this->carDeliveryConfig->isDisabled() ) {
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/Packetery/Module/Carrier/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ public function hasAnyActiveFeedCarrier(): bool {
*
* @return array
*/
public function getCountries(): array {
return $this->wpdbAdapter->get_col( 'SELECT `country` FROM `' . $this->wpdbAdapter->packeteryCarrier . '` WHERE `deleted` = false AND `available` = true GROUP BY `country` ORDER BY `country`' );
public function getCountriesWithUnavailable(): array {
return $this->wpdbAdapter->get_col( 'SELECT `country` FROM `' . $this->wpdbAdapter->packeteryCarrier . '` WHERE `deleted` = false GROUP BY `country` ORDER BY `country`' );
}

/**
Expand Down

0 comments on commit d2c4811

Please sign in to comment.