Удобный онлайн генератор паролей

Добавить во вкладку с товарами свою формулу расчета нужной величины



Задача:
сумма чека по еде для одного гостя

На языке программиста:
Добавить во вкладку с товарами расчет:
сумма товаров со значением свойства PROPERTY_626 318,320, 322 (относятся к еде) / сумму количества гостей (UF_CRM_1530623573843+UF_CRM_1530623600935)

Чуть позже стали ЭТО дополнительно хранить в поле сделки

файл /local/assets/entities-expansion/js/deal.js
BX.addCustomEvent( 'onAjaxSuccess' ,   function  (params, event) {
    if(event){
        if(event.url == '/bitrix/services/main/ajax.php?action=catalog.productSelector.getProduct'){
            if(Object.values(params.data.fields.PROPERTIES[0].PROPERTY_VALUES)[0].VALUE == 318){
                checkEntities();
            }
        }else if(event.url == '/bitrix/services/main/ajax.php?mode=class&c=bitrix%3Acrm.entity.product.list&action=calculateTotalData' || event.url == '/bitrix/tools/uf.php'){
            checkEntities();
        }
    }
});

function checkEntities(){
    var sum = 0;
    let dealId = window.location.pathname.split('/')[4];
    $('.crm-product-list-payment-menu-category-awg-sum').remove();
    BX.rest.callMethod(
        "crm.deal.productrows.get", 
        { id: dealId }, 
        function(res1) 
        {
            if(res1.error())
                console.error(res1.error());
            else{                  
                let products = res1.data();
                let j = 0;
                for (var i = 0; i < products.length; i++) {
                    let product = products[i];                    
                    setTimeout(function(){
                        BX.rest.callMethod('crm.product.get', {id: product.PRODUCT_ID}, function(res){                         
                            if(res.error())
                                    console.error(res.error()); 
                            else{                                            
                                product1 = res.data();                            
                                if(product1.PROPERTY_626.value == '318' || product1.PROPERTY_626.value == '322' || product1.PROPERTY_626.value == '320'){                                   
                                   sum = sum + product.PRICE*product.QUANTITY;
                                }                                
                                if(j == (products.length - 1)){                                    
                                    if(sum > 0){
                                        BX.rest.callMethod('crm.deal.get', {id: dealId}, function(res){
                                            let goustsCount = Number(res.answer.result['UF_CRM_1530623573843'])+Number(res.answer.result['UF_CRM_1530623600935']);
                                            if(parseInt(goustsCount)<1){
                                                goustsCount = 1;
                                            }
                                            sum = parseInt(sum/goustsCount);                                            
                                            $('.crm-product-list-payment-menu-category-awg-sum').remove();
                                            $('.crm-product-list-payment-side-table tbody').prepend('<tr class="crm-product-list-payment-side-table-row crm-product-list-payment-menu-category-awg-sum" style="display: table-row;"><td>Сумма товаров категории "Меню" / кол-во гостей:</td><td><span style="margin-right: 4px;" class="priceMenuAwg" data-total="totalMenu">'+sum+'</span><span data-role="currency-wrapper" class="crm-product-list-result-grid-item-currency-symbol">руб.</span> </td></tr>');
                                            if(sum<850)
                                                $('.priceMenuAwg').attr('style', 'margin-right: 4px;color: #e04343;');
                                            else
                                                $('.priceMenuAwg').attr('style', 'margin-right: 4px;');
                                            
                                        });
                                    }
                                }
                            }  
                            j++;  
                        });    
                    },i*200);                    
                }                
            }
        }
    );
}
Если блог был полезным, можете угостить меня "чашечкой кофе" :)

Сбер по номеру телефона +7 (953) 585-13-09 Вероника.
Спасибо!