Example #1
0
 /**
  * @Route("/api/{id}/batch", requirements={"id" = "\d+"}, name="admin_yahoo_api_batch", options={"expose"=true})
  * @ParamConverter("brand", class="WoojinGoodsBundle:Brand")
  * @Method("GET")
  */
 public function batchUpload(Brand $brand, Request $request)
 {
     set_time_limit(0);
     // 3 is brand Chanel
     if ($brand->getId() !== 6) {
         throw new \Exception('品牌不正確! 要是Parada');
     }
     if ($request->query->get('token') !== 'mk123OOpadkkk!3r1') {
         throw $this->createNotFoundException();
     }
     list($client, $session) = $this->getNeededServices();
     $em = $this->getDoctrine()->getManager();
     $qb = $em->createQueryBuilder();
     $qb->select('g')->from('WoojinGoodsBundle:GoodsPassport', 'g')->where($qb->expr()->andX($qb->expr()->eq('g.brand', $brand->getId()), $qb->expr()->eq('g.status', Avenue::GS_ONSALE), $qb->expr()->eq('g.isAllowWeb', true), $qb->expr()->isNull('g.yahooId')));
     $products = $qb->getQuery()->getResult();
     foreach ($products as $key => $product) {
         echo $product->getSn() . ", 品牌:" . $product->getBrand()->getName() . ", 狀態:" . $product->getStatus()->getName();
         echo "<br />";
     }
     foreach ($products as $product) {
         $r = new \stdClass();
         $r->product = $product;
         // 付費方式
         $r->mallCategoryId = $brand->getYc()->getYahooId();
         $r->storeCategoryIds = $this->assignStoreCategory($product);
         $r->payTypeIds = array(1, 2, 4, 5, 6, 7, 12);
         $r->shippingIds = array(2);
         //$this->updateMainFlow($product, $session, $client, $r);
         if ($this->createMainFlow($product, $session, $client, $r)) {
             if ($this->uploadImageFlow($product, $session, $client)) {
                 $this->onlineFlow($product, $session, $client);
             }
         }
         echo $product->getSn();
         echo "<br />";
         unset($r);
         unset($product);
         sleep(1);
     }
     return new Response('---- OK ----- 共' . count($products) . '筆');
 }