📜 ⬆️ ⬇️

How Bitrix didn’t ruin the New Year

We lived in a small fun web-studio, did business cards, online stores and small portals. There were projects on the 1C-Bitrix platform. We, of course, were not the official integrator of Bitrix, but we did workable projects as far as strength and experience allowed. It would seem that we only had to use some components, but this miracle of domestic brains managed to make a surprise for the new year.

Received us a new order - online store. By the way, we also had online stores, they worked on our CMS, based on the Codeigniter framework. Worked quite well, quite quickly. But time took its toll, Laravel4 came out (as everything is simple and wonderful), Yii2 (finally stable), Phalcon (C is very fast) and finally using the deceased CI (somebody take me home) did not have more strength. Having exchanged glances with the assistant, we immediately realized that I did not want to create a new order on the old system. There were thoughts to rewrite the successful solutions of the online store on Yii2, we looked in the direction of Open Cart, CS Cart and PrestaShop, but the customer put the end to the question - 1C Bitrix (edited by Business). Bright hopes neatly laid the soap and rope in a suitcase and set off home. On the other hand, not everything is so bad, I thought. We will have a set of ready-made high-quality solutions (the key word is ready-made, as the customer was warned about), all that remains is to implement the layout. And after a couple of days the work began to boil.

"Hooray! It was loaded and installed! ”I exclaimed, finishing up the cup of tea lost in the bill. “Damn it, what a bunch of files ?!”, thought git and thought.

As a basis, I took an online clothing store, which can be installed with Bitrix.
')
We sit with a friend in the office, we pull on minor components and suddenly we get the first prize from Beatrix. This system has the ability to merge and compress css and js files connected in the correct way. “Where I screwed up” - the first soap that came to my head when jquery stopped connecting. Convulsively press Ctrl + Z, canceling the written code, but nothing helps. Unthinkable options go into battle, but they also do not bring success. Chaos in the head. I leave to drink tea. While I was gone, Bitrix solemnly begged to return, saying that he would forgive everything and earned it. When I launched the site again, the static build was in perfect order. Magic, I thought, and wanted to forget about it already, as my comrade, who was sitting a few meters away from me, stumbles upon the same bug. Googling ruled that people face this, but there is no solution.

As in my case, after some time the static on the site was fixed by itself. By the way, this bug we have emerged even once in the development process. The essence of this bug, apparently, lies in the fact that, for an unspecified reason, the order of js files when merged is confused or some necessary js files do not fall into the union.

Who cares, the head part looked like this:
head
<head>
		<meta charset="utf-8"/>
        <?
        $APPLICATION->ShowMeta("robots", false, true);
        $APPLICATION->ShowMeta("keywords", false, true);
        $APPLICATION->ShowMeta("description", false, true);
        ?>
		<link rel="shortcut icon" type="image/x-icon" href="<?= SITE_DIR ?>/favicon.ico"/>
		<link rel="stylesheet"
			  type="text/css"
			  href="<?= CUtil::GetAdditionalFileURL('http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic&subset=latin,cyrillic'
			  ) ?>"/>
		<link rel="stylesheet"
			  type="text/css"
			  href="<?= CUtil::GetAdditionalFileURL('http://fonts.googleapis.com/css?family=Noto+Sans&subset=latin,cyrillic'
			  ) ?>"/>
		<link rel="stylesheet"
			  type="text/css"
			  href="<?= CUtil::GetAdditionalFileURL('http://fonts.googleapis.com/css?family=Roboto+Slab:400,300,700&subset=latin,cyrillic'
			  ) ?>"/>
		<?
		$APPLICATION->ShowCSS(true, true);
		?>
		<link rel="stylesheet"
			  type="text/css"
			  href="<?= CUtil::GetAdditionalFileURL(SITE_TEMPLATE_PATH . "/css/jquery.formstyler.css") ?>"/>
		<link rel="stylesheet"
			  type="text/css"
			  href="<?= CUtil::GetAdditionalFileURL(SITE_TEMPLATE_PATH . "/css/jquery.nouislider.css") ?>"/>
		<link rel="stylesheet"
			  type="text/css"
			  href="<?= CUtil::GetAdditionalFileURL(SITE_TEMPLATE_PATH . "/css/jquery.ad-gallery.css") ?>"/>
        <link rel="stylesheet"
              type="text/css"
              href="<?= CUtil::GetAdditionalFileURL(SITE_TEMPLATE_PATH . "/css/keyboard.css") ?>"/>

        <?$APPLICATION->AddHeadScript(SITE_TEMPLATE_PATH."/js/jquery-1.11.1.min.js");?>
        <?$APPLICATION->AddHeadScript(SITE_TEMPLATE_PATH."/functions.js");?>

		<?
		$APPLICATION->ShowHeadStrings();
		$APPLICATION->ShowHeadScripts();
		?>

        <!--[if lt IE 9]>
        <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->

		<title><? $APPLICATION->ShowTitle() ?></title>
	</head>


, .

