Beispiel #1
0
 private static function EnsureProduct($externalID, $catalogID, $arFields)
 {
     $rsProducts = CCrmProduct::GetList(array(), array('CATALOG_ID' => $catalogID, 'ORIGIN_ID' => $externalID), array('ID'));
     $arProduct = $rsProducts ? $rsProducts->Fetch() : false;
     if (is_array($arProduct)) {
         return intval($arProduct['ID']);
     }
     $arFields['CATALOG_ID'] = $catalogID;
     $arFields['ORIGIN_ID'] = $externalID;
     return CCrmProduct::Add($arFields);
 }
 private function SaveOrderDataProducts($arOrder, $dealId)
 {
     if (!isset($arOrder["ITEMS"]) || !is_array($arOrder["ITEMS"])) {
         return false;
     }
     if (!$this->catalogId) {
         if ($this->arExternalSale == null) {
             $this->arExternalSale = CCrmExternalSale::GetDefaultSettings($this->externalSaleId);
         }
         $this->catalogId = CCrmCatalog::GetCatalogId($this->arExternalSale["NAME"], $this->externalSaleId, SITE_ID);
         if (!$this->catalogId) {
             if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) {
                 $this->AddError($ex->GetID(), $ex->GetString());
             } else {
                 $this->AddError("CCA", "Catalog creation error");
             }
             return false;
         }
     }
     $arProductRows = array();
     foreach ($arOrder["ITEMS"] as $arItem) {
         $productId = 0;
         $dbProduct = CCrmProduct::GetList(array(), array("CATALOG_ID" => $this->catalogId, "ORIGINATOR_ID" => $this->externalSaleId, "ORIGIN_ID" => $arItem["ID"], "CHECK_PERMISSIONS" => "N"), array('ID'), array('nTopCount' => 1));
         if ($arProduct = $dbProduct->Fetch()) {
             $productId = $arProduct["ID"];
         }
         $arFields = array('NAME' => $arItem["NAME"], 'ACTIVE' => "Y", 'CATALOG_ID' => $this->catalogId, 'PRICE' => $arItem["PRICE"], 'CURRENCY_ID' => $arOrder["CURRENCY"], 'ORIGINATOR_ID' => $this->externalSaleId, 'ORIGIN_ID' => $arItem["ID"]);
         if ($productId == 0) {
             $res = CCrmProduct::Add($arFields);
             if ($res > 0) {
                 $productId = (int) $res;
             }
         } else {
             $res = CCrmProduct::Update($productId, $arFields);
         }
         if (!$res) {
             if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) {
                 $this->AddError($ex->GetID(), $ex->GetString());
             } else {
                 $this->AddError("CDA", "Product creation error");
             }
             continue;
         }
         $arProductRows[] = array('PRODUCT_ID' => $productId, 'PRICE' => $arItem["PRICE"], 'QUANTITY' => $arItem["QUANTITY"]);
     }
     if (is_array($arOrder["TAXES"])) {
         foreach ($arOrder["TAXES"] as $arItem) {
             if (intval($arItem["IN_PRICE"]) > 0) {
                 continue;
             }
             $productId = 0;
             $dbProduct = CCrmProduct::GetList(array(), array("CATALOG_ID" => $this->catalogId, "ORIGINATOR_ID" => $this->externalSaleId, "ORIGIN_ID" => "tax_" . $arItem["NAME"], "CHECK_PERMISSIONS" => "N"), array('ID'), array('nTopCount' => 1));
             if ($arProduct = $dbProduct->Fetch()) {
                 $productId = $arProduct["ID"];
             }
             $arFields = array('NAME' => $arItem["NAME"], 'ACTIVE' => "Y", 'CATALOG_ID' => $this->catalogId, 'PRICE' => $arItem["PRICE"], 'CURRENCY_ID' => $arOrder["CURRENCY"], 'ORIGINATOR_ID' => $this->externalSaleId, 'ORIGIN_ID' => "tax_" . $arItem["NAME"]);
             if ($productId == 0) {
                 $res = CCrmProduct::Add($arFields);
                 $productId = intval($res);
             } else {
                 $res = CCrmProduct::Update($productId, $arFields);
             }
             if (!$res) {
                 if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) {
                     $this->AddError($ex->GetID(), $ex->GetString());
                 } else {
                     $this->AddError("CDA", "Product creation error");
                 }
                 continue;
             }
             $arProductRows[] = array('PRODUCT_ID' => $productId, 'PRICE' => $arItem["PRICE"], 'QUANTITY' => 1);
         }
     }
     if (is_array($arOrder["DISCOUNTS"])) {
         foreach ($arOrder["DISCOUNTS"] as $arItem) {
             if (intval($arItem["IN_PRICE"]) > 0) {
                 continue;
             }
             $productId = 0;
             $dbProduct = CCrmProduct::GetList(array(), array("CATALOG_ID" => $this->catalogId, "ORIGINATOR_ID" => $this->externalSaleId, "ORIGIN_ID" => "discount_" . $arItem["NAME"], "CHECK_PERMISSIONS" => "N"), array('ID'), array('nTopCount' => 1));
             if ($arProduct = $dbProduct->Fetch()) {
                 $productId = $arProduct["ID"];
             }
             $arFields = array('NAME' => $arItem["NAME"], 'ACTIVE' => "Y", 'CATALOG_ID' => $this->catalogId, 'PRICE' => $arItem["PRICE"], 'CURRENCY_ID' => $arOrder["CURRENCY"], 'ORIGINATOR_ID' => $this->externalSaleId, 'ORIGIN_ID' => "discount_" . $arItem["NAME"]);
             if ($productId == 0) {
                 $res = CCrmProduct::Add($arFields);
                 $productId = intval($res);
             } else {
                 $res = CCrmProduct::Update($productId, $arFields);
             }
             if (!$res) {
                 if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false) {
                     $this->AddError($ex->GetID(), $ex->GetString());
                 } else {
                     $this->AddError("CDA", "Product creation error");
                 }
                 continue;
             }
             $arProductRows[] = array('PRODUCT_ID' => $productId, 'PRICE' => -$arItem["PRICE"], 'QUANTITY' => 1);
         }
     }
     CCrmProductRow::SaveRows("D", $dealId, $arProductRows, null, false, false);
     return true;
 }
