public function action_update_orders() { WPLA()->logger->info("do_action: wpla_update_orders"); $accounts = WPLA_AmazonAccount::getAll(); foreach ($accounts as $account) { $api = new WPLA_AmazonAPI($account->id); // get date of last order $om = new WPLA_OrdersModel(); $lastdate = $om->getDateOfLastOrder($account->id); WPLA()->logger->info('getDateOfLastOrder() returned: ' . $lastdate); $days = isset($_REQUEST['days']) && $_REQUEST['days'] ? $_REQUEST['days'] : false; if (!$lastdate && !$days) { $days = 1; } // get orders $orders = $api->getOrders($lastdate, $days); // echo "<pre>";print_r($orders);echo"</pre>";#die(); if (is_array($orders)) { // run the import $importer = new WPLA_OrdersImporter(); $success = $importer->importOrders($orders, $account); $msg = sprintf(__('%s order(s) were processed for account %s.', 'wpla'), sizeof($orders), $account->title); if ($importer->updated_count > 0) { $msg .= "\n" . 'Updated orders: ' . $importer->updated_count; } if ($importer->imported_count > 0) { $msg .= "\n" . 'Created orders: ' . $importer->imported_count; } WPLA()->logger->info($msg); $this->showMessage(nl2br($msg), 0, 1); } elseif ($orders->Error->Message) { $msg = sprintf(__('There was a problem downloading orders for account %s.', 'wpla'), $account->title) . ' - Error: ' . $orders->Error->Message; WPLA()->logger->error($msg); $this->showMessage(nl2br($msg), 1, 1); } else { $msg = sprintf(__('There was a problem downloading orders for account %s.', 'wpla'), $account->title); WPLA()->logger->error($msg); $this->showMessage(nl2br($msg), 1, 1); } } $this->message = ''; }