Esempio n. 1
0
	protected function addCatalogProducts($arParams){
		if (!CModule::IncludeModule("iblock") && !CModule::IncludeModule("catalog") && !CModule::IncludeModule("sale")):
			return false;
		endif;
		$arFields = array(
			"ID" => $arParams["PRODUCT_ID"],
			"QUANTITY" => $arParams["BALANCE"],
			"CAN_BUY_ZERO" => "Y",
			"NEGATIVE_AMOUNT_TRACE" => "Y",
			"QUANTITY_TRACE" => "Y"
			);
		$db_res = CCatalogProduct::GetList(
			array(),
			array("ID" => $arParams["PRODUCT_ID"]),
			false,
			array()
			);
		if ($ar_res = $db_res->Fetch()):
			if (!CCatalogProduct::Update($ar_res["ID"], $arFields)):
				return false;
			endif;
		else:
			if(!CCatalogProduct::Add($arFields)):
				return false;
			endif;
		endif;
		return true;
	}
Esempio n. 2
0
	public function Add($arFields, $boolCheck = true)
	{
		global $DB;

		$boolFlag = false;
		$boolCheck = (false == $boolCheck ? false : true);

		$arFields["ID"] = intval($arFields["ID"]);
		if ($arFields["ID"]<=0)
			return false;

		if ($boolCheck)
		{
			$db_result = $DB->Query("SELECT 'x' FROM b_catalog_product WHERE ID = ".$arFields["ID"], false, "File: ".__FILE__."<br>Line: ".__LINE__);
			if ($db_result->Fetch())
			{
				$boolFlag = true;
			}
		}

		if (true == $boolFlag)
		{
			return CCatalogProduct::Update($arFields["ID"], $arFields);
		}
		else
		{
			foreach (GetModuleEvents("catalog", "OnBeforeProductAdd", true) as $arEvent)
			{
				if (ExecuteModuleEventEx($arEvent, array(&$arFields))===false)
					return false;
			}

			if (!CCatalogProduct::CheckFields("ADD", $arFields, 0))
				return false;

			$arInsert = $DB->PrepareInsert("b_catalog_product", $arFields);

			$strSql = "INSERT INTO b_catalog_product(".$arInsert[0].") VALUES(".$arInsert[1].")";
			$DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);

			foreach (GetModuleEvents("catalog", "OnProductAdd", true) as $arEvent)
			{
				ExecuteModuleEventEx($arEvent, array($arFields["ID"], $arFields));
			}

			// strange copy-paste bug
			foreach (GetModuleEvents("sale", "OnProductAdd", true) as $arEvent)
			{
				ExecuteModuleEventEx($arEvent, array($arFields["ID"], $arFields));
			}
		}

		return true;
	}
Esempio n. 3
0
 public function Add($arFields, $boolCheck = true)
 {
     global $DB;
     $existProduct = false;
     $boolCheck = $boolCheck !== false;
     if (empty($arFields['ID'])) {
         return false;
     }
     $arFields['ID'] = (int) $arFields['ID'];
     if ($arFields['ID'] <= 0) {
         return false;
     }
     if ($boolCheck) {
         $existProduct = Catalog\ProductTable::isExistProduct($arFields['ID']);
     }
     if ($existProduct) {
         return CCatalogProduct::Update($arFields['ID'], $arFields);
     } else {
         foreach (GetModuleEvents("catalog", "OnBeforeProductAdd", true) as $arEvent) {
             if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) {
                 return false;
             }
         }
         if (!CCatalogProduct::CheckFields("ADD", $arFields, 0)) {
             return false;
         }
         $arInsert = $DB->PrepareInsert("b_catalog_product", $arFields);
         $strSql = "INSERT INTO b_catalog_product(" . $arInsert[0] . ") VALUES(" . $arInsert[1] . ")";
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         Catalog\ProductTable::clearProductCache($arFields['ID']);
         foreach (GetModuleEvents("catalog", "OnProductAdd", true) as $arEvent) {
             ExecuteModuleEventEx($arEvent, array($arFields["ID"], $arFields));
         }
         // strange copy-paste bug
         foreach (GetModuleEvents("sale", "OnProductAdd", true) as $arEvent) {
             ExecuteModuleEventEx($arEvent, array($arFields["ID"], $arFields));
         }
     }
     return true;
 }
Esempio n. 4
0
 function ImportElementPrices($arXMLElement, &$counter, $arParent = false)
 {
     /** @global CMain $APPLICATION */
     global $APPLICATION;
     static $catalogs = array();
     $arElement = array("ID" => 0, "XML_ID" => $arXMLElement[$this->mess["IBLOCK_XML2_ID"]]);
     $hashPosition = strrpos($arElement["XML_ID"], "#");
     if ($this->use_offers && $hashPosition === false && !$this->force_offers && isset($this->PROPERTY_MAP["CML2_LINK"]) && isset($this->arProperties[$this->PROPERTY_MAP["CML2_LINK"]])) {
         $IBLOCK_ID = $this->arProperties[$this->PROPERTY_MAP["CML2_LINK"]]["LINK_IBLOCK_ID"];
         if (!isset($catalogs[$IBLOCK_ID])) {
             $catalogs[$IBLOCK_ID] = true;
             $rs = CCatalog::GetList(array(), array("IBLOCK_ID" => $IBLOCK_ID));
             if (!$rs->Fetch()) {
                 $obCatalog = new CCatalog();
                 $boolFlag = $obCatalog->Add(array("IBLOCK_ID" => $IBLOCK_ID, "YANDEX_EXPORT" => "N", "SUBSCRIPTION" => "N"));
                 if (!$boolFlag) {
                     if ($ex = $APPLICATION->GetException()) {
                         $this->LAST_ERROR = $ex->GetString();
                     }
                     return 0;
                 }
             }
         }
     } else {
         $IBLOCK_ID = $this->next_step["IBLOCK_ID"];
     }
     $obElement = new CIBlockElement();
     $rsElement = $obElement->GetList(array("ID" => "asc"), array("=XML_ID" => $arElement["XML_ID"], "IBLOCK_ID" => $IBLOCK_ID), false, false, array("ID", "TMP_ID", "ACTIVE"));
     $arDBElement = $rsElement->Fetch();
     if ($arDBElement) {
         $arElement["ID"] = $arDBElement["ID"];
     }
     if (isset($arXMLElement[$this->mess["IBLOCK_XML2_STORE_AMOUNT_LIST"]])) {
         $arElement["STORE_AMOUNT"] = array();
         foreach ($arXMLElement[$this->mess["IBLOCK_XML2_STORE_AMOUNT_LIST"]] as $storeAmount) {
             if (isset($storeAmount[$this->mess["IBLOCK_XML2_STORE_ID"]])) {
                 $storeXMLID = $storeAmount[$this->mess["IBLOCK_XML2_STORE_ID"]];
                 $amount = $this->ToFloat($storeAmount[$this->mess["IBLOCK_XML2_AMOUNT"]]);
                 $arElement["STORE_AMOUNT"][$storeXMLID] = $amount;
             }
         }
     } elseif (isset($arXMLElement[$this->mess["IBLOCK_XML2_RESTS"]])) {
         $arElement["STORE_AMOUNT"] = array();
         foreach ($arXMLElement[$this->mess["IBLOCK_XML2_RESTS"]] as $xmlRest) {
             foreach ($xmlRest as $storeAmount) {
                 if (is_array($storeAmount)) {
                     if (isset($storeAmount[$this->mess["IBLOCK_XML2_ID"]])) {
                         $storeXMLID = $storeAmount[$this->mess["IBLOCK_XML2_ID"]];
                         $amount = $this->ToFloat($storeAmount[$this->mess["IBLOCK_XML2_AMOUNT"]]);
                         $arElement["STORE_AMOUNT"][$storeXMLID] = $amount;
                     }
                 } else {
                     if (strlen($storeAmount) > 0) {
                         $amount = $this->ToFloat($storeAmount);
                         $arElement["QUANTITY"] = $amount;
                     }
                 }
             }
         }
     } elseif ($arParent && (array_key_exists($this->mess["IBLOCK_XML2_STORES"], $arXMLElement) || array_key_exists($this->mess["IBLOCK_XML2_STORE"], $arXMLElement))) {
         $arElement["STORE_AMOUNT"] = array();
         $rsStores = $this->_xml_file->GetList(array("ID" => "asc"), array("><LEFT_MARGIN" => array($arParent["LEFT_MARGIN"], $arParent["RIGHT_MARGIN"]), "NAME" => $this->mess["IBLOCK_XML2_STORE"]), array("ID", "ATTRIBUTES"));
         while ($arStore = $rsStores->Fetch()) {
             if (strlen($arStore["ATTRIBUTES"]) > 0) {
                 $info = unserialize($arStore["ATTRIBUTES"]);
                 if (is_array($info) && array_key_exists($this->mess["IBLOCK_XML2_STORE_ID"], $info) && array_key_exists($this->mess["IBLOCK_XML2_STORE_AMOUNT"], $info)) {
                     $arElement["STORE_AMOUNT"][$info[$this->mess["IBLOCK_XML2_STORE_ID"]]] = $this->ToFloat($info[$this->mess["IBLOCK_XML2_STORE_AMOUNT"]]);
                 }
             }
         }
     }
     if (isset($arElement["STORE_AMOUNT"])) {
         $this->ImportStoresAmount($arElement["STORE_AMOUNT"], $arElement["ID"], $counter);
     }
     if ($arDBElement) {
         $arProduct = array("ID" => $arElement["ID"]);
         if (isset($arXMLElement[$this->mess["IBLOCK_XML2_PRICES"]])) {
             $arElement["PRICES"] = array();
             foreach ($arXMLElement[$this->mess["IBLOCK_XML2_PRICES"]] as $price) {
                 if (isset($price[$this->mess["IBLOCK_XML2_PRICE_TYPE_ID"]]) && array_key_exists($price[$this->mess["IBLOCK_XML2_PRICE_TYPE_ID"]], $this->PRICES_MAP)) {
                     $price["PRICE"] = $this->PRICES_MAP[$price[$this->mess["IBLOCK_XML2_PRICE_TYPE_ID"]]];
                     $arElement["PRICES"][] = $price;
                     if (array_key_exists($this->mess["IBLOCK_XML2_MEASURE"], $price) && !isset($arProduct["MEASURE"])) {
                         $tmp = $this->convertBaseUnitFromXmlToPropertyValue($price[$this->mess["IBLOCK_XML2_MEASURE"]]);
                         if ($tmp["DESCRIPTION"] > 0) {
                             $arProduct["MEASURE"] = $tmp["DESCRIPTION"];
                         }
                     }
                 }
             }
             $arElement["DISCOUNTS"] = array();
             if (isset($arXMLElement[$this->mess["IBLOCK_XML2_DISCOUNTS"]])) {
                 foreach ($arXMLElement[$this->mess["IBLOCK_XML2_DISCOUNTS"]] as $discount) {
                     if (isset($discount[$this->mess["IBLOCK_XML2_DISCOUNT_CONDITION"]]) && $discount[$this->mess["IBLOCK_XML2_DISCOUNT_CONDITION"]] === $this->mess["IBLOCK_XML2_DISCOUNT_COND_VOLUME"]) {
                         $discount_value = $this->ToInt($discount[$this->mess["IBLOCK_XML2_DISCOUNT_COND_VALUE"]]);
                         $discount_percent = $this->ToFloat($discount[$this->mess["IBLOCK_XML2_DISCOUNT_COND_PERCENT"]]);
                         if ($discount_value > 0 && $discount_percent > 0) {
                             $arElement["DISCOUNTS"][$discount_value] = $discount_percent;
                         }
                     }
                 }
             }
         }
         if (array_key_exists($this->mess["IBLOCK_XML2_AMOUNT"], $arXMLElement)) {
             $arElementTmp = array();
             $arElement["QUANTITY_RESERVED"] = 0;
             if ($arElement["ID"]) {
                 $arElementTmp = CCatalogProduct::GetById($arElement["ID"]);
             }
             if (is_array($arElementTmp) && !empty($arElementTmp) && isset($arElementTmp["QUANTITY_RESERVED"])) {
                 $arElement["QUANTITY_RESERVED"] = $arElementTmp["QUANTITY_RESERVED"];
             }
             $arElement["QUANTITY"] = $this->ToFloat($arXMLElement[$this->mess["IBLOCK_XML2_AMOUNT"]]) - doubleval($arElement["QUANTITY_RESERVED"]);
         }
         if (isset($arElement["PRICES"]) && $this->bCatalog) {
             if (isset($arElement["QUANTITY"])) {
                 $arProduct["QUANTITY"] = $arElement["QUANTITY"];
             } elseif (isset($arElement["STORE_AMOUNT"]) && !empty($arElement["STORE_AMOUNT"])) {
                 $arProduct["QUANTITY"] = array_sum($arElement["STORE_AMOUNT"]);
             }
             $rsWeight = CIBlockElement::GetProperty($IBLOCK_ID, $arElement["ID"], array(), array("CODE" => "CML2_TRAITS"));
             while ($arWeight = $rsWeight->Fetch()) {
                 if ($arWeight["DESCRIPTION"] == $this->mess["IBLOCK_XML2_WEIGHT"]) {
                     $arProduct["WEIGHT"] = $this->ToFloat($arWeight["VALUE"]) * 1000;
                 }
             }
             $rsUnit = CIBlockElement::GetProperty($IBLOCK_ID, $arElement["ID"], array(), array("CODE" => "CML2_BASE_UNIT"));
             while ($arUnit = $rsUnit->Fetch()) {
                 if ($arUnit["DESCRIPTION"] > 0) {
                     $arProduct["MEASURE"] = $arUnit["DESCRIPTION"];
                 }
             }
             //Here start VAT handling
             //Check if all the taxes exists in BSM catalog
             $arTaxMap = array();
             $rsTaxProperty = CIBlockElement::GetProperty($IBLOCK_ID, $arElement["ID"], array("sort" => "asc"), array("CODE" => "CML2_TAXES"));
             while ($arTaxProperty = $rsTaxProperty->Fetch()) {
                 if (strlen($arTaxProperty["VALUE"]) > 0 && strlen($arTaxProperty["DESCRIPTION"]) > 0 && !array_key_exists($arTaxProperty["DESCRIPTION"], $arTaxMap)) {
                     $arTaxMap[$arTaxProperty["DESCRIPTION"]] = array("RATE" => $this->ToFloat($arTaxProperty["VALUE"]), "ID" => $this->CheckTax($arTaxProperty["DESCRIPTION"], $this->ToFloat($arTaxProperty["VALUE"])));
                 }
             }
             //First find out if all the prices have TAX_IN_SUM true
             $TAX_IN_SUM = "Y";
             foreach ($arElement["PRICES"] as $price) {
                 if ($price["PRICE"]["TAX_IN_SUM"] !== "true") {
                     $TAX_IN_SUM = "N";
                     break;
                 }
             }
             //If there was found not included tax we'll make sure
             //that all prices has the same flag
             if ($TAX_IN_SUM === "N") {
                 foreach ($arElement["PRICES"] as $price) {
                     if ($price["PRICE"]["TAX_IN_SUM"] !== "false") {
                         $TAX_IN_SUM = "Y";
                         break;
                     }
                 }
                 //Check if there is a mix of tax in sum
                 //and correct it by recalculating all the prices
                 if ($TAX_IN_SUM === "Y") {
                     foreach ($arElement["PRICES"] as $key => $price) {
                         if ($price["PRICE"]["TAX_IN_SUM"] !== "true") {
                             $TAX_NAME = $price["PRICE"]["TAX_NAME"];
                             if (array_key_exists($TAX_NAME, $arTaxMap)) {
                                 $PRICE_WO_TAX = $this->ToFloat($price[$this->mess["IBLOCK_XML2_PRICE_FOR_ONE"]]);
                                 $PRICE = $PRICE_WO_TAX + $PRICE_WO_TAX / 100.0 * $arTaxMap[$TAX_NAME]["RATE"];
                                 $arElement["PRICES"][$key][$this->mess["IBLOCK_XML2_PRICE_FOR_ONE"]] = $PRICE;
                             }
                         }
                     }
                 }
             }
             if ($TAX_IN_SUM == "Y" && $arTaxMap) {
                 $vat = current($arTaxMap);
                 $arProduct["VAT_ID"] = $vat["ID"];
             } else {
                 foreach ($arElement["PRICES"] as $price) {
                     $TAX_NAME = $price["PRICE"]["TAX_NAME"];
                     if (array_key_exists($TAX_NAME, $arTaxMap)) {
                         $arProduct["VAT_ID"] = $arTaxMap[$TAX_NAME]["ID"];
                         break;
                     }
                 }
             }
             $arProduct["VAT_INCLUDED"] = $TAX_IN_SUM;
             CCatalogProduct::Add($arProduct);
             $this->SetProductPrice($arElement["ID"], $arElement["PRICES"], $arElement["DISCOUNTS"]);
         } elseif ($this->bCatalog && isset($arElement["STORE_AMOUNT"]) && !empty($arElement["STORE_AMOUNT"]) && CCatalogProduct::GetById($arElement["ID"])) {
             CCatalogProduct::Update($arElement["ID"], array("QUANTITY" => array_sum($arElement["STORE_AMOUNT"])));
         } elseif ($this->bCatalog && isset($arElement["QUANTITY"]) && CCatalogProduct::GetById($arElement["ID"])) {
             CCatalogProduct::Update($arElement["ID"], array("QUANTITY" => $arElement["QUANTITY"]));
         }
     }
     $counter["UPD"]++;
     return $arElement["ID"];
 }
