#die('die');
set_time_limit(0);
ignore_user_abort();
ini_set('memory_limit', '1024M');
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
CModule::IncludeModule("iblock");
CModule::IncludeModule("catalog");
if(!$USER->IsAdmin()) {
echo "
Need Admin
-login-";
die();
}
ini_set('display_errors',1);
ini_set("error_reporting", E_ERROR);
if (empty($_GET)) {
?>
exit();
}
$intSKUIBlock = (int)$_GET[sku];
$arCatalog = CCatalog::GetByID($intSKUIBlock);
if (!$arCatalog) {
echo "arCatalog die - error intSKUIBlock = ".$intSKUIBlock;
return;
}
$sectID = (int)$_GET[sectionID];
$proc = (int)$_GET[proc];
#die('die');
if ($sectID>0) {
$res = CIBlockSection::GetByID($sectID);
if($ar_res = $res->GetNext()) {
?>
}
}
echo "start
\n";
$intProductIBlock = $arCatalog['PRODUCT_IBLOCK_ID']; // ID IBlock goods
$intSKUProperty = $arCatalog['SKU_PROPERTY_ID']; // ID prop (SKU)
$obElement = new CIBlockElement();
$arSelect1 = Array("ID", "IBLOCK_ID", "NAME");
if($sectID>0) {
$arFilter1 = Array("IBLOCK_ID"=>$intProductIBlock, "SECTION_ID"=>$sectID, "INCLUDE_SUBSECTIONS" => "Y",);
} else {
$arFilter1 = Array("IBLOCK_ID"=>$intProductIBlock);
}
$rsEl1 = CIBlockElement::GetList(Array(), $arFilter1, false, false, $arSelect1);
while($ob1 = $rsEl1->GetNextElement()) {
if (file_exists('stop.txt')) die('stop');
$obFields1 = $ob1->GetFields();
$intProductID = $obFields1["ID"];
$PRODUCT_ID = $intProductID;
$name = $obFields1["NAME"];
echo "intProductID $intProductID $name";
$arSelect = Array("ID", "IBLOCK_ID", "NAME", "DATE_ACTIVE_FROM", "PROPERTY_*");//IBLOCK_ID и ID - REQUIRED!!!
$arFilter = Array("IBLOCK_ID"=>$intSKUProperty, "PROPERTY_CML2_LINK"=>$PRODUCT_ID);
$rsEl = CIBlockElement::GetList(Array(), $arFilter, false, false, $arSelect);
$off=0;
while($ob = $rsEl->GetNextElement()) {
if (file_exists('stop.txt')) die('stop');
$off=1;
$obFields = $ob->GetFields();
$intOfferID = $obFields["ID"];
$obProps = $ob->GetProperties();
$res = CPrice::GetBasePrice($intOfferID);
$price = $res[PRICE] + $res[PRICE]*$proc/100;
$price = round($price/10)*10;
echo "New price OFFER $intOfferID $res[PRICE] => $price";
CPrice::SetBasePrice($intOfferID, $price, 'RUB');
}
if($off==0) {
$res = CPrice::GetBasePrice($intProductID);
$price = $res[PRICE] + $res[PRICE]*$proc/100;
$price = round($price/10)*10;
echo "New price CATALOG $res[PRICE] => $price";
CPrice::SetBasePrice($intProductID, $price, 'RUB');
}
}
echo "done";
?>