Your IP : 3.138.69.55


Current Path : /proc/self/cwd/
Upload File :
Current File : //proc/self/cwd/initialization.php

<?php
/**
 * Created by PhpStorm.
 * User: Max
 * Date: 08.02.2017
 * Time: 18:07
 */
require_once($_SERVER["DOCUMENT_ROOT"] ."/bitrix/modules/main/include/prolog_before.php");

\CModule::IncludeModule('catalog');
\CModule::IncludeModule('sale');

$cntProduct = 0;
$cntWBPProduct = 0;

$cycleFrom = 341;
$cycleTo = 6000; //2986
for ($i = $cycleFrom; $i <= $cycleTo; $i++) {

    $arProductID = $i;
    $minPrice = false;
    $minDiscount = false;

    /**
     * get discount of product
     */
    $dbProductDiscounts = CCatalogDiscount::GetList(
        false,
        array(
            "+PRODUCT_ID" => $arProductID,
            "ACTIVE" => "Y",
        ),
        false,
        false,
        array(
            "VALUE",
        )
    );
    while ($arProductDiscounts = $dbProductDiscounts->Fetch()) {
        $DISCOUNT = $arProductDiscounts['VALUE'];
        if ($minDiscount === false || $minDiscount > $DISCOUNT) {
            $minDiscount = $DISCOUNT;
        }
    }

    /**
     * get prices
     */
    $rsPrices = CPrice::GetList(
        array(),
        array(
            "PRODUCT_ID" => $arProductID,
        )
    );
    $basePrice = CPrice::GetBasePrice(
        $i
);

    while ($arPrice = $rsPrices->Fetch()) {
        $PRICE = [$arPrice["PRICE"], ($minDiscount != false) ? $minDiscount : $arPrice["PRICE"]];
        foreach ($PRICE as $keyAllPrice => $valueAllPrice) {
            if ($minPrice === false || $minPrice > $valueAllPrice) {
                $minPrice = $valueAllPrice;
            }
        }
    }

    /**
     * save found minimal price into property
     */
    if ($minPrice !== false && $basePrice !== false) {
        CIBlockElement::SetPropertyValuesEx(
            $arProductID,
            false, //$IBLOCK_ID,
            array(
                "MINIMUM_PRICE" => $minPrice,
            )
        );
        echo "-----------------------------" . "<br>";
        echo "<b> ID: </b>" . $arProductID . "<br>";
        echo  "<b>PRICE: </b>";
        \Bitrix\Main\Diag\Debug::dump($minPrice) ;
        $cntProduct++;
    } else {
        CIBlockElement::SetPropertyValuesEx(
            $arProductID,
            false, //$IBLOCK_ID,
            array(
                "MINIMUM_PRICE" => "",
            )
        );
        echo "-----------------------------" . "<br>";
        echo "<b> ID: </b>" . $arProductID . "<br>";
        echo  "<b>BASE_PRICE: </b>";
        \Bitrix\Main\Diag\Debug::dump($minPrice) ;
        $cntWBPProduct++;
    }

}
echo "&rarr;&rarr;&rarr;&rarr;&rarr;&rarr;&rarr;&rarr;&rarr;&rarr;&rarr;&rarr;&rarr;" . "<br>";
echo "<b> CountProducts: </b>" . $cntProduct . "<br>";
echo "<b> CountWBPProducts: </b>" . $cntWBPProduct . "<br>";