0

If I want to get data from sales_order_grid table, which CollectionFactory I should inject?

for example: If I want to get Sales_order_item, I should use

\Magento\Sales\Model\ResourceModel\Order\Item\CollectionFactory $itemCollectionFactory,

so If I want get data from sales_order_grid, which CollectionFactory I should use?

IS there any documentation I can learn the difference of those different Collection Factory? Thanks

I just showing my code below, but I have no idea why magento saying "has an error: Call to undefined method Magento\Sales\Model\ResourceModel\Order\Grid\Collection\Interceptor::create(). [] [] "

use Magento\Sales\Model\ResourceModel\Order\Grid\Collection as SalesOrderGridCollection;

    /**
     * @var SalesOrderGridCollection
     */
    private $sOGcollection; 


    public function __construct(

        SalesOrderGridCollection $sOGcollection
    ) {

        $this->sOGcollection = $sOGcollection;
        


     public function getSalesOrderGrid()
        {
            
        try {
            $itemData = $this->sOGcollection->create();
                $currentDate = date("Y-m-d H:i:s"); // Y-m-d h:i:s
                $newDate = strtotime('-30 MINUTE', strtotime($currentDate));
                $newDate = date('Y-m-d H:i:s', $newDate);
                $itemData->addFieldToFilter('updated_at', ['gteq' => $newDate]);
                $itemData->addFieldToFilter('updated_at', ['lteq' => $currentDate]);
                $itemData->load();
            return $itemData;
            
            } catch (LocalizedException $e) {
                $this->logger->error($e->getMessage());
            }
            return null;
        }   


$SalesOrderGride = $this->getSalesOrderGrid();

1 Answer 1

1

I would suggest, Try this class, \Magento\Sales\Model\ResourceModel\Order\CollectionFactory

if this will not work please let us know your requirement/problem in detail, so I can help you to get the correct information.

1
  • I finally used this Magento\Sales\Model\ResourceModel\Order\Grid\CollectionFactory
    – Paul Fan
    May 21, 2021 at 19:21

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.