Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
->in(__DIR__ . '/src/Services/SonetGroup/')
->in(__DIR__ . '/src/Services/IMOpenLines/')
->in(__DIR__ . '/src/Services/Landing/')
->in(__DIR__ . '/src/Services/Catalog/')
->name('*.php')
->exclude(['vendor', 'storage', 'docker', 'docs']) // Exclude directories
->ignoreDotFiles(true)
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@

### Added

- Added service `Services\Catalog\Document` with support methods,
see [catalog.document.* methods](https://apidocs.bitrix24.com/api-reference/catalog/document/index.html) ([#559](https://github.com/bitrix24/b24phpsdk/issues/559)):
- `add` creates a new warehouse accounting document, with batch calls support
- `update` updates an existing document, with batch calls support
- `list` gets the list of documents
- `delete` deletes a document, with batch calls support
- `deleteList` deletes a group of documents
- `conduct` conducts (activates) a document
- `conductList` conducts a group of documents
- `cancel` cancels conducting of a document
- `cancelList` cancels conducting of a group of documents
- `getFields` returns the description of document fields
- `modeStatus` checks whether warehouse accounting mode is enabled
- Added service `Services\Catalog\DocumentElement` with support methods,
see [catalog.document.element.* methods](https://apidocs.bitrix24.com/api-reference/catalog/document/document-element/index.html) ([#559](https://github.com/bitrix24/b24phpsdk/issues/559)):
- `add` adds a product line item to a warehouse accounting document, with batch calls support
- `update` updates a document line item, with batch calls support
- `list` gets the list of document line items
- `delete` deletes a document line item, with batch calls support
- `getFields` returns the description of document element fields
- Added service `Services\Landing\Site\Service\Site` with support methods,
see [landing.site.* methods](https://github.com/bitrix24/b24phpsdk/issues/267):
- `add` adds a site
Expand Down
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,20 @@ test-integration-landing-role:
test-integration-landing-repowidget:
docker compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_landing_repowidget

.PHONY: test-integration-catalog-document
test-integration-catalog-document:
docker compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_catalog_document
.PHONY: test-integration-catalog-document-annotations
test-integration-catalog-document-annotations:
docker compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_catalog_document_annotations

.PHONY: test-integration-catalog-document-element
test-integration-catalog-document-element:
docker compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_catalog_document_element
.PHONY: test-integration-catalog-document-element-annotations
test-integration-catalog-document-element-annotations:
docker compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_catalog_document_element_annotations

# work dev environment
.PHONY: php-dev-server-up
php-dev-server-up:
Expand Down
12 changes: 12 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,18 @@
<testsuite name="integration_tests_landing_repowidget">
<directory>./tests/Integration/Services/Landing/RepoWidget/</directory>
</testsuite>
<testsuite name="integration_tests_catalog_document">
<directory>./tests/Integration/Services/Catalog/Document/Service/</directory>
</testsuite>
<testsuite name="integration_tests_catalog_document_annotations">
<file>./tests/Integration/Services/Catalog/Document/Result/DocumentItemResultTest.php</file>
</testsuite>
<testsuite name="integration_tests_catalog_document_element">
<directory>./tests/Integration/Services/Catalog/DocumentElement/Service/</directory>
</testsuite>
<testsuite name="integration_tests_catalog_document_element_annotations">
<file>./tests/Integration/Services/Catalog/DocumentElement/Result/DocumentElementItemResultTest.php</file>
</testsuite>
</testsuites>
<source>
<include>
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Catalog/Catalog/Result/CatalogItemResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
*/
class CatalogItemResult extends AbstractCatalogItem
{
}
}
2 changes: 1 addition & 1 deletion src/Services/Catalog/Catalog/Result/CatalogResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public function catalog(): CatalogItemResult
{
return new CatalogItemResult($this->getCoreResponse()->getResponseData()->getResult()['catalog']);
}
}
}
2 changes: 1 addition & 1 deletion src/Services/Catalog/Catalog/Result/CatalogsResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ public function getCatalogs(): array