Beispiel #3
0
if (CCrmSecurityHelper::GetCurrentUserID() > 0) {
    // Convert LEAD & DEAL PRODUCT  -->
    if (COption::GetOptionString('crm', '~crm_11_0_6_convertion', 'N') !== 'Y') {
        $baseCurrencyID = "USD";
        $rsLang = CLanguage::GetByID("ru");
        if ($arLang = $rsLang->Fetch()) {
            $baseCurrencyID = "RUB";
        } else {
            $rsLang = CLanguage::GetByID("de");
            if ($arLang = $rsLang->Fetch()) {
                $baseCurrencyID = "EUR";
            }
        }
        $arProducts = CCrmStatus::GetStatusList('PRODUCT', true);
        foreach ($arProducts as $prodCode => $prodName) {
            CCrmProduct::Add(array('NAME' => $prodName, 'ACTIVE' => 'Y', 'CURRENCY_ID' => $baseCurrencyID, 'PRICE' => 1, 'ORIGIN_ID' => 'CRM_PROD_' . $prodCode, 'ORIGINATOR_ID' => 'CRM_PRODUCT_REFERENCE'));
        }
        $rsDeals = CCrmDeal::GetListEx(array('ID' => 'ASC'), array("CHECK_PERMISSIONS" => "N"), false, false, array('ID', 'PRODUCT_ID', 'OPPORTUNITY', 'CURRENCY_ID'));
        while ($arDeal = $rsDeals->Fetch()) {
            $ID = isset($arDeal['ID']) ? intval($arDeal['ID']) : 0;
            if ($ID <= 0) {
                continue;
            }
            $productID = isset($arDeal['PRODUCT_ID']) ? $arDeal['PRODUCT_ID'] : '';
            if (isset($productID[0])) {
                $arProductRows = CCrmDeal::LoadProductRows($ID);
                if (count($arProductRows) > 0) {
                    // Already converted
                    continue;
                }
                $arProduct = CCrmProduct::GetByOriginID('CRM_PROD_' . $productID);
Beispiel #4
0
                 }
                 $productFields['PROPERTY_VALUES'][$arPropV['ID']][$arPropV['PROPERTY_VALUE_ID']] = array('VALUE' => $arPropV['VALUE'], 'DESCRIPTION' => $arPropV['DESCRIPTION']);
             }
         }
     }
 }
 $err = '';
 if ($productID > 0) {
     if (!CCrmProduct::Update($productID, $productFields)) {
         $err = CCrmProduct::GetLastError();
         if (!isset($err[0])) {
             $err = GetMessage('CRM_PRODUCT_UPDATE_UNKNOWN_ERROR');
         }
     }
 } else {
     $productID = CCrmProduct::Add($productFields);
     if (!$productID) {
         $err = CCrmProduct::GetLastError();
         if (!isset($err[0])) {
             $err = GetMessage('CRM_PRODUCT_ADD_UNKNOWN_ERROR');
         }
     }
 }
 if ($bAjax || $bAjaxSubmit) {
     $APPLICATION->RestartBuffer();
     $ajaxResponse = array('err' => '', 'productId' => 0, 'productData' => array());
     if (isset($err[0])) {
         $ajaxResponse['err'] = $err;
     } else {
         $ajaxResponse['productId'] = $productID;
         $dbRes = CCrmProduct::GetList(array(), array('ID' => $productID, '~REAL_PRICE' => true), array('ID', 'NAME', 'ACTIVE', 'PRICE', 'CURRENCY_ID', 'MEASURE', 'VAT_ID', 'VAT_INCLUDED'), array('nTopCount' => 1));
Beispiel #5
0
         if (substr($key, 0, 11) === 'SECTION_ID_') {
             $strLevel = substr($key, 11);
             if ($strLevel !== false && strlen($strLevel) > 0) {
                 $sectionLevel = intval($strLevel);
                 if ($sectionLevel > 0) {
                     $sectionLevel--;
                     $sectionName = $value;
                     $arProductSections[$sectionLevel] = $sectionName;
                 }
                 unset($sectionName, $sectionLevel);
             }
             unset($strLevel, $arProduct[$key]);
         }
     }
     $arProduct['SECTION_ID'] = $sectionHelper->ImportSectionArray($arProductSections);
     if (!CCrmProduct::Add($arProduct)) {
         $err = CCrmProduct::GetLastError();
         if (!isset($err[0])) {
             $err = GetMessage('CRM_PRODUCT_ADD_UNKNOWN_ERROR');
         }
         $arResult['error']++;
         $arResult['error_data'][] = array('message' => $err, 'data' => $arProduct['__CSV_DATA__']);
         unset($err);
     } else {
         if (!empty($arProduct)) {
             $arResult['import']++;
         }
     }
 }
 $_SESSION['CRM_IMPORT_FILE_POS'] = $filePos;
 $_SESSION['CRM_IMPORT_FILE_FIRST_HEADER'] = false;
