0

I have a function defined in Magento 1

public function getStatusMappingCollection()
{
    if (is_null($this->_statusCollection)) {
        $this->_plentyStatusCollection = new Varien_Data_Collection;
        $configStatusMapping = $this->_helper()->getOrderStatusMapping();
        foreach ($configStatusMapping as $status) {
            $item = new Varien_Object();
            if (isset($status['plenty_order_status'])) {
                $item->setPlentyStatus($status['plenty_order_status']);
            }
            if (isset($status['magento_order_status'])) {
                $item->setMageStatus($status['magento_order_status']);
            }
            $this->_plentyStatusCollection->addItem($item);
        }
    }
    echo "<pre>";print_r($this->_plentyStatusCollection);die;
    return $this->_plentyStatusCollection;
}

I am trying to replicate it in Magento 2. I have done something like this using the code-migration-develop tool.

public function __construct(
    \Plenty\Orders\Helper\Data $ordersHelper,
    \Magento\Framework\Data\CollectionFactory $collectionFactory,
    \Magento\Framework\DataObjectFactory $dataObjectFactory
    array $data = []
) {
    $this->ordersHelper = $ordersHelper;
    $this->collectionFactory = $collectionFactory;
    $this->dataObjectFactory = $dataObjectFactory;
    parent::__construct(
        $data
    );
}    

public function getStatusMappingCollection()
{
    if (is_null($this->_statusCollection)) {
        $this->_plentyStatusCollection = $this->collectionFactory->create();
        $configStatusMapping = $this->ordersHelper()->getOrderStatusMapping();
        foreach ($configStatusMapping as $status) {
            $item = $this->dataObjectFactory->create();
            if (isset($status['plenty_order_status'])) {
                $item->setPlentyStatus($status['plenty_order_status']);
            }
            if (isset($status['magento_order_status'])) {
                $item->setMageStatus($status['magento_order_status']);
            }
            $this->_plentyStatusCollection->addItem($item);
        }
    }
    echo "<pre>";print_r($this->_plentyStatusCollection);die;
    return $this->_plentyStatusCollection;
}

In Magento 1 code I was able to print the collection $this->_plentyStatusCollection and check the values in it, but when I try to print the same value in magento 2 I get an error

 Allowed memory size of 792723456 bytes exhausted.

I have checked in php.ini file, a memory limit is specified as

memory_limit=4G

This should be sufficient.

I also checked by using getData().

echo "<pre>";print_r($this->_plentyStatusCollection->getData());die;

After using getData() I get the following error.

Fatal error:  Uncaught Error: Call to undefined method Magento\Framework\Data\Collection::getData()

It means something is wrong with my way of assigning object to collection but I googled it and found that this is the correct way. I followed this thread Magento2: Convert DataObject/Array into magento2 Collection?

My question is If it is the correct way of assigning object to a collection and also how I can check the values inside collection.

2

Not sure but I think you are trying to print an object which leads to you memory limit error that's correct Magent object contains more data we cant print it directly. For debug you can use var_dump in stead of print_r. That might help you or you can use zend_debug from zend lib.

Like below, Example

 \Zend_Debug::dump($item->debug()); or    $yourObject->debug();

Take a look here. https://github.com/magento/magento2/blob/2.3-develop/lib/internal/Magento/Framework/DataObject.php#L461-L489

Ref. https://magento.stackexchange.com/a/245147/49826

0

Please add getData(); to this line echo "<pre>";print_r($this->_plentyStatusCollection);die;

Like:

echo "<pre>";print_r($this->_plentyStatusCollection->getData());die;
  • Sorry for not mentioning it in my question. I did checked using getData(). Updating my question please check. – Rajeev Singh Aug 20 at 8:17
0

Use print_r($this->_plentyStatusCollection->getData()).

  • Updated my question. have a look – Rajeev Singh Aug 20 at 8:23

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.