Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
product.php
1<?php
2
4
10
17class Product extends DataSource implements \Iterator
18{
19 protected $feeds = array();
20 protected $currentFeed;
21 protected $startPosition = array();
22
23 protected $vk;
24 protected $exportId;
25
31 public function __construct($exportId, $startPosition)
32 {
33 $this->vk = Vk\Vk::getInstance();
34
35 if (!$this->vk->isActive())
36 throw new SystemException("Vk is not active!" . __METHOD__);
37
38// check and set EXPORT ID
39 if (!isset($exportId) || $exportId == '')
40 throw new ArgumentNullException("EXPORT_ID");
41 $this->exportId = $exportId;
42
43// check and set START POSITION
45
46 if (!Loader::includeModule('catalog'))
47 throw new SystemException("Can't include module \"Catalog\"! " . __METHOD__);
48
49// get items only from sections, that was checked to export. And get them iblocksIds
50 $sectionsList = new Vk\SectionsList($this->exportId);
51 $sectionsToExport = $sectionsList->getSectionsToProductExport();
52 $logger = new Vk\Logger($this->exportId);
53 if(!empty($sectionsToExport))
54 {
55 $logger->addLog('Sections to export', $sectionsToExport);
56 }
57 $iblockIds = $sectionsList->getMappedIblocks();
58
59// if not products to export - ERROR
60 if (empty($sectionsToExport))
61 {
62 $logger->addError('EMPTY_SECTIONS_LIST');
63 }
64
65// create FEEDS
66 foreach ($iblockIds as $iblockId)
67 {
68 $exportOfferParams = array(
69 "IBLOCK_ID" => $iblockId,
70 "PRODUCT_GROUPS" => $sectionsToExport[$iblockId],
71 "INCLUDE_SUBSECTION" => false // we have all sections in PRODUCT_GROUPS, subsections is not needed
72 );
73// set start position, if exist. Set current feed as start
74 if (isset($this->startPosition[$iblockId]))
75 {
76 $exportOfferParams["START_POSITION"] = $this->startPosition[$iblockId];
77 $this->startFeed = count($this->feeds);
78 }
79
80 $feed = ExportOfferCreator::getOfferObject($exportOfferParams);
81 if($this->vk->getAvailableFlag($this->exportId))
82 $feed->setOnlyAvailableFlag(true);
83
84 $this->feeds[] = $feed;
85 unset($feed);
86 }
87 }
88
89
90 protected function setStartPosition($startPosition)
91 {
92 if ($startPosition <> '')
93 {
94// todo: maybe can use cache from sectionslist
95// find IblockId for this product ID
96 if (Loader::includeModule("catalog") && Loader::includeModule("iblock"))
97 {
98 $resIblockId = \CIBlockElement::GetList(array(), array("ID" => $startPosition), false, false, array("IBLOCK_ID"));
99 if ($iblockId = $resIblockId->Fetch())
100 $this->startPosition[$iblockId["IBLOCK_ID"]] = $startPosition;
101 }
102 }
103 }
104
109 public function current()
110 {
111 $current = $this->feeds[$this->currentFeed]->current();
112 return $current;
113 }
114
119 public function key()
120 {
121 return $this->currentFeed . "_" . $this->feeds[$this->currentFeed]->key();
122 }
123
127 public function next()
128 {
129 $this->feeds[$this->currentFeed]->next();
130
131 // step to the next product feed
132 if (!$this->valid() && $this->currentFeed < count($this->feeds) - 1)
133 {
134 $this->currentFeed++;
135 $this->next();
136 }
137 }
138
142 public function rewind()
143 {
144 $this->currentFeed = $this->startFeed;
145
146 foreach ($this->feeds as $feed)
147 $feed->rewind();
148 }
149
154 public function valid()
155 {
156 return $this->feeds[$this->currentFeed]->valid();
157 }
158}
static getOfferObject(array $offerParams)