Beispiel #6
0
 protected function innerAdd(&$fields, &$errors, array $params = null)
 {
     if (!CCrmProduct::CheckCreatePermission()) {
         $errors[] = 'Access denied.';
         return false;
     }
     $result = CCrmProduct::Add($fields);
     if (!is_int($result)) {
         $errors[] = CCrmProduct::GetLastError();
     }
     return $result;
 }
Beispiel #7
0
 protected function innerAdd(&$fields, &$errors, array $params = null)
 {
     if (!CModule::IncludeModule('iblock')) {
         throw new RestException('Could not load iblock module.');
     }
     if (!CCrmProduct::CheckCreatePermission()) {
         $errors[] = 'Access denied.';
         return false;
     }
     $catalogID = intval(CCrmCatalog::EnsureDefaultExists());
     if ($catalogID <= 0) {
         $errors[] = 'Default catalog is not exists.';
         return false;
     }
     // Product properties
     $this->initializePropertiesInfo($catalogID);
     $propertyValues = array();
     foreach ($this->properties as $propId => $property) {
         if (isset($fields[$propId])) {
             $propertyValues[$property['ID']] = $fields[$propId];
         }
         unset($fields[$propId]);
     }
     if (count($propertyValues) > 0) {
         $fields['PROPERTY_VALUES'] = $propertyValues;
     }
     $result = CCrmProduct::Add($fields);
     if (!is_int($result)) {
         $errors[] = CCrmProduct::GetLastError();
     }
     return $result;
 }