Advertisement
Guest User

Untitled

a guest
Jul 10th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. GET /actions/oneShipStation/orders/process?SS-UserName=username&SS-Password=wh@t3v3rthep@ssw0rd1s&action=export&start_date=07%2f10%2f2017+15%3a54&end_date=07%2f10%2f2017+15%3a59&page=1
  2.  
  3. public function actionProcess(array $variables=[]) {
  4. if (!$this->authenticate()) {
  5. throw new HttpException(401);
  6. }
  7. switch (craft()->request->getParam('action')) {
  8. case 'export':
  9. return $this->getOrders();
  10. case 'shipnotify':
  11. return $this->postShipment();
  12. default:
  13. throw new HttpException(400);
  14. }
  15. }
  16.  
  17. /**
  18. * Authenticate the user using HTTP Basic auth. This is NOT using Craft's sessions/authentication.
  19. *
  20. * @return bool, true if successfully authenticated or false otherwise
  21. */
  22. protected function authenticate() {
  23. $expectedUsername = craft()->plugins->getPlugin('oneshipstation')->getSettings()->oneshipstation_username;
  24. $expectedPassword = craft()->plugins->getPlugin('oneshipstation')->getSettings()->oneshipstation_password;
  25. $username = array_key_exists('PHP_AUTH_USER', $_SERVER) ? $_SERVER['PHP_AUTH_USER'] : null;
  26. $password = array_key_exists('PHP_AUTH_PW', $_SERVER) ? $_SERVER['PHP_AUTH_PW'] : null;
  27.  
  28. return $expectedUsername == $username && $expectedPassword == $password;
  29. }
  30. /**
  31. * Renders a big XML file of all orders in a format described by ShipStation
  32. * Note: this should probably get orders using Craft Commerce's variable/service if possible
  33. *
  34. * @param DateTime $start
  35. * @param DateTime $end
  36. *
  37. * @return Commerce_OrderModel[]|null
  38. */
  39. protected function getOrders() {
  40. $criteria = craft()->elements->getCriteria('Commerce_Order');
  41. if ($start_date = $this->parseDate('start_date') && $end_date = $this->parseDate('end_date')) {
  42. $criteria->dateOrdered = array('and', '> '.$start_date, '< '.$end_date);
  43. }
  44. $criteria->orderStatusId = true;
  45.  
  46. $num_pages = $this->paginateOrders($criteria);
  47.  
  48. $parent_xml = new SimpleXMLElement('<Orders />');
  49. $parent_xml->addAttribute('pages', $num_pages);
  50.  
  51. craft()->oneShipStation_xml->orders($parent_xml, $criteria->find());
  52.  
  53. $this->returnXML($parent_xml);
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement