function mergerMenu(menu) {
let depthPath = {};
depthPath.quantity = 0;
depthPath.products = [];
try {
for (let i = 0; i < menu.subCategoryLocal.length; i++) {
let item = menu.subCategoryLocal[i];
if (item.name == 'Коврики для ванной' || item.name == 'Шторы для ванной' || item.name == 'Полотенца') {
depthPath.name = 'Текстиль для ванной';
depthPath.pathCategory = '/departments/bathroom/bathroom_textiles_depth';
item.products = item.products.map(clientPath);
item.pathCategory = clientPath(item.pathCategory);
depthPath.products.push(item);
depthPath.quantity = (depthPath.quantity + item.quantity);
menu.subCategoryLocal.splice(i, 1);
i--;
}
}
}
catch (err) {
if (err) {
console.log(err, 1107);
}
}
menu.subCategoryLocal.forEach(item => {
item.pathCategory = clientPath(item.pathCategory);
item.products = item.products.map(clientPath);
item.products.sort(sortString);
});
menu.subCategoryLocal.sort(sortString);
menu.subCategoryLocal.push(depthPath);
return menu;
function clientPath(item) {
let path;
let link = '';
if (typeof item == 'object') path = item.path;
else path = item;
path = path.split('/');
path.splice(0, 1);
path.forEach(item => {
if (item == 'simsCategory') item = 'departments';
if (item != 'Users' &&
item != 'che' &&
item != 'Desktop' &&
item != 'WEB' &&
item != 'node-js' &&
item != 'categories') {
link += '/' + item;
}
});
if (typeof item == 'object') {
item.path = link;
return item;
}
else {
return link;
}
}
function sortString(a, b) {
if (a.name > b.name) return 1;
if (a.name < b.name) return -1;
}
}
var msg = {},
str;
msg.name = name.value;
msg.mail = mail.value;
msg.phone = phone.value;
msg.select = select;
msg.comment = comment;
str = JSON.stringify(msg);
//msg = serialize(document.querySelector('form'));
var xhr = new XMLHttpRequest();
// 2. Конфигурируем его: POST-запрос на URL 'mail.php'
xhr.open('POST', 'mail.php', true);
xhr.addEventListener('load', function() {
if (xhr.status != 200) {
// обработать ошибку
alert( xhr.status + ': ' + xhr.statusText ); // пример вывода: 404: Not Found
} else {
document.querySelector('.form__content').style.display = 'none';
document.querySelector('.form-successful').style.display = 'block';
}
});
xhr.send(str);
console.log(str);
$obj = json_decode($_POST, true);
$to = "9111721308@mail.ru";
$subject = "Заявка";
$from = "info@giraffe-ra.ru";
$headers = "From: $from";
mail($to,$subject,$obj,$headers);
echo "Mail Sent.";