Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #52 from sanmai/pr/calculator2
Browse files Browse the repository at this point in the history
Расчёт стоимости по тарифам без приоритета
  • Loading branch information
sanmai committed Jun 21, 2019
2 parents 346995e + 929599c commit f21ea8c
Show file tree
Hide file tree
Showing 33 changed files with 1,437 additions and 293 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -16,7 +16,7 @@

- [x] расчёт тарифов и обращения к справочникам
- [x] [расчёт стоимости доставки по тарифам с приоритетом](https://cdek-sdk.readthedocs.io/#CalculationRequest) :unlock: :closed_lock_with_key:
- [ ] расчёт стоимости по тарифам без приоритета :unlock: :closed_lock_with_key:
- [x] [расчёт стоимости по тарифам без приоритета](https://cdek-sdk.readthedocs.io/#CalculationWithTariffListRequest) :unlock: :closed_lock_with_key:
- [x] [получение списка пунктов выдачи заказов (ПВЗ) с фильтрацией](https://cdek-sdk.readthedocs.io/#PvzListRequest) :unlock:
- [x] [получение списка регионов-субъектов РФ](https://cdek-sdk.readthedocs.io/#RegionsRequest) :unlock:
- [x] [получение списка городов](https://cdek-sdk.readthedocs.io/#CitiesRequest) :unlock:
Expand Down
60 changes: 58 additions & 2 deletions docs/index.md
Expand Up @@ -66,7 +66,8 @@ $client = new \CdekSDK\CdekClient('Account', 'Secure', new \GuzzleHttp\Client([
| [Вызов курьера](#CallCourierRequest) | `sendCallCourierRequest` | `CallCourierRequest` |
| [Создание преалерта](#PreAlertRequest) | `sendPreAlertRequest` | `PreAlertRequest` |
| [Отчет "Информация по заказам"](#InfoReportRequest) | `sendInfoReportRequest` | `InfoReportRequest` |
| [Расчёт стоимости доставки](#CalculationRequest) | `sendCalculationRequest` | `CalculationRequest` |
| [Расчёт стоимости доставки с приоритетом](#CalculationRequest) | `sendCalculationRequest` | `CalculationRequest` |
| [Расчёт стоимости доставки без приоритета](#CalculationWithTariffListRequest) | `sendCalculationWithTariffListRequest` | `CalculationWithTariffListRequest` |
| [Отчет "Статусы заказов"](#StatusReportRequest) | `sendStatusReportRequest` | `StatusReportRequest` |
| [Печать квитанции к заказу](#PrintReceiptsRequest) | `sendPrintReceiptsRequest` | `PrintReceiptsRequest` |
| [Печать ШК-мест](#PrintLabelsRequest) | `sendPrintLabelsRequest` | `PrintLabelsRequest` |
Expand Down Expand Up @@ -160,7 +161,7 @@ foreach ($response as $item) {
}
```

### Расчёт стоимости доставки {: #CalculationRequest }
### Расчёт стоимости доставки с приоритетом {: #CalculationRequest }

```php
use CdekSDK\Requests;
Expand Down Expand Up @@ -199,6 +200,61 @@ $response->getPrice();

При прочих равных лучше всегда использовать запрос с авторизацией.

### Расчет стоимости по тарифам без приоритета {: #CalculationWithTariffListRequest }

Этот способ расчёта подразумевает получение нескольких расчётов стоимости доставки для каждого из запрошенных тарифов.

```
use CdekSDK\Requests;
// для выполнения запроса без авторизации используется
// $request = new Requests\CalculationWithTariffListRequest();
// $request->set...() и так далее
$request = new Requests\CalculationWithTariffListAuthorizedRequest();
$request->setSenderCityPostCode('295000')
->setReceiverCityPostCode('652632')
->addTariffToList(1)
->addTariffToList(8)
->addPackage([
'weight' => 0.2,
'length' => 25,
'width' => 15,
'height' => 10,
]);
$response = $client->sendCalculationWithTariffListRequest($request);
/** @var \CdekSDK\Responses\CalculationWithTariffListResponse $response */
if ($response->hasErrors()) {
// обработка ошибок
}
foreach ($response->getResults() as $result) {
if ($result->hasErrors()) {
// обработка ошибок
continue;
}
if (!$result->getStatus()) {
continue;
}
$result->getTariffId();
// int(1)
$result->getPrice();
// double(1570)
$result->getDeliveryPeriodMin();
// int(4)
$result->getDeliveryPeriodMax();
// int(5)
}
```

### Список регионов/субъектов РФ {: #RegionsRequest }

```php
Expand Down
77 changes: 77 additions & 0 deletions examples/045_CalculationWithTariffListRequest.php
@@ -0,0 +1,77 @@
<?php
/**
* This code is licensed under the MIT License.
*
* Copyright (c) 2018 Appwilio (http://appwilio.com), greabock (https://github.com/greabock), JhaoDa (https://github.com/jhaoda)
* Copyright (c) 2018 Alexey Kopytko <alexey@kopytko.com> and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

declare(strict_types=1);
use CdekSDK\Requests;

$client = new \CdekSDK\CdekClient('account', 'password');

// для выполнения запроса без авторизации используется
// $request = new Requests\CalculationWithTariffListRequest();
// $request->set...() и так далее

$request = new Requests\CalculationWithTariffListAuthorizedRequest();
$request->setSenderCityPostCode('295000')
->setReceiverCityPostCode('652632')
->addTariffToList(1)
->addTariffToList(8)
->addPackage([
'weight' => 0.2,
'length' => 25,
'width' => 15,
'height' => 10,
]);

$response = $client->sendCalculationWithTariffListRequest($request);

/** @var \CdekSDK\Responses\CalculationWithTariffListResponse $response */
if ($response->hasErrors()) {
// обработка ошибок
}

foreach ($response->getResults() as $result) {
if ($result->hasErrors()) {
// обработка ошибок

continue;
}

if (!$result->getStatus()) {
continue;
}

$result->getTariffId();
// int(1)

$result->getPrice();
// double(1570)

$result->getDeliveryPeriodMin();
// int(4)

$result->getDeliveryPeriodMax();
// int(5)
}
1 change: 1 addition & 0 deletions src/CdekClient.php
Expand Up @@ -59,6 +59,7 @@
* @method Responses\PreAlertResponse sendPreAlertRequest(Requests\PreAlertRequest $request)
* @method Responses\InfoReportResponse|Common\Order[] sendInfoReportRequest(Requests\InfoReportRequest $request)
* @method Responses\CalculationResponse sendCalculationRequest(Requests\CalculationAuthorizedRequest $request)
* @method Responses\CalculationWithTariffListResponse sendCalculationWithTariffListRequest(Requests\CalculationWithTariffListAuthorizedRequest $request)
* @method Responses\StatusReportResponse|Common\Order[] sendStatusReportRequest(Requests\StatusReportRequest $request)
* @method Responses\FileResponse sendPrintReceiptsRequest(Requests\PrintReceiptsRequest $request)
* @method Responses\FileResponse sendPrintLabelsRequest(Requests\PrintLabelsRequest $request)
Expand Down
4 changes: 4 additions & 0 deletions src/Common/Fillable.php
Expand Up @@ -35,6 +35,8 @@ trait Fillable
* @psalm-suppress MixedArgument
*
* @param array<string, mixed> $data
*
* @final
*/
public function __construct(array $data = [])
{
Expand All @@ -55,6 +57,8 @@ public function __construct(array $data = [])
* @phan-suppress PhanTypeInstantiateTrait
*
* @return static
*
* @final
*/
public static function create($data = [])
{
Expand Down

0 comments on commit f21ea8c

Please sign in to comment.