Exemplo n.º 1
0
    if (isset($_POST['MEASURE_CODE'])) {
        $fields['MEASURE_CODE'] = intval($_POST['MEASURE_CODE']);
    }
    if (isset($_POST['MEASURE_NAME'])) {
        $fields['MEASURE_NAME'] = $_POST['MEASURE_NAME'];
    }
    if (isset($_POST['TAX_RATE'])) {
        $fields['TAX_RATE'] = round(doubleval($_POST['TAX_RATE']), 2);
    }
    if (isset($_POST['TAX_INCLUDED'])) {
        $fields['TAX_INCLUDED'] = strtoupper($_POST['TAX_INCLUDED']) === 'Y' ? 'Y' : 'N';
    }
    //Is always enabled for disable requests to product catalog
    $fields['CUSTOMIZED'] = 'Y';
    $fields['SORT'] = isset($_POST['SORT']) ? intval($_POST['SORT']) : 0;
    $ID = CCrmProductRow::Add($fields);
    if (!$ID) {
        echo CUtil::PhpToJSObject(array('ERROR' => CCrmProductRow::GetLastError()));
    } else {
        echo CUtil::PhpToJSObject(array('PRODUCT_ROW' => array('ID' => $ID)));
    }
} elseif ($mode === 'UPDATE_PRODUCT') {
    if ($perms->HavePerm($ownerName, BX_CRM_PERM_NONE, 'WRITE')) {
        echo CUtil::PhpToJSObject(array('ERROR' => 'PERMISSION_DENIED'));
        die;
    }
    //'ID':1 'PRODUCT_ID':100, 'QUANTITY':1, 'CURRENCY_ID':1 'PRICE':100.50
    $fields = array();
    $ID = isset($_POST['ID']) ? intval($_POST['ID']) : 0;
    if ($ID <= 0) {
        echo CUtil::PhpToJSObject(array('ERROR' => 'ID_NOT_FOUND'));
Exemplo n.º 2
0
 protected function innerAdd(&$fields, &$errors, array $params = null)
 {
     $ownerID = isset($fields['OWNER_ID']) ? intval($fields['OWNER_ID']) : 0;
     $ownerType = isset($fields['OWNER_TYPE']) ? $fields['OWNER_TYPE'] : '';
     if ($ownerID <= 0 || $ownerType === '') {
         if ($ownerID <= 0) {
             $errors[] = 'The field OWNER_ID is required.';
         }
         if ($ownerType === '') {
             $errors[] = 'The field OWNER_TYPE is required.';
         }
         return false;
     }
     if (!CCrmAuthorizationHelper::CheckCreatePermission(CCrmProductRow::ResolveOwnerTypeName($ownerType))) {
         $errors[] = 'Access denied.';
         return false;
     }
     $result = CCrmProductRow::Add($fields, true, true);
     if (!is_int($result)) {
         $errors[] = CCrmProductRow::GetLastError();
     }
     return $result;
 }