first commit
This commit is contained in:
65
cron-bestsellery.php
Normal file
65
cron-bestsellery.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
require_once(dirname(__FILE__) . '/config/config.inc.php');
|
||||
require_once(dirname(__FILE__) . '/init.php');
|
||||
require_once(_PS_ROOT_DIR_ . '/classes/SpecificPrice.php');
|
||||
|
||||
|
||||
// ID kategorii, do której chcesz dodać lub z której chcesz usunąć produkty
|
||||
$categoryId = 573;
|
||||
|
||||
// Dzisiejsza data
|
||||
$today = new DateTime();
|
||||
|
||||
// Pobierz wszystkie produkty
|
||||
$allProducts = Product::getProducts(Context::getContext()->language->id, 0, 0, 'id_product', 'ASC');
|
||||
|
||||
$query = "
|
||||
SELECT `product_id`, COUNT(*) as `count`
|
||||
FROM `ps_order_detail`
|
||||
GROUP BY `product_id`
|
||||
ORDER BY `count` DESC, `product_id` ASC
|
||||
LIMIT 72
|
||||
";
|
||||
$products = Db::getInstance()->executeS($query);
|
||||
$productIds = array();
|
||||
|
||||
foreach ($products as $product) {
|
||||
$productIds[] = $product['product_id'];
|
||||
}
|
||||
|
||||
|
||||
// Iteruj po produktach
|
||||
foreach ($allProducts as $product) {
|
||||
// $productId = $product['product_id'];
|
||||
$productId = $product['id_product'];
|
||||
|
||||
// Produkt jest w kategorii "NOWOŚCI", dodaj go do kategorii
|
||||
$isProductInCategory = Db::getInstance()->getValue(
|
||||
"SELECT COUNT(*)
|
||||
FROM " . _DB_PREFIX_ . "category_product
|
||||
WHERE id_category = $categoryId
|
||||
AND id_product = $productId"
|
||||
);
|
||||
|
||||
// Sprawdzamy czy produkt jest w nowej liście "BESTSELLERS"
|
||||
if (in_array($productId, $productIds)) {
|
||||
// Sprawdzamy czy on ma już przepisaną kategorie BESTSELLERS"
|
||||
if ($isProductInCategory == 0) {
|
||||
Db::getInstance()->execute(
|
||||
"INSERT INTO " . _DB_PREFIX_ . "category_product (id_category, id_product)
|
||||
VALUES ($categoryId, $productId)"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
Db::getInstance()->execute(
|
||||
"DELETE FROM " . _DB_PREFIX_ . "category_product
|
||||
WHERE id_category = $categoryId
|
||||
AND id_product = $productId"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// echo "<pre>";
|
||||
// print_r($productId);
|
||||
// echo "</>";
|
||||
}
|
||||
Reference in New Issue
Block a user