13 isset($productFields[
'QUANTITY'])
14 || isset($productFields[
'QUANTITY_TRACE'])
15 || isset($productFields[
'CAN_BUY_ZERO'])
23 $productIterator = ProductTable::getList(array(
24 'filter' => array(
'=ID' => $ID),
25 'select' => array(
'QUANTITY',
'QUANTITY_TRACE',
'CAN_BUY_ZERO'),
27 $product = $productIterator->fetch();
30 if($product[
"QUANTITY_TRACE"] ==
"Y" && $product[
'CAN_BUY_ZERO'] ==
'N')
32 $linkIterator = LinkTable::getList(array(
48 "AUTO_QUANTITY_ON" =>
"BANNER.AUTO_QUANTITY_ON",
49 "AUTO_QUANTITY_OFF" =>
"BANNER.AUTO_QUANTITY_OFF",
53 $zeroQuantity = $product[
'QUANTITY'] <= 0;
55 $linkIdMark = array();
56 $linkIdUnMark = array();
57 while($link = $linkIterator->fetch())
59 $linkIdMark[] = $link[
"BANNER_ID"];
66 $linkIdUnMark[] = $link[
"BANNER_ID"];
70 if(count($linkIdMark) > 0)
81 if(count($linkIdUnMark) > 0)
99 if(!IsModuleInstalled(
"catalog"))
101 return __CLASS__.
"::checkQuantityAgent();";
104 $dbRes = YandexBannerTable::getList(array(
115 'ID',
'XML_ID',
'CAMPAIGN_ID',
'CAMPAIGN_XML_ID' =>
'CAMPAIGN.XML_ID',
116 'AUTO_QUANTITY_ON',
'AUTO_QUANTITY_OFF',
126 return __CLASS__.
"::checkQuantityAgent();";
129 $bannersListToStop = array();
130 $bannersListToResume = array();
131 $bannersListToUnMarkStopped = array();
132 $bannersListToUnMarkResumed = array();
134 $bannersLogData = array();
135 while($banner = $dbRes->fetch())
139 if(!isset($bannersListToResume[$banner[
"CAMPAIGN_XML_ID"]]))
141 $bannersListToResume[$banner[
"CAMPAIGN_XML_ID"]] = array();
144 $bannersListToResume[$banner[
"CAMPAIGN_XML_ID"]][$banner[
"ID"]] = $banner[
"XML_ID"];
149 $bannersListToUnMarkStopped[] = $banner[
"ID"];
154 if(!isset($bannersListToResume[$banner[
"CAMPAIGN_XML_ID"]]))
156 $bannersListToStop[$banner[
"CAMPAIGN_XML_ID"]] = array();
159 $bannersListToStop[$banner[
"CAMPAIGN_XML_ID"]][$banner[
"ID"]] = $banner[
"XML_ID"];
164 $bannersListToUnMarkResumed[] = $banner[
"ID"];
168 $bannersLogData[$banner[
"ID"]] = array(
169 'CAMPAIGN_ID' => $banner[
'CAMPAIGN_ID'],
170 'CAMPAIGN_XML_ID' => $banner[
'CAMPAIGN_XML_ID'],
171 'BANNER_ID' => $banner[
'ID'],
172 'BANNER_XML_ID' => $banner[
'XML_ID'],
173 'CAUSE_CODE' => $causeCode,
177 if(count($bannersLogData) > 0)
179 foreach($bannersListToResume as $campaignId => $bannersList)
181 if(count($bannersList) > 0)
187 $engine->resumeBanners($campaignId, array_values($bannersList));
194 foreach($bannersList as $bannerId => $bannerXmlId)
196 $logEntry = $bannersLogData[$bannerId];
197 $logEntry[
'ENGINE_ID'] = $engine->getId();
200 AutologTable::add($logEntry);
203 $bannersListToUnMarkResumed = array_merge(
204 $bannersListToUnMarkResumed,
205 array_keys($bannersList)
210 foreach($bannersListToStop as $campaignId => $bannersList)
212 if(count($bannersList) > 0)
217 $engine->stopBanners($campaignId, array_values($bannersList));
224 foreach($bannersList as $bannerId => $bannerXmlId)
226 $logEntry = $bannersLogData[$bannerId];
227 $logEntry[
'ENGINE_ID'] = $engine->getId();
230 AutologTable::add($logEntry);
233 $bannersListToUnMarkStopped = array_merge(
234 $bannersListToUnMarkStopped,
235 array_keys($bannersList)
240 if(count($bannersListToUnMarkStopped) > 0)
245 if(count($bannersListToUnMarkResumed) > 0)
251 return __CLASS__.
"::checkQuantityAgent();";