Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- public function actionProcess(array $variables=[]) {
- if (!$this->authenticate()) {
- throw new HttpException(401);
- }
- switch (craft()->request->getParam('action')) {
- case 'export':
- return $this->getOrders();
- case 'shipnotify':
- return $this->postShipment();
- default:
- throw new HttpException(400);
- }
- }
- /**
- * Authenticate the user using HTTP Basic auth. This is NOT using Craft's sessions/authentication.
- *
- * @return bool, true if successfully authenticated or false otherwise
- */
- protected function authenticate() {
- $expectedUsername = craft()->plugins->getPlugin('oneshipstation')->getSettings()->oneshipstation_username;
- $expectedPassword = craft()->plugins->getPlugin('oneshipstation')->getSettings()->oneshipstation_password;
- $username = array_key_exists('PHP_AUTH_USER', $_SERVER) ? $_SERVER['PHP_AUTH_USER'] : null;
- $password = array_key_exists('PHP_AUTH_PW', $_SERVER) ? $_SERVER['PHP_AUTH_PW'] : null;
- return $expectedUsername == $username && $expectedPassword == $password;
- }
- /**
- * Renders a big XML file of all orders in a format described by ShipStation
- * Note: this should probably get orders using Craft Commerce's variable/service if possible
- *
- * @param DateTime $start
- * @param DateTime $end
- *
- * @return Commerce_OrderModel[]|null
- */
- protected function getOrders() {
- $criteria = craft()->elements->getCriteria('Commerce_Order');
- if ($start_date = $this->parseDate('start_date') && $end_date = $this->parseDate('end_date')) {
- $criteria->dateOrdered = array('and', '> '.$start_date, '< '.$end_date);
- }
- $criteria->orderStatusId = true;
- $num_pages = $this->paginateOrders($criteria);
- $parent_xml = new SimpleXMLElement('<Orders />');
- $parent_xml->addAttribute('pages', $num_pages);
- craft()->oneShipStation_xml->orders($parent_xml, $criteria->find());
- $this->returnXML($parent_xml);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement