export const convertObjectValues = (obj, numToStr) => {
// Перебирает весь объект и производит конвертацию числа в строку и обратно.
// numToStr = true конвертирует числовые значения в строковые
// numToStr = false конвертирует строковые значения в числовые
if (numToStr !== true && numToStr !== false) return;
if (typeof obj === "object" && obj !== null) {
//Получен объект
if (Array.isArray(obj)) {
// Объект оказался массивом. Перебор массива
return obj.map(elem => convertObjectValues(elem, numToStr));
} else {
// Перебор объекта
const result = {};
for (const key in obj) {
result[key] = convertObjectValues(obj[key], numToStr)
}
return result;
}
} else {
// Получено простое значение (не объект и не массив)
return isNaN(obj) ? obj : numToStr ? obj + '' : +obj;
}
};
import chai from "chai";
import {convertObjectValues} from "./convertData";
const numbers = {
"id": 7302,
"enabled": 1,
"capacity": 4,
"manualEdited": 1,
"cutoffs": [
1235.25,
{
"id": 3468,
"cutoffType": {
"id": 1,
"name": "Cutoff общий",
"code": "MNFGNRL"
},
"value": "12:00"
},
{
"id": 3467,
"cutoffType": {
"id": 4,
"name": "Cutoff груза",
"code": "CRGRGST"
},
"value": "14:00"
}
]
};
const strings = {
"id": "7302",
"enabled": "1",
"capacity": "4",
"manualEdited": "1",
"cutoffs": [
"1235.25",
{
"id": "3468",
"cutoffType": {
"id": "1",
"name": "Cutoff общий",
"code": "MNFGNRL"
},
"value": "12:00"
},
{
"id": "3467",
"cutoffType": {
"id": "4",
"name": "Cutoff груза",
"code": "CRGRGST"
},
"value": "14:00"
}
]
};
describe("Тестирование глобальных функций конвертации данных", () => {
it("Преобразование числа в строку", () => {
const result = convertObjectValues(numbers, true);
// console.log(JSON.stringify(numbers));
// console.log(JSON.stringify(result));
chai.expect(result).to.deep.include(strings);
});
it("Преобразование строки число", () => {
const result = convertObjectValues(strings, false);
// console.log(JSON.stringify(strings));
// console.log(JSON.stringify(result));
chai.expect(result).to.deep.include(numbers);
});
});
SELECT SQL_NO_CACHE p.product_id
FROM oc_product p
WHERE p.status = '1' AND ( p.model = 'ao' OR p.sku = 'ao' )
SELECT SQL_NO_CACHE p.product_id
FROM oc_product p LEFT JOIN oc_product p2 ON (p.product_id=p2.product_id)
WHERE p.status = '1' AND ( p2.model = 'ao' OR p2.sku = 'ao' )
SELECT SQL_NO_CACHE p.product_id
FROM oc_product p LEFT JOIN oc_product p2 ON (p.product_id=p2.product_id)
WHERE p.status = '1' AND ( LCASE(p2.model) = 'ao' OR LCASE(p2.sku) = 'ao' )
SELECT SQL_NO_CACHE SQL_CALC_FOUND_ROWS p3.product_id, NULL AS rating, NULL AS discount, NULL AS special
FROM
(SELECT p.product_id
FROM oc_product p
LEFT JOIN oc_product p2 ON (p.product_id=p2.product_id)
WHERE p.status = '1' AND ( p2.model = 'ao' OR p2.sku = 'ao' )
UNION
SELECT p.product_id
FROM oc_product p
LEFT JOIN oc_product_description pd ON (p.product_id = pd.product_id)
WHERE p.status = '1' AND ( pd.name LIKE '%ao%' OR pd.tag LIKE '%ao%') ) as t1
LEFT JOIN oc_product p3 ON (t1.product_id=p3.product_id)
LEFT JOIN oc_product_description pd ON (p3.product_id = pd.product_id)
GROUP BY p3.product_id
ORDER BY (p3.price=0 OR p3.price >= 7000000), p3.price DESC, LCASE(pd.name) DESC
LIMIT 0,20
<?php
include('../config.php'); //подключаем файл конфигурации cms. оттуда берем настройки БД
$maxquerytime = 200;//максимальное время запроса в секундах
$db = DB_DATABASE;//THE NAME OF YOUR MYSQL DATABASE
$user = DB_USERNAME;//YOUR USERNAME TO ACCESS MYSQL
$pass = DB_PASSWORD;//YOUR PASSWORD TO ACCESS MYSQL
$host = DB_HOSTNAME;//THE ADDRESS OF YOUR MYSQL SERVER
$link = mysql_connect($host, $user, $pass);// Connect to the database
if ($link) echo '<b>OK.</b> - Soedinenie ustanovleno.';
else die('<b>Error</b>');
mysql_select_db($db);
mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");
mysql_query("SET SESSION collation_connection = 'utf8_general_ci'");
$result = mysql_query("SHOW FULL PROCESSLIST");
while ($row=mysql_fetch_array($result)) {
$process_id=$row["Id"];
if ($row["Time"] > $maxquerytime ) {
$sql="KILL $process_id";
echo "<br>Убит процесс ".$row["Info"]." - ".$sql;
mysql_query($sql);
}
}
?>
То есть количество товара определенного цвета и количество товара без цвета
SELECT SQL_NO_CACHE attribute_id, text FROM (
SELECT DISTINCT p.product_id, p2a.attribute_id, p2a.text, p.price as realprice
FROM oc_product p
LEFT JOIN oc_manufacturer m ON(m.manufacturer_id=p.manufacturer_id)
LEFT JOIN oc_product_option_value pov ON (pov.product_id=p.product_id)
LEFT JOIN oc_product_to_store p2s ON (p2s.product_id=p.product_id)
LEFT JOIN oc_product_to_category p2c ON (p2c.product_id=p.product_id)
LEFT JOIN oc_category_path cp ON(cp.category_id=p2c.category_id)
LEFT JOIN oc_product_attribute p2a ON (p2a.product_id=p.product_id)
WHERE p2a.attribute_id IS NOT NULL AND EXISTS
(select 1 FROM oc_product_attribute p2a0
WHERE p2a0.product_id=p2a.product_id AND p2a0.attribute_id = 20
AND (p2a0.text = '2х36 Вт' OR p2a0.text like '2х36 Вт:%' OR p2a0.text like '%:2х36 Вт' OR p2a0.text like '%:2х36 Вт:%'))
AND EXISTS (select 1 FROM oc_product_attribute p2a1 WHERE p2a1.product_id=p2a.product_id AND p2a1.attribute_id = 22
AND (p2a1.text = 'накладные' OR p2a1.text like 'накладные:%' OR p2a1.text like '%:накладные' OR p2a1.text like '%:накладные:%'))
AND EXISTS (select 1 FROM oc_product_attribute p2a2 WHERE p2a2.product_id=p2a.product_id AND p2a2.attribute_id = 27
AND (p2a2.text = '120 см' OR p2a2.text like '120 см:%' OR p2a2.text like '%:120 см' OR p2a2.text like '%:120 см:%'))
AND p.status = '1' AND p2s.store_id = 0) as innertable WHERE 1 GROUP BY attribute_id, text
SELECT SQL_NO_CACHE attribute_id, text FROM (
SELECT DISTINCT p.product_id, p2a.attribute_id, p2a.text, p.price as realprice
FROM oc_product p
LEFT JOIN oc_manufacturer m ON(m.manufacturer_id=p.manufacturer_id)
LEFT JOIN oc_product_option_value pov ON (pov.product_id=p.product_id)
LEFT JOIN oc_product_to_store p2s ON (p2s.product_id=p.product_id)
LEFT JOIN oc_product_to_category p2c ON (p2c.product_id=p.product_id)
LEFT JOIN oc_category_path cp ON(cp.category_id=p2c.category_id)
LEFT JOIN oc_product_attribute_id p2a ON (p2a.product_id=p.product_id)
INNER JOIN oc_product_attribute_id p2a0 ON (p2a0.product_id=p.product_id)
INNER JOIN oc_product_attribute_id p2a1 ON (p2a1.product_id=p.product_id)
INNER JOIN oc_product_attribute_id p2a2 ON (p2a2.product_id=p.product_id)
WHERE (p2a0.attribute_id = 20 AND p2a0.text like '%2х36 Вт%')
AND (p2a1.attribute_id = 22 AND p2a1.text like '%накладные%')
AND (p2a2.attribute_id = 27 AND p2a2.text like '%120 см%')
) as innertable WHERE 1 GROUP BY attribute_id, text
SELECT SQL_NO_CACHE attribute_id, text FROM (
SELECT DISTINCT p.product_id, p2a.attribute_id, p2a.text, p.price as realprice
FROM oc_product p
LEFT JOIN oc_manufacturer m ON(m.manufacturer_id=p.manufacturer_id)
LEFT JOIN oc_product_option_value pov ON (pov.product_id=p.product_id)
LEFT JOIN oc_product_to_store p2s ON (p2s.product_id=p.product_id)
LEFT JOIN oc_product_to_category p2c ON (p2c.product_id=p.product_id)
LEFT JOIN oc_category_path cp ON(cp.category_id=p2c.category_id)
INNER JOIN oc_product_attribute_id p2a0 ON (p2a0.product_id=p.product_id)
INNER JOIN oc_product_attribute_id p2a1 ON (p2a1.product_id=p.product_id)
INNER JOIN oc_product_attribute_id p2a2 ON (p2a2.product_id=p.product_id)
LEFT JOIN oc_product_attribute_id p2a ON (p2a.product_id=p.product_id)
WHERE (p2a0.text_id = '67')
AND (p2a1.text_id = '82')
AND (p2a2.text_id = '88')
) as innertable WHERE 1 GROUP BY attribute_id, text