Esempio n. 5
0
    /**
     * функция после добавлением элемента в инфоблока
     * @param $arFields поля элемента ифоблока
     * для страницы Объявления
     * eсли VIP объявление то добавляет корзину
     * привязывает по ID созданное объявления к товару в корзине
     * редирект на необходимы url
     */
     function AuthtorizeAfterAds(&$arFields){
         unset($_SESSION['user777999authorize']);
         if($arFields['PROPERTY_VALUES']['114']){
             foreach($arFields['PROPERTY_VALUES']['114'] as $key114 => $item114){
                 if($item114['VALUE']){
                     foreach($arFields['PROPERTY_VALUES']['113'] as $key113 => $item113){
                         if($item113['VALUE']){
                             $arFields['PROPERTY_VALUES']['113'][$key113]=ConvertDateTime($item114['VALUE'], "YYYY-MM-DD HH:MI:SS");
                         }else{
                             $arFields['PROPERTY_VALUES']['113'][n0]=ConvertDateTime($item114['VALUE'], "YYYY-MM-DD HH:MI:SS");
                         }

                     }
                 }
             }
         }

        if(($arFields["IBLOCK_ID"] == 16)&&(!CUser::IsAuthorized())){
            global $USER;
            $rsUser = CUser::GetByID($_SESSION['NEW_USER_ID']);
            $arUser = $rsUser->Fetch();
            $_SESSION['$arUser']=$arUser;
            $USER = new CUser;
            $arAuthResult = $USER->Login($arUser['LOGIN'], $arUser['PASSWORD'], "Y","N");
        }
         //$_SESSION['user777authorize']=$arFields;


         if(($arFields["IBLOCK_ID"] == 16)&&(CModule::IncludeModule("catalog"))&&(CModule::IncludeModule("sale"))){

             $price_product=floatval($arFields["PROPERTY_VALUES"][86]);
             $quantity_product=floatval($arFields["PROPERTY_VALUES"][87]);
             if($price_product){
             $PRODUCT_ID = $arFields['ID'];
             $PRICE_TYPE_ID = 1;

             $arFieldsprice = Array(
                 "PRODUCT_ID" => $PRODUCT_ID,
                 "CATALOG_GROUP_ID" => $PRICE_TYPE_ID,
                 "PRICE" =>$price_product,
                 "CURRENCY" => "RUB",
                 "QUANTITY_FROM" => 1,
             );

             $res = CPrice::GetList(
                 array(),
                 array(
                     "PRODUCT_ID" => $PRODUCT_ID,
                     "CATALOG_GROUP_ID" => $PRICE_TYPE_ID
                 )
             );

             if ($arr = $res->Fetch())
             {
                 CPrice::Update($arr["ID"], $arFieldsprice);
             }
             else
             {
                 CPrice::Add($arFieldsprice,true);
             }
             }

         }

         if (
             (
                 (($arFields["IBLOCK_ID"] == 2)&& (is_numeric($arFields["PROPERTY_VALUES"][73])))
                 ||
                 (($arFields["IBLOCK_ID"] == 15)&& (is_numeric($arFields["PROPERTY_VALUES"][76])))
                 ||
                 (($arFields["IBLOCK_ID"] == 14)&& (is_numeric($arFields["PROPERTY_VALUES"][78])))
             )
             &&
             CModule::IncludeModule("catalog")
             &&
             CModule::IncludeModule("sale")
             &&
             ((strstr($_SERVER['REQUEST_URI'],'/personal/moy-magazin/'))||(strstr($_SERVER['REQUEST_URI'],'/obyavleniya/add-ads/')))
         )
         {


             switch($arFields["IBLOCK_ID"]){
                 case 2:
                     $price_product=floatval($arFields["PROPERTY_VALUES"][73]);
                     $quantity_product=floatval($arFields["PROPERTY_VALUES"][75]);

                     break;
                 case 14:
                     $price_product=floatval($arFields["PROPERTY_VALUES"][78]);
                     $quantity_product=floatval($arFields["PROPERTY_VALUES"][79]);

                     break;
                 case 15:
                     $price_product=floatval($arFields["PROPERTY_VALUES"][76]);
                     $quantity_product=floatval($arFields["PROPERTY_VALUES"][77]);

                     break;
             }
             if($price_product){
                 $PRODUCT_ID = $arFields['ID'];
                 $PRICE_TYPE_ID = 1;
                 if($quantity_product){
                     $ar_res_product=CCatalogProduct::GetByID($PRODUCT_ID);
                     if($ar_res_product['QUANTITY']!=""){
                         $arFields_quant = array(
                             'QUANTITY' => $quantity_product
                         );
                         CCatalogProduct::Update($PRODUCT_ID, $arFields_quant);

                     }else{
                         $arFields_quant = array(
                             'ID'=>$PRODUCT_ID,
                             'QUANTITY' => $quantity_product
                         );
                         CCatalogProduct::Add($arFields_quant);
                     }
                 }
                 $arFieldsprice = Array(
                     "PRODUCT_ID" => $PRODUCT_ID,
                     "CATALOG_GROUP_ID" => $PRICE_TYPE_ID,
                     "PRICE" =>$price_product,
                     "CURRENCY" => "RUB",
                 );

                 $res = CPrice::GetList(
                     array(),
                     array(
                         "PRODUCT_ID" => $PRODUCT_ID,
                         "CATALOG_GROUP_ID" => $PRICE_TYPE_ID
                     )
                 );

                 if ($arr = $res->Fetch())
                 {
                     CPrice::Update($arr["ID"], $arFieldsprice,true);
                     $_SESSION['price_add']=$arr;
                 }
                 else
                 {
                     CPrice::Add($arFieldsprice,true);
                 }
             }

         }


        // добавление в корзину vip и поднять
        if(($arFields["IBLOCK_ID"] == 16)&&(($arFields["PROPERTY_VALUES"][81][0]==40)||($arFields["PROPERTY_VALUES"][81][0]==46))){
            
            unset($_SESSION['ELEMENT_ADS_ID']);
            if(($_REQUEST['CODE'])&&(CModule::IncludeModule("iblock"))){

                if((CModule::IncludeModule("catalog"))&&(CModule::IncludeModule("sale"))){

                    $dbBasketItems = CSaleBasket::GetList(
                        array(),
                        array(
                            "FUSER_ID" => CSaleBasket::GetBasketUserID(),
                            "LID" => SITE_ID,
				            "ORDER_ID" => "NULL"
                        ),
                        false,
                        false,
                        array("ID", "NAME")
                    );
                    if($arFields["PROPERTY_VALUES"][81][0]==46){
                        $test_ads="TEST_ADSUP";
                    }
                    if($arFields["PROPERTY_VALUES"][81][0]==40){
                        $test_ads="TEST_VIP";
                    }
                    while ($arBasketItems = $dbBasketItems->Fetch())
                    {
                        $dbProp = CSaleBasket::GetPropsList(array("SORT" => "ASC", "ID" => "ASC"), array("BASKET_ID" => $arBasketItems["ID"]));
                        if($arProp = $dbProp -> GetNext())
                        {
                            $props[] = $arProp;
                            $dbProp = CSaleBasket::GetPropsList(array("SORT" => "ASC", "ID" => "ASC"), array("BASKET_ID" => $arBasketItems["ID"]));
                            if($arProp = $dbProp -> GetNext())
                            {
                                

                                if($arProp['CODE']==$test_ads){
                                    $ELEMENT_ID = intval($arProp['VALUE']);
                                    if($ELEMENT_ID==$_REQUEST['CODE']){
                                        $vip=true;
                                    }
                                }

                            }
                        }
                    }
                }
            }
            //var_dump($vip);die();
            if(!$vip){
            $arPropsBasket = array();
            if($arFields["PROPERTY_VALUES"][81][0]==46){
                $code_price="up-ads";
                $arPropsBasket[] = array(
                    "NAME" => "Название: ".$arFields['NAME'],
                    "CODE" => "TEST_ADSUP",
                    "VALUE" => $arFields['ID']
                );
            }
            if($arFields["PROPERTY_VALUES"][81][0]==40){
                $code_price="vip-ads";
                $arPropsBasket[] = array(
                    "NAME" => "Название: ".$arFields['NAME'],
                    "CODE" => "TEST_VIP",
                    "VALUE" => $arFields['ID']
                );
            }
            $arSelect2 = Array("ID", "IBLOCK_ID", "NAME","PROPERTY_*");
            $arFilter2 = Array("IBLOCK_ID"=>17, "CODE"=>$code_price, "ACTIVE"=>"Y");
            $res2 = CIBlockElement::GetList(Array(), $arFilter2, false, Array("nPageSize"=>1), $arSelect2);
            while($ob2 = $res2->GetNextElement()){
                $arFieldIdAds = $ob2->GetFields();
                if (CModule::IncludeModule("sale"))
                {

                    $base_price=CPrice::GetBasePrice($arFieldIdAds['ID']);
                    $arFieldsB = array(
                        "PRODUCT_ID" => $arFieldIdAds['ID'],
                        "PRICE" => $base_price['PRICE'],
                        "CURRENCY" => "RUB",
                        "QUANTITY" => 1,
                        "LID" => LANG,
                        "NAME" => $arFieldIdAds['NAME'],
                    );

                    $arFieldsB["PROPS"] = $arPropsBasket;

                    $id_basket = CSaleBasket::Add($arFieldsB);

                    $db_res = CSaleBasket::GetPropsList(
                        array(
                            "SORT" => "ASC",
                            "NAME" => "ASC"
                        ),
                        array("BASKET_ID" => $id_basket)
                    );
                    while ($ar_res = $db_res->Fetch())
                    {
                        $_SESSION['order_fields_after'][]= $ar_res["NAME"]."=".$ar_res["VALUE"]."<br>";
                    }
                }
            }




            }


            unset($_SESSION['NEW_USER_ID']);
            LocalRedirect('/personal/cart/');

        }

         if(($arFields["IBLOCK_ID"] == 16)&&($arFields["PROPERTY_VALUES"][81][0]==47)){
             $_SESSION['ELEMENT_ADS_ID']=$arFields['ID'];

         }



         }
