From ae31cb0bb5405ccef1cd8dc8a87070265e73589d Mon Sep 17 00:00:00 2001 From: O K Date: Thu, 25 Sep 2025 18:34:37 +0300 Subject: [PATCH] added ProductLinkCheckerProductDataGenerateModuleFrontController --- controllers/front/productdatagenerate.php | 120 ++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 controllers/front/productdatagenerate.php diff --git a/controllers/front/productdatagenerate.php b/controllers/front/productdatagenerate.php new file mode 100644 index 0000000..63c8cab --- /dev/null +++ b/controllers/front/productdatagenerate.php @@ -0,0 +1,120 @@ + (int)$product->id, + 'id_product_attribute' => 0, // 0 for the main product + 'meta_title' => $product->meta_title, + // Grouping meta fields for clarity + 'meta_description' => $product->meta_description, + 'title' => $product->name, + 'description' => $product->description, + 'description_short' => $product->description_short, + 'mpn' => $product->mpn, + 'reference' => $product->reference, + 'ean13' => $product->ean13, + 'upc' => $product->upc, + 'id_language' => (int)$id_lang, + 'id_shop' => (int)$id_shop, + 'link' => $this->context->link->getProductLink($product), + 'link_rewrite' => $product->link_rewrite, + ]; + + // 2. Add data for all attribute combinations + if ($product->hasAttributes()) { + // getAttributeCombinations provides detailed data for each combination + $combinations = $product->getAttributeCombinations($id_lang); + if ($combinations) { + foreach ($combinations as $combination) { + $all_product_data[] = [ + 'id_product' => (int)$product->id, + 'id_product_attribute' => (int)$combination['id_product_attribute'], + 'meta_title' => $product->meta_title, // Meta is usually product-level + 'meta_description' => $product->meta_description, + // Title and descriptions are also from the main product + 'title' => $product->name, + 'description' => $product->description, + 'description_short' => $product->description_short, + // These fields are specific to the combination + 'mpn' => $combination['mpn'], + 'reference' => $combination['reference'], + 'ean13' => $combination['ean13'], + 'upc' => $combination['upc'], + 'id_language' => (int)$id_lang, + 'id_shop' => (int)$id_shop, + 'link' => $this->context->link->getProductLink($product, null, null, null, (int)$id_lang, (int)$id_shop, (int)$combination['id_product_attribute']), + 'link_rewrite' => $product->link_rewrite, + ]; + } + } + } + } + } + } + + // Output the final array as a JSON object + echo json_encode($all_product_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); + exit; + } +}