first commit
This commit is contained in:
45
cron-promotion.php
Normal file
45
cron-promotion.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?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 = 571;
|
||||
$i = 0;
|
||||
|
||||
// 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'];
|
||||
|
||||
// Sprawdź, czy produkt jest na promocji
|
||||
$regularPrice_with_module = Product::getPriceStatic($productId, false, null, 6, null, false, true, 1, false, null, 0, 0 );
|
||||
$regularPrice_without_module = Db::getInstance()->getValue('SELECT `price` FROM `' . _DB_PREFIX_ . 'product` WHERE `id_product` = ' . (int)$productId);
|
||||
|
||||
$specificPrice = SpecificPrice::getSpecificPrice($productId, Context::getContext()->shop->id, null, null, null, null, null);
|
||||
if (!empty($specificPrice) or ( $regularPrice_with_module < $regularPrice_without_module ) )
|
||||
{
|
||||
// Produkt jest na promocji, 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) {
|
||||
Db::getInstance()->execute(
|
||||
"INSERT INTO " . _DB_PREFIX_ . "category_product (id_category, id_product)
|
||||
VALUES ($categoryId, $productId)"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Produkt nie jest na promocji, usuń go z kategorii
|
||||
Db::getInstance()->execute(
|
||||
"DELETE FROM " . _DB_PREFIX_ . "category_product
|
||||
WHERE id_category = $categoryId
|
||||
AND id_product = $productId"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user