public function AddOffer arOffer el new CIBlockElement fl new CFile ca

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
public function AddOffer($arOffer)
{
$el = new CIBlockElement;
$fl = new CFile;
$catId = $this->GetParentID($arOffer['UF_SECTION_ID']);
if ($catId == '')
{
unset($el);
return false;
}
if ($arOffer['PRICE'] <> '' && $arOffer['OLD_PRICE'] <> '')
{
if($arOffer['OLD_PRICE'] > $arOffer['PRICE'])
{
$arOffer['DISCOUNT'] = 100 - intval(100.0 * $arOffer['PRICE'] / $arOffer['OLD_PRICE']);
}
}
$arProp['ID'] = $arOffer['ID'];
$arProp['UF_ID'] = $arOffer['UF_ID'];
$arProp['UF_SECTION_ID'] = $arOffer['UF_SECTION_ID'];
$arProp['BRAND'] = $arOffer['BRAND'];
$arColors = explode(',', $arOffer['COLORS']);
if(sizeof($arColors) > 0)
{
foreach($arColors as $color)
{
$arProp['COLORS'][] = array('VALUE' => $color);
}
}
else
{
$arProp['COLORS'] = array('VALUE' => mb_strtolower(trim($arOffer['COLORS'])));
}
$arSeason = explode(',', $arOffer['SEASON']);
if(sizeof($arSeason) > 0)
{
foreach($arSeason as $season)
{
$arProp['SEASON'][] = array('VALUE' => mb_strtolower(trim($season)));
}
}
else
{
$arProp['SEASON'] = array('VALUE' => mb_strtolower(trim($arOffer['SEASON'])));
}
$arProp['PRICE'] = $arOffer['PRICE'];
$arProp['SHOP'] = $arOffer['SHOP'];
$arProp['DISCOUNT'] = $arOffer['DISCOUNT'];
$arProp['LINK'] = $arOffer['LINK'];
$arProp['MATERIAL'] = $arOffer['MATERIAL'];
$arProp['COLLECTION'] = $arOffer['COLLECTION'];
$arProp['MFR'] = $arOffer['MFR'];
$arProp['SIZE'] = $arOffer['SIZE'];
$arProp['GENDER'] = $arOffer['GENDER'];
$arProp['AGE'] = $arOffer['AGE'];
$arProp['VENDOR_CODE'] = $arOffer['VENDOR_CODE'];
$arProp['SIMILAR_PRODUCTS'] = $arOffer['SIMILAR_PRODUCTS'];
$arProp['OLD_PRICE'] = $arOffer['OLD_PRICE'];
$arProp['SALES_LEADER'] = $arOffer['SALES_LEADER'];
$arLoadProductArray = Array(
'IBLOCK_SECTION_ID' => $catId,
'IBLOCK_ID' => (int)$this->iblockId,
'PROPERTY_VALUES'=> $arProp,
'NAME' => (string)$arOffer['NAME'],
'CODE' => $this->translitIt((string)TruncateText($arOffer['NAME'], 16)).'_'.$arOffer['UF_ID'],
'ACTIVE' => 'Y',
'PREVIEW_TEXT' => substr((string)$arOffer['DESCRIPTION'], 0, 255),
'DETAIL_TEXT' => (string)$arOffer['DESCRIPTION'],
);
if ($id = $el->Add($arLoadProductArray))
{
if ($arOffer['PREVIEW_PHOTO'] <> '')
{
$arPicture = $this->SaveImgFile($arOffer['PREVIEW_PHOTO']);
$arProp['PREVIEW_PHOTO'] = array('VALUE' => $arPicture['PREVIEW_PHOTO']['SRC'], 'DESCRIPTION' => $arPicture['PREVIEW_PHOTO']['ID']);
}
unset($arPicture);
if (sizeof($arOffer['DETAIL_PHOTO']) > 0)
{
foreach($arOffer['DETAIL_PHOTO'] as $url)
{
$arPicture = $this->SaveImgFile($url);
$arProp['DETAIL_PHOTO'][] = array('VALUE' => $fl->MakeFileArray($arPicture['SRC']), 'DESCRIPTION' => $arPicture['ID']);
}
}
//else
//{
// $arPicture = $this->SaveImgFile($arOffer['DETAIL_PHOTO']);
// $arProp['DETAIL_PHOTO'] = array('VALUE' => $fl->MakeFileArray($arPicture['SRC']), 'DESCRIPTION' => $arPicture['ID']);
//}
//echo "<pre>"; var_dump($arProp['DETAIL_PHOTO']); echo "</pre>";
$el->SetPropertyValuesEx($id, $this->iblockId, array('DETAIL_PHOTO' => $arProp['DETAIL_PHOTO']));
unset($arPicture, $arOffer, $el);
//die();
return $id;
}
else
{
die();
unset($arOffer);
$this->WriteLog('error', '', 'w+', $el->LAST_ERROR, '');
unset($el);
return false;
}
}