fix IDs logic.

This commit is contained in:
O K
2025-09-23 10:55:57 +03:00
parent 60ba511804
commit b4c3108c22
3 changed files with 129 additions and 8 deletions

120
README.md Normal file
View File

@@ -0,0 +1,120 @@
Of course! A good `README.md` is essential for any project. Here is a comprehensive README file tailored for your `productlinkchecker` module, crediting you as the developer.
Just copy and paste the content below into a new file named `README.md` in the root of your `productlinkchecker` module directory.
---
# PrestaShop Product Link Checker Module
> A PrestaShop module developed by **panariga**.
![PS Version](https://img.shields.io/badge/PrestaShop-1.7.6%2B-blue.svg)
![License](https://img.shields.io/badge/License-AFL_3.0-orange.svg)
![Author](https://img.shields.io/badge/Author-panariga-green.svg)
A simple, secure, and powerful PrestaShop module designed to generate a comprehensive JSON list of all product URLs. It's the perfect tool for developers and QA testers who need to perform automated checks, SEO audits, or verify that all product pages are accessible and return a `200 OK` status.
## Features
- **JSON Output**: Generates a clean, machine-readable JSON array of product links.
- **Includes Combinations**: Lists URLs for both base products and all their attribute combinations.
- **Multi-Shop Support**: Works seamlessly in a multi-store environment.
- **Multi-Language Support**: Generates links for all installed languages.
- **Secure Access**: The endpoint is protected by a unique, auto-generated security token to prevent unauthorized access.
- **Filtering**: Easily filter the results by a specific shop (`plc_id_shop`) or language (`plc_id_lang`).
- **User-Friendly Configuration**: The module configuration page displays the security token and provides a list of ready-to-use links for quick access.
## Compatibility
- **PrestaShop Version**: 1.7.6 or newer.
## Installation
You can install the module using one of two methods:
#### Method 1: Using the PrestaShop Module Manager (Recommended)
1. Download the latest release as a `.zip` file from the repository.
2. Log in to your PrestaShop Back Office.
3. Navigate to **Modules > Module Manager**.
4. Click the **"Upload a module"** button.
5. Drag and drop the downloaded `.zip` file into the upload area.
6. The module will be installed automatically. Find "Product Link Checker" in your module list and click **Install**.
#### Method 2: Manual Installation
1. Download and unzip the latest release.
2. Rename the folder to `productlinkchecker`.
3. Upload the `productlinkchecker` folder to the `modules/` directory of your PrestaShop installation.
4. In your PrestaShop Back Office, navigate to **Modules > Module Manager**.
5. Find "Product Link Checker" in your module list and click **Install**.
## Configuration
After installing the module, click the **"Configure"** button.
The configuration page provides two key pieces of information:
1. **Your Security Token**: A unique 32-character string that must be included in every request to the generator endpoint.
2. **Available URLs**: A list of pre-built URLs for all shops and languages, making it easy to copy the link you need for your tests.
*(Optional: Replace this with a link to a screenshot of your module's configuration page)*
## Usage: The `generate` Endpoint
The module exposes a single front controller endpoint to generate the links.
**Base URL:** `https://your-prestashop-url/module/productlinkchecker/generate`
### Parameters
- `token` (string, **required**): Your unique security token found on the module's configuration page.
- `plc_id_shop` (integer, *optional*): The ID of a specific shop. If omitted, the module will scan all active shops.
- `plc_id_lang` (integer, *optional*): The ID of a specific language. If omitted, the module will scan all active languages for the selected shop(s).
### Examples
#### 1. Get all links for all shops and all languages
```
https://your-prestashop-url/module/productlinkchecker/generate?token=YOUR_SECRET_TOKEN
```
#### 2. Get all links for a specific shop (e.g., Shop ID 1)
```
https://your-prestashop-url/module/productlinkchecker/generate?token=YOUR_SECRET_TOKEN&plc_id_shop=1
```
#### 3. Get all links for a specific shop (ID 1) and a specific language (e.g., English, ID 2)
```
https://your-prestashop-url/module/productlinkchecker/generate?token=YOUR_SECRET_TOKEN&plc_id_shop=1&plc_id_lang=2
```
### Example Output
The endpoint will return a JSON array of strings, where each string is a complete, friendly URL.
```json
[
"https://your-prestashop-url/en/men/1-hummingbird-printed-t-shirt.html",
"https://your-prestashop-url/en/men/1-1-hummingbird-printed-t-shirt.html#/1-size-s/8-color-white",
"https://your-prestashop-url/en/men/1-2-hummingbird-printed-t-shirt.html#/2-size-m/11-color-black",
"https://your-prestashop-url/fr/hommes/1-tee-shirt-imprime-colibri.html",
"https://your-prestashop-url/fr/hommes/1-1-tee-shirt-imprime-colibri.html#/1-taille-s/8-couleur-blanc",
"https://your-prestashop-url/fr/hommes/1-2-tee-shirt-imprime-colibri.html#/2-taille-m/11-couleur-noir",
...
]
```
## ⚠️ Security
The security token is the only thing preventing public access to this endpoint. **Keep it secret.** If you believe your token has been compromised, you can uninstall and reinstall the module to generate a new one.
## License
This module is released under the [Academic Free License (AFL 3.0)](http://opensource.org/licenses/afl-3.0.php).
## Author
Developed by **panariga**.
* [GitHub Profile](https://github.com/panariga)
* [Gitea Profile](https://git.panariga.com/PrestashopModules/productlinkchecker)

View File

@@ -1,4 +1,5 @@
<?php <?php
/** /**
* Product Link Checker Generate Controller * Product Link Checker Generate Controller
*/ */
@@ -25,8 +26,8 @@ class ProductLinkCheckerGenerateModuleFrontController extends ModuleFrontControl
header('Content-Type: application/json'); header('Content-Type: application/json');
$id_shop_filter = (int)Tools::getValue('id_shop'); $id_shop_filter = (int)Tools::getValue('plc_id_shop');
$id_lang_filter = (int)Tools::getValue('id_lang'); $id_lang_filter = (int)Tools::getValue('plc_id_lang');
// Determine which shops to scan // Determine which shops to scan
if ($id_shop_filter) { if ($id_shop_filter) {
@@ -60,7 +61,7 @@ class ProductLinkCheckerGenerateModuleFrontController extends ModuleFrontControl
// Get base product link // Get base product link
$base_link = $this->context->link->getProductLink($product, null, null, null, $id_lang, $id_shop); $base_link = $this->context->link->getProductLink($product, null, null, null, $id_lang, $id_shop);
$all_links[] = $base_link; $all_links[] = $base_link;
// Get links for combinations if they exist // Get links for combinations if they exist
if ($product->hasAttributes()) { if ($product->hasAttributes()) {
$combinations = $product->getAttributesResume($id_lang); $combinations = $product->getAttributesResume($id_lang);
@@ -90,4 +91,4 @@ class ProductLinkCheckerGenerateModuleFrontController extends ModuleFrontControl
echo json_encode(array_values(array_unique($all_links)), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); echo json_encode(array_values(array_unique($all_links)), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
exit; exit;
} }
} }

View File

@@ -21,14 +21,14 @@
</a> </a>
{foreach from=$shops item=shop} {foreach from=$shops item=shop}
<a href="{$base_controller_url}?token={$security_token|escape:'html':'UTF-8'}&id_shop={$shop.id_shop|intval}" target="_blank" class="list-group-item"> <a href="{$base_controller_url}?token={$security_token|escape:'html':'UTF-8'}&plc_id_shop={$shop.id_shop|intval}" target="_blank" class="list-group-item">
<strong>{l s='Shop:' mod='productlinkchecker'} {$shop.name|escape:'html':'UTF-8'} ({l s='All Languages' mod='productlinkchecker'})</strong><br> <strong>{l s='Shop:' mod='productlinkchecker'} {$shop.name|escape:'html':'UTF-8'} ({l s='All Languages' mod='productlinkchecker'})</strong><br>
<code>{$base_controller_url}?token={$security_token|escape:'html':'UTF-8'}&id_shop={$shop.id_shop|intval}</code> <code>{$base_controller_url}?token={$security_token|escape:'html':'UTF-8'}&plc_id_shop={$shop.id_shop|intval}</code>
</a> </a>
{foreach from=$languages item=lang} {foreach from=$languages item=lang}
<a href="{$base_controller_url}?token={$security_token|escape:'html':'UTF-8'}&id_shop={$shop.id_shop|intval}&id_lang={$lang.id_lang|intval}" target="_blank" class="list-group-item"> <a href="{$base_controller_url}?token={$security_token|escape:'html':'UTF-8'}&plc_id_shop={$shop.id_shop|intval}&plc_id_lang={$lang.id_lang|intval}" target="_blank" class="list-group-item">
<strong>{l s='Shop:' mod='productlinkchecker'} {$shop.name|escape:'html':'UTF-8'} | {l s='Language:' mod='productlinkchecker'} {$lang.name|escape:'html':'UTF-8'}</strong><br> <strong>{l s='Shop:' mod='productlinkchecker'} {$shop.name|escape:'html':'UTF-8'} | {l s='Language:' mod='productlinkchecker'} {$lang.name|escape:'html':'UTF-8'}</strong><br>
<code>{$base_controller_url}?token={$security_token|escape:'html':'UTF-8'}&id_shop={$shop.id_shop|intval}&id_lang={$lang.id_lang|intval}</code> <code>{$base_controller_url}?token={$security_token|escape:'html':'UTF-8'}&plc_id_shop={$shop.id_shop|intval}&plc_id_lang={$lang.id_lang|intval}</code>
</a> </a>
{/foreach} {/foreach}
{/foreach} {/foreach}