1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
FacebookProductRepository.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\v2\Integration\Seo\Facebook;
4
5use Bitrix\Catalog\v2\Integration\Seo\Entity\ExportedProduct;
6use Bitrix\Catalog\v2\Integration\Seo\Entity\ExportedProductCollection;
7use Bitrix\Catalog\v2\Integration\Seo\Entity\ExportedProductTable;
8use Bitrix\Main\Result;
9use Bitrix\Main\Type\DateTime;
10
12{
13 private const SERVICE_ID = 'facebook';
14
15 public function save(array $data)
16 {
17 $collection = $this->loadCollection(array_keys($data));
18 foreach ($collection as $exportedProduct)
19 {
20 $productId = $exportedProduct->getProductId();
21 $exportedProduct->setTimestampX(new DateTime());
22 $error = $data[$productId]['ERROR'] ?? null;
23 $exportedProduct->setError($error);
24 unset($data[$productId]);
25 }
26
27 foreach ($data as $productId => $productData)
28 {
29 $exportedProduct = new ExportedProduct();
30 $exportedProduct
31 ->setServiceId(self::SERVICE_ID)
32 ->setProductId($productId)
33 ->setError($productData['ERROR'] ?? null)
34 ;
35 $collection[] = $exportedProduct;
36 }
37
38 return $collection->save(true);
39 }
40
41 public function delete(array $ids): Result
42 {
43 $result = new Result();
44
45 $collection = $this->loadCollection($ids);
46 foreach ($collection as $exportedProduct)
47 {
48 $res = $exportedProduct->delete();
49 if (!$res->isSuccess())
50 {
51 $result->addErrors($res->getErrors());
52 }
53 }
54
55 return $result;
56 }
57
58 public function getProductsByIds(array $ids): array
59 {
60 $products = [];
61 $collection = $this->loadCollection($ids);
62 foreach ($collection as $exportedProduct)
63 {
64 $products[] = [
65 'ID' => $exportedProduct->getProductId(),
66 'ERROR' => $exportedProduct->getError(),
67 ];
68 }
69
70 return $products;
71 }
72
73 public function loadCollection(array $productIds): ExportedProductCollection
74 {
75 if (empty($productIds))
76 {
77 return ExportedProductTable::createCollection();
78 }
79
80 return
81 ExportedProductTable::getList([
82 'filter' => [
83 '=SERVICE_ID' => self::SERVICE_ID,
84 '@PRODUCT_ID' => $productIds,
85 ],
86 ])
87 ->fetchCollection()
88 ;
89 }
90}
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$error
Определения subscription_card_product.php:20