Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
catalog.php
1<?php
2
4
13
14abstract class Catalog extends AbstractBase
15{
16 private function getSetup(): Setup
17 {
18 static $setup = null;
19
20 if ($setup === null)
21 {
22 $setup = Setup::load();
23 }
24
25 return $setup;
26 }
27
28 private function getBusinessId(): ?string
29 {
30 $setup = $this->getSetup();
31
32 return $setup->get($setup::BUSINESS_ID);
33 }
34
35 private function getInstalls(): Installs
36 {
37 static $installs = null;
38
39 if ($installs === null)
40 {
41 $installs = Installs::load();
42 }
43
44 return $installs;
45 }
46
47 public function getCatalogId(): ?string
48 {
49 return $this->getInstalls()->getCatalog();
50 }
51
52 private function createResponseWithError(string $error): Response
53 {
54 return Response::create(self::TYPE_CODE)->addError(new Error($error));
55 }
56
57 private function sendRequest(string $name, array $data = []): Response
58 {
59 $businessId = $this->getBusinessId();
60 if ($businessId === null)
61 {
62 return $this->createResponseWithError('Empty business id.');
63 }
64
65 return
66 $this
67 ->getRequest()
68 ->send([
69 'methodName' => $this->getMethodName($name),
70 'parameters' => array_merge(
71 $data,
72 [
73 'fbe_external_business_id' => $businessId,
74 'catalog_id' => $this->getCatalogId(),
75 ]
76 ),
77 ])
78 ;
79 }
80
81 public function batchCatalogProducts(array $productData): Response
82 {
83 if (empty($productData))
84 {
85 return $this->createResponseWithError('Empty product data.');
86 }
87
88 return $this->sendRequest('products.batch', [
89 'catalog_id' => $this->getCatalogId(),
90 'allow_upsert' => true,
91 'requests' => $productData,
92 ]);
93 }
94
95 public function checkBatchRequestStatus(string $queueId): Response
96 {
97 if ($queueId === '')
98 {
99 return $this->createResponseWithError('Empty queue id.');
100 }
101
102 return $this->sendRequest('products.check.batch.status', [
103 'queue_id' => $queueId,
104 ]);
105 }
106
107 public function getProductsInfo(array $retailerIds): Response
108 {
109 if (empty($retailerIds))
110 {
111 return $this->createResponseWithError('Empty retailer ids.');
112 }
113
114 return $this->sendRequest('products.get.info', [
115 'catalog_id' => $this->getCatalogId(),
116 'filter' => Json::encode([
117 'retailer_id' => [
118 'is_any' => $retailerIds,
119 ]
120 ]),
121 'fields' => 'id, retailer_id, review_status, review_rejection_reasons',
122 ]);
123 }
124}
getProductsInfo(array $retailerIds)
Definition catalog.php:107
batchCatalogProducts(array $productData)
Definition catalog.php:81
checkBatchRequestStatus(string $queueId)
Definition catalog.php:95