Skip to content

Commit

Permalink
Merge pull request #118 from noweasily/issues/117
Browse files Browse the repository at this point in the history
Issues/117
  • Loading branch information
bessudnov authored Aug 31, 2020
2 parents cfc6bc2 + b4fb444 commit 2a8ec0f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/catalogs_actions.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use AmoCRM\AmoCRM\Filters\CatalogsFilter;
use AmoCRM\Collections\CustomFields\CustomFieldNestedCollection;
use AmoCRM\Exceptions\AmoCRMApiException;
use AmoCRM\Helpers\EntityTypesInterface;
Expand Down Expand Up @@ -53,6 +54,16 @@ function (AccessTokenInterface $accessToken, string $baseDomain) {
// die;
//}

//Получим каталоги по типу
try {
$catalogsFilter = new CatalogsFilter();
$catalogsFilter->setType(EntityTypesInterface::INVOICES_CATALOG_TYPE_STRING);
$catalogsCollection = $apiClient->catalogs()->get($catalogsFilter);
} catch (AmoCRMApiException $e) {
printError($e);
die;
}

//Получим все каталоги
try {
$catalogsCollection = $apiClient->catalogs()->get();
Expand Down
46 changes: 46 additions & 0 deletions src/AmoCRM/Filters/CatalogsFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace AmoCRM\AmoCRM\Filters;

use AmoCRM\Filters\BaseEntityFilter;

use function is_null;

class CatalogsFilter extends BaseEntityFilter
{
/** @var null|string */
private $type = null;

/**
* @param null|string $type
*
* @return $this
*/
public function setType(?string $type): self
{
$this->type = $type;

return $this;
}

/**
* @return null|string
*/
public function getType(): ?string
{
return $this->type;
}

public function buildFilter(): array
{
$filter = [];

if (!is_null($this->getType())) {
$filter['type'] = $this->getType();
}

return $filter;
}
}

0 comments on commit 2a8ec0f

Please sign in to comment.