I am trying to insert data into my custom table using my Model class.

Using the InstallSchema only table got created, but values are not getting added.

(only main code added)


<preference for="Vendor\Module\Api\Data\QueueInterface" type="Vendor\Module\Model\Queue" />


<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<route url="/V1/sync/getProduct" method="GET">                                    <!--route: contains the URL and a method (GET, POST, and DELETE) -->
    <service class="Vendor\Module\Api\Data\QueueInterface" method="getProductUpdate"/>   <!--service: defines the interface class and the method for handling -->
        <resource ref="anonymous" />


namespace Vendor\Module\Api\Data;
interface QueueInterface
    public function getProductUpdate($limit);


 class Queue extends \Magento\Framework\Model\AbstractModel implements \Magento\Framework\DataObject\IdentityInterface, 
   const STATUS_ENABLED = 1;
   const STATUS_DISABLED = 0;
   const CACHE_TAG = 'tgs_queue';  //custom table name
   protected $_cacheTag = 'tgs_queue';
   protected $_eventPrefix = 'tgs_queue';

  public function getProductUpdate($limit)


class Queue extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
protected function _construct()


class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
  public function _construct()


<event name="catalog_product_save_after">
    <observer name="catalog_product_save_after_handler" instance="Vendor\Module\Observer\SyncObserver"/>


use \Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
class SyncObserver implements ObserverInterface
  function __construct(
    \Vendor\Module\Model\QueueFactory $syncQueueFactory      
    $this->syncQueueFactory = $syncQueueFactory;
    //$this->_queue = $this->syncQueueFactory->create();

  public function execute(\Magento\Framework\Event\Observer $observer)
    $event = $observer->getEvent();

UPDATED Vendor\Module\Model\QueueFactory.php

use Vendor\Module\Model\QueueFactory as QueueAlias;
class QueueFactory extends \Magento\Framework\Model\AbstractModel
    protected $syncQueueFactory;

    public function __construct(
     \Magento\Framework\Model\Context $context,
    \Magento\Framework\Registry $registry,
    \Magento\Framework\View\LayoutInterface $layout,
    \Magento\Framework\View\LayoutFactory $layoutFactory,
    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
    \Magento\Framework\App\Request\Http $request,
    \Magento\Catalog\Model\Session $catalogSession, 
    \Psr\Log\LoggerInterface $logger,   
    QueueAlias $syncQueueFactory,    //If I keep this i get circular dependency error.
    array $data = []
    ) {
     $this->syncQueueFactory = $syncQueueFactory;
    $this->logger = $logger;
    $this->_queue = $this->syncQueueFactory->create();

public function productUpdate(\Magento\Framework\Event\Observer $observer)

1) Have i used the methods and events correctly? Are my folders structures proper?

2) Why is my data not getting inserted into my custom table?

3) The purpose of this is im trying to add the product id using my custom api!

Suggestion highly appreciated!

1 Answer 1


productUpdate should not be in model class, move it to separate

  • Is my QueueFactory required? if not where to keep my productUpdate()?
    – Sushivam
    Jul 22, 2016 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.