return $res;
}
}
}
2 changes: 1 addition & 1 deletion src/Services/Catalog/Catalog/Service/Catalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@ public function fields(): FieldsResult
{
return new FieldsResult($this->core->call('catalog.catalog.getFields'));
}
}
}
35 changes: 34 additions & 1 deletion src/Services/Catalog/CatalogServiceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Bitrix24\SDK\Core\Credentials\Scope;
use Bitrix24\SDK\Services\AbstractServiceBuilder;
use Bitrix24\SDK\Services\Catalog;

#[ApiServiceBuilderMetadata(new Scope(['catalog']))]
class CatalogServiceBuilder extends AbstractServiceBuilder
{
Expand Down Expand Up @@ -44,4 +45,36 @@ public function catalog(): Catalog\Catalog\Service\Catalog

return $this->serviceCache[__METHOD__];
}
}

public function document(): Catalog\Document\Service\Document
{
if (!isset($this->serviceCache[__METHOD__])) {
$this->serviceCache[__METHOD__] = new Catalog\Document\Service\Document(
new Catalog\Document\Service\Batch(
new Catalog\Document\Batch($this->core, $this->log),
$this->log
),
$this->core,
$this->log
);
}

return $this->serviceCache[__METHOD__];
}

public function documentElement(): Catalog\DocumentElement\Service\DocumentElement
{
if (!isset($this->serviceCache[__METHOD__])) {
$this->serviceCache[__METHOD__] = new Catalog\DocumentElement\Service\DocumentElement(
new Catalog\DocumentElement\Service\Batch(
new Catalog\DocumentElement\Batch($this->core, $this->log),
$this->log
),
$this->core,
$this->log
);
}

return $this->serviceCache[__METHOD__];
}
}
2 changes: 1 addition & 1 deletion src/Services/Catalog/Common/ProductType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ enum ProductType: int
case SKU = 3;
case productOffer = 4;
case genericOffer = 5;
}
}
2 changes: 1 addition & 1 deletion src/Services/Catalog/Common/Result/AbstractCatalogItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ protected function getKeyWithUserfieldByFieldName(string $fieldName)

return $this->$fieldName;
}
}
}
108 changes: 108 additions & 0 deletions src/Services/Catalog/Document/Batch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

