I have a custom Order
model, it has a method in it @method int getIncrementId()
I have a template to transfer the id of the current order/app/code/Qq/Www/view/frontend/templates/success/index/success_page.phtml
How do I get the ID after the form is submitted by this controller.
if ($data) {
/** @var QqWwwModelOrder $model */
$model = $this->_objectManager->create('QqWwwModelOrder');
$model->setData($data);
$model->setStoreId($this->_storeManager->getStore()->getId());
try {
$this->objectRepository->save($model);
$this->messageManager->addSuccess(__('Request was added to processing.'));
$this->dataPersistor->clear('dv_sample_order');
// Send email
$this->helper->sendEmail($model);
} catch (MagentoFrameworkExceptionLocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (Exception $e) {
$this->messageManager->addException($e, __('Something went wrong while saving the data.'));
}
}
return $resultRedirect->setPath('qq_success_page/success/index');
update
There is already a method in my Model
public function getLastIncrementId()
{
$result = null;
try {
$result = $this->collection->create()->getLastIncrementId();
} catch (Exception $e) {
$this->_logger->error($e->getMessage());
}
return $result;
}
I create a block, pass such data to it
namespace VendorModuleBlock;
class Success
{
protected $_orderData;
public function __construct(
VendorModuleModelOrder $_orderData
) {
$this->_orderData = $_orderData;
}
public function getLastOrderId():? int
{
return $this->_orderData->getLastIncrementId();
}
}
xml for my controller
my template
< ?php echo $block->escapeHtml($block->getLastOrderId());?>
that not work for me