1

I need to solve this below error,

Fatal error: Method Magento\Ui\TemplateEngine\Xhtml\Result::__toString() must not throw an exception, caught TypeError: Argument 1 passed to Webkul\Pos\Model\ResourceModel\Agent\Collection::__construct() must be an instance of Magento\Framework\DataObject\Copy\Config, instance of Magento\Framework\Data\Collection\EntityFactory given, called in /var/www/sqdelivery/app/code/Webkul/Pos/Model/ResourceModel/Agent/Grid/Collection.php on line 50 in /var/www/sqdelivery/vendor/magento/module-ui/Component/Wrapper/UiComponent.php on line 0

My collection file is below.

<?php
 namespace Webkul\Pos\Model\ResourceModel\Agent;
    use 
Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;

class Collection extends AbstractCollection  {

    protected $_idFieldName = "id";

     protected $_fieldsetConfig;

     public function __construct( \Magento\Framework\DataObject\Copy\Config $fieldsetConfig)
     {
        $this->_fieldsetConfig = $fieldsetConfig;
     }

    protected function _construct()  {
        $this->_init("Webkul\Pos\Model\Agent", "Webkul\Pos\Model\ResourceModel\Agent");
        $this->_map["fields"]["id"] = "main_table.id";
    }




    public function setAgentData($condition, $attributeData)  {
        return $this->getConnection()->update($this->getTable("pos_agent"), $attributeData, $where = $condition);
    }

    public function groupByEmail()
    {
    $this->getSelect()->from(
        ['email' => $this->getEntity()->getEntityTable()],
        ['email_count' => new \Zend_Db_Expr('COUNT(email.id)')]
    )->where(
        'email.id = e.id'
    )->group(
        'email.email'
    );

    return $this;
    }


     public function addNameToSelect()
    {
    $fields = [];
    $agentAccount = $this->_fieldsetConfig->getFieldset('agent_account');



    foreach ($agentAccount as $code => $field) {
        if (isset($field['name'])) {
            $fields[$code] = $code;

        }
    }

    $connection = $this->getConnection();
    $concatenate = [];

    $concatenate[] = 'LTRIM(RTRIM({{firstname}}))';

    $concatenate[] = 'LTRIM(RTRIM({{lastname}}))';


    $nameExpr = $connection->getConcatSql($concatenate);

    $this->addExpressionAttributeToSelect('name', $nameExpr, $fields);

    return $this;
     }

     public function getSelectCountSql()
    {
    $select = parent::getSelectCountSql();
    $select->resetJoinLeft();

    return $select;
     }


    protected function _getAllIdsSelect($limit = null, $offset = null)
    {
    $idsSelect = parent::_getAllIdsSelect($limit, $offset);
    $idsSelect->resetJoinLeft();
    return $idsSelect;
    }

}

I don't known why it is happening.. please hep me to resolve this error Thanks in Advance

  • remove generated/code folder – Mukesh Prajapati Sep 29 '18 at 7:31
  • @MukeshPrajapati i had removed and tried again.. still same error shows – Ask Bytes Sep 29 '18 at 7:33
1

Try this:

    namespace Webkul\Pos\Model\ResourceModel\Agent;


     use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
     use Magento\Framework\Data\Collection\Db\FetchStrategyInterface;
     use Magento\Framework\Data\Collection\EntityFactory;
     use Magento\Framework\DB\Adapter\AdapterInterface;
     use Magento\Framework\Event\ManagerInterface;
     use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
     use Magento\Framework\DataObject\Copy\Config;
     use Psr\Log\LoggerInterface;

     class Collection extends AbstractCollection  {

         protected $_idFieldName = "id";

         protected $_fieldsetConfig;
         /**
          * @param EntityFactory $entityFactory
          * @param LoggerInterface $logger
          * @param FetchStrategyInterface $fetchStrategy
          * @param ManagerInterface $eventManager
          * @param Config $fieldsetConfig
          * @param mixed $connection
          * @param AbstractDb $resource
          */
         public function __construct(
             EntityFactory $entityFactory,
             LoggerInterface $logger,
             FetchStrategyInterface $fetchStrategy,
             ManagerInterface $eventManager,
             Config $fieldsetConfig,
             AdapterInterface $connection = null,
             AbstractDb $resource = null
         ) {
             $this->_fieldsetConfig = $fieldsetConfig;
             parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
         }

         protected function _construct()  {
             $this->_init("Webkul\Pos\Model\Agent", "Webkul\Pos\Model\ResourceModel\Agent");
             $this->_map["fields"]["id"] = "main_table.id";
         }




         public function setAgentData($condition, $attributeData)  {
             return $this->getConnection()->update($this->getTable("pos_agent"), $attributeData, $where = $condition);
         }

         public function groupByEmail()
         {
             $this->getSelect()->from(
                 ['email' => $this->getEntity()->getEntityTable()],
                 ['email_count' => new \Zend_Db_Expr('COUNT(email.id)')]
             )->where(
                 'email.id = e.id'
             )->group(
                 'email.email'
             );

             return $this;
         }


         public function addNameToSelect()
         {
             $fields = [];
             $agentAccount = $this->_fieldsetConfig->getFieldset('agent_account');



             foreach ($agentAccount as $code => $field) {
                 if (isset($field['name'])) {
                     $fields[$code] = $code;

                 }
             }

             $connection = $this->getConnection();
             $concatenate = [];

             $concatenate[] = 'LTRIM(RTRIM({{firstname}}))';

             $concatenate[] = 'LTRIM(RTRIM({{lastname}}))';


             $nameExpr = $connection->getConcatSql($concatenate);

             $this->addExpressionAttributeToSelect('name', $nameExpr, $fields);

             return $this;
         }

         public function getSelectCountSql()
         {
             $select = parent::getSelectCountSql();
             $select->resetJoinLeft();

             return $select;
         }


         protected function _getAllIdsSelect($limit = null, $offset = null)
         {
             $idsSelect = parent::_getAllIdsSelect($limit, $offset);
             $idsSelect->resetJoinLeft();
             return $idsSelect;
         }

     }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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