public function _clone(GoodsPassport $product) { $this->product = new GoodsPassport(); $this->product->setImg($product->getImg())->setModel($product->getModel())->setColor($product->getColor())->setPattern($product->getPattern())->setColorSn($product->getColorSn())->setBrand($product->getBrand())->setMt($product->getMt())->setStatus($product->getStatus())->setLevel($product->getLevel())->setSource($product->getSource())->setName($product->getName())->setParent($product->getParent())->setCost($product->getCost())->setPrice($product->getPrice())->setOrgSn($product->getOrgSn())->setMemo($product->getMemo())->setCustom($product->getCustom())->setPromotion($product->getPromotion())->setIsBehalf($product->getIsBehalf())->setWebPrice($product->getWebPrice())->setDesimg($product->getDesimg())->setBrief($product->getBrief())->setDescription($product->getDescription())->setIsAllowWeb($product->getIsAllowWeb())->setSeoSlogan($product->getSeoSlogan())->setSeoSlogan2($product->getSeoSlogan2())->setIsAllowCreditCard($product->getIsAllowCreditCard())->setYahooId($product->getYahooId())->setIsAlanIn(false)->setIsAllowAuction(false)->setBsoCustomPercentage(NULL); foreach ($product->getCategorys() as $category) { $this->product->addCategory($category); } return $this; }
protected function genArr(GoodsPassport $product) { $arr = array(); $arr['auth_key'] = 'jasodijQQ3Eoinaaoidll'; // GoodsPassport (分類???) $arr['GoodsPassport']['id'] = $product->getId(); $arr['GoodsPassport']['status_id'] = $product->getStatus()->getId(); $arr['GoodsPassport']['source_id'] = $product->getSource() ? $product->getSource()->getId() : 0; $arr['GoodsPassport']['img_id'] = $product->getImg() ? $product->getImg()->getId() : 0; $arr['GoodsPassport']['level_id'] = $product->getLevel() ? $product->getLevel()->getId() : 0; $arr['GoodsPassport']['inherit_id'] = $product->getParent()->getId(); $arr['GoodsPassport']['sn'] = $product->getSn(); $arr['GoodsPassport']['name'] = $product->getName(); $arr['GoodsPassport']['cost'] = $product->getCost(); $arr['GoodsPassport']['price'] = $product->getPrice(); $arr['GoodsPassport']['org_sn'] = $product->getOrgSn(); $arr['GoodsPassport']['memo'] = $product->getMemo(); $arr['GoodsPassport']['created_at'] = $product->getCreatedAt()->format('Y-m-d H:i:s'); $arr['GoodsPassport']['mt_id'] = $product->getMt() ? $product->getMt()->getId() : 0; $arr['GoodsPassport']['activity_id'] = $product->getActivity() ? $product->getActivity()->getId() : 0; $arr['GoodsPassport']['custom_id'] = $product->getCustom() ? $product->getCustom()->getId() : 0; $arr['GoodsPassport']['brand_id'] = $product->getBrand() ? $product->getBrand()->getId() : 0; //$arr['GoodsPassport']['color_id'] = $product->; $arr['GoodsPassport']['pattern_id'] = $product->getPattern() ? $product->getPattern()->getId() : 0; $arr['GoodsPassport']['colorSn'] = $product->getColorSn(); $arr['GoodsPassport']['model'] = $product->getModel(); $arr['GoodsPassport']['customSn'] = $product->getCustomSn(); $arr['GoodsPassport']['desimg_id'] = $product->getDesimg() ? $product->getDesimg()->getId() : 0; $arr['GoodsPassport']['description_id'] = $product->getDescription() ? $product->getDescription()->getId() : 0; $arr['GoodsPassport']['brief_id'] = $product->getBrief() ? $product->getBrief()->getId() : 0; $arr['GoodsPassport']['store_id'] = $product->getStore() ? $product->getStore()->getId() : 0; $arr['GoodsPassport']['promotion_id'] = $product->getPromotion() ? $product->getPromotion()->getId() : 0; $arr['GoodsPassport']['is_allow_web'] = $product->getIsAllowWeb(); $arr['GoodsPassport']['update_at'] = $product->getUpdateAt() ? $product->getUpdateAt()->format('Y-m-d H:i:s') : null; $arr['GoodsPassport']['web_price'] = $product->getWebPrice(); $arr['GoodsPassport']['categorys'] = array(0); foreach ($product->getCategorys() as $category) { $arr['GoodsPassport']['categorys'][] = $category->getId(); } $i = 0; // Orders foreach ($product->getOrders() as $order) { $arr['Orders'][$i]['id'] = $order->getId(); $arr['Orders'][$i]['goods_passport_id'] = $product->getId(); $arr['Orders'][$i]['pay_type_id'] = $order->getPayType() ? $order->getPayType()->getId() : 0; $arr['Orders'][$i]['status_id'] = $order->getStatus()->getId(); $arr['Orders'][$i]['kind_id'] = $order->getKind()->getId(); $arr['Orders'][$i]['custom_id'] = $order->getCustom() ? $order->getCustom()->getId() : 0; $arr['Orders'][$i]['memo'] = $order->getMemo(); $arr['Orders'][$i]['required'] = $order->getRequired(); $arr['Orders'][$i]['paid'] = $order->getPaid(); $arr['Orders'][$i]['relate_id'] = $order->getParent() ? $order->getParent()->getId() : 0; $arr['Orders'][$i]['invoice_id'] = $order->getInvoice() ? $order->getInvoice()->getId() : 0; $arr['Orders'][$i]['org_required'] = $order->getOrgRequired(); $arr['Orders'][$i]['org_paid'] = $order->getOrgPaid(); // Ope $j = 0; foreach ($order->getOpes() as $ope) { //$arr['Ope'][]['orders_id'] = $order->get; $arr['Ope'][$order->getId()][$j]['user_id'] = $ope->getUser() ? $ope->getUser()->getId() : 0; $arr['Ope'][$order->getId()][$j]['act'] = $ope->getAct(); $arr['Ope'][$order->getId()][$j]['datetime'] = $ope->getDatetime()->format('Y-m-d H:i:s'); $arr['Ope'][$order->getId()][$j]['memo'] = $ope->getMemo(); $j++; } $i++; } return $arr; }
/** * 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; }