/** * Get the specify goods detail information, 這邊其實可以用 JMS serialize 直接序列物件 * * @Route("/api/{id}", requirements={"id" = "\d+"}, name="api_get_goods_detail", options={"expose"=true}) * @ParamConverter("goods", class="WoojinGoodsBundle:GoodsPassport") * @Method("GET") */ public function apiShowActivityGoodsDetailAction(Request $request, GoodsPassport $goods) { $rData = array(); $em = $this->getDoctrine()->getManager(); $user = $this->get('security.token_storage')->getToken()->getUser(); $role = $user->getRole(); $oMt = $goods->getMt(); $oImg = $goods->getImg(); $oGoodsLevel = $goods->getLevel(); $oGoodsSource = $goods->getSource(); $oGoodsStatus = $goods->getStatus(); $rData['id'] = $goods->getId(); $rData['sn'] = $goods->getSn(); $rData['name'] = $goods->getName(); $rData['price'] = $goods->getPrice(); $rData['cost'] = $role->hasAuth('READ_COST_OWN') && $goods->isOwnProduct($user) || $role->hasAuth('READ_COST_ALL') ? $goods->getCost() : null; $rData['memo'] = $goods->getMemo(); $rData['level'] = is_object($oGoodsLevel) ? $oGoodsLevel->getName() : '未設定'; $rData['material'] = is_object($oMt) ? $oMt->getName() : '未設定'; $rData['source'] = is_object($oGoodsSource) ? $oGoodsSource->getName() : '未設定'; $rData['imgURL'] = is_object($oImg) ? $oImg->getPath() : ''; $rData['status'] = is_object($oGoodsStatus) ? $oGoodsStatus->getName() : '未知'; $rData['model'] = $goods->getModel(); $rData['pattern'] = $goods->getPattern()->getName(); $rData['brand'] = $goods->getBrand()->getName(); $response = new Response(json_encode($rData)); $response->headers->set('Content-Type', 'application/json'); return $response; }
/** * Is product belong store the same as user belongs? * * @param \Woojin\UserBundle\Entity\User $user * @param \Woojin\GoodsBundle\Entity\GoodsPassport $product * @return boolean */ protected function isProductBelongStoreUser(User $user, GoodsPassport $product) { return $product->isOwnProduct($user); }