Skip to content

Commit

Permalink
Add frontend validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Wacławczyk committed Dec 12, 2024
1 parent 11d2486 commit 588bb7d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Magewire/Locker.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,11 @@ public function evaluateCompletion(EvaluationResultFactory $resultFactory): Eval
}

if ($this->locker === null) {
return $resultFactory->createErrorMessageEvent(__('Please select locker'))
->withCustomEvent('shipping:method:error');
$errorMessageEvent = $resultFactory->createErrorMessageEvent(__('Please select locker'))
->withCustomEvent('shipping:method:error')
->asError();
return $resultFactory->createValidation('validateInpostLocker')
->withFailureResult($errorMessageEvent);
}

$quote = $this->session->getQuote();
Expand Down
10 changes: 10 additions & 0 deletions src/view/frontend/layout/hyva_checkout_index_index.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="hyva.checkout.init-evaluation.after">
<block name="hyva.checkout.init-evaluation.validate-inpost-locker"
template="Snowdog_HyvaCheckoutInpost::validate-inpost-locker.phtml"/>
</referenceContainer>
</body>
</page>
8 changes: 8 additions & 0 deletions src/view/frontend/templates/validate-inpost-locker.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
hyvaCheckout.evaluation.registerValidator('validateInpostLocker', async (element, component) => {
return new Promise(resolve => {
let currentLocker = component.get('locker');
resolve(null !== currentLocker);
})
})
</script>

0 comments on commit 588bb7d

Please sign in to comment.