示例#1
0
	/**
	 * [addPriceProducts description]
	 * @param array $arParams
	 * @return bool
	 */
	protected function addPriceProducts($arParams){
		if (!CModule::IncludeModule("iblock") && !CModule::IncludeModule("catalog") && !CModule::IncludeModule("sale")):
			return false;
		endif;
		$PRICE_TYPE_ID = 1; // идентификатор типы базовой цены
		$arFields = Array(
		    "PRODUCT_ID" => $arParams["PRODUCT_ID"],
		    "CATALOG_GROUP_ID" => $PRICE_TYPE_ID,
		    "PRICE" => $arParams["OLD_PRICE"],
		    "CURRENCY" => "RUB",
		    "QUANTITY_FROM" => 1,
		);
		$res = CPrice::GetList(
		        array(),
		        array(
	                "PRODUCT_ID" => $arParams["PRODUCT_ID"],
	                "CATALOG_GROUP_ID" => $PRICE_TYPE_ID
	            )
		    );
		if ($arr = $res->Fetch()):
		    if (!CPrice::Update($arr["ID"], $arFields)):
		    	return false;
		    endif;
		else:
		    if (!CPrice::Add($arFields)):
		    	return false;
		    endif;
		endif;
		if (!$this->addCatalogProducts($arParams)):
			return false;
		endif;
		return true;
	}
示例#2
0
 public static function setPrice($productID, $priceValue = 0.0, $currency = false, $priceTypeId = false, $priceTypeId = false)
 {
     $productID = intval($productID);
     if ($currency === false) {
         $currency = CCrmCurrency::GetBaseCurrencyID();
     }
     if (strlen($currency) < 3) {
         return false;
     }
     if ($priceTypeId === false) {
         $priceTypeId = self::getSelectedPriceTypeId();
     }
     if (intval($priceTypeId) < 1) {
         return false;
     }
     $ID = false;
     $arFields = false;
     if ($arFields = self::getPrice($productID, $priceTypeId)) {
         $ID = $arFields["ID"];
         $arFields = array("PRICE" => doubleval($priceValue), "CURRENCY" => $currency);
         $ID = CPrice::Update($ID, $arFields);
     } else {
         $arFields = array("PRICE" => doubleval($priceValue), "CURRENCY" => $currency, "QUANTITY_FROM" => 0, "QUANTITY_TO" => 0, "EXTRA_ID" => false, "CATALOG_GROUP_ID" => $priceTypeId, "PRODUCT_ID" => $productID);
         $ID = CPrice::Add($arFields);
     }
     return $ID ? $ID : false;
 }
 private function setExtra($productId, $priceTypeId, $extraId)
 {
     $list = CPrice::GetList(array(), array('PRODUCT_ID' => $productId, 'CATALOG_GROUP_ID' => $priceTypeId), false, false, array('ID', 'EXTRA_ID'));
     $arFields = array('PRODUCT_ID' => $productId, 'CATALOG_GROUP_ID' => $priceTypeId, 'EXTRA_ID' => $extraId, 'CURRENCY' => 'USD');
     if ($res = $list->Fetch()) {
         if ($res['EXTRA_ID'] != $extraId) {
             CPrice::Update($res['ID'], $arFields, true);
         }
     } else {
         CPrice::Add($arFields, true);
     }
     unset($list);
     unset($res);
     unset($resultUp);
 }
示例#4
0
	function ReCountForBase(&$arFields)
	{
		static $arExtraList = array();
		$boolSearch = false;

		$arFilter = array('PRODUCT_ID' => $arFields['PRODUCT_ID'],'!CATALOG_GROUP_ID' => $arFields['CATALOG_GROUP_ID']);
		if (isset($arFields['QUANTITY_FROM']))
			$arFilter['QUANTITY_FROM'] = $arFields['QUANTITY_FROM'];
		if (isset($arFields['QUANTITY_TO']))
			$arFilter['QUANTITY_TO'] = $arFields['QUANTITY_TO'];

		$rsPrices = CPrice::GetListEx(
			array('CATALOG_GROUP_ID' => 'ASC',"QUANTITY_FROM" => "ASC", "QUANTITY_TO" => "ASC"),
			$arFilter,
			false,
			false,
			array('ID','EXTRA_ID')
		);
		while ($arPrice = $rsPrices->Fetch())
		{
			$arPrice['EXTRA_ID'] = intval($arPrice['EXTRA_ID']);
			if ($arPrice['EXTRA_ID'] > 0)
			{
				$boolSearch = isset($arExtraList[$arPrice['EXTRA_ID']]);
				if (!$boolSearch)
				{
					$arExtra = CExtra::GetByID($arPrice['EXTRA_ID']);
					if (!empty($arExtra))
					{
						$boolSearch = true;
						$arExtraList[$arExtra['ID']] = $arExtra['PERCENTAGE'];
					}
				}
				if ($boolSearch)
				{
					$arNewPrice = array(
						'CURRENCY' => $arFields['CURRENCY'],
						'PRICE' => RoundEx($arFields["PRICE"] * (1 + DoubleVal($arExtraList[$arPrice['EXTRA_ID']])/100), CATALOG_VALUE_PRECISION),
					);
					CPrice::Update($arPrice['ID'],$arNewPrice,false);
				}
			}
		}
	}
示例#5
0
     }
 }
 foreach ($arFields as $key => $value) {
     $strPriceErr = '';
     $res = CPrice::GetListEx(array(), array("PRODUCT_ID" => $value['PRODUCT_ID'], "CATALOG_GROUP_ID" => $value['CATALOG_GROUP_ID'], "QUANTITY_FROM" => $value['QUANTITY_FROM'], "QUANTITY_TO" => $value['QUANTITY_TO']), false, false, array('ID'));
     if ($arr = $res->Fetch()) {
         $boolEraseClear = false;
         if ('Y' == $CLEAR_EMPTY_PRICE) {
             $boolEraseClear = isset($value['PRICE']) && '' === $value['PRICE'] && (isset($value['CURRENCY']) && '' === $value['CURRENCY']);
         }
         if ($boolEraseClear) {
             if (!CPrice::Delete($arr["ID"])) {
                 $strPriceErr = GetMessage('CATI_ERR_PRICE_DELETE');
             }
         } else {
             if (CPrice::Update($arr["ID"], $value)) {
                 $bUpdatePrice = 'Y';
             } else {
                 if ($ex = $APPLICATION->GetException()) {
                     $strPriceErr = GetMessage('CATI_ERR_PRICE_UPDATE') . $ex->GetString();
                 } else {
                     $strPriceErr = GetMessage('CATI_ERR_PRICE_UPDATE_UNKNOWN');
                 }
             }
         }
     } else {
         $boolEmptyNewPrice = isset($value['PRICE']) && '' === $value['PRICE'] && (isset($value['CURRENCY']) && '' === $value['CURRENCY']);
         if (!$boolEmptyNewPrice) {
             if (CPrice::Add($value)) {
                 $bUpdatePrice = 'Y';
             } else {
示例#6
0
								}
							}
							elseif(!isset($CATALOG_EXTRA[$elID][$arCatalogGroup["ID"]]))
							{
								$arFields = array(
									"PRODUCT_ID" => $elID,
									"CATALOG_GROUP_ID" => $arCatalogGroup["ID"],
									"PRICE" => $arPrice[$arCatalogGroup["ID"]],
									"CURRENCY" => $arCurrency[$arCatalogGroup["ID"]],
									"QUANTITY_FROM" => $CATALOG_QUANTITY_FROM[$elID][$arCatalogGroup["ID"]],
									"QUANTITY_TO" => $CATALOG_QUANTITY_TO[$elID][$arCatalogGroup["ID"]]
								);
								if($arFields["PRICE"] < 0 || trim($arFields["PRICE"]) === '')
									CPrice::Delete($CATALOG_PRICE_ID[$elID][$arCatalogGroup["ID"]]);
								elseif(intval($CATALOG_PRICE_ID[$elID][$arCatalogGroup["ID"]])>0)
									CPrice::Update(intval($CATALOG_PRICE_ID[$elID][$arCatalogGroup["ID"]]), $arFields);
								elseif($arFields["PRICE"] >= 0)
									CPrice::Add($arFields);
							}
						}
					}
					unset($arCatalogGroup);
				}
			}
		}
	}
}


// Handle actions here
if(($arID = $lAdmin->GroupAction()))
示例#7
0
文件: cml2.php 项目: nycmic/bittest
 /**
  * @param int $PRODUCT_ID
  * @param array $arPrices
  * @param bool|array $arDiscounts
  */
 function SetProductPrice($PRODUCT_ID, $arPrices, $arDiscounts = false)
 {
     $arDBPrices = array();
     $rsPrice = CPrice::GetList(array(), array("PRODUCT_ID" => $PRODUCT_ID));
     while ($ar = $rsPrice->Fetch()) {
         $arDBPrices[$ar["CATALOG_GROUP_ID"] . ":" . $ar["QUANTITY_FROM"] . ":" . $ar["QUANTITY_TO"]] = $ar["ID"];
     }
     $arToDelete = $arDBPrices;
     if (!is_array($arPrices)) {
         $arPrices = array();
     }
     foreach ($arPrices as $price) {
         if (!isset($price[$this->mess["IBLOCK_XML2_CURRENCY"]])) {
             $price[$this->mess["IBLOCK_XML2_CURRENCY"]] = $price["PRICE"]["CURRENCY"];
         }
         $arPrice = array("PRODUCT_ID" => $PRODUCT_ID, "CATALOG_GROUP_ID" => $price["PRICE"]["ID"], "^PRICE" => $this->ToFloat($price[$this->mess["IBLOCK_XML2_PRICE_FOR_ONE"]]), "CURRENCY" => $this->CheckCurrency($price[$this->mess["IBLOCK_XML2_CURRENCY"]]));
         foreach ($this->ConvertDiscounts($arDiscounts) as $arDiscount) {
             $arPrice["QUANTITY_FROM"] = $arDiscount["QUANTITY_FROM"];
             $arPrice["QUANTITY_TO"] = $arDiscount["QUANTITY_TO"];
             if ($arDiscount["PERCENT"] > 0) {
                 $arPrice["PRICE"] = $arPrice["^PRICE"] - $arPrice["^PRICE"] / 100 * $arDiscount["PERCENT"];
             } else {
                 $arPrice["PRICE"] = $arPrice["^PRICE"];
             }
             $id = $arPrice["CATALOG_GROUP_ID"] . ":" . $arPrice["QUANTITY_FROM"] . ":" . $arPrice["QUANTITY_TO"];
             if (array_key_exists($id, $arDBPrices)) {
                 CPrice::Update($arDBPrices[$id], $arPrice);
                 unset($arToDelete[$id]);
             } else {
                 CPrice::Add($arPrice);
             }
         }
     }
     foreach ($arToDelete as $id) {
         CPrice::Delete($id);
     }
 }
