public function execute() { $OrdersCon = new OrdersController(); /** * Get unpaid Oxxo orders that are 7 days old */ $orders = $this->Order->oxxoPayOverdueOrders(); if (empty($orders)) { $this->out('No OxxoPay Orders that need to be cancelled.', 1, Shell::NORMAL); return false; } for ($i = 0; $i < count($orders); $i++) { if ($this->Order->canCancelOrder($orders[$i], TRUE) == FALSE) { $this->out("Can not cancel order id: " . $orders[$i] . '.', 1, Shell::NORMAL); unset($orders[$i]); } } $sent = 0; $order_count = count($orders); foreach ($orders as $order) { $cancel = $OrdersCon->admin_cancelOrder($order); $result = $this->sendNotice($order); $this->Order->id = $order; $orderDetails = $this->Order->loadDisplayDetails(); if ($result == true) { $this->out("Sent cancellation notice to " . $orderDetails['OrderShipment'][0]['email_address'], 1, Shell::VERBOSE); $sent++; } else { $this->out("Failed to send cancellation notice to." . $orderDetails['OrderShipment'][0]['email_address'], 1, Shell::VERBOSE); } } $this->out("{$sent} of {$order_count} order cancellation notice emails."); return true; }