コード例 #1
0
ファイル: crm_product.php プロジェクト: DarneoStudio/bitrix
 public static function Delete($ID)
 {
     global $DB, $APPLICATION;
     $ID = intval($ID);
     $arProduct = self::GetByID($ID);
     if (!is_array($arProduct)) {
         // Is no exists
         return true;
     }
     $rowsCount = CCrmProductRow::GetList(array(), array('PRODUCT_ID' => $ID), array(), false, array());
     if ($rowsCount > 0 || CCrmInvoice::HasProductRows($ID)) {
         self::RegisterError(GetMessage('CRM_COULD_NOT_DELETE_PRODUCT_ROWS_EXIST', array('#NAME#' => $arProduct['~NAME'])));
         return false;
     }
     foreach (GetModuleEvents('crm', 'OnBeforeCrmProductDelete', true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array($ID)) === false) {
             return false;
         }
     }
     //$DB->StartTransaction();
     //$APPLICATION->ResetException();
     //		$sql = 'DELETE FROM '.CCrmProduct::TABLE_NAME.' WHERE ID = '.$ID;
     //		if(!$DB->Query($sql, true))
     //		{
     //			//$DB->Rollback();
     //			return false;
     //		}
     CCrmEntityHelper::RemoveCached(self::CACHE_NAME, $ID);
     if (self::IsIBlockElementExists($ID)) {
         $element = new CIBlockElement();
         if (!$element->Delete($ID)) {
             //$DB->Rollback();
             if ($ex = $APPLICATION->GetException()) {
                 self::RegisterError($ex->GetString());
             }
             return false;
         }
     }
     //$DB->Commit();
     foreach (GetModuleEvents('crm', 'OnCrmProductDelete', true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ID));
     }
     return true;
 }
コード例 #2
0
 public static function isIncludesUsedProducts($iblockId, $sectionId)
 {
     $iblockId = intval($iblockId);
     $sectionId = intval($sectionId);
     if ($iblockId <= 0 || $sectionId <= 0) {
         return false;
     }
     $result = false;
     $stepSize = 500;
     $element = new CIBlockElement();
     $rs = $element->GetList(array('SORT' => 'ASC'), array('IBLOCK_ID' => $iblockId, 'SECTION_ID' => $sectionId, 'INCLUDE_SUBSECTIONS' => 'Y', 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID'));
     if ($rs) {
         $i = 0;
         $arProductId = array();
         while ($row = $rs->Fetch()) {
             $i++;
             $arProductId[] = $row['ID'];
             if ($i === $stepSize) {
                 $rowsCount = CCrmProductRow::GetList(array(), array('PRODUCT_ID' => $arProductId), array(), false, array());
                 if ($rowsCount > 0 || CCrmInvoice::HasProductRows($arProductId)) {
                     $result = true;
                 }
                 $i = 0;
                 $arProductId = array();
             }
             if ($result) {
                 break;
             }
         }
         if (!$result && count($arProductId) > 0) {
             $rowsCount = CCrmProductRow::GetList(array(), array('PRODUCT_ID' => $arProductId), array(), false, array());
             if ($rowsCount > 0 || CCrmInvoice::HasProductRows($arProductId)) {
                 $result = true;
             }
         }
     }
     return $result;
 }