elasticsuite
elasticsuite copied to clipboard
Dynamic/Programatic Optimizers
Is your feature request related to a problem? Please describe. Maybe this is already possible, but it'd be really helpful if there was a supported mechanism for creating custom optimizers iprogramatically that would be loaded by relevant queries the same way as ones added through the backend UI that would allow for more advanced conditions than could be accounted for using the UI
The way I see this working is you'd potentially have a section you could add to a custom module's di.xml like
<!-- Optimizer resolver -->
<type name="Smile\ElasticsuiteCatalogOptimizer\Model\Optimizer\OptimizerResolver">
<arguments>
<argument name="optimizers" xsi:type="array">
<item name="my_optimizer" xsi:type="object">MyCompany\MyModule\Model\Optimizer\MyOptimizerResolver</item>
</argument>
</arguments>
</type>
and then the class would be like
<?php
namespace MyCompany\MyModule\Model\Optimizer;
use Smile\ElasticsuiteCatalogOptimizer\Model\Optimizer\OptimizerResolverInterface;
use Magento\Catalog\Model\Product;
class MyOptimizerResolver implements OptimizerResolverInterface
{
/**
* @param Product $product
* @return bool
*/
public function applicableCondition(Product $product)
{
return ($product->getData('some_attribute') == 'some_value');
}
/**
* @param Product $product
* @return float
*/
public function boostAmount(Product $product)
{
if ($product->getData('some_attribute') == 'some_value') {
return 10.0;
}
if ($product->getData('some_attribute') == 'other_value') {
return 20.0;
}
return 0.0;
}
}
obviously names of classes/namespaces/methods subject to change
Please let me know if I can provide any more details to help define the scope of this feature