I need to get and add a new Core table data. So, I tried based on get custom table data way(Model, ResourceModel) but it's not working for me.
For example I need to collect customer_group data
What I did: (Using Api)
<?php
namespace Vendor\Module\Controller\Index;
use Magento\Checkout\Model\Cart as CustomerCart;
use Magento\Customer\Model\Session;
use Magento\Customer\Api\Data\GroupInterfaceFactory;
use Magento\Customer\Api\Data\GroupInterface;
use Magento\Customer\Api\GroupRepositoryInterface;
class Test extends \Magento\Framework\App\Action\Action
{
protected $_groupDataFactory;
protected $dataObjectProcessor;
public function __construct(
\Magento\Framework\App\Action\Context $context,
Session $csession,
\Psr\Log\LoggerInterface $logger,
\Magento\Framework\Registry $coreRegistry,
GroupRepositoryInterface $groupRepository,
GroupInterfaceFactory $groupDataFactory,
\Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor
)
{
$this->dataObjectProcessor = $dataObjectProcessor;
parent::__construct($context,$groupRepository,
$groupDataFactory);
}
public function execute()
{
try
{
$customerGroup = $this->_groupDataFactory->create();
$this->_logger->addDebug(serialize($customerGroup));
}
catch (\Exception $e)
{
// echo $e;
}
}
}
}
}
Model Way:
protected $_groupFactory;
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Customer\Model\Group $groupFactory
)
{
parent::__construct($context);
$this->_groupFactory=$groupFactory;
}
public function getTableData()
{
$result=$this->_groupFactory->create()->getCollection();
var_dump($result);
}
Both above way not working for me , Suggest me How to get and add a data to core table.