public static function Update($ID, $arFields) { if (!CModule::IncludeModule('catalog')) { return false; } global $DB; if (!self::CheckFields('UPDATE', $arFields, $ID)) { return false; } if (isset($arFields['NAME']) || isset($arFields['SECTION_ID']) || isset($arFields['SORT']) || isset($arFields['ACTIVE']) || isset($arFields['DETAIL_PICTURE']) || isset($arFields['DESCRIPTION']) || isset($arFields['DESCRIPTION_TYPE']) || isset($arFields['PREVIEW_PICTURE']) || isset($arFields['PREVIEW_TEXT']) || isset($arFields['PREVIEW_TEXT_TYPE']) || isset($arFields['ORIGINATOR_ID']) || isset($arFields['ORIGIN_ID']) || isset($arFields['XML_ID']) || isset($arFields['PROPERTY_VALUES'])) { $element = new CIBlockElement(); $obResult = $element->GetById($ID); if ($arElement = $obResult->Fetch()) { // files $arElement['PREVIEW_PICTURE'] = CFile::MakeFileArray($arElement['PREVIEW_PICTURE']); $arElement['DETAIL_PICTURE'] = CFile::MakeFileArray($arElement['DETAIL_PICTURE']); if (isset($arFields['NAME'])) { $arElement['NAME'] = $arFields['NAME']; } if (isset($arFields['SECTION_ID'])) { $arElement['IBLOCK_SECTION_ID'] = $arFields['SECTION_ID']; } if (isset($arFields['SORT'])) { $arElement['SORT'] = $arFields['SORT']; } if (isset($arFields['ACTIVE'])) { $arElement['ACTIVE'] = $arFields['ACTIVE']; } if (isset($arFields['DETAIL_PICTURE'])) { $arElement['DETAIL_PICTURE'] = $arFields['DETAIL_PICTURE']; } if (isset($arFields['DESCRIPTION'])) { $arElement['DETAIL_TEXT'] = $arFields['DESCRIPTION']; } if (isset($arFields['DESCRIPTION_TYPE'])) { $arElement['DETAIL_TEXT_TYPE'] = $arFields['DESCRIPTION_TYPE']; } if (isset($arFields['PREVIEW_PICTURE'])) { $arElement['PREVIEW_PICTURE'] = $arFields['PREVIEW_PICTURE']; } if (isset($arFields['PREVIEW_TEXT'])) { $arElement['PREVIEW_TEXT'] = $arFields['PREVIEW_TEXT']; $arElement['PREVIEW_TEXT_TYPE'] = 'text'; } if (isset($arFields['PREVIEW_TEXT_TYPE'])) { $arElement['PREVIEW_TEXT_TYPE'] = $arFields['PREVIEW_TEXT_TYPE']; } if (isset($arFields['XML_ID'])) { $arElement['XML_ID'] = $arElement['EXTERNAL_ID'] = $arFields['XML_ID']; } else { if (isset($arFields['ORIGINATOR_ID']) || isset($arFields['ORIGIN_ID'])) { if (strlen($arFields['ORIGINATOR_ID']) > 0 && strlen($arFields['ORIGIN_ID']) > 0) { $arElement['XML_ID'] = $arFields['ORIGINATOR_ID'] . '#' . $arFields['ORIGIN_ID']; } else { $delimiterPos = strpos($arElement['XML_ID'], '#'); if (strlen($arFields['ORIGINATOR_ID']) > 0) { if ($delimiterPos !== false) { $arElement['XML_ID'] = $arFields['ORIGINATOR_ID'] . substr($arElement['XML_ID'], $delimiterPos); } else { $arElement['XML_ID'] = $arFields['ORIGINATOR_ID']; } } else { if ($delimiterPos !== false) { $arElement['XML_ID'] = substr($arElement['XML_ID'], 0, $delimiterPos) . $arFields['ORIGIN_ID']; } else { $arElement['XML_ID'] = '#' . $arFields['ORIGINATOR_ID']; } } } } } if (isset($arFields['PROPERTY_VALUES'])) { $arElement['PROPERTY_VALUES'] = $arFields['PROPERTY_VALUES']; } if (!$element->Update($ID, $arElement)) { self::$LAST_ERROR = $element->LAST_ERROR; return false; } } } // update VAT $CCatalogProduct = new CCatalogProduct(); $arCatalogProductFields = array(); if (isset($arFields['VAT_INCLUDED'])) { $arCatalogProductFields['VAT_INCLUDED'] = $arFields['VAT_INCLUDED']; } if (isset($arFields['VAT_ID']) && !empty($arFields['VAT_ID'])) { $arCatalogProductFields['VAT_ID'] = $arFields['VAT_ID']; } if (isset($arFields['MEASURE']) && !empty($arFields['MEASURE'])) { $arCatalogProductFields['MEASURE'] = $arFields['MEASURE']; } if (count($arCatalogProductFields) > 0) { $CCatalogProduct->Update($ID, $arCatalogProductFields); } if (isset($arFields['PRICE']) && isset($arFields['CURRENCY_ID'])) { self::setPrice($ID, $arFields['PRICE'], $arFields['CURRENCY_ID']); } else { if (isset($arFields['PRICE']) || isset($arFields['CURRENCY_ID'])) { $CPrice = new CPrice(); $price = $currency = false; if (!isset($arFields['PRICE'])) { $basePriceInfo = self::getPrice($ID); if ($basePriceInfo !== false && is_array($basePriceInfo) && isset($basePriceInfo['PRICE'])) { $price = $basePriceInfo['PRICE']; $currency = $arFields['CURRENCY_ID']; } } elseif (!isset($arFields['CURRENCY_ID'])) { $basePriceInfo = self::getPrice($ID); if ($basePriceInfo !== false && is_array($basePriceInfo) && isset($basePriceInfo['PRICE'])) { $price = $arFields['PRICE']; $currency = $basePriceInfo['CURRENCY']; } } else { $price = $arFields['PRICE']; $currency = $arFields['CURRENCY_ID']; } if ($price !== false && $currency !== false) { CCrmProduct::setPrice($ID, $price, $currency); } } } // $sUpdate = trim($DB->PrepareUpdate(CCrmProduct::TABLE_NAME, $arFields)); // if (!empty($sUpdate)) // { // $sQuery = 'UPDATE '.CCrmProduct::TABLE_NAME.' SET '.$sUpdate.' WHERE ID = '.$ID; // $DB->Query($sQuery, false, 'File: '.__FILE__.'<br/>Line: '.__LINE__); // // CCrmEntityHelper::RemoveCached(self::CACHE_NAME, $ID); // } CCrmEntityHelper::RemoveCached(self::CACHE_NAME, $ID); return true; }