PHP code example of lupasearch / prestashop-lupasearch-plugin
1. Go to this page and download the library: Download lupasearch/prestashop-lupasearch-plugin library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lupasearch / prestashop-lupasearch-plugin example snippets
public function install()
{
return parent::install() &&
$this->registerHook('actionLupaSearchAddProductAttributes') &&
$this->registerHook('actionLupaSearchAddVariantAttributes');
}
public function hookActionLupaSearchAddProductAttributes($params)
{
$productIds = $params['product_ids'] ?? [];
$shopId = $params['shop_id'] ?? null;
$langId = $params['language_id'] ?? null;
$data = [];
foreach ($productIds as $id) {
$data[$id] = [
'custom_label' => 'Extra info for product ' . $id,
'rating' => rand(1, 5),
];
}
return $data;
}
public function hookActionLupaSearchAddVariantAttributes($params)
{
$productIds = $params['product_ids'] ?? [];
$combinationIds = $params['combination_ids'] ?? [];
$shopId = $params['shop_id'] ?? null;
$langId = $params['language_id'] ?? null;
$data = [
'products' => [],
'combinations' => [],
];
// Add custom attributes for simple product variants
foreach ($productIds as $id) {
$data['products'][$id] = [
'variant_type' => 'simple',
'sku_group' => 'product_' . $id,
];
}
// Add custom attributes for combination-based variants
foreach ($combinationIds as $id) {
$data['combinations'][$id] = [
'variant_type' => 'combination',
'color_label' => 'Color for combo #' . $id,
'limited_edition' => (bool) rand(0, 1),
];
}
return $data;
}