Esempio n. 6
0
 /**
  * @param $arFields
  * @return array|bool
  */
 public static function cancellationDocument($arFields)
 {
     global $DB;
     $id = intval($arFields["ID"]);
     $i = 0;
     $dbDocElements = CCatalogStoreDocsElement::getList(array(), array("DOC_ID" => $id));
     while ($arDocElement = $dbDocElements->Fetch()) {
         $arResult = array();
         $arProductInfo = CCatalogProduct::GetByID($arDocElement["ELEMENT_ID"]);
         $newReserved = $arProductInfo["QUANTITY_RESERVED"] + $arDocElement["AMOUNT"];
         $arResult["QUANTITY_RESERVED"] = $newReserved;
         $dbAmount = $DB->Query("SELECT SUM(SP.AMOUNT) as SUM, CP.QUANTITY_RESERVED as RESERVED FROM b_catalog_store_product SP INNER JOIN b_catalog_product CP ON SP.PRODUCT_ID = CP.ID INNER JOIN b_catalog_store CS ON SP.STORE_ID = CS.ID WHERE SP.PRODUCT_ID = " . $arDocElement["ELEMENT_ID"] . "  AND CS.ACTIVE = 'Y' GROUP BY QUANTITY_RESERVED ", true);
         if ($arAmount = $dbAmount->Fetch()) {
             $arResult["QUANTITY"] = doubleval($arAmount["SUM"] - $newReserved);
             if (!CCatalogProduct::Update($arDocElement["ELEMENT_ID"], $arResult)) {
                 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("CAT_DOC_PURCHASING_INFO_ERROR"));
                 return false;
             }
         }
         $i++;
     }
     if ($i > 0) {
         return true;
     }
     return false;
 }
