I have a custom module that checks Pincode, kindly check the screenshots below:-

I have created a custom import function and added a table to the database which will hold the value imported by CSV below is the screenshot:-
now I want to fetch this table on the frontend where I check Pincode and if the Pincode exist in the database then it should show the message of delivery available.
please also check the code below
vendor/module/Model/Pincode.php
<?php
namespace Learn\CheckDelivery\Model;
class Pincode extends \Magento\Framework\Model\AbstractModel
{
public function _construct()
{
$this->_init('Learn\CheckDelivery\Model\ResourceModel\Pincode');
}
}
vendor/module/Model/ResourceModel/Pincode.php
<?php
namespace Learn\CheckDelivery\Model\ResourceModel;
class Pincode extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{
public function _construct()
{
$this->_init('learn_checkdelivery', 'id');
}
}
vendor/module/Model/ResourceModel/Pincode/Collection.php
<?php
namespace Learn\CheckDelivery\Model\ResourceModel\Pincode;
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
protected function _construct()
{
$this->_init('Learn\CheckDelivery\Model\Pincode','Learn\CheckDelivery\Model\ResourceModel\Pincode');
}
//print_r($datacollection);
}
now I want to know how to achieve this
UPDATE
VENDOR/MODULE/view/frontend/layout/templates/product/view/check_delivery.phtml
<?php $product = $this->getCurrentProduct() ?>
<?php $helper=$this->helper("Learn\CheckDelivery\Helper\Data");?>
<?php if($product && $product->getCheckDeliveryEnable() != 2 && $helper->getIsActive() == 1): ?>
<form class="form" id="check-delivery-form" method="post">
<fieldset class="fieldset">
<legend class="legend"><span><?php echo __('Check Delivery') ?></span></legend><br>
<div class="field required">
<label for="delivery_postcode" class="label"><span><?php echo __('Postcode') ?></span></label>
<div class="control">
<input type="text" name="postcode" id="delivery_postcode" value="" title="<?php echo __('Postcode') ?>" class="input-text" data-validate="{required:true, 'validate-digits':true}">
</div>
</div>
<div class="message"></div>
</fieldset>
<div class="actions-toolbar">
<div class="primary">
<button type="submit" class="action submit primary action-check-delivery" title="<?php echo __('Check') ?>"><span><?php echo __('Check') ?></span></button>
</div>
</div>
</form>
<script>
require([
'jquery',
'mage/mage'
], function ($) {
var dataForm = $('#check-delivery-form');
dataForm.mage('validation', {});
var dataFormMessage = $('#check-delivery-form .message');
dataFormMessage.removeClass('success').removeClass('error').hide();
$('.action-check-delivery').on('click',function () {
var formData = new FormData();
formData.append('postcode', $('#check-delivery-form input[name="postcode"]').val());
$.ajax({
url: '<?php echo $this->getUrl('checkDelivery/postcode/check',['id'=> $product->getId()]) ?>',
data: formData,
processData: false,
contentType: false,
showLoader: true,
type: 'POST',
dataType: 'json',
success: function (response) {
dataFormMessage.removeClass('success').removeClass('error').hide();
dataFormMessage.addClass(response.type).html(response.message).show();
}
});
return false;
});
});
</script>
<?php endif; ?>
Block.php
<?php
namespace Learn\CheckDelivery\Block\Product\View;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
class CheckDelivery extends Template
{
protected $_registry;
public function __construct(
Context $context,
Registry $registry,
array $data = []
) {
parent::__construct($context, $data);
$this->_registry = $registry;
}
public function getCurrentProduct()
{
return $this->_registry->registry('current_product');
}
}
