Salamek/PplMyApi

by city?

Closed this issue · 3 comments

ne2d commented

Ahoj, proc z Api zmizela metoda getParcelShopsByCity? Potrebuji vytahovat jen parcelshopy pro dane mesto a prislo mi to fajn. Dik

Zadnou takovou funkci v https://myapi.ppl.cz/MyApi.svc?singleWsdl nevidim... ani si nepamatuji ze by jsme takovou funkci odstranovali... v ktere verzi prosim mela byt tato funkce dostupna?

ne2d commented

V nejake sve starsi verzi jsem pouzival toto

/**
 * @param null $city
 * @param string $countryCode
 * @return mixed
 * @throws \Exception
 * @throws WrongDataException
 */
public function getParcelShopsByCity($city = null, $countryCode = Country::CZ)
{
    if (!in_array($countryCode, Country::$list)) {
        throw new WrongDataException(sprintf('Country Code %s is not supported, use one of %s', $countryCode, implode(', ', Country::$list)));
    }

    $result = $this->soap->GetParcelShops([
        'Filter' => [
            'City' => $city,
            'CountryCode' => $countryCode
        ]
    ]);

    return isset($result->GetParcelShopsResult->ResultData->MyApiParcelShop)
        ? $result->GetParcelShopsResult->ResultData->MyApiParcelShop
        : [];
} `

ale po pravde receno uz nevim, kde jsem to vzal. Kazdopadne bylo by mozne to tam doplnit, abych o to neprisel pri pristim update?

Ve verzi 2.7 jsem implementoval dodatecne filtrovaci argumenty:

public function getParcelShops(string $code = null, string $countryCode = Country::CZ, string $accessPointType = null, bool $activeCardPayment = null, string $city = null, float $latitude = null, float $longitude = null, int $radius = null, string $zipCode = null): array
    {
        if (!in_array($countryCode, Country::$list)) {
            throw new WrongDataException(sprintf('Country Code %s is not supported, use one of %s', $countryCode, implode(', ', Country::$list)));
        }
        
        if (!is_null($accessPointType) && !in_array($accessPointType, AccessPointType::$list)) {
            throw new WrongDataException(sprintf('AccessPoint Type %s is not supported, use one of %s', $accessPointType, implode(', ', AccessPointType::$list)));
        }

        $result = $this->soap->GetParcelShops([
            'Filter' => [
                'AccessPointType' => $accessPointType,
                'ActiveCardPayment' => $activeCardPayment,
                'City' => $city,
                'Code' => $code,
                'CountryCode' => $countryCode,
                'Latitude' => $latitude,
                'Longitude' => $longitude,
                'Radius' => $radius,
                'ZipCode' => $zipCode
            ]
        ]);

        return isset($result->GetParcelShopsResult->ResultData->MyApiParcelShop)
            ? $result->GetParcelShopsResult->ResultData->MyApiParcelShop
            : [];
    }

Takze v PHP8 si to muzes volat nejak takhle:

$api->getParcelShops(city: $city);

Ve starsich verzich je to standardni PHP peklo:

$api->getParcelShops(null, Country::CZ, null, null, $city);