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 #2
0
         while ($arPropV = $dbPropV->Fetch()) {
             if (isset($arPropV['USER_TYPE']) && !empty($arPropV['USER_TYPE']) && !array_key_exists($arPropV['USER_TYPE'], $arPropUserTypeList)) {
                 continue;
             }
             if ($arPropV['PROPERTY_TYPE'] != 'F' && !array_key_exists($arPropV['ID'], $arPropsValues)) {
                 if (!array_key_exists($arPropV['ID'], $productFields['PROPERTY_VALUES'])) {
                     $productFields['PROPERTY_VALUES'][$arPropV['ID']] = array();
                 }
                 $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) {
Beispiel #3
0
                                 $errorMessage .= '<br />';
                             }
                             $errorMessage .= CCrmProduct::GetLastError();
                         }
                     }
                 } else {
                     $arUpdateData = array();
                     reset($arResult['HEADERS']);
                     foreach ($arResult['HEADERS'] as $arHead) {
                         if (isset($arHead['editable']) && $arHead['editable'] == true && isset($arSrcData[$arHead['id']])) {
                             $arUpdateData[$arHead['id']] = $arSrcData[$arHead['id']];
                         }
                     }
                     if (!empty($arUpdateData)) {
                         $DB->StartTransaction();
                         if (CCrmProduct::Update($ID, $arUpdateData)) {
                             $DB->Commit();
                         } else {
                             if ($errorMessage !== '') {
                                 $errorMessage .= '<br />';
                             }
                             $errorMessage .= CCrmProduct::GetLastError();
                         }
                     }
                 }
             }
         }
     }
 }
 if (strlen($errorMessage) > 0) {
     if (!$actionData['AJAX_CALL']) {
Beispiel #4
0
 protected function innerUpdate($ID, &$fields, &$errors, array $params = null)
 {
     if (!(CCrmProduct::CheckUpdatePermission($ID) && CCrmProduct::EnsureDefaultCatalogScope($ID))) {
         $errors[] = 'Access denied.';
         return false;
     }
     $result = CCrmProduct::Update($ID, $fields);
     if ($result !== true) {
         $errors[] = CCrmProduct::GetLastError();
     }
     return $result;
 }
Beispiel #5
0
 protected function innerUpdate($ID, &$fields, &$errors, array $params = null)
 {
     if (!CModule::IncludeModule('iblock')) {
         throw new RestException('Could not load iblock module.');
     }
     if (!(CCrmProduct::CheckUpdatePermission($ID) && CCrmProduct::EnsureDefaultCatalogScope($ID))) {
         $errors[] = 'Access denied.';
         return false;
     }
     $catalogID = CCrmCatalog::GetDefaultID();
     if ($catalogID <= 0) {
         $errors[] = 'Product is not found.';
         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;
         $rsProperties = CIBlockElement::GetProperty($catalogID, $ID, 'sort', 'asc', array('ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N'));
         while ($property = $rsProperties->Fetch()) {
             if (isset($property['USER_TYPE']) && !empty($property['USER_TYPE']) && !array_key_exists($property['USER_TYPE'], $this->userTypes)) {
                 continue;
             }
             if ($property['PROPERTY_TYPE'] !== 'F' && !array_key_exists($property['ID'], $propertyValues)) {
                 if (!array_key_exists($property['ID'], $fields['PROPERTY_VALUES'])) {
                     $fields['PROPERTY_VALUES'][$property['ID']] = array();
                 }
                 $fields['PROPERTY_VALUES'][$property['ID']][$property['PROPERTY_VALUE_ID']] = array('VALUE' => $property['VALUE'], 'DESCRIPTION' => $property['DESCRIPTION']);
             }
         }
     }
     $result = CCrmProduct::Update($ID, $fields);
     if ($result !== true) {
         $errors[] = CCrmProduct::GetLastError();
     }
     return $result;
 }