/**
* This file is part of the bitrix24-php-sdk package.
*
* © Dmitriy Ignatenko <algonexys@gmail.com>
*
* For the full copyright and license information, please view the MIT-LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Bitrix24\SDK\Services\Catalog\Document;

use Bitrix24\SDK\Core\Exceptions\BaseException;
use Bitrix24\SDK\Core\Exceptions\InvalidArgumentException;
use Bitrix24\SDK\Core\Response\DTO\ResponseData;
use Generator;

/**
* Class Batch
*
* Overrides base Batch to handle parameter naming differences in catalog.document.* REST methods:
* - delete uses lowercase 'id' instead of 'ID'
*
* @see https://apidocs.bitrix24.com/api-reference/catalog/document/catalog-document-delete.html
* @see https://apidocs.bitrix24.com/api-reference/catalog/document/catalog-document-list.html
*/
class Batch extends \Bitrix24\SDK\Core\Batch
{
/**
* Determines the ID key — lowercase 'id' for catalog document
*/
#[\Override]
protected function determineKeyId(string $apiMethod, ?array $additionalParameters): string
{
return 'id';
}

/**
* Delete entity items with batch call using lowercase 'id' parameter
*
* @param int[] $entityItemId
* @param array<mixed>|null $additionalParameters
*
* @return Generator<int, ResponseData>|ResponseData[]
* @throws BaseException
*/
#[\Override]
public function deleteEntityItems(
string $apiMethod,
array $entityItemId,
?array $additionalParameters = null
): Generator {
$this->logger->debug(
'deleteEntityItems.start',
[
'apiMethod' => $apiMethod,
'entityItems' => $entityItemId,
'additionalParameters' => $additionalParameters,
]
);

try {
$this->clearCommands();
foreach ($entityItemId as $cnt => $itemId) {
if (!is_int($itemId)) {
throw new InvalidArgumentException(
sprintf(
'invalid type «%s» of document id «%s» at position %s, document id must be integer type',
gettype($itemId),
$itemId,
$cnt
)
);
}

$this->registerCommand($apiMethod, ['id' => $itemId]);
}

foreach ($this->getTraversable(true) as $cnt => $deletedItemResult) {
yield $cnt => $deletedItemResult;
}
} catch (InvalidArgumentException $exception) {
$errorMessage = sprintf('batch delete document items: %s', $exception->getMessage());
$this->logger->error(
$errorMessage,
[
'trace' => $exception->getTrace(),
]
);
throw $exception;
} catch (\Throwable $exception) {
$errorMessage = sprintf('batch delete document items: %s', $exception->getMessage());
$this->logger->error(
$errorMessage,
[
'trace' => $exception->getTrace(),
]
);

throw new BaseException($errorMessage, $exception->getCode(), $exception);
}

$this->logger->debug('deleteEntityItems.finish');
}
}
33 changes: 33 additions & 0 deletions src/Services/Catalog/Document/Result/DocumentAddedBatchResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* This file is part of the bitrix24-php-sdk package.
*
* © Dmitriy Ignatenko <algonexys@gmail.com>
*
* For the full copyright and license information, please view the MIT-LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Bitrix24\SDK\Services\Catalog\Document\Result;

use Bitrix24\SDK\Core\Response\DTO\ResponseData;

class DocumentAddedBatchResult
{
public function __construct(private readonly ResponseData $responseData)
{
}

public function getResponseData(): ResponseData
{
return $this->responseData;
}

public function document(): DocumentItemResult
{
return new DocumentItemResult($this->responseData->getResult()['document']);
}
}
29 changes: 29 additions & 0 deletions src/Services/Catalog/Document/Result/DocumentFieldsResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/**
* This file is part of the bitrix24-php-sdk package.
*
* © Dmitriy Ignatenko <algonexys@gmail.com>
*
* For the full copyright and license information, please view the MIT-LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Bitrix24\SDK\Services\Catalog\Document\Result;

use Bitrix24\SDK\Core\Exceptions\BaseException;
use Bitrix24\SDK\Core\Result\AbstractResult;

class DocumentFieldsResult extends AbstractResult
{
/**
* @return array<string, array<string, mixed>>
* @throws BaseException
*/
public function getFieldsDescription(): array
{
return $this->getCoreResponse()->getResponseData()->getResult()['document'];
}
}
41 changes: 41 additions & 0 deletions src/Services/Catalog/Document/Result/DocumentItemResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* This file is part of the bitrix24-php-sdk package.
*
* © Dmitriy Ignatenko <algonexys@gmail.com>
*
* For the full copyright and license information, please view the MIT-LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Bitrix24\SDK\Services\Catalog\Document\Result;

use Bitrix24\SDK\Core\Result\AbstractItem;
use Carbon\CarbonImmutable;
use Money\Money;

/**
* @property-read int $id
* @property-read string $docType
* @property-read string $currency
* @property-read int $responsibleId
* @property-read string|null $siteId
* @property-read CarbonImmutable|null $dateDocument
* @property-read CarbonImmutable|null $dateCreate
* @property-read CarbonImmutable|null $dateModify
* @property-read CarbonImmutable|null $dateStatus
* @property-read string|null $title
* @property-read string|null $commentary
* @property-read Money|null $total
* @property-read string|null $docNumber
* @property-read int|null $createdBy
* @property-read int|null $modifiedBy
* @property-read string|null $status
* @property-read int|null $statusBy
*/
class DocumentItemResult extends AbstractItem
{
}
Loading
Loading