Пример #1
0
 function ReCalculate($TYPE, $ID, $VAL)
 {
     $ID = (int) $ID;
     if ($ID <= 0) {
         return;
     }
     $iblockList = array();
     if ($TYPE == 'EXTRA') {
         $baseType = CCatalogGroup::GetBaseGroup();
         if (empty($baseType)) {
             return;
         }
         $db_res = CPrice::GetListEx(array(), array('EXTRA_ID' => $ID), false, false, array('ID', 'PRODUCT_ID', 'EXTRA_ID', 'QUANTITY_FROM', 'QUANTITY_TO'));
         while ($res = $db_res->Fetch()) {
             $parentFilter = array('PRODUCT_ID' => $res['PRODUCT_ID'], 'CATALOG_GROUP_ID' => $baseType['ID'], 'QUANTITY_FROM' => $res['QUANTITY_FROM'] === null ? false : $res['QUANTITY_FROM'], 'QUANTITY_TO' => $res['QUANTITY_TO'] === null ? false : $res['QUANTITY_TO']);
             $parentIterator = CPrice::GetListEx(array(), $parentFilter, false, false, array('ID', 'PRODUCT_ID', 'PRICE', 'CURRENCY', 'ELEMENT_IBLOCK_ID'));
             $basePrice = $parentIterator->Fetch();
             if (!empty($basePrice)) {
                 $basePrice['ELEMENT_IBLOCK_ID'] = (int) $basePrice['ELEMENT_IBLOCK_ID'];
                 $fields = array('PRICE' => roundex($basePrice['PRICE'] * (1 + 1 * $VAL / 100), 2), 'CURRENCY' => $basePrice['CURRENCY']);
                 CPrice::Update($res['ID'], $fields);
                 unset($arFields);
                 $iblockList[$basePrice['ELEMENT_IBLOCK_ID']] = $basePrice['ELEMENT_IBLOCK_ID'];
             }
             unset($basePrice, $parentIterator);
         }
         unset($res, $db_res, $baseType);
     } else {
         $db_res = CPrice::GetListEx(array(), array("PRODUCT_ID" => $ID), false, false, array('ID', 'PRODUCT_ID', 'EXTRA_ID', 'ELEMENT_IBLOCK_ID'));
         while ($res = $db_res->Fetch()) {
             $res['ELEMENT_IBLOCK_ID'] = (int) $res['ELEMENT_IBLOCK_ID'];
             $res["EXTRA_ID"] = (int) $res["EXTRA_ID"];
             if ($res["EXTRA_ID"] > 0) {
                 $res1 = CExtra::GetByID($res["EXTRA_ID"]);
                 $arFields = array("PRICE" => $VAL * (1 + 1 * $res1["PERCENTAGE"] / 100));
                 CPrice::Update($res["ID"], $arFields);
                 $iblockList[$res['ELEMENT_IBLOCK_ID']] = $res['ELEMENT_IBLOCK_ID'];
             }
         }
         unset($res, $db_res);
     }
     if (!empty($iblockList) && Main\Loader::includeModule('iblock')) {
         foreach ($iblockList as &$iblock) {
             CIblock::clearIblockTagCache($iblock);
         }
         unset($iblock);
     }
     unset($iblockList);
 }