maksimerohin
12/29/2018 - 10:45 AM

for (key in priceSet)

Перебор элементов формы. Создаём набор элементов по идентификатору и перебираем.

// Перебор продуктов

	priceSet = $('.price');
	priceSet = Array.from(priceSet);

	orderDiscount = $('.order-discount').text(); // Общая скидка на заказ
	orderDiscount = orderDiscount / 100;
	// console.log('orderDiscount: ' + orderDiscount);

	for (key in priceSet) {
		// console.log( "Ключ: " + key + " значение: " + priceSet[key].innerText );
		
		price = priceSet[key].innerText;
		id = priceSet[key].dataset.id;
		dprice = priceSet[key].dataset.dprice;
		prodDiscount = priceSet[key].dataset.discount;
		if( prodDiscount == '' ) {
			prodDiscount = orderDiscount;
		} else {
			prodDiscount = Number(prodDiscount) / 100;
		}
		prodName = $('input#input-' + id).data('prodname');
		count = $('input#input-' + id).val();
		unit = $('span.unit-' + id).text();
		// console.log(price + ' ' + id + ' ' + count);
		
		orderSum = orderSum + price * count / unit; // Сумма заказ
		orderSumByDPrice = orderSumByDPrice + dprice * count / unit; // Сумма заказа по дилерским ценам
		orderDiscountSum = orderDiscountSum + ( price * count / unit ) * prodDiscount; // Сумма скидки
		order = order + prodName + ': ' + count + '\n'; // Состав заказа
		
	}