public function ajaxFindProduct() { try { $products = array(); if (isset($_POST['query'])) { $query = trim(htmlspecialchars(strip_tags($_POST['query']))); if (!empty($query)) { $products = $this->productService->findLike($query); } } else { if (isset($_POST['value'])) { $query = explode(',', trim(htmlspecialchars(strip_tags($_POST['value'])))); foreach ($query as $id) { $products[] = $this->productService->find($id); } } else { throw new Exception(__('Neither query nor value is provided to find products.', 'jigoshop')); } } $result = array('success' => true, 'results' => $this->prepareResults($products)); } catch (Exception $e) { $result = array('success' => false, 'error' => $e->getMessage()); } echo json_encode($result); exit; }
/** * Finds items by trying to match their name. * * @param $name string Post name to match. * @return array List of matched products. */ public function findLike($name) { return $this->service->findLike($name); }