Actually I am getting the data of the catalog_category_entity in my custom grid and delete the record. Before delete I want to save the complete data in my custom table. But only saves the three column.
This is my controller
<?php
namespace VendorModuleControllerAdminhtmlCategory;
use VendorModuleModelCategoryRuleRecordFactory;
use VendorModuleModelResourceModelCategoryRuleRecord as ResourceModel;
use VendorModuleModelCategoryFactory;
use MagentoCatalogModelCategoryRepository;
use MagentoBackendAppAction;
use MagentoFrameworkAppRequestInterface;
use MagentoBackendAppActionContext;
use MagentoBackendModelViewResultRedirect;
use MagentoFrameworkAppActionHttpGetActionInterface;
use MagentoFrameworkAppActionHttpPostActionInterface;
/**
* Class Delete
*
* Delete banner action.
*/
class Delete extends Action implements HttpGetActionInterface, HttpPostActionInterface
{
protected ResourceModel $categoryResource;
protected CategoryRuleRecordFactory $categoryRecord;
protected CategoryFactory $categoryFactory;
private RequestInterface $request;
private CategoryRepository $categoryRepository;
/**
* @param Context $context
* @param CategoryRepository $categoryRepository
*/
public function __construct(
ResourceModel $categoryResource,
CategoryRuleRecordFactory $categoryRecord,
RequestInterface $request,
CategoryFactory $categoryFactory,
Context $context,
CategoryRepository $categoryRepository
) {
parent::__construct($context);
$this->request = $request;
$this->categoryRecord = $categoryRecord;
$this->categoryFactory =$categoryFactory;
$this->categoryResource =$categoryResource;
$this->categoryRepository = $categoryRepository;
}
/**
* Delete action
*
* @return Redirect
*/
public function execute()
{
$model = "";
$data = $this->request->getPostValue('entity_id');
$categoryRecord = $this->categoryRecord->create();
$this->categoryResource->load($categoryRecord, $data);
{
if ($categoryRecord->getData())
$model = $this->categoryFactory->create();
$model->setData($data)->save();
}
/** @var Redirect $resultRedirect */
$resultRedirect = $this->resultRedirectFactory->create();
{
try {
$data = $this->getRequest()->getParams();
$this->categoryRepository->deleteByIdentifier($data['entity_id']);
$this->messageManager->addSuccessMessage(__('The Record has been deleted.'));
return $resultRedirect->setPath('*/*/');
} catch (Exception $e) {
$this->messageManager->addErrorMessage($e->getMessage());
return $resultRedirect->setPath('*/*/index');
}
}
}
}
I am trying to save the same table data in the another table before deleting but when its saves it saves only three columns in the other tables that are entity_id, created_in, updated_in.
I want to save all columns in my table not only three.