示例#1
0
 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 Exists($ID)
 {
     $dbRes = CCrmProductRow::GetList(array(), array('ID' => $ID), false, false, array('ID'));
     return $dbRes->Fetch() ? true : false;
 }
 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;
 }
示例#4
0
 protected function innerGetList($order, $filter, $select, $navigation, &$errors)
 {
     $ownerID = isset($filter['OWNER_ID']) ? intval($filter['OWNER_ID']) : 0;
     $ownerType = isset($filter['OWNER_TYPE']) ? $filter['OWNER_TYPE'] : '';
     if ($ownerID <= 0 || $ownerType === '') {
         if ($ownerID <= 0) {
             $errors[] = 'The field OWNER_ID is required in filer.';
         }
         if ($ownerType === '') {
             $errors[] = 'The field OWNER_TYPE is required in filer.';
         }
         return false;
     }
     if ($ownerType === 'I') {
         //Crutch for Invoices
         if (!CCrmInvoice::CheckReadPermission($ownerID)) {
             $errors[] = 'Access denied.';
             return false;
         }
         $result = array();
         $productRows = CCrmInvoice::GetProductRows($ownerID);
         foreach ($productRows as $productRow) {
             $price = isset($productRow['PRICE']) ? $productRow['PRICE'] : 0.0;
             $discountSum = isset($productRow['DISCOUNT_PRICE']) ? $productRow['DISCOUNT_PRICE'] : 0.0;
             $taxRate = isset($productRow['VAT_RATE']) ? $productRow['VAT_RATE'] * 100 : 0.0;
             $exclusivePrice = CCrmProductRow::CalculateExclusivePrice($price, $taxRate);
             $discountRate = \Bitrix\Crm\Discount::calculateDiscountRate($exclusivePrice + $discountSum, $exclusivePrice);
             $result[] = array('ID' => $productRow['ID'], 'OWNER_ID' => $ownerID, 'OWNER_TYPE' => 'I', 'PRODUCT_ID' => isset($productRow['PRODUCT_ID']) ? $productRow['PRODUCT_ID'] : 0, 'PRODUCT_NAME' => isset($productRow['PRODUCT_NAME']) ? $productRow['PRODUCT_NAME'] : '', 'PRICE' => $price, 'QUANTITY' => isset($productRow['QUANTITY']) ? $productRow['QUANTITY'] : 0, 'DISCOUNT_TYPE_ID' => \Bitrix\Crm\Discount::MONETARY, 'DISCOUNT_RATE' => $discountRate, 'DISCOUNT_SUM' => $discountSum, 'TAX_RATE' => $taxRate, 'TAX_INCLUDED' => 'Y', 'MEASURE_CODE' => isset($productRow['MEASURE_CODE']) ? $productRow['MEASURE_CODE'] : '', 'MEASURE_NAME' => isset($productRow['MEASURE_NAME']) ? $productRow['MEASURE_NAME'] : '', 'CUSTOMIZED' => isset($productRow['CUSTOM_PRICE']) ? $productRow['CUSTOM_PRICE'] : 'N');
         }
         return $result;
     }
     if (!CCrmAuthorizationHelper::CheckReadPermission(CCrmProductRow::ResolveOwnerTypeName($ownerType), $ownerID)) {
         $errors[] = 'Access denied.';
         return false;
     }
     return CCrmProductRow::GetList($order, $filter, false, $navigation, $select, array('IS_EXTERNAL_CONTEXT' => true));
 }