, . . (#SITE_DIR#/catalog/#SECTION_CODE#/). , #SITE_DIR#/catalog/ . /catalog/index.php . « » – , 30 . . . ajax , . :

if($_REQUEST['ajax']=='Y')

, , $_REQUEST[‘ajax’] NOTICE, - . isset .

if(isset($_REQUEST['ajax']) && $_REQUEST['ajax']=='Y')

, . , , , , , - . — . , - , . , , ( ) , . js \bitrix\components\bitrix\catalog.element\templates\.default\script.js, 2839 , result_modifier.php , js .

, « - ». . jquery, , 1 BX.js, . 200 .

, - . , - , . , , 1000 mA « » : ? , , . . , . , , .

, , - , ajax , . , , . “” .

. - . CSaleBasket::Add, , , . , .

, , . «». . Update . .

$code = Add2BasketByProductID($productID, $QUANTITY, $arRewriteFields, $product_properties);

if (!$code) {
    $response['status'] = 400;
    $response['message'] = '     ';
} else {
    $response['basket'] = getActualSmallBasket();

    /*fix     sku  */
    if (is_array($productProperties)) {
        $arFields["PROPS"] = $productProperties;
        CSaleBasket::Update($code, $arFields);
     }
}

. , , . , , . , (bitrix:search.page), , arResult . , . arResult[‘PARAM2’], id , , ITEM_ID S, . arResult, , - . , . , .

. , -, ajax . Ajax . « ». , , -. . PAGEN_1, PAGEN_2. , . . , , ajax . . , .

. . , , . - , , , . . «» . : – . . . . , : , . , . OnAfterIBlockElementAdd . :

/*       */
AddEventHandler("catalog", "OnPriceUpdate", Array("DiEvent", "OnPriceUpdateHandler"));
AddEventHandler("catalog", "OnPriceAdd", Array("DiEvent", "OnPriceAddHandler"));

/*       */
AddEventHandler("catalog", "OnProductAdd", Array("DiEvent", "OnProductAddHandler"));
AddEventHandler("iblock", "OnAfterIBlockElementUpdate", Array("DiEvent", "OnProductUpdateHandler"));

/**
     *        
     *
     * @param $id
     * @param $arFields
     */
    function OnPriceUpdateHandler($id, $arFields) {
        self::updateFilterPrice($arFields['PRODUCT_ID']);
    }

    /**
     *        
     *
     * @param $id
     * @param $arFields
     */
    function OnPriceAddHandler($id, $arFields) {
        self::updateFilterPrice($arFields['PRODUCT_ID']);
    }

    /**
     *        
     *
     * @param $id
     * @param $arFields
     */
    function OnProductAddHandler($id, $arFields) {
        self::updateFilterPrice($id);
    }

    /**
     *        
     * OnProductUpdate    ((
     * @param $arFields
     */
    function OnProductUpdateHandler(&$arFields) {
        if ($arFields['IBLOCK_ID'] == 2) {
            self::updateFilterPrice($arFields['ID']);
        }
    }

/**
     *          
     * MIN_OFFER_PRICE, MAX_OFFER_PRICE     .
     *      BASE!      .
     *
     * @param $PRODUCT_ID id 
     */
    public static function updateFilterPrice($PRODUCT_ID) {
        $EL = new CIBlockElement();

        //    
        $arr = CIBlockPriceTools::GetOffersArray(
            array('IBLOCK_ID' => 2),
            array($PRODUCT_ID),
            array(),
            array(),
            array(),
            0,
            CIBlockPriceTools::GetCatalogPrices(2, array('BASE'))
        );

        if (is_array($arr) && count($arr) > 0) {
            $minPrice = null;
            $maxPrice = 0;

            //      ,     

            foreach ($arr as $offer) {
                $offerMinPrice = $offer['MIN_PRICE']['VALUE'];

                if (is_null($minPrice)) {
                    $minPrice = $offerMinPrice;
                } else {
                    if ($offerMinPrice < $minPrice) {
                        $minPrice = $offerMinPrice;
                    }
                }

                if ($offerMinPrice > $maxPrice) {
                    $maxPrice = $offerMinPrice;
                }
            }

            //   MIN_OFFER_PRICE, MAX_OFFER_PRICE
            $EL->SetPropertyValuesEx($PRODUCT_ID, 2,
                                     array('MIN_OFFER_PRICE'=>$minPrice,
                                           'MAX_OFFER_PRICE'=>$maxPrice,)
            );
        } else {
            //   
            $priceType = CIBlockPriceTools::GetCatalogPrices(2, array('BASE'));
            $cgroup = $priceType['BASE']['SELECT'];

            //       !
            $result = $EL->GetList(array(), array('IBLOCK_ID'=>2, 'ID'=>$PRODUCT_ID), false, false, array('*', $cgroup));
            $arrElm = $result->GetNextElement();

            if (is_object($arrElm)) {
                $fields = $arrElm->GetFields();

                //   
                $price = CIBlockPriceTools::GetItemPrices(2, $priceType, $fields);

                //   MIN_OFFER_PRICE, MAX_OFFER_PRICE
                $EL->SetPropertyValuesEx($PRODUCT_ID, 2,
                                         array('MIN_OFFER_PRICE'=>$price['BASE']['VALUE'],
                                               'MAX_OFFER_PRICE'=>$price['BASE']['VALUE'],)
                );
            }
        }
    }

(sale.order.full). , , EDOST , , . . . .

. , . , , , – , N . , 1C , . . , . , . , . , , . , , . : , , , . , , .

, , , , , , . - 30 , 31, . «» .

Source: https://habr.com/ru/post/247769/


All Articles