/**
  * sample_GetOrders::dispatchCall()
  * 
  * Dispatch the call
  *
  * @param array $params array of parameters for the eBay API call
  * 
  * @return boolean success
  */
 public function dispatchCall($params)
 {
     $req = new GetOrdersRequestType();
     $req->setCreateTimeFrom($params['CreateTimeFrom']);
     $req->setCreateTimeTo($params['CreateTimeTo']);
     $req->setOrderRole($params['OrderRole']);
     $req->setOrderStatus($params['OrderStatus']);
     $res = $this->proxy->GetOrders($req);
     if ($this->testValid($res)) {
         $this->dumpObject($res);
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 2
0
 function updateOrders($session, $days = false, $current_page = 1, $order_ids = false)
 {
     WPLE()->logger->info('*** updateOrders(' . $days . ') - page ' . $current_page);
     // this is a cron job if no number of days and no order IDs are requested
     $is_cron_job = $days == false && $order_ids == false ? true : false;
     $this->initServiceProxy($session);
     // set request handler
     $this->_cs->setHandler('OrderType', array(&$this, 'handleOrderType'));
     // $this->_cs->setHandler( 'PaginationResultType', array( & $this, 'handlePaginationResultType' ) );
     // build request
     $req = new GetOrdersRequestType();
     $req->setOrderRole('Seller');
     // $req->setIncludeContainingOrder(true);
     // check if we need to calculate lastdate
     if ($this->current_lastdate) {
         $lastdate = $this->current_lastdate;
         WPLE()->logger->info('used current_lastdate from last run: ' . $lastdate);
     } else {
         // period 30 days, which is the maximum allowed
         $now = time();
         $lastdate = $this->getDateOfLastOrder($this->account_id);
         WPLE()->logger->info("getDateOfLastOrder( {$this->account_id} ) returned: " . $lastdate);
         if ($lastdate) {
             $lastdate = mysql2date('U', $lastdate);
         }
         // if last date is older than 30 days, fall back to default
         if ($lastdate < $now - 3600 * 24 * 30) {
             WPLE()->logger->info('resetting lastdate - fall back default ');
             $lastdate = false;
         }
     }
     // save lastdate for next page
     $this->current_lastdate = $lastdate;
     // fetch orders by IDs
     if (is_array($order_ids)) {
         $OrderIDArray = new OrderIDArrayType();
         foreach ($order_ids as $id) {
             $order = $this->getItem($id);
             $OrderIDArray->addOrderID($order['order_id']);
         }
         $req->setOrderIDArray($OrderIDArray);
         // parameter $days
     } elseif ($days) {
         $req->NumberOfDays = $days;
         $this->NumberOfDays = $days;
         WPLE()->logger->info('NumberOfDays: ' . $req->NumberOfDays);
         // default: orders since last change
     } elseif ($lastdate) {
         $req->ModTimeFrom = gmdate('Y-m-d H:i:s', $lastdate);
         $req->ModTimeTo = gmdate('Y-m-d H:i:s', time());
         $this->ModTimeFrom = $req->ModTimeFrom;
         $this->ModTimeTo = $req->ModTimeTo;
         WPLE()->logger->info('lastdate: ' . $lastdate);
         WPLE()->logger->info('ModTimeFrom: ' . $req->ModTimeFrom);
         WPLE()->logger->info('ModTimeTo: ' . $req->ModTimeTo);
         // fallback: one day (max allowed by ebay: 30 days)
     } else {
         $days = 1;
         $req->NumberOfDays = $days;
         $this->NumberOfDays = $days;
         WPLE()->logger->info('NumberOfDays (fallback): ' . $req->NumberOfDays);
     }
     // $req->DetailLevel = $Facet_DetailLevelCodeType->ReturnAll;
     if (!$this->is_ajax()) {
         $req->setDetailLevel('ReturnAll');
     }
     // set pagination for first page
     $custom_page_size = get_option('wplister_fetch_orders_page_size', 50);
     $items_per_page = $is_cron_job ? $custom_page_size : 100;
     // For GetOrders, the maximum value is 100 and the default value is 25 (which is too low in some rare cases)
     $this->current_page = $current_page;
     $Pagination = new PaginationType();
     $Pagination->setEntriesPerPage($items_per_page);
     $Pagination->setPageNumber($this->current_page);
     $req->setPagination($Pagination);
     // get orders (single page)
     WPLE()->logger->info('fetching orders - page ' . $this->current_page);
     $res = $this->_cs->GetOrders($req);
     $this->total_pages = $res->PaginationResult->TotalNumberOfPages;
     $this->total_items = $res->PaginationResult->TotalNumberOfEntries;
     // get order with pagination helper (doesn't work as expected)
     // EbatNs_PaginationHelper($proxy, $callName, $request, $responseElementToMerge = '__COUNT_BY_HANDLER', $maxEntries = 200, $pageSize = 200, $initialPage = 1)
     // $helper = new EbatNs_PaginationHelper( $this->_cs, 'GetOrders', $req, 'OrderArray', 20, 10, 1);
     // $res = $helper->QueryAll();
     // handle response and check if successful
     if ($this->handleResponse($res)) {
         WPLE()->logger->info("*** Orders updated successfully.");
         // WPLE()->logger->info( "*** PaginationResult:".print_r($res->PaginationResult,1) );
         // WPLE()->logger->info( "*** processed response:".print_r($res,1) );
         WPLE()->logger->info("*** current_page : " . $this->current_page);
         WPLE()->logger->info("*** total_pages  : " . $this->total_pages);
         WPLE()->logger->info("*** total_items  : " . $this->total_items);
         WPLE()->logger->info("** count_inserted: " . $this->count_inserted);
         WPLE()->logger->info("** count_updated : " . $this->count_updated);
         WPLE()->logger->info("** count_skipped : " . $this->count_skipped);
         WPLE()->logger->info("** count_failed  : " . $this->count_failed);
         // fetch next page recursively - only in days mode, or if no new orders have been fetched yet
         if ($res->HasMoreOrders && (!$is_cron_job || $this->count_inserted == 0)) {
             $this->current_page++;
             $this->updateOrders($session, $days, $this->current_page);
         }
     } else {
         WPLE()->logger->error("Error on orders update" . print_r($res, 1));
     }
 }