示例#8
0
文件: class.php 项目: ASDAFF/gpbitrix
    /**
     * функция после добавлением элемента в инфоблока
     * @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'];

         }



         }
示例#9
0
             if (!$ID_tmp) {
                 $strWarning .= str_replace("#PRICE#", $arCatalogFields["PRICE"], GetMessage("C2IT_ERROR_SAVEPRICE")) . "<br>";
             }
         }
     }
 }
 foreach ($arCatalogPrices as $catalogGroupID => $arCatalogPrice_tmp) {
     $intCountPrice = count($arCatalogPrice_tmp);
     for ($i = 0; $i < $intCountPrice; $i++) {
         if (strlen($arCatalogPrice_tmp[$i]["PRICE"]) > 0) {
             $arCatalogFields = array("EXTRA_ID" => $arCatalogPrice_tmp[$i]["EXTRA_ID"] > 0 ? $arCatalogPrice_tmp[$i]["EXTRA_ID"] : false, "PRODUCT_ID" => $PRODUCT_ID, "CATALOG_GROUP_ID" => $catalogGroupID, "PRICE" => DoubleVal($arCatalogPrice_tmp[$i]["PRICE"]), "CURRENCY" => $arCatalogPrice_tmp[$i]["CURRENCY"], "QUANTITY_FROM" => $arCatalogPrice_tmp[$i]["QUANTITY_FROM"] > 0 ? $arCatalogPrice_tmp[$i]["QUANTITY_FROM"] : false, "QUANTITY_TO" => $arCatalogPrice_tmp[$i]["QUANTITY_TO"] > 0 ? $arCatalogPrice_tmp[$i]["QUANTITY_TO"] : false);
             if ($arCatalogPrice_tmp[$i]["ID"] > 0) {
                 $arCatalogPrice = CPrice::GetByID($arCatalogPrice_tmp[$i]["ID"]);
                 if ($arCatalogPrice && $arCatalogPrice["PRODUCT_ID"] == $PRODUCT_ID) {
                     $arUpdatedIDs[] = $arCatalogPrice_tmp[$i]["ID"];
                     if (!CPrice::Update($arCatalogPrice_tmp[$i]["ID"], $arCatalogFields)) {
                         $strWarning .= str_replace("#ID#", $arCatalogPrice_tmp[$i]["ID"], GetMessage("C2IT_ERROR_PRPARAMS")) . "<br>";
                     }
                 } else {
                     $ID_tmp = CPrice::Add($arCatalogFields);
                     $arUpdatedIDs[] = $ID_tmp;
                     if (!$ID_tmp) {
                         $strWarning .= str_replace("#PRICE#", $arCatalogFields["PRICE"], GetMessage("C2IT_ERROR_SAVEPRICE")) . "<br>";
                     }
                 }
             } else {
                 $ID_tmp = CPrice::Add($arCatalogFields);
                 $arUpdatedIDs[] = $ID_tmp;
                 if (!$ID_tmp) {
                     $strWarning .= str_replace("#PRICE#", $arCatalogFields["PRICE"], GetMessage("C2IT_ERROR_SAVEPRICE")) . "<br>";
                 }
			$arFields = Array(
					"PRODUCT_ID" => $PRODUCT_ID,
					"CATALOG_GROUP_ID" => $PRICE_ID,
					"PRICE" => $OFFER_PRICE,
					"CURRENCY" => $OFFER_CURRENCY
				);

			$res = CPrice::GetList(
					array(),
					array(
							"PRODUCT_ID" => $PRODUCT_ID,
							"CATALOG_GROUP_ID" => $PRICE_ID
						)
				);
			if ($arr = $res->Fetch())
				$khjk = CPrice::Update($arr["ID"], $arFields);
			else
				$khjk = CPrice::Add($arFields);
		}
	}

	if (COption::GetOptionString("catalog", "deactivate_1c_no_price", "N")=="Y")
	{
		foreach ($arProductsTmpA as $keyA=>$valA)
		{
			foreach ($valA["arProducts"] as $keyB=>$valB)
			{
				$res = $el->Update(IntVal($valB), Array("ACTIVE" => "N"));
			}
		}
	}