Esempio n. 7
0
                     $arCatalogQuantity['WEIGHT'] = $CATALOG_WEIGHT;
                 }
                 CCatalogProduct::Add($arCatalogQuantity);
             } else {
                 $arCatalogQuantity = array();
                 if (strlen($CATALOG_QUANTITY) > 0) {
                     $arCatalogQuantity["QUANTITY"] = $CATALOG_QUANTITY;
                 }
                 if (strlen($CATALOG_QUANTITY_TRACE) > 0) {
                     $arCatalogQuantity["QUANTITY_TRACE"] = $CATALOG_QUANTITY_TRACE == "Y" ? "Y" : ($CATALOG_QUANTITY_TRACE == "D" ? "D" : "N");
                 }
                 if (strlen($CATALOG_WEIGHT) > 0) {
                     $arCatalogQuantity['WEIGHT'] = $CATALOG_WEIGHT;
                 }
                 if (!empty($arCatalogQuantity)) {
                     CCatalogProduct::Update($subID, $arCatalogQuantity);
                 }
             }
         }
     }
 }
 if ($boolSubCatalog) {
     if ($USER->CanDoOperation('catalog_price') && (isset($_POST["CATALOG_PRICE"]) || isset($_POST["CATALOG_CURRENCY"]))) {
         $CATALOG_PRICE = $_POST["CATALOG_PRICE"];
         $CATALOG_CURRENCY = $_POST["CATALOG_CURRENCY"];
         $CATALOG_EXTRA = $_POST["CATALOG_EXTRA"];
         $CATALOG_PRICE_ID = $_POST["CATALOG_PRICE_ID"];
         $CATALOG_QUANTITY_FROM = $_POST["CATALOG_QUANTITY_FROM"];
         $CATALOG_QUANTITY_TO = $_POST["CATALOG_QUANTITY_TO"];
         $CATALOG_PRICE_old = $_POST["CATALOG_old_PRICE"];
         $CATALOG_CURRENCY_old = $_POST["CATALOG_old_CURRENCY"];
 public static function DeductProduct($arParams)
 {
     global $DB;
     $arRes = array();
     $arFields = array();
     $strUseStoreControl = COption::GetOptionString('catalog', 'default_use_store_control', 'N');
     if (intval($arParams["PRODUCT_ID"]) <= 0) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("RSRV_INCORRECT_ID"), "NO_ORDER_ID");
         $arRes["RESULT"] = false;
         return $arRes;
     }
     $arParams["QUANTITY"] = doubleval($arParams["QUANTITY"]);
     if (intval($arParams["UNDO_DEDUCTION"]) != "Y") {
         $arParams["UNDO_DEDUCTION"] = "N";
     }
     if (intval($arParams["EMULATE"]) != "Y") {
         $arParams["EMULATE"] = "N";
     }
     if (intval($arParams["PRODUCT_RESERVED"]) != "Y") {
         $arParams["PRODUCT_RESERVED"] = "N";
     }
     if (!isset($arParams["STORE_DATA"])) {
         $arParams["STORE_DATA"] = array();
     }
     if (!is_array($arParams["STORE_DATA"])) {
         $arParams["STORE_DATA"] = array($arParams["STORE_DATA"]);
     }
     $rsProducts = CCatalogProduct::GetList(array(), array('ID' => $arParams["PRODUCT_ID"]), false, false, array('ID', 'QUANTITY', 'QUANTITY_RESERVED'));
     if ($arProduct = $rsProducts->Fetch()) {
         if ($arParams["UNDO_DEDUCTION"] == "N") {
             if ($arParams["EMULATE"] == "Y" || $arProduct["QUANTITY_TRACE"] == "N") {
                 $arRes["RESULT"] = true;
             } else {
                 if ($strUseStoreControl == "Y") {
                     if (!empty($arParams["STORE_DATA"])) {
                         $totalAmount = 0;
                         foreach ($arParams["STORE_DATA"] as $id => $arRecord) {
                             if (!isset($arRecord["STORE_ID"]) || intval($arRecord["STORE_ID"]) < 0 || !isset($arRecord["QUANTITY"]) || intval($arRecord["QUANTITY"]) < 0) {
                                 $GLOBALS["APPLICATION"]->ThrowException(GetMessage("DDCT_DEDUCTION_STORE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DDCT_DEDUCTION_STORE_ERROR");
                                 $arRes["RESULT"] = false;
                                 return $arRes;
                             }
                             $rsProps = CCatalogStoreProduct::GetList(array(), array("PRODUCT_ID" => $arParams["PRODUCT_ID"], "STORE_ID" => $arRecord["STORE_ID"]), false, false, array('ID', 'AMOUNT'));
                             if ($arProp = $rsProps->Fetch()) {
                                 if ($arProp["AMOUNT"] < $arRecord["QUANTITY"]) {
                                     $GLOBALS["APPLICATION"]->ThrowException(GetMessage("DDCT_DEDUCTION_QUANTITY_STORE_ERROR", array_merge(self::GetProductCatalogInfo($arParams["PRODUCT_ID"]), array("#STORE_ID#" => $arRecord["STORE_ID"]))), "DDCT_DEDUCTION_QUANTITY_STORE_ERROR");
                                     $arRes["RESULT"] = false;
                                     return $arRes;
                                 } else {
                                     $res = CCatalogStoreProduct::Update($arProp["ID"], array("AMOUNT" => $arProp["AMOUNT"] - $arRecord["QUANTITY"]));
                                     if ($res) {
                                         $arRes["STORES"][$arRecord["STORE_ID"]] = $arRecord["QUANTITY"];
                                         $totalAmount += $arRecord["QUANTITY"];
                                         //deleting barcodes
                                         if (isset($arRecord["BARCODE"]) && is_array($arRecord["BARCODE"]) && count($arRecord["BARCODE"]) > 0) {
                                             foreach ($arRecord["BARCODE"] as $barcodeId => $barcodeValue) {
                                                 $arFields = array("STORE_ID" => $arRecord["STORE_ID"], "BARCODE" => $barcodeValue, "PRODUCT_ID" => $arParams["PRODUCT_ID"]);
                                                 $dbres = CCatalogStoreBarcode::GetList(array(), $arFields, false, false, array("ID", "STORE_ID", "BARCODE", "PRODUCT_ID"));
                                                 if ($arRes = $dbres->Fetch()) {
                                                     CCatalogStoreBarcode::Delete($arRes["ID"]);
                                                 }
                                             }
                                         }
                                     } else {
                                         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("DDCT_DEDUCTION_SAVE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DDCT_DEDUCTION_SAVE_ERROR");
                                         $arRes["RESULT"] = false;
                                         return $arRes;
                                     }
                                 }
                             }
                         }
                         //updating total sum
                         //TODO
                         // $dbAmount = $DB->Query("SELECT SUM(AMOUNT) as AMOUNT FROM b_catalog_store_product WHERE PRODUCT_ID = ".intval($arParams["PRODUCT_ID"])." ", true);
                         // if ($amount = $dbAmount->Fetch())
                         // {
                         if ($arParams["PRODUCT_RESERVED"] == "Y") {
                             if ($totalAmount <= $arProduct["QUANTITY_RESERVED"]) {
                                 $arFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] - $totalAmount;
                             } else {
                                 if ($totalAmount <= $arProduct["QUANTITY_RESERVED"] + $arProduct["QUANTITY"]) {
                                     $arFields["QUANTITY_RESERVED"] = 0;
                                     $arFields["QUANTITY"] = $arProduct["QUANTITY"] - ($totalAmount - $arProduct["QUANTITY_RESERVED"]);
                                 } else {
                                     $arRes["RESULT"] = false;
                                     return $arRes;
                                 }
                             }
                         } else {
                             if ($totalAmount <= $arProduct["QUANTITY"]) {
                                 $arFields["QUANTITY"] = $arProduct["QUANTITY"] - $totalAmount;
                             } else {
                                 if ($totalAmount <= $arProduct["QUANTITY_RESERVED"] + $arProduct["QUANTITY"]) {
                                     $arFields["QUANTITY"] = 0;
                                     $arFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] - ($totalAmount - $arProduct["QUANTITY"]);
                                 } else {
                                     $arRes["RESULT"] = false;
                                     return $arRes;
                                 }
                             }
                         }
                         CCatalogProduct::Update($arParams["PRODUCT_ID"], $arFields);
                         // }
                         $arRes["RESULT"] = true;
                     } else {
                         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("DDCT_DEDUCTION_STORE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DEDUCTION_STORE_ERROR1");
                         $arRes["RESULT"] = false;
                         return $arRes;
                     }
                 } else {
                     if ($arParams["QUANTITY"] <= $arProduct["QUANTITY_RESERVED"] + $arProduct["QUANTITY"]) {
                         if ($arParams["PRODUCT_RESERVED"] == "Y") {
                             if ($arParams["QUANTITY"] <= $arProduct["QUANTITY_RESERVED"]) {
                                 $arFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] - $arParams["QUANTITY"];
                             } else {
                                 $arFields["QUANTITY_RESERVED"] = 0;
                                 $arFields["QUANTITY"] = $arProduct["QUANTITY"] - ($arParams["QUANTITY"] - $arProduct["QUANTITY_RESERVED"]);
                             }
                         } else {
                             if ($arParams["QUANTITY"] <= $arProduct["QUANTITY"]) {
                                 $arFields["QUANTITY"] = $arProduct["QUANTITY"] - $arParams["QUANTITY"];
                             } else {
                                 $arFields["QUANTITY"] = 0;
                                 $arFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] - ($arParams["QUANTITY"] - $arProduct["QUANTITY"]);
                             }
                         }
                         $arRes["RESULT"] = CCatalogProduct::Update($arParams["PRODUCT_ID"], $arFields);
                     } else {
                         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("DDCT_DEDUCTION_QUANTITY_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DDCT_DEDUCTION_QUANTITY_ERROR");
                         $arRes["RESULT"] = false;
                         return $arRes;
                     }
                 }
                 //store control
             }
             //emulate /quantity trace
         } else {
             if ($arParams["EMULATE"] == "Y" || $arProduct["QUANTITY_TRACE"] == "N") {
                 $arRes["RESULT"] = true;
             } else {
                 if ($strUseStoreControl == "Y") {
                     if (!empty($arParams["STORE_DATA"])) {
                         $totalAddedAmount = 0;
                         foreach ($arParams["STORE_DATA"] as $id => $arRecord) {
                             $rsProps = CCatalogStoreProduct::GetList(array(), array("PRODUCT_ID" => $arParams["PRODUCT_ID"], "STORE_ID" => $arRecord["STORE_ID"]), false, false, array('ID', 'AMOUNT'));
                             if ($arProp = $rsProps->Fetch()) {
                                 $res = CCatalogStoreProduct::Update($arProp["ID"], array("AMOUNT" => $arProp["AMOUNT"] + $arRecord["QUANTITY"]));
                                 if ($res) {
                                     $arRes["STORES"][$arRecord["STORE_ID"]] = $arRecord["QUANTITY"];
                                     $totalAddedAmount += $arRecord["QUANTITY"];
                                     //adding barcodes
                                     if (isset($arRecord["BARCODE"]) && strlen($arRecord["BARCODE"]) > 0) {
                                         $arFields = array("STORE_ID" => $arRecord["STORE_ID"], "BARCODE" => $arRecord["BARCODE"], "PRODUCT_ID" => $arParams["PRODUCT_ID"]);
                                         CCatalogStoreBarcode::Add($arFields);
                                     }
                                 } else {
                                     $GLOBALS["APPLICATION"]->ThrowException(GetMessage("DDCT_DEDUCTION_SAVE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DDCT_DEDUCTION_SAVE_ERROR");
                                     $arRes["RESULT"] = false;
                                     return $arRes;
                                 }
                             }
                         }
                         // $dbAmount = $DB->Query("SELECT SUM(AMOUNT) as AMOUNT FROM b_catalog_store_product WHERE PRODUCT_ID = ".$arParams["PRODUCT_ID"]." ", true);
                         // if ($totalAddedAmount = $dbAmount->Fetch())
                         // {
                         // }
                         if ($arParams["PRODUCT_RESERVED"] == "Y") {
                             $arUpdateFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] + $totalAddedAmount;
                         } else {
                             $arUpdateFields["QUANTITY"] = $arProduct["QUANTITY"] + $totalAddedAmount;
                         }
                         CCatalogProduct::Update($arParams["PRODUCT_ID"], $arUpdateFields);
                         $arRes["RESULT"] = true;
                     } else {
                         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("DDCT_DEDUCTION_STORE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DEDUCTION_STORE_ERROR2");
                         $arRes["RESULT"] = false;
                         return $arRes;
                     }
                 } else {
                     if ($arParams["PRODUCT_RESERVED"] == "Y") {
                         $arFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] + $arParams["QUANTITY"];
                         // $arFields["QUANTITY"] = $arProduct["QUANTITY"] - $arParams["QUANTITY_RESERVED"];
                     } else {
                         $arFields["QUANTITY"] = $arProduct["QUANTITY"] + $arParams["QUANTITY"];
                         // $arFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] - $arParams["QUANTITY_RESERVED"];
                     }
                     $arRes["RESULT"] = CCatalogProduct::Update($arParams["PRODUCT_ID"], $arFields);
                 }
             }
             //emulate or quantity trace
         }
     } else {
         $arRes["RESULT"] = false;
     }
     if (!$arRes["RESULT"]) {
         $GLOBALS["APPLICATION"]->ThrowException(GetMessage("DDCT_UNKNOWN_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "UNKNOWN_DEDUCTION_ERROR");
     }
     return $arRes;
 }
Esempio n. 9
0
	/**
	 * <p>Уменьшает количество на складе товара с кодом PRODUCT_ID на величину DELTA_QUANTITY, если указанное количество есть на складе и у товара установлен флаг "уменьшать количество товара при заказе" </p>
	 *
	 *
	 *
	 *
	 * @param int $PRODUCT_ID  Код товара.
	 *
	 *
	 *
	 * @param int $DELTA_QUANTITY  Число, на которое нужно уменьшить количество товара на складе.
	 *
	 *
	 *
	 * @return bool <p>Возвращает <i>true</i> в случае успешного уменьшения и <i>false</i> - в
	 * противном случае </p><a name="examples"></a>
	 *
	 *
	 * <h4>Example</h4> 
	 * <pre>
	 * &lt;?
	 * // Уменьшим количество на складе товара 5 на 12 штук
	 * CCatalogProduct::QuantityTracer(5, 12);
	 * ?&gt;
	 * </pre>
	 *
	 *
	 * @static
	 * @link http://dev.1c-bitrix.ru/api_help/catalog/classes/ccatalogproduct/ccatalogproduct__quantitytracer.8cc817fa.php
	 * @author Bitrix
	 */
	public static function QuantityTracer($ProductID, $DeltaQuantity)
	{
		global $DB;
		global $CACHE_MANAGER;

		$boolClearCache = false;

		$ProductID = intval($ProductID);
		if (0 >= $ProductID)
			return false;
		$DeltaQuantity = doubleval($DeltaQuantity);
		if ($DeltaQuantity==0)
			return false;

		$rsProducts = CCatalogProduct::GetList(
			array(),
			array('ID' => $ProductID),
			false,
			false,
			array('ID', 'CAN_BUY_ZERO', 'NEGATIVE_AMOUNT_TRACE', 'QUANTITY_TRACE', 'QUANTITY', 'ELEMENT_IBLOCK_ID')
		);
		if (($arProduct = $rsProducts->Fetch())
			&& ($arProduct["QUANTITY_TRACE"]=="Y"))
		{
			$strAllowNegativeAmount = $arProduct["NEGATIVE_AMOUNT_TRACE"];

			$arFields = array();
			$arFields["QUANTITY"] = doubleval($arProduct["QUANTITY"]) - $DeltaQuantity;

			if ('Y' != $arProduct['CAN_BUY_ZERO'])
			{
				if (defined("BX_COMP_MANAGED_CACHE"))
				{
					$boolClearCache = (0 >= $arFields["QUANTITY"]*$arProduct["QUANTITY"]);
				}
			}

			if ('Y' != $arProduct['CAN_BUY_ZERO'] || 'Y' != $strAllowNegativeAmount)
			{
				if (0 >= $arFields["QUANTITY"])
					$arFields["QUANTITY"] = 0;
			}

			$arFields['OLD_QUANTITY'] = $arProduct["QUANTITY"];
			CCatalogProduct::Update($arProduct["ID"], $arFields);

			if ($boolClearCache)
				$CACHE_MANAGER->ClearByTag('iblock_id_'.$arProduct['ELEMENT_IBLOCK_ID']);

			$arProduct['OLD_QUANTITY'] = $arFields['OLD_QUANTITY'];
			$arProduct['QUANTITY'] = $arFields['QUANTITY'];
			$arProduct['ALLOW_NEGATIVE_AMOUNT'] = $strAllowNegativeAmount;
			$arProduct['DELTA'] = $DeltaQuantity;
			foreach (GetModuleEvents("catalog", "OnProductQuantityTrace", true) as $arEvent)
			{
				ExecuteModuleEventEx($arEvent, array($arProduct["ID"], $arProduct));
			}

			return true;
		}

		return false;
	}
Esempio n. 10
0
 public static function Update($ID, $arFields)
 {
     if (!CModule::IncludeModule('catalog')) {
         return false;
     }
     global $DB;
     if (!self::CheckFields('UPDATE', $arFields, $ID)) {
         return false;
     }
     if (isset($arFields['NAME']) || isset($arFields['SECTION_ID']) || isset($arFields['SORT']) || isset($arFields['ACTIVE']) || isset($arFields['DETAIL_PICTURE']) || isset($arFields['DESCRIPTION']) || isset($arFields['DESCRIPTION_TYPE']) || isset($arFields['PREVIEW_PICTURE']) || isset($arFields['PREVIEW_TEXT']) || isset($arFields['PREVIEW_TEXT_TYPE']) || isset($arFields['ORIGINATOR_ID']) || isset($arFields['ORIGIN_ID']) || isset($arFields['XML_ID']) || isset($arFields['PROPERTY_VALUES'])) {
         $element = new CIBlockElement();
         $obResult = $element->GetById($ID);
         if ($arElement = $obResult->Fetch()) {
             // files
             $arElement['PREVIEW_PICTURE'] = CFile::MakeFileArray($arElement['PREVIEW_PICTURE']);
             $arElement['DETAIL_PICTURE'] = CFile::MakeFileArray($arElement['DETAIL_PICTURE']);
             if (isset($arFields['NAME'])) {
                 $arElement['NAME'] = $arFields['NAME'];
             }
             if (isset($arFields['SECTION_ID'])) {
                 $arElement['IBLOCK_SECTION_ID'] = $arFields['SECTION_ID'];
             }
             if (isset($arFields['SORT'])) {
                 $arElement['SORT'] = $arFields['SORT'];
             }
             if (isset($arFields['ACTIVE'])) {
                 $arElement['ACTIVE'] = $arFields['ACTIVE'];
             }
             if (isset($arFields['DETAIL_PICTURE'])) {
                 $arElement['DETAIL_PICTURE'] = $arFields['DETAIL_PICTURE'];
             }
             if (isset($arFields['DESCRIPTION'])) {
                 $arElement['DETAIL_TEXT'] = $arFields['DESCRIPTION'];
             }
             if (isset($arFields['DESCRIPTION_TYPE'])) {
                 $arElement['DETAIL_TEXT_TYPE'] = $arFields['DESCRIPTION_TYPE'];
             }
             if (isset($arFields['PREVIEW_PICTURE'])) {
                 $arElement['PREVIEW_PICTURE'] = $arFields['PREVIEW_PICTURE'];
             }
             if (isset($arFields['PREVIEW_TEXT'])) {
                 $arElement['PREVIEW_TEXT'] = $arFields['PREVIEW_TEXT'];
                 $arElement['PREVIEW_TEXT_TYPE'] = 'text';
             }
             if (isset($arFields['PREVIEW_TEXT_TYPE'])) {
                 $arElement['PREVIEW_TEXT_TYPE'] = $arFields['PREVIEW_TEXT_TYPE'];
             }
             if (isset($arFields['XML_ID'])) {
                 $arElement['XML_ID'] = $arElement['EXTERNAL_ID'] = $arFields['XML_ID'];
             } else {
                 if (isset($arFields['ORIGINATOR_ID']) || isset($arFields['ORIGIN_ID'])) {
                     if (strlen($arFields['ORIGINATOR_ID']) > 0 && strlen($arFields['ORIGIN_ID']) > 0) {
                         $arElement['XML_ID'] = $arFields['ORIGINATOR_ID'] . '#' . $arFields['ORIGIN_ID'];
                     } else {
                         $delimiterPos = strpos($arElement['XML_ID'], '#');
                         if (strlen($arFields['ORIGINATOR_ID']) > 0) {
                             if ($delimiterPos !== false) {
                                 $arElement['XML_ID'] = $arFields['ORIGINATOR_ID'] . substr($arElement['XML_ID'], $delimiterPos);
                             } else {
                                 $arElement['XML_ID'] = $arFields['ORIGINATOR_ID'];
                             }
                         } else {
                             if ($delimiterPos !== false) {
                                 $arElement['XML_ID'] = substr($arElement['XML_ID'], 0, $delimiterPos) . $arFields['ORIGIN_ID'];
                             } else {
                                 $arElement['XML_ID'] = '#' . $arFields['ORIGINATOR_ID'];
                             }
                         }
                     }
                 }
             }
             if (isset($arFields['PROPERTY_VALUES'])) {
                 $arElement['PROPERTY_VALUES'] = $arFields['PROPERTY_VALUES'];
             }
             if (!$element->Update($ID, $arElement)) {
                 self::$LAST_ERROR = $element->LAST_ERROR;
                 return false;
             }
         }
     }
     // update VAT
     $CCatalogProduct = new CCatalogProduct();
     $arCatalogProductFields = array();
     if (isset($arFields['VAT_INCLUDED'])) {
         $arCatalogProductFields['VAT_INCLUDED'] = $arFields['VAT_INCLUDED'];
     }
     if (isset($arFields['VAT_ID']) && !empty($arFields['VAT_ID'])) {
         $arCatalogProductFields['VAT_ID'] = $arFields['VAT_ID'];
     }
     if (isset($arFields['MEASURE']) && !empty($arFields['MEASURE'])) {
         $arCatalogProductFields['MEASURE'] = $arFields['MEASURE'];
     }
     if (count($arCatalogProductFields) > 0) {
         $CCatalogProduct->Update($ID, $arCatalogProductFields);
     }
     if (isset($arFields['PRICE']) && isset($arFields['CURRENCY_ID'])) {
         self::setPrice($ID, $arFields['PRICE'], $arFields['CURRENCY_ID']);
     } else {
         if (isset($arFields['PRICE']) || isset($arFields['CURRENCY_ID'])) {
             $CPrice = new CPrice();
             $price = $currency = false;
             if (!isset($arFields['PRICE'])) {
                 $basePriceInfo = self::getPrice($ID);
                 if ($basePriceInfo !== false && is_array($basePriceInfo) && isset($basePriceInfo['PRICE'])) {
                     $price = $basePriceInfo['PRICE'];
                     $currency = $arFields['CURRENCY_ID'];
                 }
             } elseif (!isset($arFields['CURRENCY_ID'])) {
                 $basePriceInfo = self::getPrice($ID);
                 if ($basePriceInfo !== false && is_array($basePriceInfo) && isset($basePriceInfo['PRICE'])) {
                     $price = $arFields['PRICE'];
                     $currency = $basePriceInfo['CURRENCY'];
                 }
             } else {
                 $price = $arFields['PRICE'];
                 $currency = $arFields['CURRENCY_ID'];
             }
             if ($price !== false && $currency !== false) {
                 CCrmProduct::setPrice($ID, $price, $currency);
             }
         }
     }
     //		$sUpdate = trim($DB->PrepareUpdate(CCrmProduct::TABLE_NAME, $arFields));
     //		if (!empty($sUpdate))
     //		{
     //			$sQuery = 'UPDATE '.CCrmProduct::TABLE_NAME.' SET '.$sUpdate.' WHERE ID = '.$ID;
     //			$DB->Query($sQuery, false, 'File: '.__FILE__.'<br/>Line: '.__LINE__);
     //
     //			CCrmEntityHelper::RemoveCached(self::CACHE_NAME, $ID);
     //		}
     CCrmEntityHelper::RemoveCached(self::CACHE_NAME, $ID);
     return true;
 }
Esempio n. 11
0
 function recalculateStoreBalances($id)
 {
     global $DB;
     $arFields = array();
     if (COption::GetOptionString('catalog', 'default_use_store_control', 'N') != 'Y') {
         return false;
     }
     $dbStoreProduct = CCatalogStoreProduct::GetList(array(), array("STORE_ID" => $id, "!AMOUNT" => 0), false, false, array("PRODUCT_ID", "AMOUNT"));
     while ($arStoreProduct = $dbStoreProduct->Fetch()) {
         $dbAmount = $DB->Query("SELECT SUM(SP.AMOUNT) as SUM, CP.QUANTITY_RESERVED as RESERVED, CS.ACTIVE FROM b_catalog_store_product SP INNER JOIN b_catalog_product CP ON SP.PRODUCT_ID = CP.ID INNER JOIN b_catalog_store CS ON SP.STORE_ID = CS.ID WHERE SP.PRODUCT_ID = " . $arStoreProduct['PRODUCT_ID'] . " AND CS.ACTIVE = 'Y' GROUP BY QUANTITY_RESERVED, ACTIVE ", true);
         if ($arAmount = $dbAmount->Fetch()) {
             $arFields["QUANTITY"] = doubleval($arAmount["SUM"] - $arAmount["RESERVED"]);
         } else {
             if ($arReservAmount = CCatalogProduct::GetByID($arStoreProduct['PRODUCT_ID'])) {
                 $arFields["QUANTITY"] = doubleval(0 - $arReservAmount["QUANTITY_RESERVED"]);
             }
         }
         if (!CCatalogProduct::Update($arStoreProduct["PRODUCT_ID"], $arFields)) {
             $GLOBALS["APPLICATION"]->ThrowException(GetMessage("CAT_DOC_PURCHASING_INFO_ERROR"));
             return false;
         }
     }
     return true;
 }
Esempio n. 12
0
 /**
  * @param $documentId
  * @param $userId
  * @return bool
  */
 public static function cancellationDocument($documentId, $userId)
 {
     global $DB, $APPLICATION;
     $documentId = (int) $documentId;
     $i = 0;
     $dbDocElements = CCatalogStoreDocsElement::getList(array(), array("DOC_ID" => $documentId));
     while ($arDocElement = $dbDocElements->Fetch()) {
         $arResult = array();
         $arProductInfo = CCatalogProduct::GetByID($arDocElement["ELEMENT_ID"]);
         $newReserved = $arProductInfo["QUANTITY_RESERVED"] + $arDocElement["AMOUNT"];
         $arResult["QUANTITY_RESERVED"] = $newReserved;
         $dbAmount = $DB->Query("SELECT SUM(SP.AMOUNT) as SUM, CP.QUANTITY_RESERVED as RESERVED FROM b_catalog_store_product SP INNER JOIN b_catalog_product CP ON SP.PRODUCT_ID = CP.ID INNER JOIN b_catalog_store CS ON SP.STORE_ID = CS.ID WHERE SP.PRODUCT_ID = " . $arDocElement["ELEMENT_ID"] . "  AND CS.ACTIVE = 'Y' GROUP BY QUANTITY_RESERVED ", true);
         if ($arAmount = $dbAmount->Fetch()) {
             $arResult["QUANTITY"] = doubleval($arAmount["SUM"] - $newReserved);
             if (!CCatalogProduct::Update($arDocElement["ELEMENT_ID"], $arResult)) {
                 $APPLICATION->ThrowException(GetMessage("CAT_DOC_PURCHASING_INFO_ERROR"));
                 return false;
             }
             if (self::isNeedClearPublicCache($arProductInfo['QUANTITY'], $arResult['QUANTITY'], $arProductInfo['QUANTITY_TRACE'], $arProductInfo['CAN_BUY_ZERO'])) {
                 $productInfo = array('CAN_BUY_ZERO' => $arProductInfo['CAN_BUY_ZERO'], 'NEGATIVE_AMOUNT_TRACE' => $arProductInfo['NEGATIVE_AMOUNT_TRACE'], 'QUANTITY_TRACE' => $arProductInfo['QUANTITY_TRACE'], 'OLD_QUANTITY' => $arProductInfo['QUANTITY'], 'QUANTITY' => $arResult['QUANTITY'], 'DELTA' => $arResult['QUANTITY'] - $arProductInfo['QUANTITY']);
                 self::clearPublicCache($arProductInfo['ID'], $productInfo);
             }
         }
         $i++;
     }
     return $i > 0;
 }
Esempio n. 13
0
 function recalculateStoreBalances($id)
 {
     global $DB;
     $arFields = array();
     if (COption::GetOptionString('catalog', 'default_use_store_control', 'N') != 'Y') {
         return true;
     }
     $dbStoreProduct = CCatalogStoreProduct::GetList(array(), array("STORE_ID" => $id, "!AMOUNT" => 0), false, false, array("PRODUCT_ID", "AMOUNT"));
     while ($arStoreProduct = $dbStoreProduct->Fetch()) {
         $dbAmount = $DB->Query("select SUM(SP.AMOUNT) as SUM, CP.QUANTITY_RESERVED as RESERVED, CS.ACTIVE FROM b_catalog_store_product SP inner join b_catalog_product CP on SP.PRODUCT_ID = CP.ID inner join b_catalog_store CS on SP.STORE_ID = CS.ID where SP.PRODUCT_ID = " . $arStoreProduct['PRODUCT_ID'] . " and CS.ACTIVE = 'Y' group by QUANTITY_RESERVED, ACTIVE", true);
         if ($arAmount = $dbAmount->Fetch()) {
             $arFields["QUANTITY"] = doubleval($arAmount["SUM"] - $arAmount["RESERVED"]);
         } else {
             if ($arReservAmount = CCatalogProduct::GetByID($arStoreProduct['PRODUCT_ID'])) {
                 $arFields["QUANTITY"] = doubleval(0 - $arReservAmount["QUANTITY_RESERVED"]);
             }
         }
         CCatalogProduct::Update($arStoreProduct["PRODUCT_ID"], $arFields);
     }
     return true;
 }
	public static function DeductProduct($arParams)
	{
		global $APPLICATION;

		$arRes = array();
		$arFields = array();

		$strUseStoreControl = COption::GetOptionString('catalog','default_use_store_control');

		$disableReservation = (COption::GetOptionString("catalog", "enable_reservation") == "N"
			&& COption::GetOptionString("sale", "product_reserve_condition", "O") != "S"
			&& $strUseStoreControl != "Y");

		if ($disableReservation)
		{
			$arRes["RESULT"] = true;
			return $arRes;
		}

		if ((int)$arParams["PRODUCT_ID"] <= 0)
		{
			$APPLICATION->ThrowException(Loc::getMessage("RSRV_INCORRECT_ID"), "NO_ORDER_ID");
			$arRes["RESULT"] = false;
			return $arRes;
		}

		$arParams["QUANTITY"] = doubleval($arParams["QUANTITY"]);

		if ((string)$arParams["UNDO_DEDUCTION"] != "Y")
			$arParams["UNDO_DEDUCTION"] = "N";

		if ((string)$arParams["EMULATE"] != "Y")
			$arParams["EMULATE"] = "N";

		if ((string)$arParams["PRODUCT_RESERVED"] != "Y")
			$arParams["PRODUCT_RESERVED"] = "N";

		if (!isset($arParams["STORE_DATA"]))
			$arParams["STORE_DATA"] = array();

		if (!is_array($arParams["STORE_DATA"]))
			$arParams["STORE_DATA"] = array($arParams["STORE_DATA"]);

		$rsProducts = CCatalogProduct::GetList(
			array(),
			array('ID' => $arParams["PRODUCT_ID"]),
			false,
			false,
			array('ID', 'QUANTITY', 'QUANTITY_RESERVED', 'QUANTITY_TRACE', 'CAN_BUY_ZERO', 'NEGATIVE_AMOUNT_TRACE')
		);

		if ($arProduct = $rsProducts->Fetch())
		{
			if ($arParams["UNDO_DEDUCTION"] == "N")
			{
				if ($arParams["EMULATE"] == "Y" || $arProduct["QUANTITY_TRACE"] == "N")
				{
					$arRes["RESULT"] = true;
				}
				else
				{
					if ($strUseStoreControl == "Y")
					{
						if (!empty($arParams["STORE_DATA"]))
						{
							$totalAmount = 0;
							foreach ($arParams["STORE_DATA"] as $id => $arRecord)
							{
								if (!isset($arRecord["STORE_ID"]) || intval($arRecord["STORE_ID"]) < 0 || !isset($arRecord["QUANTITY"]) || intval($arRecord["QUANTITY"]) < 0)
								{
									$APPLICATION->ThrowException(Loc::getMessage("DDCT_DEDUCTION_STORE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DDCT_DEDUCTION_STORE_ERROR");
									$arRes["RESULT"] = false;
									return $arRes;
								}

								$rsProps = CCatalogStoreProduct::GetList(
									array(),
									array(
										"PRODUCT_ID" => $arParams["PRODUCT_ID"],
										"STORE_ID" => $arRecord["STORE_ID"]
									),
									false,
									false,
									array('ID', 'AMOUNT')
								);
								if ($arProp = $rsProps->Fetch())
								{
									if ($arProp["AMOUNT"] < $arRecord["QUANTITY"])
									{
										$APPLICATION->ThrowException(
											Loc::getMessage(
												"DDCT_DEDUCTION_QUANTITY_STORE_ERROR",
												array_merge(self::GetProductCatalogInfo($arParams["PRODUCT_ID"]), array("#STORE_ID#" => $arRecord["STORE_ID"]))
											),
											"DDCT_DEDUCTION_QUANTITY_STORE_ERROR"
										);
										$arRes["RESULT"] = false;
										return $arRes;
									}
									else
									{
										$res = CCatalogStoreProduct::Update($arProp["ID"], array("AMOUNT" => $arProp["AMOUNT"] - $arRecord["QUANTITY"]));

										if ($res)
										{
											$arRes["STORES"][$arRecord["STORE_ID"]] = $arRecord["QUANTITY"];
											$totalAmount += $arRecord["QUANTITY"];

											//deleting barcodes
											if (isset($arRecord["BARCODE"]) && is_array($arRecord["BARCODE"]) && count($arRecord["BARCODE"]) > 0)
											{
												foreach ($arRecord["BARCODE"] as $barcodeId => $barcodeValue)
												{
													$arFields = array(
														"STORE_ID" => $arRecord["STORE_ID"],
														"BARCODE" => $barcodeValue,
														"PRODUCT_ID" => $arParams["PRODUCT_ID"]
													);

													$dbres = CCatalogStoreBarcode::GetList(
														array(),
														$arFields,
														false,
														false,
														array("ID", "STORE_ID", "BARCODE", "PRODUCT_ID")
													);

													if ($arRes = $dbres->Fetch())
													{
														CCatalogStoreBarcode::Delete($arRes["ID"]);
													}
													else
													{
														$APPLICATION->ThrowException(
															Loc::getMessage(
																"DDCT_DEDUCTION_BARCODE_ERROR",
																array_merge(self::GetProductCatalogInfo($arParams["PRODUCT_ID"]), array("#BARCODE#" => $barcodeValue))
															),
															"DDCT_DEDUCTION_BARCODE_ERROR"
														);
														$arRes["RESULT"] = false;
														return $arRes;
													}
												}
											}
										}
										else
										{
											$APPLICATION->ThrowException(Loc::getMessage("DDCT_DEDUCTION_SAVE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DDCT_DEDUCTION_SAVE_ERROR");
											$arRes["RESULT"] = false;
											return $arRes;
										}
									}
								}
							}

							//updating total sum
							if ($arParams["PRODUCT_RESERVED"] == "Y")
							{
								if ($totalAmount <= $arProduct["QUANTITY_RESERVED"])
								{
									$arFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] - $totalAmount;
								}
								else if ($totalAmount <= $arProduct["QUANTITY_RESERVED"] + $arProduct["QUANTITY"])
								{
									$arFields["QUANTITY_RESERVED"] = 0;
									$arFields["QUANTITY"] = $arProduct["QUANTITY"] - ($totalAmount - $arProduct["QUANTITY_RESERVED"]);
								}
								else //not enough products - don't deduct anything
								{
									$arRes["RESULT"] = false;
									return $arRes;
								}
							}
							else //product not reserved, use main quantity field to deduct from, quantity_reserved only if there is shortage in the main field
							{
								if ($totalAmount <= $arProduct["QUANTITY"])
								{
									$arFields["QUANTITY"] = $arProduct["QUANTITY"] - $totalAmount;
								}
								else if ($totalAmount <= $arProduct["QUANTITY_RESERVED"] + $arProduct["QUANTITY"])
								{
									$arFields["QUANTITY"] = 0;
									$arFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] - ($totalAmount - $arProduct["QUANTITY"]);
								}
								else //not enough products - don't deduct anything
								{
									$arRes["RESULT"] = false;
									return $arRes;
								}
							}

							CCatalogProduct::Update($arParams["PRODUCT_ID"], $arFields);
							if (isset($arFields['QUANTITY']) && self::isNeedClearPublicCache(
								$arProduct['QUANTITY'],
								$arFields['QUANTITY'],
								$arProduct['QUANTITY_TRACE'],
								$arProduct['CAN_BUY_ZERO']
							))
							{
								$productInfo = array(
									'CAN_BUY_ZERO' => $arProduct['CAN_BUY_ZERO'],
									'NEGATIVE_AMOUNT_TRACE' => $arProduct['NEGATIVE_AMOUNT_TRACE'],
									'QUANTITY_TRACE' => $arProduct['QUANTITY_TRACE'],
									'OLD_QUANTITY' => $arProduct['QUANTITY'],
									'QUANTITY' => $arFields['QUANTITY'],
									'DELTA' => $arFields['QUANTITY'] - $arProduct['QUANTITY']
								);
								self::clearPublicCache($arProduct['ID'], $productInfo);
							}

							$arRes["RESULT"] = true;
						}
						else
						{
							$APPLICATION->ThrowException(Loc::getMessage("DDCT_DEDUCTION_STORE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DEDUCTION_STORE_ERROR1");
							$arRes["RESULT"] = false;
							return $arRes;
						}
					}
					else // store control not used
					{
						if ($arParams["QUANTITY"] <= $arProduct["QUANTITY_RESERVED"] + $arProduct["QUANTITY"])
						{
							if ($arParams["PRODUCT_RESERVED"] == "Y")
							{
								if ($arParams["QUANTITY"] <= $arProduct["QUANTITY_RESERVED"])
								{
									$arFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] - $arParams["QUANTITY"];
								}
								else
								{
									$arFields["QUANTITY_RESERVED"] = 0;
									$arFields["QUANTITY"] = $arProduct["QUANTITY"] - ($arParams["QUANTITY"] - $arProduct["QUANTITY_RESERVED"]);
								}
							}
							else //product not reserved, use main quantity field to deduct from, quantity_reserved only if there is shortage in the main field
							{
								if ($arParams["QUANTITY"] <= $arProduct["QUANTITY"])
								{
									$arFields["QUANTITY"] = $arProduct["QUANTITY"] - $arParams["QUANTITY"];
								}
								else
								{
									$arFields["QUANTITY"] = 0;
									$arFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] - ($arParams["QUANTITY"] - $arProduct["QUANTITY"]);
								}
							}

							$arRes["RESULT"] = CCatalogProduct::Update($arParams["PRODUCT_ID"], $arFields);
							if (isset($arFields['QUANTITY']) && self::isNeedClearPublicCache(
									$arProduct['QUANTITY'],
									$arFields['QUANTITY'],
									$arProduct['QUANTITY_TRACE'],
									$arProduct['CAN_BUY_ZERO']
								))
							{
								$productInfo = array(
									'CAN_BUY_ZERO' => $arProduct['CAN_BUY_ZERO'],
									'NEGATIVE_AMOUNT_TRACE' => $arProduct['NEGATIVE_AMOUNT_TRACE'],
									'QUANTITY_TRACE' => $arProduct['QUANTITY_TRACE'],
									'OLD_QUANTITY' => $arProduct['QUANTITY'],
									'QUANTITY' => $arFields['QUANTITY'],
									'DELTA' => $arFields['QUANTITY'] - $arProduct['QUANTITY']
								);
								self::clearPublicCache($arProduct['ID'], $productInfo);
							}
						}
						else //not enough products - don't deduct anything
						{
							$APPLICATION->ThrowException(Loc::getMessage("DDCT_DEDUCTION_QUANTITY_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DDCT_DEDUCTION_QUANTITY_ERROR");
							$arRes["RESULT"] = false;
							return $arRes;
						}

					} //store control
				} //emulate /quantity trace
			}
			else //undo deduction
			{
				if ($arParams["EMULATE"] == "Y" || $arProduct["QUANTITY_TRACE"] == "N")
				{
					$arRes["RESULT"] = true;
				}
				else
				{
					if ($strUseStoreControl == "Y")
					{
						if (!empty($arParams["STORE_DATA"]))
						{
							$totalAddedAmount = 0;
							foreach ($arParams["STORE_DATA"] as $id => $arRecord)
							{
								$rsProps = CCatalogStoreProduct::GetList(
									array(),
									array(
										"PRODUCT_ID" => $arParams["PRODUCT_ID"],
										"STORE_ID" => $arRecord["STORE_ID"]
									),
									false,
									false,
									array('ID', 'AMOUNT')
								);

								if ($arProp = $rsProps->Fetch())
								{
									$res = CCatalogStoreProduct::Update(
										$arProp["ID"],
										array("AMOUNT" => $arProp["AMOUNT"] + $arRecord["QUANTITY"])
									);

									if ($res)
									{
										$arRes["STORES"][$arRecord["STORE_ID"]] = $arRecord["QUANTITY"];
										$totalAddedAmount += $arRecord["QUANTITY"];

										//adding barcodes
										if (isset($arRecord["BARCODE"]) && strlen($arRecord["BARCODE"]) > 0)
										{
											$arFields = array(
												"STORE_ID" => $arRecord["STORE_ID"],
												"BARCODE" => $arRecord["BARCODE"],
												"PRODUCT_ID" => $arParams["PRODUCT_ID"]
											);

											CCatalogStoreBarcode::Add($arFields);
										}
									}
									else
									{
										$APPLICATION->ThrowException(Loc::getMessage("DDCT_DEDUCTION_SAVE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DDCT_DEDUCTION_SAVE_ERROR");
										$arRes["RESULT"] = false;
										return $arRes;
									}
								}
							}

							// $dbAmount = $DB->Query("SELECT SUM(AMOUNT) as AMOUNT FROM b_catalog_store_product WHERE PRODUCT_ID = ".$arParams["PRODUCT_ID"]." ", true);
							// if ($totalAddedAmount = $dbAmount->Fetch())
							// {
							// }
							if ($arParams["PRODUCT_RESERVED"] == "Y")
							{
								$arUpdateFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] + $totalAddedAmount;
							}
							else
							{
								$arUpdateFields["QUANTITY"] = $arProduct["QUANTITY"] + $totalAddedAmount;
							}

							CCatalogProduct::Update($arParams["PRODUCT_ID"], $arUpdateFields);
							if (isset($arUpdateFields['QUANTITY']) && self::isNeedClearPublicCache(
									$arProduct['QUANTITY'],
									$arUpdateFields['QUANTITY'],
									$arProduct['QUANTITY_TRACE'],
									$arProduct['CAN_BUY_ZERO']
								))
							{
								$productInfo = array(
									'CAN_BUY_ZERO' => $arProduct['CAN_BUY_ZERO'],
									'NEGATIVE_AMOUNT_TRACE' => $arProduct['NEGATIVE_AMOUNT_TRACE'],
									'QUANTITY_TRACE' => $arProduct['QUANTITY_TRACE'],
									'OLD_QUANTITY' => $arProduct['QUANTITY'],
									'QUANTITY' => $arUpdateFields['QUANTITY'],
									'DELTA' => $arUpdateFields['QUANTITY'] - $arProduct['QUANTITY']
								);
								self::clearPublicCache($arProduct['ID'], $productInfo);
							}

							$arRes["RESULT"] = true;
						}
						else
						{
							$APPLICATION->ThrowException(Loc::getMessage("DDCT_DEDUCTION_STORE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DEDUCTION_STORE_ERROR2");
							$arRes["RESULT"] = false;
							return $arRes;
						}
					}
					else //store control not used
					{
						if ($arParams["PRODUCT_RESERVED"] == "Y")
						{
							$arFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] + $arParams["QUANTITY"];
							// $arFields["QUANTITY"] = $arProduct["QUANTITY"] - $arParams["QUANTITY_RESERVED"];
						}
						else
						{
							$arFields["QUANTITY"] = $arProduct["QUANTITY"] + $arParams["QUANTITY"];
							// $arFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] - $arParams["QUANTITY_RESERVED"];
						}

						$arRes["RESULT"] = CCatalogProduct::Update($arParams["PRODUCT_ID"], $arFields);
						if (isset($arFields['QUANTITY']) && self::isNeedClearPublicCache(
								$arProduct['QUANTITY'],
								$arFields['QUANTITY'],
								$arProduct['QUANTITY_TRACE'],
								$arProduct['CAN_BUY_ZERO']
							))
						{
							$productInfo = array(
								'CAN_BUY_ZERO' => $arProduct['CAN_BUY_ZERO'],
								'NEGATIVE_AMOUNT_TRACE' => $arProduct['NEGATIVE_AMOUNT_TRACE'],
								'QUANTITY_TRACE' => $arProduct['QUANTITY_TRACE'],
								'OLD_QUANTITY' => $arProduct['QUANTITY'],
								'QUANTITY' => $arFields['QUANTITY'],
								'DELTA' => $arFields['QUANTITY'] - $arProduct['QUANTITY']
							);
							self::clearPublicCache($arProduct['ID'], $productInfo);
						}
					}
				} //emulate or quantity trace
			}
		}
		else
		{
			$arRes["RESULT"] = false;
		}

		if (!$arRes["RESULT"])
		{
			$APPLICATION->ThrowException(Loc::getMessage("DDCT_UNKNOWN_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "UNKNOWN_DEDUCTION_ERROR");
		}

		return $arRes;
	}
Esempio n. 15
0
						$arCatalogProduct['QUANTITY_TRACE'] = $arFields['CATALOG_QUANTITY_TRACE'];
					if ('Y' != $strUseStoreControl)
					{
						if (isset($arFields['CATALOG_QUANTITY']) && '' != $arFields['CATALOG_QUANTITY'])
							$arCatalogProduct['QUANTITY'] = $arFields['CATALOG_QUANTITY'];
					}

					if (!CCatalogProduct::IsExistProduct($ID))
					{
						$arCatalogProduct['ID'] = $ID;
						CCatalogProduct::Add($arCatalogProduct, false);
					}
					else
					{
						if (!empty($arCatalogProduct))
							CCatalogProduct::Update($ID, $arCatalogProduct);
					}

					if (isset($arFields['CATALOG_MEASURE_RATIO']) && '' != trim($arFields['CATALOG_MEASURE_RATIO']))
					{
						$intRatioID = 0;
						$rsRatios = CCatalogMeasureRatio::getList(
							array(),
							array('PRODUCT_ID' => $ID),
							false,
							false,
							array('ID', 'PRODUCT_ID')
						);
						if ($arRatio = $rsRatios->Fetch())
						{
							$intRatioID = intval($arRatio['ID']);
Esempio n. 16
0
         if (!($bAllLinesLoaded = CSVCheckTimeout($max_execution_time))) {
             break;
         }
     }
 }
 // update or delete 'not-in-file' elements
 if ($bAllLinesLoaded && $outFileAction != "F") {
     $arProductArray = array('QUANTITY' => 0, 'QUANTITY_TRACE' => 'Y', 'CAN_BUY_ZERO' => 'N', 'NEGATIVE_AMOUNT_TRACE' => 'N');
     $res = CIBlockElement::GetList(array(), array("IBLOCK_ID" => $IBLOCK_ID, "!TMP_ID" => $tmpid), false, false, array('ID'));
     while ($arr = $res->Fetch()) {
         if ($outFileAction == "D") {
             CIBlockElement::Delete($arr["ID"], "Y", "N");
             $killed_lines++;
         } elseif ($outFileAction == "F") {
         } elseif ($bIBlockIsCatalog && $outFileAction == "M") {
             CCatalogProduct::Update($arr['ID'], $arProductArray);
             $killed_lines++;
         } else {
             $bDeactivationStarted = true;
             $el->Update($arr["ID"], array("ACTIVE" => "N", "TMP_ID" => $tmpid));
             $killed_lines++;
         }
         if (!($bAllLinesLoaded = CSVCheckTimeout($max_execution_time))) {
             break;
         }
     }
 }
 // delete 'not-in-file' element prices
 if ($bAllLinesLoaded && $bIBlockIsCatalog && 'Y' == $bUpdatePrice && $outFileAction == "D") {
     $res = CPrice::GetList(array(), array("ELEMENT_IBLOCK_ID" => $IBLOCK_ID, "!TMP_ID" => $tmpid), false, false, array("ID"));
     while ($arr = $res->Fetch()) {
Esempio n. 17
0
 public static function DeductProduct($arParams)
 {
     global $APPLICATION;
     $arRes = array();
     $arFields = array();
     $basketItem = null;
     $strUseStoreControl = COption::GetOptionString('catalog', 'default_use_store_control');
     $disableReservation = COption::GetOptionString("catalog", "enable_reservation") == "N" && COption::GetOptionString("sale", "product_reserve_condition") != "S" && $strUseStoreControl != "Y";
     if ($disableReservation) {
         $arRes["RESULT"] = true;
         return $arRes;
     }
     if ((int) $arParams["PRODUCT_ID"] <= 0) {
         $APPLICATION->ThrowException(Loc::getMessage("RSRV_INCORRECT_ID"), "NO_ORDER_ID");
         $arRes["RESULT"] = false;
         return $arRes;
     }
     $isOrderConverted = \Bitrix\Main\Config\Option::get("main", "~sale_converted_15", 'N');
     $arParams["QUANTITY"] = doubleval($arParams["QUANTITY"]);
     if ((string) $arParams["UNDO_DEDUCTION"] != "Y") {
         $arParams["UNDO_DEDUCTION"] = "N";
     }
     if ((string) $arParams["EMULATE"] != "Y") {
         $arParams["EMULATE"] = "N";
     }
     if ((string) $arParams["PRODUCT_RESERVED"] != "Y") {
         $arParams["PRODUCT_RESERVED"] = "N";
     }
     if (!isset($arParams["STORE_DATA"])) {
         $arParams["STORE_DATA"] = array();
     }
     if (!is_array($arParams["STORE_DATA"])) {
         $arParams["STORE_DATA"] = array($arParams["STORE_DATA"]);
     }
     $basketItem = null;
     if (isset($arParams["BASKET_ITEM"]) && $isOrderConverted == "Y") {
         if ($arParams["BASKET_ITEM"] instanceof \Bitrix\Sale\BasketItem) {
             /** @var \Bitrix\Sale\BasketItem $basketItem */
             $basketItem = $arParams["BASKET_ITEM"];
         }
     }
     $rsProducts = CCatalogProduct::GetList(array(), array('ID' => $arParams["PRODUCT_ID"]), false, false, array('ID', 'QUANTITY', 'QUANTITY_RESERVED', 'QUANTITY_TRACE', 'CAN_BUY_ZERO'));
     if ($arProduct = $rsProducts->Fetch()) {
         if ($arParams["UNDO_DEDUCTION"] == "N") {
             if ($arParams["EMULATE"] == "Y" || $arProduct["QUANTITY_TRACE"] == "N") {
                 $arRes["RESULT"] = true;
             } else {
                 if ($strUseStoreControl == "Y") {
                     if ($isOrderConverted == "Y" && empty($arParams["STORE_DATA"]) && $basketItem) {
                         $countStores = static::GetStoresCount(array('SITE_ID' => $basketItem->getField('LID')));
                         $defaultDeductionStore = Main\Config\Option::get("sale", "deduct_store_id", "", $basketItem->getField('LID'));
                         if (($countStores == 1 || $countStores == -1 || $defaultDeductionStore > 0) && !$basketItem->isBarcodeMulti()) {
                             if ($productStore = static::GetProductStores(array('PRODUCT_ID' => $arParams["PRODUCT_ID"], 'SITE_ID' => $basketItem->getField('LID')))) {
                                 $productStore = reset($productStore);
                                 $arParams["STORE_DATA"] = array($productStore['STORE_ID'] => array('STORE_ID' => $productStore['STORE_ID'], 'QUANTITY' => $arParams["QUANTITY"]));
                             }
                         }
                     }
                     $barcodeMulti = false;
                     if ($isOrderConverted == "Y") {
                         $barcodeMulti = $basketItem->isBarcodeMulti();
                     }
                     if ($barcodeMulti) {
                         if (!empty($arParams["STORE_DATA"])) {
                             foreach ($arParams["STORE_DATA"] as $id => $arRecord) {
                                 if (!empty($arRecord["BARCODE"]) && is_array($arRecord["BARCODE"])) {
                                     foreach ($arRecord["BARCODE"] as $barcodeId => $barcodeValue) {
                                         if (strval(trim($barcodeValue)) == "") {
                                             $APPLICATION->ThrowException(Loc::getMessage("DDCT_DEDUCTION_MULTI_BARCODE_EMPTY", array_merge(self::GetProductCatalogInfo($arParams["PRODUCT_ID"]), array("#STORE_ID#" => $arRecord['STORE_ID']))), "DDCT_DEDUCTION_MULTI_BARCODE_EMPTY");
                                             $arRes["RESULT"] = false;
                                             return $arRes;
                                         }
                                     }
                                 } else {
                                     $APPLICATION->ThrowException(Loc::getMessage("DDCT_DEDUCTION_MULTI_BARCODE_EMPTY", array_merge(self::GetProductCatalogInfo($arParams["PRODUCT_ID"]), array("#STORE_ID#" => $arRecord['STORE_ID']))), "DDCT_DEDUCTION_MULTI_BARCODE_EMPTY");
                                     $arRes["RESULT"] = false;
                                     return $arRes;
                                 }
                             }
                         }
                     }
                     if (!empty($arParams["STORE_DATA"])) {
                         foreach ($arParams["STORE_DATA"] as $id => $arRecord) {
                             if (!empty($arRecord["BARCODE"]) && is_array($arRecord["BARCODE"])) {
                                 foreach ($arRecord["BARCODE"] as $barcodeValue) {
                                     $arRes['BARCODE'][$barcodeValue] = false;
                                 }
                             }
                         }
                         $totalAmount = 0;
                         foreach ($arParams["STORE_DATA"] as $id => $arRecord) {
                             if (!isset($arRecord["STORE_ID"]) || intval($arRecord["STORE_ID"]) < 0 || !isset($arRecord["QUANTITY"]) || intval($arRecord["QUANTITY"]) < 0) {
                                 $APPLICATION->ThrowException(Loc::getMessage("DDCT_DEDUCTION_STORE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DDCT_DEDUCTION_STORE_ERROR");
                                 $arRes["RESULT"] = false;
                                 return $arRes;
                             }
                             $rsProps = CCatalogStoreProduct::GetList(array(), array("PRODUCT_ID" => $arParams["PRODUCT_ID"], "STORE_ID" => $arRecord["STORE_ID"]), false, false, array('ID', 'AMOUNT'));
                             if ($arProp = $rsProps->Fetch()) {
                                 if ($arProp["AMOUNT"] < $arRecord["QUANTITY"]) {
                                     $APPLICATION->ThrowException(Loc::getMessage("DDCT_DEDUCTION_QUANTITY_STORE_ERROR", array_merge(self::GetProductCatalogInfo($arParams["PRODUCT_ID"]), array("#STORE_ID#" => $arRecord["STORE_ID"]))), "DDCT_DEDUCTION_QUANTITY_STORE_ERROR");
                                     $arRes["RESULT"] = false;
                                     return $arRes;
                                 } else {
                                     $res = CCatalogStoreProduct::Update($arProp["ID"], array("AMOUNT" => $arProp["AMOUNT"] - $arRecord["QUANTITY"]));
                                     if ($res) {
                                         $arRes["STORES"][$arRecord["STORE_ID"]] = $arRecord["QUANTITY"];
                                         $totalAmount += $arRecord["QUANTITY"];
                                         //deleting barcodes
                                         if (isset($arRecord["BARCODE"]) && is_array($arRecord["BARCODE"]) && count($arRecord["BARCODE"]) > 0) {
                                             foreach ($arRecord["BARCODE"] as $barcodeId => $barcodeValue) {
                                                 if (strval(trim($barcodeValue)) == "" || !$barcodeMulti) {
                                                     continue;
                                                 }
                                                 $arFields = array("STORE_ID" => $arRecord["STORE_ID"], "BARCODE" => $barcodeValue, "PRODUCT_ID" => $arParams["PRODUCT_ID"]);
                                                 $dbres = CCatalogStoreBarcode::GetList(array(), $arFields, false, false, array("ID", "STORE_ID", "BARCODE", "PRODUCT_ID"));
                                                 if ($catalogStoreBarcodeRes = $dbres->Fetch()) {
                                                     CCatalogStoreBarcode::Delete($catalogStoreBarcodeRes["ID"]);
                                                     $arRes['BARCODE'][$barcodeValue] = true;
                                                 } else {
                                                     $APPLICATION->ThrowException(Loc::getMessage("DDCT_DEDUCTION_BARCODE_ERROR", array_merge(self::GetProductCatalogInfo($arParams["PRODUCT_ID"]), array("#BARCODE#" => $barcodeValue))), "DDCT_DEDUCTION_BARCODE_ERROR");
                                                     $arRes['BARCODE'][$barcodeValue] = false;
                                                     $arRes["RESULT"] = false;
                                                     return $arRes;
                                                 }
                                             }
                                         }
                                     } else {
                                         $APPLICATION->ThrowException(Loc::getMessage("DDCT_DEDUCTION_SAVE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DDCT_DEDUCTION_SAVE_ERROR");
                                         $arRes["RESULT"] = false;
                                         return $arRes;
                                     }
                                 }
                             }
                         }
                         //updating total sum
                         if ($arParams["PRODUCT_RESERVED"] == "Y") {
                             if ($totalAmount <= $arProduct["QUANTITY_RESERVED"]) {
                                 $needReserved = $arProduct["QUANTITY_RESERVED"] - $totalAmount;
                                 if ($totalAmount > $arProduct["QUANTITY_RESERVED"]) {
                                     $needReserved = $arProduct["QUANTITY_RESERVED"];
                                 }
                                 $arFields["QUANTITY_RESERVED"] = $needReserved;
                             } else {
                                 if ($totalAmount <= $arProduct["QUANTITY_RESERVED"] + $arProduct["QUANTITY"]) {
                                     $arFields["QUANTITY_RESERVED"] = 0;
                                     $arFields["QUANTITY"] = $arProduct["QUANTITY"] - ($totalAmount - $arProduct["QUANTITY_RESERVED"]);
                                 } else {
                                     $arRes["RESULT"] = false;
                                     return $arRes;
                                 }
                             }
                         } else {
                             if ($totalAmount <= $arProduct["QUANTITY"]) {
                                 $arFields["QUANTITY"] = $arProduct["QUANTITY"] - $totalAmount;
                             } else {
                                 if ($totalAmount <= $arProduct["QUANTITY_RESERVED"] + $arProduct["QUANTITY"]) {
                                     $arFields["QUANTITY"] = 0;
                                     $minusQuantity = $totalAmount - $arProduct["QUANTITY"];
                                     $needReserved = $arProduct["QUANTITY_RESERVED"] - $minusQuantity;
                                     if ($minusQuantity > $arProduct["QUANTITY_RESERVED"]) {
                                         $needReserved = $arProduct["QUANTITY_RESERVED"];
                                     }
                                     $arFields["QUANTITY_RESERVED"] = $needReserved;
                                 } else {
                                     $arRes["RESULT"] = false;
                                     return $arRes;
                                 }
                             }
                         }
                         CCatalogProduct::Update($arParams["PRODUCT_ID"], $arFields);
                         if (isset($arFields['QUANTITY']) && self::isNeedClearPublicCache($arProduct['QUANTITY'], $arFields['QUANTITY'], $arProduct['QUANTITY_TRACE'], $arProduct['CAN_BUY_ZERO'])) {
                             $productInfo = array('CAN_BUY_ZERO' => $arProduct['CAN_BUY_ZERO'], 'QUANTITY_TRACE' => $arProduct['QUANTITY_TRACE'], 'OLD_QUANTITY' => $arProduct['QUANTITY'], 'QUANTITY' => $arFields['QUANTITY'], 'DELTA' => $arFields['QUANTITY'] - $arProduct['QUANTITY']);
                             self::clearPublicCache($arProduct['ID'], $productInfo);
                         }
                         $arRes["RESULT"] = true;
                     } else {
                         $APPLICATION->ThrowException(Loc::getMessage("DDCT_DEDUCTION_STORE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DEDUCTION_STORE_ERROR1");
                         $arRes["RESULT"] = false;
                         return $arRes;
                     }
                 } else {
                     if ($arParams["QUANTITY"] <= $arProduct["QUANTITY_RESERVED"] + $arProduct["QUANTITY"]) {
                         if ($arParams["PRODUCT_RESERVED"] == "Y") {
                             if ($arParams["QUANTITY"] <= $arProduct["QUANTITY_RESERVED"]) {
                                 $needReserved = $arProduct["QUANTITY_RESERVED"] - $arParams["QUANTITY"];
                                 if ($arParams["QUANTITY"] > $arProduct["QUANTITY_RESERVED"]) {
                                     $needReserved = $arProduct["QUANTITY_RESERVED"];
                                 }
                                 $arFields["QUANTITY_RESERVED"] = $needReserved;
                             } else {
                                 $arFields["QUANTITY_RESERVED"] = 0;
                                 $arFields["QUANTITY"] = $arProduct["QUANTITY"] - ($arParams["QUANTITY"] - $arProduct["QUANTITY_RESERVED"]);
                             }
                         } else {
                             if ($arParams["QUANTITY"] <= $arProduct["QUANTITY"]) {
                                 $arFields["QUANTITY"] = $arProduct["QUANTITY"] - $arParams["QUANTITY"];
                             } else {
                                 $arFields["QUANTITY"] = 0;
                                 $minusQuantity = $arParams["QUANTITY"] - $arProduct["QUANTITY"];
                                 $needReserved = $arProduct["QUANTITY_RESERVED"] - $minusQuantity;
                                 if ($minusQuantity > $arProduct["QUANTITY_RESERVED"]) {
                                     $needReserved = $arProduct["QUANTITY_RESERVED"];
                                 }
                                 $arFields["QUANTITY_RESERVED"] = $needReserved;
                             }
                         }
                         $arRes["RESULT"] = CCatalogProduct::Update($arParams["PRODUCT_ID"], $arFields);
                         if (isset($arFields['QUANTITY']) && self::isNeedClearPublicCache($arProduct['QUANTITY'], $arFields['QUANTITY'], $arProduct['QUANTITY_TRACE'], $arProduct['CAN_BUY_ZERO'])) {
                             $productInfo = array('CAN_BUY_ZERO' => $arProduct['CAN_BUY_ZERO'], 'QUANTITY_TRACE' => $arProduct['QUANTITY_TRACE'], 'OLD_QUANTITY' => $arProduct['QUANTITY'], 'QUANTITY' => $arFields['QUANTITY'], 'DELTA' => $arFields['QUANTITY'] - $arProduct['QUANTITY']);
                             self::clearPublicCache($arProduct['ID'], $productInfo);
                         }
                     } else {
                         $APPLICATION->ThrowException(Loc::getMessage("DDCT_DEDUCTION_QUANTITY_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DDCT_DEDUCTION_QUANTITY_ERROR");
                         $arRes["RESULT"] = false;
                         return $arRes;
                     }
                 }
                 //store control
             }
             //emulate /quantity trace
         } else {
             if ($arParams["EMULATE"] == "Y" || $arProduct["QUANTITY_TRACE"] == "N") {
                 $arRes["RESULT"] = true;
             } else {
                 if ($strUseStoreControl == "Y") {
                     if ($isOrderConverted == "Y" && empty($arParams["STORE_DATA"]) && $basketItem) {
                         $countStores = static::GetStoresCount(array('SITE_ID' => $basketItem->getField('LID')));
                         if ($countStores == 1 && !$basketItem->isBarcodeMulti()) {
                             if ($productStore = static::GetProductStores(array('PRODUCT_ID' => $arParams["PRODUCT_ID"], 'SITE_ID' => $basketItem->getField('LID')))) {
                                 $productStore = reset($productStore);
                                 $arParams["STORE_DATA"] = array($productStore['STORE_ID'] => array('STORE_ID' => $productStore['STORE_ID'], 'QUANTITY' => $arParams["QUANTITY"]));
                             }
                         }
                     }
                     if (!empty($arParams["STORE_DATA"])) {
                         $totalAddedAmount = 0;
                         foreach ($arParams["STORE_DATA"] as $id => $arRecord) {
                             $rsProps = CCatalogStoreProduct::GetList(array(), array("PRODUCT_ID" => $arParams["PRODUCT_ID"], "STORE_ID" => $arRecord["STORE_ID"]), false, false, array('ID', 'AMOUNT'));
                             if ($arProp = $rsProps->Fetch()) {
                                 $res = CCatalogStoreProduct::Update($arProp["ID"], array("AMOUNT" => $arProp["AMOUNT"] + $arRecord["QUANTITY"]));
                                 if ($res) {
                                     $arRes["STORES"][$arRecord["STORE_ID"]] = $arRecord["QUANTITY"];
                                     $totalAddedAmount += $arRecord["QUANTITY"];
                                     $barcodeMulti = false;
                                     if ($isOrderConverted == "Y") {
                                         $barcodeMulti = $basketItem->isBarcodeMulti();
                                     }
                                     //adding barcodes
                                     if (isset($arRecord["BARCODE"])) {
                                         if (!empty($arRecord["BARCODE"]) && is_array($arRecord["BARCODE"])) {
                                             foreach ($arRecord["BARCODE"] as $barcodeValue) {
                                                 if (strval(trim($barcodeValue)) == '' || strval(trim($barcodeValue)) != '' && !$barcodeMulti) {
                                                     continue;
                                                 }
                                                 $arFields = array("STORE_ID" => $arRecord["STORE_ID"], "BARCODE" => $barcodeValue, "PRODUCT_ID" => $arParams["PRODUCT_ID"]);
                                                 CCatalogStoreBarcode::Add($arFields);
                                             }
                                         } elseif (!is_array($arRecord["BARCODE"])) {
                                             $arFields = array("STORE_ID" => $arRecord["STORE_ID"], "BARCODE" => $arRecord["BARCODE"], "PRODUCT_ID" => $arParams["PRODUCT_ID"]);
                                             CCatalogStoreBarcode::Add($arFields);
                                         }
                                     }
                                 } else {
                                     $APPLICATION->ThrowException(Loc::getMessage("DDCT_DEDUCTION_SAVE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DDCT_DEDUCTION_SAVE_ERROR");
                                     $arRes["RESULT"] = false;
                                     return $arRes;
                                 }
                             }
                         }
                         // $dbAmount = $DB->Query("SELECT SUM(AMOUNT) as AMOUNT FROM b_catalog_store_product WHERE PRODUCT_ID = ".$arParams["PRODUCT_ID"]." ", true);
                         // if ($totalAddedAmount = $dbAmount->Fetch())
                         // {
                         // }
                         if ($arParams["PRODUCT_RESERVED"] == "Y") {
                             $arUpdateFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] + $totalAddedAmount;
                         } else {
                             $arUpdateFields["QUANTITY"] = $arProduct["QUANTITY"] + $totalAddedAmount;
                         }
                         CCatalogProduct::Update($arParams["PRODUCT_ID"], $arUpdateFields);
                         if (isset($arUpdateFields['QUANTITY']) && self::isNeedClearPublicCache($arProduct['QUANTITY'], $arUpdateFields['QUANTITY'], $arProduct['QUANTITY_TRACE'], $arProduct['CAN_BUY_ZERO'])) {
                             $productInfo = array('CAN_BUY_ZERO' => $arProduct['CAN_BUY_ZERO'], 'QUANTITY_TRACE' => $arProduct['QUANTITY_TRACE'], 'OLD_QUANTITY' => $arProduct['QUANTITY'], 'QUANTITY' => $arUpdateFields['QUANTITY'], 'DELTA' => $arUpdateFields['QUANTITY'] - $arProduct['QUANTITY']);
                             self::clearPublicCache($arProduct['ID'], $productInfo);
                         }
                         $arRes["RESULT"] = true;
                     } else {
                         $APPLICATION->ThrowException(Loc::getMessage("DDCT_DEDUCTION_STORE_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "DEDUCTION_STORE_ERROR2");
                         $arRes["RESULT"] = false;
                         return $arRes;
                     }
                 } else {
                     if ($arParams["PRODUCT_RESERVED"] == "Y") {
                         $arFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] + $arParams["QUANTITY"];
                         // $arFields["QUANTITY"] = $arProduct["QUANTITY"] - $arParams["QUANTITY_RESERVED"];
                     } else {
                         $arFields["QUANTITY"] = $arProduct["QUANTITY"] + $arParams["QUANTITY"];
                         // $arFields["QUANTITY_RESERVED"] = $arProduct["QUANTITY_RESERVED"] - $arParams["QUANTITY_RESERVED"];
                     }
                     $arRes["RESULT"] = CCatalogProduct::Update($arParams["PRODUCT_ID"], $arFields);
                     if (isset($arFields['QUANTITY']) && self::isNeedClearPublicCache($arProduct['QUANTITY'], $arFields['QUANTITY'], $arProduct['QUANTITY_TRACE'], $arProduct['CAN_BUY_ZERO'])) {
                         $productInfo = array('CAN_BUY_ZERO' => $arProduct['CAN_BUY_ZERO'], 'QUANTITY_TRACE' => $arProduct['QUANTITY_TRACE'], 'OLD_QUANTITY' => $arProduct['QUANTITY'], 'QUANTITY' => $arFields['QUANTITY'], 'DELTA' => $arFields['QUANTITY'] - $arProduct['QUANTITY']);
                         self::clearPublicCache($arProduct['ID'], $productInfo);
                     }
                 }
             }
             //emulate or quantity trace
         }
     } else {
         $arRes["RESULT"] = false;
     }
     if (!$arRes["RESULT"]) {
         $APPLICATION->ThrowException(Loc::getMessage("DDCT_UNKNOWN_ERROR", self::GetProductCatalogInfo($arParams["PRODUCT_ID"])), "UNKNOWN_DEDUCTION_ERROR");
     }
     if ($arRes['RESULT'] === true) {
         static::clearHitCache('CATALOG_PRODUCT');
     }
     return $arRes;
 }
Esempio n. 18
0
                    'QUANTITY_RESERVED' => (int)$ar_res['QUANTITY_RESERVED'] + (int)$item['quantity'],
                );
                $d = CCatalogProduct::Update($item['offer']['externalId'], $arFields);
            }
        }
        //удаляем лишние товары
        foreach($bItms as $bItm){
            if(!in_array($bItm['PRODUCT_ID'], $CrmItms)){
                CSaleBasket::Delete($bItm['ID']);
                //удаляем товары из резерва
                $ar_res = CCatalogProduct::GetByID($bItm['PRODUCT_ID']);
                $arFields = array(
                    'QUANTITY' => (int)$ar_res['QUANTITY'] + (int)$bItm['QUANTITY'],
                    'QUANTITY_RESERVED' => (int)$ar_res['QUANTITY_RESERVED'] - (int)$bItm['QUANTITY'],
                );
                $d = CCatalogProduct::Update($bItm['PRODUCT_ID'], $arFields);
            }
        }

        if (isset($order['delivery']) === false || isset($order['delivery']['cost']) === false) {
            $order['delivery']['cost'] = $arFields['PRICE_DELIVERY'];
        }

        if (isset($order['summ']) === false || $order['summ'] <= 0) {
            $order['summ'] = $arFields['PRICE'] - $arFields['PRICE_DELIVERY'];
        }

        $wasCanaceled = $arFields['CANCELED'] == 'Y' ? true : false;

        if (isset($optionsDelivTypes[$order['delivery']['code']])) {
            $resultDeliveryTypeId = $optionsDelivTypes[$order['delivery']['code']];
Esempio n. 19
0
            CCatalogProduct::Update($arElements["ID"], array("QUANTITY_RESERVED" => 0, "QUANTITY" => $quantity));
        }
        COption::SetOptionString('catalog', 'clear_reserved_quantity_user', $userId);
        COption::SetOptionString('catalog', 'clear_reserved_quantity_date', $strDateAction);
    } elseif ($_REQUEST['action'] == "clearStore") {
        $storeId = isset($_REQUEST["storeId"]) ? intval($_REQUEST["storeId"]) : 0;
        if ($storeId > 0 || $storeId == -1) {
            $arElementsId = array();
            $dbElements = CCatalogProduct::GetList(array(), array("ELEMENT_IBLOCK_ID" => $iblockId), false, false, array("ID", "QUANTITY"));
            while ($arElements = $dbElements->Fetch()) {
                $arElementsId[$arElements["ID"]] = $arElements["QUANTITY"];
            }
            if ($storeId === -1) {
                $dbStoreElements = CCatalogStoreProduct::GetList(array(), array("PRODUCT_ID" => array_keys($arElementsId)), false, false, array("ID", "AMOUNT", "PRODUCT_ID"));
            } else {
                $dbStoreElements = CCatalogStoreProduct::GetList(array(), array("STORE_ID" => $storeId, "PRODUCT_ID" => array_keys($arElementsId)), false, false, array("ID", "AMOUNT", "PRODUCT_ID"));
            }
            while ($arStoreElements = $dbStoreElements->Fetch()) {
                CCatalogStoreProduct::Update($arStoreElements["ID"], array("AMOUNT" => 0));
                if ($strUseStoreControl === 'Y') {
                    $arElementsId[$arStoreElements["PRODUCT_ID"]] = $arElementsId[$arStoreElements["PRODUCT_ID"]] - $arStoreElements["AMOUNT"];
                    CCatalogProduct::Update($arStoreElements["PRODUCT_ID"], array("QUANTITY" => $arElementsId[$arStoreElements["PRODUCT_ID"]]));
                }
            }
            COption::SetOptionString('catalog', 'clear_store_user', $userId);
            COption::SetOptionString('catalog', 'clear_store_date', $strDateAction);
        }
    }
}
echo CUtil::PhpToJSObject($buttonId);
require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_after.php";