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