private function handle(Request $request, Response $response) { $route = $request->getRoute(); if ($route->is('GET', '/api/commerce/{me}')) { $customer = \Craft\craft()->commerce_customers->getCustomer(); $response = $response->withItem($customer); } if ($route->is('GET', '/api/commerce/product')) { \Craft\Craft::dd($request->getCriteria()); $products = \Craft\craft()->elements->getCriteria('Commerce_Product', $request->getCriteria())->find(); $response = $response->withCollection($products); } return $response; }
/** * Get Transformer * * @param Request $request Request * * @return Transformer Transformer */ private function getTransformer(Request $request) { $transformer = $request->getRoute()->getMiddlewareVariable('transformer', 'fractal'); return $transformer ? new $transformer() : null; }