Load Supported
public function onLoadSupportedDeals( array &$config ) : void
Fires while loading all the supported deals.
Description
This hook can be used to support custom types of deals.
It is enough to include the directory containing the new rules. Only the files that inherits the DealRule
class will be taken.
In addition, the loaded classes must have a name built as DealRule + [FILE_NAME].
In case the class name is not correct or it doesn't extend DealRule
, the file will be ignored.
onSetupTakeawayDeals
action.Parameters
- &$config
-
(array) It is possible to inject here the configuration for a specific deal. The parameters have to be assigned by using the deal file name.
Return Value
None.
Example
The example below adds support for all the deals contained in a specific folder of a third-party plugin. Such as:
/plugins/vikrestaurants/e4j/deals/
All the PHP
files contained within the deals folder of the VikRestaurants - E4J plugin will be loaded.
/**
* This hook can be used to support custom deals.
* It is enough to include the directory containing
* the new rules. Only the files that inherits the
* DealRule class will be taken.
*
* @param array &$config It is possible to inject the configuration for
* a specific deal. The parameters have to be assigned
* by using the deal file name.
*
* @return void
*/
public function onLoadSupportedDeals(&$config)
{
// fetch deals folder path
$folder = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'deals';
// include deals folder
DealsHandler::addIncludePath($folder);
// recover deal configuration from database
$params = [];
// register plugin configuration for being used
// while trying to apply the deal
$config['test'] = $params;
}
The class (shell) of the deal will be built as follows. The path of the file will be equal to this one.
/plugins/vikrestaurants/e4j/deals/test.php
class DealRuleTest extends DealRule
{
/**
* Returns the deal code identifier.
*
* @return integer
*/
public function getID()
{
// DO NOT use values between 1 and 10, because
// they have been reserved by the system
return 76;
}
/**
* Returns a deal readable name.
*
* @return string
*/
public function getName()
{
return 'E4J - Test Deal'
}
/**
* Returns the description of the deal
*
* @return string
*/
public function getDescription()
{
// return empty description
return 'Deal for test purposes';
}
/**
* Executes the rule before start checking for deals to apply.
*
* @param TakeAwayCart &$cart The cart with the items.
*
* @return void
*/
public function preflight(&$cart)
{
/**
* @todo optional preflight method
*/
}
/**
* Applies the deal to the cart instance, if needed.
*
* @param TakeAwayCart &$cart The cart with the items.
* @param array $deal The deal to apply.
*
* @return boolean True if applied, false otherwise.
*/
public function apply(&$cart, $deal)
{
/**
* @todo apply the deal in case all the conditions
* have been satisfied
*/
}
}
Changelog
Version | Description |
---|---|
1.9 | This filter has been officially deprecated and will be no longer supported starting from the 1.10 version. |
1.8 | Introduced. |