first commit
This commit is contained in:
49
cron-news.php
Normal file
49
cron-news.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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 = 572;
|
||||
|
||||
// Dzisiejsza data
|
||||
$today = new DateTime();
|
||||
|
||||
// Pobierz wszystkie produkty
|
||||
$products = Product::getProducts(Context::getContext()->language->id, 0, 0, 'id_product', 'ASC');
|
||||
// Iteruj po produktach
|
||||
foreach ($products as $product) {
|
||||
$productId = $product['id_product'];
|
||||
// Formatowanie daty produktu
|
||||
$date = new DateTime($product['date_add']);
|
||||
$interval = $today->diff($date);
|
||||
// Różnica między datami
|
||||
$daysPassed = $interval->format('%a');
|
||||
|
||||
if($daysPassed <= '30') {
|
||||
// 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"
|
||||
);
|
||||
|
||||
|
||||
if ($isProductInCategory == 0) {
|
||||
// Produkt jest dodany mniej jak 30 dni, dodaj go do kategorii "NOWOŚCI"
|
||||
Db::getInstance()->execute(
|
||||
"INSERT INTO " . _DB_PREFIX_ . "category_product (id_category, id_product)
|
||||
VALUES ($categoryId, $productId)"
|
||||
);
|
||||
}
|
||||
|
||||
} else {
|
||||
// Produkt jest dodany powyżej jak 30 dni, usuń go z kategorii "NOWOŚCI"
|
||||
Db::getInstance()->execute(
|
||||
"DELETE FROM " . _DB_PREFIX_ . "category_product
|
||||
WHERE id_category = $categoryId
|
||||
AND id_product = $productId"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user