I'm beginner to Magento2 and I want to validate pincode which exists in custom table or not on Checkout page (www.test.com/checkout/), according to that I want to display error message on same page. Following is sample code of my plugin:
public function beforeSaveAddressInformation(
\Magento\Checkout\Model\ShippingInformationManagement $subject,
$cartId,
\Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation
) {
$shippingAddress = $addressInformation->getShippingAddress();
$pincode = $shippingAddress->getPostcode();
$enable = $this->helper->getIsEnable();
$checkAddToCart = $this->helper->getIsCheckonAddtoCart();
if ($enable && $checkAddToCart && $pincode) {
$pincodeStatus = $this->helper->getPincodeStatus($pincode);
if(!$pincodeStatus) {
// Following error message want to show on checkout page
throw new InputException(__($this->helper->getFailMessage()));
exit;
}
}
}
Can anyone let me know is there any way to display standard error message thrown through plugin using Magento2 Standards. Or else I have to use custom jquery validation rule on Checkout page? if I have to use custom jquery validation rule, then let me know how can I apply jquery validation rule on Checkout page, please elaborate in brief.
Thanks in advance!