Skip to content

Commit 784fd7a

Browse files
committed
add deal product rows
1 parent 03b3e78 commit 784fd7a

File tree

4 files changed

+153
-79
lines changed

4 files changed

+153
-79
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* add in scope «CRM» Products service and integration test
1111
* add in scope «CRM» Settings service and integration test
1212
* add in scope «CRM» DealCategoryStage service and integration test
13+
* add in scope «CRM» DealProductRows service and integration test
1314
* add in scope «IM» IM service and integration test
1415
* add in default scope «Main» default service
1516

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bitrix24\SDK\Services\CRM\Deal\Service;
6+
7+
use Bitrix24\SDK\Core\Exceptions\BaseException;
8+
use Bitrix24\SDK\Core\Exceptions\TransportException;
9+
use Bitrix24\SDK\Core\Result\UpdatedItemResult;
10+
use Bitrix24\SDK\Services\AbstractService;
11+
use Bitrix24\SDK\Services\CRM\Deal\Result\DealProductRowItemsResult;
12+
13+
/**
14+
* Class DealProductRows
15+
*
16+
* @package Bitrix24\SDK\Services\CRM\Deals\Service
17+
*/
18+
class DealProductRows extends AbstractService
19+
{
20+
/**
21+
* @param int $dealId
22+
*
23+
* @return DealProductRowItemsResult
24+
* @throws BaseException
25+
* @throws TransportException
26+
*/
27+
public function get(int $dealId): DealProductRowItemsResult
28+
{
29+
return new DealProductRowItemsResult(
30+
$this->core->call(
31+
'crm.deal.productrows.get',
32+
[
33+
'id' => $dealId,
34+
]
35+
)
36+
);
37+
}
38+
39+
/**
40+
* @param int $dealId
41+
* @param array<int, array{
42+
* ID?: int,
43+
* OWNER_ID?: int,
44+
* OWNER_TYPE?: string,
45+
* PRODUCT_ID?: int,
46+
* PRODUCT_NAME?: string,
47+
* PRICE?: string,
48+
* PRICE_EXCLUSIVE?: string,
49+
* PRICE_NETTO?: string,
50+
* PRICE_BRUTTO?: string,
51+
* QUANTITY?: string,
52+
* DISCOUNT_TYPE_ID?: int,
53+
* DISCOUNT_RATE?: string,
54+
* DISCOUNT_SUM?: string,
55+
* TAX_RATE?: string,
56+
* TAX_INCLUDED?: string,
57+
* CUSTOMIZED?: string,
58+
* MEASURE_CODE?: int,
59+
* MEASURE_NAME?: string,
60+
* SORT?: int
61+
* }> $productRows
62+
*
63+
* @return UpdatedItemResult
64+
* @throws BaseException
65+
* @throws TransportException
66+
*/
67+
public function set(int $dealId, array $productRows): UpdatedItemResult
68+
{
69+
return new UpdatedItemResult(
70+
$this->core->call(
71+
'crm.deal.productrows.set',
72+
[
73+
'id' => $dealId,
74+
'rows' => $productRows,
75+
]
76+
)
77+
);
78+
}
79+
}

src/Services/CRM/Deals/Service/DealProductRows.php

Lines changed: 0 additions & 79 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bitrix24\SDK\Tests\Integration\Services\CRM\Deal\Service;
6+
7+
use Bitrix24\SDK\Core\Exceptions\BaseException;
8+
use Bitrix24\SDK\Core\Exceptions\TransportException;
9+
use Bitrix24\SDK\Services\CRM\Deal\Service\Deal;
10+
use Bitrix24\SDK\Services\CRM\Deal\Service\DealProductRows;
11+
use Bitrix24\SDK\Tests\Integration\Fabric;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* Class DealsTest
16+
*
17+
* @package Bitrix24\SDK\Tests\Integration\Services\CRM\Deals\Service
18+
*/
19+
class DealProductRowsTest extends TestCase
20+
{
21+
protected Deal $dealService;
22+
protected DealProductRows $dealProductRowsService;
23+
24+
/**
25+
* @throws BaseException
26+
* @throws TransportException
27+
* @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealProductRows::set
28+
*/
29+
public function testSet(): void
30+
{
31+
$newDealId = $this->dealService->add(['TITLE' => 'test deal'])->getId();
32+
$this::assertCount(0, $this->dealProductRowsService->get($newDealId)->getProductRows());
33+
$this::assertTrue(
34+
$this->dealProductRowsService->set(
35+
$newDealId,
36+
[
37+
[
38+
'PRODUCT_NAME' => 'qqqq',
39+
],
40+
]
41+
)->isSuccess()
42+
);
43+
$this::assertCount(1, $this->dealProductRowsService->get($newDealId)->getProductRows());
44+
}
45+
46+
/**
47+
* @throws BaseException
48+
* @throws TransportException
49+
* @covers \Bitrix24\SDK\Services\CRM\Deal\Service\DealProductRows::get
50+
*/
51+
public function testGet(): void
52+
{
53+
$newDealId = $this->dealService->add(['TITLE' => 'test deal'])->getId();
54+
$this::assertCount(0, $this->dealProductRowsService->get($newDealId)->getProductRows());
55+
$this::assertTrue(
56+
$this->dealProductRowsService->set(
57+
$newDealId,
58+
[
59+
[
60+
'PRODUCT_NAME' => 'qqqq',
61+
],
62+
]
63+
)->isSuccess()
64+
);
65+
$this::assertCount(1, $this->dealProductRowsService->get($newDealId)->getProductRows());
66+
}
67+
68+
public function setUp(): void
69+
{
70+
$this->dealService = Fabric::getServiceBuilder()->getCRMScope()->deal();
71+
$this->dealProductRowsService = Fabric::getServiceBuilder()->getCRMScope()->dealProductRows();
72+
}
73+
}

0 commit comments

Comments
 (0)