Esempio n. 1
0
 /**
  * @static
  * @param $arFields
  * @return bool|int
  */
 static function add($arFields)
 {
     global $DB;
     foreach (GetModuleEvents("catalog", "OnBeforeDocumentAdd", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) {
             return false;
         }
     }
     if (array_key_exists('DATE_CREATE', $arFields)) {
         unset($arFields['DATE_CREATE']);
     }
     if (array_key_exists('DATE_MODIFY', $arFields)) {
         unset($arFields['DATE_MODIFY']);
     }
     $arFields['~DATE_MODIFY'] = $DB->GetNowFunction();
     $arFields['~DATE_CREATE'] = $DB->GetNowFunction();
     if (!self::CheckFields('ADD', $arFields)) {
         return false;
     }
     $arInsert = $DB->PrepareInsert("b_catalog_store_docs", $arFields);
     $strSql = "INSERT INTO b_catalog_store_docs (" . $arInsert[0] . ") VALUES(" . $arInsert[1] . ")";
     $res = $DB->Query($strSql, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     if (!$res) {
         return false;
     }
     $lastId = intval($DB->LastID());
     if (isset($arFields["ELEMENT"]) && is_array($arFields["ELEMENT"])) {
         foreach ($arFields["ELEMENT"] as $arElement) {
             $lastDocElementId = 0;
             if (isset($arElement["ID"])) {
                 unset($arElement["ID"]);
             }
             $arElement["DOC_ID"] = $lastId;
             if (is_array($arElement)) {
                 $lastDocElementId = CCatalogStoreDocsElement::add($arElement);
             }
             if (isset($arElement["BARCODE"]) && $lastDocElementId) {
                 if (is_array($arElement["BARCODE"])) {
                     foreach ($arElement["BARCODE"] as $barcode) {
                         CCatalogStoreDocsBarcode::add(array("DOC_ELEMENT_ID" => $lastDocElementId, "BARCODE" => $barcode));
                     }
                 }
             }
         }
     }
     foreach (GetModuleEvents("catalog", "OnDocumentAdd", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($lastId, $arFields));
     }
     return $lastId;
 }
			foreach($arProducts as $key => $val)
			{
				$storeTo = $val["STORE_TO"];
				$storeFrom = $val["STORE_FROM"];

				$arAdditional = Array(
					"AMOUNT" => $val["AMOUNT"],
					"ELEMENT_ID" => $val["PRODUCT_ID"],
					"PURCHASING_PRICE" => $val["PURCHASING_PRICE"],
					"STORE_TO" => $storeTo,
					"STORE_FROM" => $storeFrom,
					"ENTRY_ID" => $key,
					"DOC_ID" => $docId,
				);

				$docElementId = CCatalogStoreDocsElement::add($arAdditional);
				if($docElementId && isset($val["BARCODE"]))
				{
					$arBarcode = array();
					if(!empty($val["BARCODE"]))
					{
						$arBarcode = explode(', ', $val["BARCODE"]);
					}
					if(!empty($arBarcode))
					{
						foreach($arBarcode as $barCode)
						{
							CCatalogStoreDocsBarcode::add(array("BARCODE" => $barCode, "DOC_ELEMENT_ID" => $docElementId));
						}
					}
				}