I running the following code

  class MyOrders extends AbstractCollection implements MyOrdersInterface{

public function _construct(){
    $this->_init('\Magento\Sales\Model\Order', 'Magento\Sales\Model\ResourceModel\Order');

* @api
* @param int $customerId
* @return array
  public function getOrders($customerId){
    //if (!$this->orders) {
        $orders = $this->create()->addFieldToSelect(
    //$ordersCollection = $this->addAttributeToFilter("customer_id", $customerId)->load();

    return $a;

but xampp error log gives me the following error

PHP Fatal error:  Allowed memory size of 792723456 bytes exhausted (tried to 
allocate 387989504 bytes) in C:\\xampp\\htdocs\\yourParts\\app\\code\\Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection.php on line 246

I've changed memory_limit = -1 in php.ini but it doesn't work


2 Answers 2


Add this: ini_set('memory_limit', '2048M'); to app/bootstrap.php.

I would recommend changing it back after you finish with your tasks.


You can check below code to get order collection filter by Customer ID.

public function __construct(
         \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory){
  $this->_orderCollectionFactory = $orderCollectionFactory;

public function getOrders($customerId){

 $collection = $this->_orderCollectionFactory->create();
 $collection->addFieldToFilter('customer_id', array('eq'=>$customerId))
 return $collection;


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