46 $this->result = array();
49 $this->result = $this->getNotSkuItemData($data);
52 $offersDescription =
'';
53 if (isset($data[
"OFFERS"]) && is_array($data[
"OFFERS"]) && !empty($data[
"OFFERS"]))
56 $this->selectOfferProps = $data[
"SELECT_OFFER_PROPS"];
57 $this->result[
"PHOTOS_OFFERS"] = array();
58 $this->result[
"PHOTOS_OFFERS_FOR_VK"] = array();
60 $offersConverted = array();
61 foreach ($data[
"OFFERS"] as $offer)
63 $resultOffer = $this->getItemDataOffersOffer($offer);
65 if (!empty($resultOffer[
"PHOTOS"]))
66 $this->result[
"PHOTOS_OFFERS"] += $resultOffer[
"PHOTOS"];
68 if (!empty($resultOffer[
"PHOTOS_FOR_VK"]))
69 $this->result[
"PHOTOS_OFFERS_FOR_VK"] += $resultOffer[
"PHOTOS_FOR_VK"];
71 $offersConverted[] = $resultOffer;
74 $offersDescription = $this->createOffersDescriptionByPrices($offersConverted);
78 if (!$this->result[
"PRICE"])
80 $logger->addError(
'PRODUCT_EMPTY_PRICE', $data[
"ID"]);
86 if ($offersDescription <>
'')
87 $this->result[
"description"] .=
"\n\n" .
Loc::getMessage(
"SALE_VK_PRODUCT_VARIANTS") .
"\n" . $offersDescription;
91 $photosSorted = $this->sortPhotosArray();
94 $photosChecked = Vk\PhotoResizer::checkPhotos($photosSorted,
'PRODUCT');
95 if (empty($photosChecked))
97 $logger->addError(
"PRODUCT_WRONG_PHOTOS", $data[
"ID"]);
102 $this->result[
"PHOTO_MAIN_BX_ID"] = $photosChecked[
"PHOTO_MAIN_BX_ID"];
103 $this->result[
"PHOTO_MAIN_URL"] = $photosChecked[
"PHOTO_MAIN_URL"];
104 $this->result[
"PHOTOS"] = $photosChecked[
"PHOTOS"];
107 if ($photosChecked[
'RESIZE_UP'])
108 $logger->addError(
'PRODUCT_PHOTOS_RESIZE_UP', $data[
"ID"]);
109 if ($photosChecked[
'RESIZE_DOWN'])
110 $logger->addError(
'PRODUCT_PHOTOS_RESIZE_DOWN', $data[
"ID"]);
114 $this->result[
"description"] = html_entity_decode($this->result[
"description"]);
115 $this->result[
"description"] = preg_replace(
'/\t*/',
'', $this->result[
"description"]);
116 $this->result[
"description"] = strip_tags($this->result[
"description"]);
118 $this->result[
'description'] = $this->validateDescription($this->result[
'description'], $logger);
119 $this->result[
"description"] = self::convertToUtf8($this->result[
"description"]);
121 $this->result[
'NAME'] = $this->validateName($this->result[
'NAME'], $logger);
122 $this->result[
'NAME'] = self::convertToUtf8($this->result[
'NAME']);
124 return array($data[
"ID"] => $this->result);
135 private function validateName($name,
Vk\
Logger $logger = NULL)
139 if (($length = self::matchLength($name)) < self::NAME_LENGHT_MIN)
141 $newName = self::extendString($name, $length, self::NAME_LENGHT_MIN);
144 $logger->addError(
'PRODUCT_SHORT_NAME', $this->result[
"BX_ID"]);
148 if (($length = self::matchLength($name)) > self::NAME_LENGHT_MAX)
150 $newName = self::reduceString($name, $length, self::NAME_LENGHT_MAX);
153 $logger->addError(
'PRODUCT_LONG_NAME', $this->result[
"BX_ID"]);
168 private function validateDescription($desc, Vk\
Logger $logger = NULL)
172 if (mb_strlen($desc) < self::DESCRIPTION_LENGHT_MIN)
174 $newDesc = $this->result[
'NAME'] .
': ' . $desc;
175 if (mb_strlen($newDesc) < self::DESCRIPTION_LENGHT_MIN)
177 $newDesc = self::mb_str_pad($newDesc, self::DESCRIPTION_LENGHT_MIN, self::PAD_STRING);
179 if ($newDesc[mb_strlen($newDesc) - 1] ==
' ')
181 $newDesc .= self::PAD_STRING;
185 $logger->addError(
'PRODUCT_SHORT_DESCRIPTION', $this->result[
"BX_ID"]);
190 if (mb_strlen($newDesc) > self::DESCRIPTION_LENGHT_MAX)
192 $newDesc = mb_substr($newDesc, 0, self::DESCRIPTION_LENGHT_MAX).
'...';
207 private function createOffersDescriptionByPrices($offers)
209 $mainPrice = isset($this->result[
'PRICE']) && $this->result[
'PRICE'] ? $this->result[
'PRICE'] : 0;
210 $needSkuPriceDescription =
false;
213 foreach ($offers as $offer)
219 $mainPrice = $offer[
'PRICE'];
222 if ($offer[
'PRICE'] != $mainPrice)
223 $needSkuPriceDescription =
true;
225 $mainPrice = ($mainPrice != 0) ? min($offer[
'PRICE'], $mainPrice) : $offer[
'PRICE'];
230 $offersDescription =
'';
231 if ($needSkuPriceDescription)
233 foreach ($offers as $offer)
235 $offersDescription .= $offer[
"DESCRIPTION_PROPERTIES"] .
" - " .
Loc::getMessage(
"SALE_VK_PRODUCT_PRICE") .
" " . $offer[
'PRICE'] .
" " .
Loc::getMessage(
"SALE_VK_PRODUCT_CURRENCY") .
"\n";
241 foreach ($offers as $offer)
243 $offersDescription .= $offer[
"DESCRIPTION_PROPERTIES"] .
"\n";
247 $this->result[
'PRICE'] = $mainPrice;
249 return $offersDescription;
258 private function sortPhotosArray()
260 $newPhotos = array();
261 if (isset($this->result[
'PHOTOS_FOR_VK']) && !empty($this->result[
'PHOTOS_FOR_VK']))
262 $newPhotos += $this->result[
'PHOTOS_FOR_VK'];
264 if (isset($this->result[
'PHOTOS_OFFERS_FOR_VK']) && !empty($this->result[
'PHOTOS_OFFERS_FOR_VK']))
265 $newPhotos += $this->result[
'PHOTOS_OFFERS_FOR_VK'];
267 if (isset($this->result[
'PHOTO_MAIN']) && !empty($this->result[
'PHOTO_MAIN']))
268 $newPhotos += $this->result[
'PHOTO_MAIN'];
270 if (isset($this->result[
'PHOTOS']) && !empty($this->result[
'PHOTOS']))
271 $newPhotos += $this->result[
'PHOTOS'];
273 if (isset($this->result[
'PHOTOS_OFFERS']) && !empty($this->result[
'PHOTOS_OFFERS']))
274 $newPhotos += $this->result[
'PHOTOS_OFFERS'];
278 $this->result[
'PHOTOS_FOR_VK'],
279 $this->result[
'PHOTOS_OFFERS_FOR_VK'],
280 $this->result[
'PHOTOS'],
281 $this->result[
'PHOTO_MAIN'],
282 $this->result[
'PHOTOS_OFFERS']
297 private function getItemDataOffersOffer($data)
299 $result = array(
"DESCRIPTION" =>
"");
302 $propertyDescriptions = array();
303 foreach ($this->selectOfferProps as $prop)
305 if ($propValue = $data[
"PROPERTIES"][$prop][
"VALUE"])
308 if ($data[
"PROPERTIES"][$prop][
"USER_TYPE"] ==
'directory')
310 if (\CModule::IncludeModule(
'highloadblock'))
313 $resHlBlocks = HighloadBlockTable::getList(array(
314 'filter' => array(
'=TABLE_NAME' => $data[
"PROPERTIES"][$prop][
"USER_TYPE_SETTINGS"][
"TABLE_NAME"]),
316 $hlBlockItemId = $resHlBlocks->fetch();
317 $hlBlockItemId = $hlBlockItemId[
'ID'];
323 $hlBlock = HighloadBlockTable::getById($hlBlockItemId)->fetch();
324 $hlEntity = HighloadBlockTable::compileEntity($hlBlock);
325 $strEntityDataClass = $hlEntity->getDataClass();
328 $resData = $strEntityDataClass::getList(array(
329 'select' => array(
'ID',
'UF_NAME'),
330 'filter' => array(
'=UF_XML_ID' => $propValue),
332 $propValue = $resData->fetch();
333 $propValue = $propValue[
'UF_NAME'];
337 if(is_array($propValue))
338 $propValue = implode(
', ', $propValue);
340 $propertyDescriptions[] = $data[
"PROPERTIES"][$prop][
"NAME"] .
": " . $propValue;
343 if (!empty($propertyDescriptions))
344 $result[
"DESCRIPTION_PROPERTIES"] = implode(
"; ", $propertyDescriptions);
347 $description = strip_tags($data[
"~DETAIL_TEXT"] <>
'' ? $data[
"~DETAIL_TEXT"] : $data[
"~PREVIEW_TEXT"]);
349 $result[
"DESCRIPTION"] .= $description;
352 $result[
'PRICE'] = $data[
"PRICES"][
"MIN_RUB"];
355 $photoId = ($data[
"DETAIL_PICTURE"] <>
'') ? $data[
"DETAIL_PICTURE"] : $data[
"PREVIEW_PICTURE"];
357 $result[
"PHOTOS"] = array($photoId => array(
"PHOTO_BX_ID" => $photoId));
360 $vkPhotosKey =
'PHOTOS_FOR_VK_' . $data[
"IBLOCK_ID"];
361 $resOfferProps = new \_CIBElement();
362 $resOfferProps->fields = array(
"IBLOCK_ID" => $data[
"IBLOCK_ID"],
"ID" => $data[
"ID"]);
363 $resOfferProps = $resOfferProps->GetProperties(array(), array(
"CODE" => $vkPhotosKey));
364 if (!empty($resOfferProps[$vkPhotosKey][
"VALUE"]))
366 foreach ($resOfferProps[$vkPhotosKey][
"VALUE"] as $ph)
368 $result[
"PHOTOS_FOR_VK"][$ph] = array(
369 "PHOTO_BX_ID" => $ph,
384 private function getNotSkuItemData($data)
387 $result[
"BX_ID"] = $data[
"ID"];
388 $result[
"IBLOCK_ID"] = $data[
"IBLOCK_ID"];
389 $result[
"NAME"] = $data[
"~NAME"];
390 $result[
"SECTION_ID"] = $data[
"IBLOCK_SECTION_ID"];
391 $result[
"CATEGORY_VK"] = $this->sectionsList->getVkCategory($data[
"IBLOCK_SECTION_ID"]);
394 $result[
"deleted"] = 0;
395 $result[
"PRICE"] = $data[
"PRICES"][
"MIN_RUB"];
396 $result[
"description"] = $data[
"~DETAIL_TEXT"] <>
'' ? $data[
"~DETAIL_TEXT"] : $data[
"~PREVIEW_TEXT"];
397 $result[
"description"] = trim(preg_replace(
'/\s{2,}/',
"\n", $result[
"description"]));
399 $photoMainBxId = $data[
"DETAIL_PICTURE"] <>
'' ? $data[
"DETAIL_PICTURE"] : $data[
"PREVIEW_PICTURE"];
400 $photoMainUrl = $data[
"DETAIL_PICTURE_URL"] <>
'' ? $data[
"DETAIL_PICTURE_URL"] : $data[
"PREVIEW_PICTURE_URL"];
401 if ($photoMainBxId && $photoMainUrl)
402 $result[
"PHOTO_MAIN"] = array(
403 $photoMainBxId => array(
404 "PHOTO_BX_ID" => $photoMainBxId,
405 "PHOTO_URL" => $photoMainUrl,
410 if (isset($data[
"PROPERTIES"][
"MORE_PHOTO"][
"VALUE"]) &&
411 is_array($data[
"PROPERTIES"][
"MORE_PHOTO"][
"VALUE"]) &&
412 !empty($data[
"PROPERTIES"][
"MORE_PHOTO"][
"VALUE"])
415 foreach ($data[
"PROPERTIES"][
"MORE_PHOTO"][
"VALUE"] as $ph)
417 $result[
"PHOTOS"][$ph] = array(
"PHOTO_BX_ID" => $ph);
422 $vkPhotosKey =
'PHOTOS_FOR_VK_' . $data[
"IBLOCK_ID"];
423 if (isset($data[
"PROPERTIES"][$vkPhotosKey][
"VALUE"]) &&
424 is_array($data[
"PROPERTIES"][$vkPhotosKey][
"VALUE"]) &&
425 !empty($data[
"PROPERTIES"][$vkPhotosKey][
"VALUE"])
428 foreach ($data[
"PROPERTIES"][$vkPhotosKey][
"VALUE"] as $ph)
430 $result[
"PHOTOS_FOR_VK"][$ph] = array(
431 "PHOTO_BX_ID" => $ph,
static getMessage($code, $replace=null, $language=null)