first commit
This commit is contained in:
93
controllers/front/generate.php
Normal file
93
controllers/front/generate.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* Product Link Checker Generate Controller
|
||||
*/
|
||||
|
||||
class ProductLinkCheckerGenerateModuleFrontController extends ModuleFrontController
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
// Security check: Validate the token
|
||||
$token = Tools::getValue('token');
|
||||
$storedToken = Configuration::get('PLC_SECURITY_TOKEN');
|
||||
|
||||
if (!$token || $token !== $storedToken) {
|
||||
header('HTTP/1.1 403 Forbidden');
|
||||
exit('Invalid security token.');
|
||||
}
|
||||
}
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
parent::initContent();
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$id_shop_filter = (int)Tools::getValue('id_shop');
|
||||
$id_lang_filter = (int)Tools::getValue('id_lang');
|
||||
|
||||
// Determine which shops to scan
|
||||
if ($id_shop_filter) {
|
||||
$shop_ids = [$id_shop_filter];
|
||||
} else {
|
||||
$shop_ids = Shop::getShops(true, null, true);
|
||||
}
|
||||
|
||||
// Determine which languages to scan
|
||||
if ($id_lang_filter) {
|
||||
$lang_ids = [$id_lang_filter];
|
||||
} else {
|
||||
$lang_ids = Language::getLanguages(true, false, true);
|
||||
}
|
||||
|
||||
$all_links = [];
|
||||
|
||||
foreach ($shop_ids as $id_shop) {
|
||||
foreach ($lang_ids as $id_lang) {
|
||||
// Get all active products for the current shop and language
|
||||
$products = Product::getProducts($id_lang, 0, 0, 'id_product', 'ASC', false, true);
|
||||
|
||||
foreach ($products as $product_data) {
|
||||
$product = new Product($product_data['id_product'], false, $id_lang, $id_shop);
|
||||
|
||||
// Skip invalid products
|
||||
if (!Validate::isLoadedObject($product)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get base product link
|
||||
$base_link = $this->context->link->getProductLink($product, null, null, null, $id_lang, $id_shop);
|
||||
$all_links[] = $base_link;
|
||||
|
||||
// Get links for combinations if they exist
|
||||
if ($product->hasAttributes()) {
|
||||
$combinations = $product->getAttributesResume($id_lang);
|
||||
if ($combinations) {
|
||||
foreach ($combinations as $combination) {
|
||||
$combo_link = $this->context->link->getProductLink(
|
||||
$product,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$id_lang,
|
||||
$id_shop,
|
||||
$combination['id_product_attribute'],
|
||||
false,
|
||||
false,
|
||||
true // Add attribute anchor
|
||||
);
|
||||
$all_links[] = $combo_link;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove duplicates that might occur in complex shop setups and output JSON
|
||||
echo json_encode(array_values(array_unique($all_links)), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user