What is the replacement for Varien_Data_Collection in magento 2? I know that Varien_Object has been replaced with \Magento\Framework\DataObject.

replacement for Varien_Data_Collection in magento 2?

You can find the data collection class in Magento 2 by your root\vendor\magento\framework\Data\Collection.php

The class Implements

\IteratorAggregate, \Countable, ArrayInterface, CollectionDataSourceInterface

Hope this helps.

  • I want to create temporary object collection. Is this helpful? @Krishna – Dhaduk Mitesh Apr 18 '18 at 9:04

The replacement of Varien_Data_Collection is :

protected $_collectionFactory;
public function __construct(
        \Magento\Framework\Data\CollectionFactory $collectionFactory

    ) {
        $this->_collectionFactory = $collectionFactory;

public function methodName(){
//this line of code should written in `foreach() loop` 
foreach($ArrayData as $RowData){
$varienObject = new \Magento\Framework\DataObject();                    $varienObject->setData($RowData->getData());
// end `foreach() loop code`

Note: This code is Tested

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.