Skip to content

Commit ec164c0

Browse files
committed
add PropertyRelation and tests; run tests and linter; update changelog
1 parent 39a4b3a commit ec164c0

File tree

10 files changed

+578
-0
lines changed

10 files changed

+578
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
- `list` returns a list of bindings of payments to shipments
2929
- `delete` deletes the binding of a payment to a shipment
3030
- `getFields` returns the available fields for payment item shipment bindings
31+
- Added service `Services\Sale\PropertyRelation\Service\PropertyRelation` with support methods,
32+
see [sale.propertyRelation.* methods](https://github.com/bitrix24/b24phpsdk/issues/253):
33+
- `add` adds a property binding
34+
- `list` retrieves a list of property bindings
35+
- `deleteByFilter` removes the property relation
36+
- `getFields` returns the available fields for property binding
3137

3238
## 1.6.0 – 2025.09.01
3339

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ help:
5353
@echo "test-integration-sale-basket-property - run BasketProperty integration tests"
5454
@echo "test-integration-sale-payment-item-basket - run PaymentItemBasket integration tests"
5555
@echo "test-integration-sale-payment-item-shipment - run PaymentItemShipment integration tests"
56+
@echo "test-integration-sale-property-relation - run PropertyRelation integration tests"
5657

5758

5859
.PHONY: docker-init
@@ -221,6 +222,10 @@ test-integration-sale-payment-item-basket:
221222
.PHONY: test-integration-sale-payment-item-shipment
222223
test-integration-sale-payment-item-shipment:
223224
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_sale_payment_item_shipment
225+
226+
.PHONY: test-integration-sale-property-relation
227+
test-integration-sale-property-relation:
228+
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_sale_property_relation
224229

225230
.PHONY: test-integration-scope-crm
226231
test-integration-scope-crm:

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@
139139
<testsuite name="integration_tests_sale_payment_item_shipment">
140140
<directory>./tests/Integration/Services/Sale/PaymentItemShipment/</directory>
141141
</testsuite>
142+
<testsuite name="integration_tests_sale_property_relation">
143+
<directory>./tests/Integration/Services/Sale/PropertyRelation/</directory>
144+
</testsuite>
142145
<testsuite name="integration_tests_sale_order">
143146
<directory>./tests/Integration/Services/Sale/Order/</directory>
144147
</testsuite>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Sally Fancen <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\Sale\PropertyRelation\Result;
15+
16+
use Bitrix24\SDK\Core\Exceptions\BaseException;
17+
use Bitrix24\SDK\Core\Result\AddedItemResult;
18+
19+
/**
20+
* Class PropertyRelationAddedResult
21+
* Represents the result of an add property relation operation.
22+
*/
23+
class PropertyRelationAddedResult extends AddedItemResult
24+
{
25+
/**
26+
* @throws BaseException
27+
*/
28+
public function getId(): int
29+
{
30+
$result = $this->getCoreResponse()->getResponseData()->getResult();
31+
return isset($result['propertyRelation']['entityId']) ? (int)$result['propertyRelation']['entityId'] : 0;
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Sally Fancen <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\Sale\PropertyRelation\Result;
15+
16+
use Bitrix24\SDK\Core\Exceptions\BaseException;
17+
use Bitrix24\SDK\Core\Result\FieldsResult;
18+
19+
/**
20+
* Class PropertyRelationFieldsResult
21+
* Represents the result of a property relation fields operation.
22+
*/
23+
class PropertyRelationFieldsResult extends FieldsResult
24+
{
25+
/**
26+
* @throws BaseException
27+
*/
28+
public function getFieldsDescription(): array
29+
{
30+
$result = $this->getCoreResponse()->getResponseData()->getResult();
31+
return $result['propertyRelation'] ?? [];
32+
}
33+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Sally Fancen <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\Sale\PropertyRelation\Result;
15+
16+
use Bitrix24\SDK\Core\Result\AbstractItem;
17+
18+
/**
19+
* Class PropertyRelationItemResult
20+
* Represents a single property relation returned by Bitrix24 REST API.
21+
*
22+
* Fields and their types are taken from Bitrix24 API (sale.propertyRelation.getFields).
23+
*
24+
* @property-read int|null $entityId Entity identifier
25+
* @property-read string|null $entityType Entity type: P — payment system, D — delivery, L — landing, T — trading platform
26+
* @property-read int|null $propertyId Property identifier
27+
*/
28+
class PropertyRelationItemResult extends AbstractItem
29+
{
30+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Sally Fancen <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\Sale\PropertyRelation\Result;
15+
16+
use Bitrix24\SDK\Core\Exceptions\BaseException;
17+
use Bitrix24\SDK\Core\Result\AbstractResult;
18+
19+
/**
20+
* Class PropertyRelationsResult
21+
* Represents the result of property relations list operation.
22+
*/
23+
class PropertyRelationsResult extends AbstractResult
24+
{
25+
/**
26+
* @return PropertyRelationItemResult[]
27+
* @throws BaseException
28+
*/
29+
public function getPropertyRelations(): array
30+
{
31+
$res = [];
32+
foreach ($this->getCoreResponse()->getResponseData()->getResult()['propertyRelations'] as $propertyRelation) {
33+
$res[] = new PropertyRelationItemResult($propertyRelation);
34+
}
35+
36+
return $res;
37+
}
38+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Sally Fancen <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\Sale\PropertyRelation\Service;
15+
16+
use Bitrix24\SDK\Attributes\ApiEndpointMetadata;
17+
use Bitrix24\SDK\Attributes\ApiServiceMetadata;
18+
use Bitrix24\SDK\Core\Contracts\CoreInterface;
19+
use Bitrix24\SDK\Core\Credentials\Scope;
20+
use Bitrix24\SDK\Core\Exceptions\BaseException;
21+
use Bitrix24\SDK\Core\Exceptions\TransportException;
22+
use Bitrix24\SDK\Core\Result\DeletedItemResult;
23+
use Bitrix24\SDK\Services\AbstractService;
24+
use Bitrix24\SDK\Services\Sale\PropertyRelation\Result\PropertyRelationAddedResult;
25+
use Bitrix24\SDK\Services\Sale\PropertyRelation\Result\PropertyRelationFieldsResult;
26+
use Bitrix24\SDK\Services\Sale\PropertyRelation\Result\PropertyRelationsResult;
27+
use Psr\Log\LoggerInterface;
28+
29+
#[ApiServiceMetadata(new Scope(['sale']))]
30+
class PropertyRelation extends AbstractService
31+
{
32+
public function __construct(CoreInterface $core, LoggerInterface $logger)
33+
{
34+
parent::__construct($core, $logger);
35+
}
36+
37+
/**
38+
* Adds a property binding.
39+
*
40+
* @link https://apidocs.bitrix24.com/api-reference/sale/property-relation/sale-property-relation-add.html
41+
*
42+
* @param array $fields Field values for creating the property binding
43+
*
44+
* @throws BaseException
45+
* @throws TransportException
46+
*/
47+
#[ApiEndpointMetadata(
48+
'sale.propertyRelation.add',
49+
'https://apidocs.bitrix24.com/api-reference/sale/property-relation/sale-property-relation-add.html',
50+
'Creates a new property binding.'
51+
)]
52+
public function add(array $fields): PropertyRelationAddedResult
53+
{
54+
return new PropertyRelationAddedResult(
55+
$this->core->call('sale.propertyRelation.add', [
56+
'fields' => $fields
57+
])
58+
);
59+
}
60+
61+
/**
62+
* Retrieves a list of property bindings.
63+
*
64+
* @link https://apidocs.bitrix24.com/api-reference/sale/property-relation/sale-property-relation-list.html
65+
*
66+
* @param array $select Fields to select
67+
* @param array $filter Filter criteria
68+
* @param array $order Sort order
69+
* @param int $start Pagination start (offset)
70+
*
71+
* @throws BaseException
72+
* @throws TransportException
73+
*/
74+
#[ApiEndpointMetadata(
75+
'sale.propertyRelation.list',
76+
'https://apidocs.bitrix24.com/api-reference/sale/property-relation/sale-property-relation-list.html',
77+
'Retrieves a list of property bindings.'
78+
)]
79+
public function list(array $select = [], array $filter = [], array $order = [], int $start = 0): PropertyRelationsResult
80+
{
81+
return new PropertyRelationsResult(
82+
$this->core->call('sale.propertyRelation.list', [
83+
'select' => $select,
84+
'filter' => $filter,
85+
'order' => $order,
86+
'start' => $start
87+
])
88+
);
89+
}
90+
91+
/**
92+
* Removes the property relation.
93+
*
94+
* @link https://apidocs.bitrix24.com/api-reference/sale/property-relation/sale-property-relation-delete-by-filter.html
95+
*
96+
* @param array $fields Field values for removing the property relation
97+
*
98+
* @throws BaseException
99+
* @throws TransportException
100+
*/
101+
#[ApiEndpointMetadata(
102+
'sale.propertyRelation.deleteByFilter',
103+
'https://apidocs.bitrix24.com/api-reference/sale/property-relation/sale-property-relation-delete-by-filter.html',
104+
'Removes a property relation.'
105+
)]
106+
public function deleteByFilter(array $fields): DeletedItemResult
107+
{
108+
return new DeletedItemResult(
109+
$this->core->call('sale.propertyRelation.deleteByFilter', [
110+
'fields' => $fields
111+
])
112+
);
113+
}
114+
115+
/**
116+
* Returns the available fields for property binding.
117+
*
118+
* @link https://apidocs.bitrix24.com/api-reference/sale/property-relation/sale-property-relation-get-fields.html
119+
*
120+
* @throws BaseException
121+
* @throws TransportException
122+
*/
123+
#[ApiEndpointMetadata(
124+
'sale.propertyRelation.getFields',
125+
'https://apidocs.bitrix24.com/api-reference/sale/property-relation/sale-property-relation-get-fields.html',
126+
'Retrieves the description of property binding fields.'
127+
)]
128+
public function getFields(): PropertyRelationFieldsResult
129+
{
130+
return new PropertyRelationFieldsResult(
131+
$this->core->call('sale.propertyRelation.getFields', [])
132+
);
133+
}
134+
}

src/Services/Sale/SaleServiceBuilder.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use Bitrix24\SDK\Services\Sale\PropertyGroup;
3131
use Bitrix24\SDK\Services\Sale\Order;
3232
use Bitrix24\SDK\Services\Sale\BasketItem;
33+
use Bitrix24\SDK\Services\Sale\PropertyRelation;
3334

3435
/**
3536
* Class SaleServiceBuilder
@@ -240,4 +241,19 @@ public function basketProperty(): BasketProperty
240241

241242
return $this->serviceCache[__METHOD__];
242243
}
244+
245+
/**
246+
* Property Relation service (sale.propertyRelation.*)
247+
*/
248+
public function propertyRelation(): PropertyRelation\Service\PropertyRelation
249+
{
250+
if (!isset($this->serviceCache[__METHOD__])) {
251+
$this->serviceCache[__METHOD__] = new PropertyRelation\Service\PropertyRelation(
252+
$this->core,
253+
$this->log
254+
);
255+
}
256+
257+
return $this->serviceCache[__METHOD__];
258+
}
243259
}

0 commit comments

Comments
 (0)