Hooks are entry points into the Isotope core (and some of its extension bundles). Have a look at the hook list of all available hooks. You can register your own callable logic that will be executed as soon as a certain point in the execution flow of the core will be reached.
There are two ways of registering hook listeners for isotope.
This feature is only available in Isotope eCommerce 2.8 and later.
The recommended way of registering hooks is to use service annotations:
// src/EventListener/Isotope/AddProductToCollectionListener.php
namespace App\EventListener\Isotope;
use Isotope\Interfaces\IsotopeProduct
use Isotope\Interfaces\IsotopeProductCollection;
use Isotope\ServiceAnnotation\IsotopeHook;
class AddProductToCollectionListener
{
/**
* @IsotopeHook("addProductToCollection")
*/
public function __invoke(IsotopeProduct $product, $quantity, IsotopeProductCollection $collection, array $config): int
{
// Your logic here
return $quantity;
}
}
The legacy way of registering hooks is to register them in the global array in your config.php
files:
// config/config.php
use App\EventListener\Isotope\AddProductToCollectionListener;
$GLOBALS['ISO_HOOKS']['addProductToCollection'][] = [AddProductToCollectionListener::class, '__invoke'];
// src/EventListener/Isotope/AddProductToCollectionListener.php
namespace App\EventListener\Isotope;
use Isotope\Interfaces\IsotopeProduct
use Isotope\Interfaces\IsotopeProductCollection;
class AddProductToCollectionListener
{
public function __invoke(IsotopeProduct $product, $quantity, IsotopeProductCollection $collection, array $config): int
{
// Your logic here
return $quantity;
}
}
This is a list of all hooks available in isotope (as of version 2.8):