Evaluation
Since: 1.1.0
The Evaluation API brings together various aspects, including the core engine behind Hyvä Checkout, which is Magewire.
In many cases, Magewire ensures that Magewire-driven components are instantiated or updated. During this cycle, the server can already determine a status based on the currently known values, such as data from the quote.
This status is predefined and sent along with the component. Depending on the result type, and as long as the user doesn't make any modifications to the component, this will produce an effect. This could be, for example, displaying a warning message.
Please refer to our dedicated Evaluation page for more details.
registerValidator
Registers a validator by name, storing it for when a Validator Evaluation result type has been registered in the backend.
Since: 1.3.5
Parameters:
name(string) - A unique validator namecallback(function) - The validator callback that is used for a validation result type.
Returns:
Promise
<?php
class MyComponent extends Magewirephp\Magewire\Component implements \Hyva\Checkout\Model\Magewire\Component\EvaluationInterface
{
public function evaluateCompletion(EvaluationResultFactory $resultFactory)
{
return $resultFactory->createValidation('my-unique-validator')
// Multiple examples for inspiration.
// Optional: Will execute automatically when `false` is returned.
->withFailureResult(
$resultFactory->createConsoleLog('My unique validator failed... please try again.')
)
->withFailureResult(
$resultFactory->createMessageDialog('Validation Failure')
->withMessage('My unique validator failed... please try again.')
->asWarning()
);
}
}
?>
To register a callback by name on the frontend, you can do something like this: