/** * @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) . '筆'); }
public function getImgRelDir(User $user) { $dirParts = array(); $dirParts[] = 'img'; $dirParts[] = 'product'; $dirParts[] = $user->getStore()->getSn(); $dirParts[] = $this->brand ? $this->brand->getName() : 'NoBrand'; $dirParts[] = $this->pattern ? $this->pattern->getName() : 'NoPattern'; $dirParts[] = $this->sn; return '/' . implode('/', $dirParts); }
/** * 品牌批次上傳自動添加程序 * * @param [string] $sBrandName [品牌名稱] * @param [string] $sBrandTypeName [款式名稱] * @param [string] $sBrandSnName [型號名稱] * @param [string] $sBrandSnColor [型號顏色] * @return [object] [this] */ protected function brandAutoProcess($sBrandName, $sBrandTypeName, $sBrandSnName, $sBrandSnColor, $colorName) { // 取得實體管理員 $em = $this->em; // 判斷品牌是否存在 // 若存在則繼續檢查款式是否存在 // 若不存在則新增傳入的品牌, 款式, 型號 // $this->oBrandSn 這行是用來讓商品綁上此型號物件用 , // 透過屬性比較快, 直接回傳也是可以可是失去鏈結性有點不喜歡 $rBrand = $this->getDoctrine()->getRepository('WoojinGoodsBundle:Brand')->findBy(array('name' => $sBrandName)); if ($rBrand) { $oBrand = $rBrand[0]; } else { $oBrand = new Brand(); $oBrand->setName($sBrandName); $em->persist($oBrand); } if ($colorName != '') { $colors = $this->getDoctrine()->getRepository('WoojinGoodsBundle:Color')->findBy(array('name' => $colorName)); if ($colors) { $color = $colors[0]; } else { $color = new Color(); $color->setName($colorName)->setCode('#FFFFFF'); $em->persist($color); } } else { $color = null; } if ($sBrandTypeName != '') { // 判斷款式是否存在 // 若存在則繼續檢查型號是否存在 // 若不存在則新增傳入的 款式, 型號 $patterns = $this->getDoctrine()->getRepository('WoojinGoodsBundle:Pattern')->findBy(array('name' => $sBrandTypeName)); if ($patterns) { $pattern = $patterns[0]; } else { $pattern = new Pattern(); $pattern->setName($sBrandTypeName); $em->persist($pattern); } } $em->flush(); $this->brand = $oBrand; $this->color = $color; $this->pattern = $pattern; return $this; }