Skip to main content
Tag added, Formatting to improve visiblity of question
Source Link

I have the following code, if there are no orders older then $days_agono orders older then $days_ago, I want that the foreachforeach loop won't be executed. I don't know how to do this.

$orders = Mage::getModel('sales/order')->getCollection()
     ->addAttributeToSelect('*')
     ->addAttributeToFilter('created_at', array('lt' => $days_ago));

     foreach ($orders as $order):
        if(!$this->_shouldBeAnonymised($order)):
            continue;
     endif;

        $this->_anonymiseSale($order);
     endforeach;

Hope someone can help me!

I have the following code, if there are no orders older then $days_ago, I want that the foreach loop won't be executed. I don't know how to do this.

$orders = Mage::getModel('sales/order')->getCollection()
     ->addAttributeToSelect('*')
     ->addAttributeToFilter('created_at', array('lt' => $days_ago));

     foreach ($orders as $order):
        if(!$this->_shouldBeAnonymised($order)):
            continue;
     endif;

        $this->_anonymiseSale($order);
     endforeach;

Hope someone can help me!

I have the following code, if there are no orders older then $days_ago, I want that the foreach loop won't be executed. I don't know how to do this.

$orders = Mage::getModel('sales/order')->getCollection()
     ->addAttributeToSelect('*')
     ->addAttributeToFilter('created_at', array('lt' => $days_ago));

     foreach ($orders as $order):
        if(!$this->_shouldBeAnonymised($order)):
            continue;
     endif;

        $this->_anonymiseSale($order);
     endforeach;

Hope someone can help me!

added 4 characters in body; edited tags
Source Link
Piyush
  • 5.9k
  • 9
  • 34
  • 66

I have the following code, if there are no orders older then $days_ago$days_ago, I want that the foreachforeach loop won't be executed. I don't know how to do this.

$orders = Mage::getModel('sales/order')->getCollection()
     ->addAttributeToSelect('*')
     ->addAttributeToFilter('created_at', array('lt' => $days_ago));

     foreach ($orders as $order):
        if(!$this->_shouldBeAnonymised($order)):
            continue;
     endif;

        $this->_anonymiseSale($order);
     endforeach;

Hope someone can help me!

I have the following code, if there are no orders older then $days_ago, I want that the foreach loop won't be executed. I don't know how to do this.

$orders = Mage::getModel('sales/order')->getCollection()
     ->addAttributeToSelect('*')
     ->addAttributeToFilter('created_at', array('lt' => $days_ago));

     foreach ($orders as $order):
        if(!$this->_shouldBeAnonymised($order)):
            continue;
     endif;

        $this->_anonymiseSale($order);
     endforeach;

Hope someone can help me!

I have the following code, if there are no orders older then $days_ago, I want that the foreach loop won't be executed. I don't know how to do this.

$orders = Mage::getModel('sales/order')->getCollection()
     ->addAttributeToSelect('*')
     ->addAttributeToFilter('created_at', array('lt' => $days_ago));

     foreach ($orders as $order):
        if(!$this->_shouldBeAnonymised($order)):
            continue;
     endif;

        $this->_anonymiseSale($order);
     endforeach;

Hope someone can help me!

Source Link
Lucas
  • 21
  • 5

Don't execute foreach loop if array is empty

I have the following code, if there are no orders older then $days_ago, I want that the foreach loop won't be executed. I don't know how to do this.

$orders = Mage::getModel('sales/order')->getCollection()
     ->addAttributeToSelect('*')
     ->addAttributeToFilter('created_at', array('lt' => $days_ago));

     foreach ($orders as $order):
        if(!$this->_shouldBeAnonymised($order)):
            continue;
     endif;

        $this->_anonymiseSale($order);
     endforeach;

Hope someone can help me!