/Blockname.php/
<?php
namespace Eaglerocket\Customquote\Block;
use Magento\Framework\View\Element\Template;
class Blockname extends Template
{
protected $_registry;
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $registry,
)
{
$this->_registry = $registry;
parent::__construct($context);
}
public function getCurrentProduct()
{
return $this->_registry->registry('current_product');
}
}
/post_requirements.phtml/
<?php
if ($currentProduct = $block->getCurrentProduct()) {
echo $currentProduct->getName() . '<br />';
echo $currentProduct->getSku() . '<br />';
echo $currentProduct->getFinalPrice() . '<br />';
echo $currentProduct->getProductUrl() . '<br />';
print_r ($currentProduct->getCategoryIds()) . '<br />';
}
?>
<button type="button" class="btn btn-primary btn-lg" id="popupButton" data-toggle="modal"
data-target="#myModal"><?php echo __('Post Requirement')?></button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog" style="display:none;">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title"><?php echo __('Get Quote')?></h4>
</div>
<div class="modal-body">
<form action="<?= $block->escapeUrl($block->getBaseUrl().'customquote/index/submit')?>" method="post">
<div class="form-group">
<label for="name"><?php echo __('Name');?>:</label>
<input type="text" class="form-control" id="name" placeholder="<?php echo __('Enter name')?>" name="product_name" value="<?= $block->escapeUrl($block->getBaseUrl().'customquote/index/submit')?>">
</div>
<div class="form-group">
<label for="requirement"><?php echo __('Requirement') ?> :</label>
<input type="text" class="form-control" id="name" placeholder="<?php echo __('Enter name')?>" name="question"
value="<?= $block->escapeUrl($block->getBaseUrl().'customquote/index/submit')?>">
<!-- <textarea class="form-control" rows="5" id="requirement" name="answer">
</textarea> -->
</div>
<div class="form-group">
<label for="requirement"><?php echo __('Requirement') ?> :</label>
<input type="text" class="form-control" id="name" name="answer"
value="<?php echo $currentProduct->getName();?>">
</div>
<button type="submit" class="btn btn-default"><?php echo __('Submit')?></button>
</form>
</div>
</div>
</div>
</div>
<script>
require(['jquery', 'Eaglerocket_Customquote/js/mymodal-component'],
function ($) {
return;
}
);
</script>