· 8 years ago · Jan 23, 2017, 08:00 AM
1public function indexAction()
2 {
3 try {
4
5 $this->init([]);
6
7 $oGroupbuy = $entityManager->getRepository('ORORI\GroupbuyBundle\Entity\Groupbuy')->find(161);
8 var_dump($oGroupbuy); die;
9 $rule = $entityManager->getRepository('ORORI\GroupbuyBundle\Entity\GroupbuyRule')->findOneBy(array('isActive'=>1, 'groupbuy'=>$oGroupbuy), array('participant'=>'desc'));
10 var_dump($rule); die;
11 // kirim email ke seluruh member yang sudah join sebelumnya
12 $customersRepo = $this->getDoctrine()->getRepository('ORORI\GroupbuyBundle\Entity\GroupbuyCustomer');
13 foreach ($customersRepo->findBy(array('isActive'=>1, 'groupbuy'=>$oGroupbuy)) as $o){
14 $this->sendEmailGroupbuyDeal($oGroupbuy, $rule, $o->getCustomer(), $o->getShoppingCart());
15 }
16
17 /*$promoRepo = $this->em->getRepository('ORORICoreBundle:Promo');
18 $tomorrow = date('Y-m-d', strtotime('tomorrow'));
19 $today = date('Y-m-d');
20 $sql = $promoRepo->createQueryBuilder('p')
21 ->andWhere("p.meta LIKE '%\"rule-id\":%'")
22 ->andWhere("p.endDate >= '$today'")
23 ->andWhere("p.startDate < '$tomorrow'")
24 ->andWhere('p.isActive = 1')
25 ->addOrderBy('p.based', 'DESC')
26 ->addOrderBy('p.id', 'DESC')
27 ;
28
29 $query = $sql->getQuery();
30 $data = $query->getResult();
31
32 $newCondition = [];
33 foreach ($data as $o){
34 $newCondition = $promoRepo->convertMetaPromo($newCondition, $o->getMeta());
35 }
36 \Symfony\Component\VarDumper\VarDumper::dump($newCondition);
37
38 $a = file_get_contents('http://search.orori.com/autocomplete/lr-100?limit=5&offset=0');
39 \Symfony\Component\VarDumper\VarDumper::dump(\GuzzleHttp\json_decode($a));die;
40 $this->cleanNewsletter();
41
42
43 $prodRepo = $this->em->getRepository('ORORICoreBundle:Product');
44 \Symfony\Component\VarDumper\VarDumper::dump($prodRepo->getPromoDMO());die;
45 $this->exportDictionary();*/
46
47 } catch (\Exception $e) {
48 \Symfony\Component\VarDumper\VarDumper::dump($e->getMessage() .' '. $e->getLine());
49 }
50 }
51
52 private function sendEmailGroupbuyDeal($groupbuy, $rule, $customer, $cart)
53 {
54 try {
55 $product=$cart->getProduct();
56
57 /* @var $prodRepo \ORORI\CoreBundle\Repository\ProductRepository */
58 $prodRepo = $this->getDoctrine()->getManager()->getRepository('ORORICoreBundle:Product');
59 $frontEndData=$prodRepo->getFrontendEntityData($product, (array) $cart->getMeta());
60
61 $sql = "SELECT oauth_token.token FROM oauth_token
62 JOIN `shopping_cart` ON shopping_cart.customer_id=oauth_token.customer_id
63 WHERE oauth_token.customer_id='{$customer->getId()}' ORDER BY oauth_token.id desc LIMIT 1";
64 $stmt = $this->getDoctrine()->getManager()->getConnection()->prepare($sql);
65 $stmt->execute();
66 $oauthToken = $stmt->fetchAll();
67
68 $this->get('gearman')->doBackgroundJob(
69 \ORORI\CoreBundle\Gearman\JobName::GROUPBUY_DEAL, json_encode([
70 'email' => $customer->getEmail(),
71 'fullname' => $customer->getFirstname() .' '. $customer->getLastname(),
72 'cart_page_cookie' => $cart->getPageCookie(),
73 'cart_id' => $cart->getId(),
74 'product_code' => $product->getCode(),
75 'product_name' => $product->getName(),
76 'product_calculated_price' => $frontEndData['calculated_price'],
77 'product_final_price' => $frontEndData['final_price'],
78 'groupbuy_discount_value' =>$frontEndData['groupbuy_discount_value'],
79 'product_description' => $product->getDescription(),
80 'product_main_image' =>$product->getMainImage(),
81 'product_meta' => $product->getMeta(),
82 'disc_type' => $groupbuy->getDiscountType(),
83 'disc' => $rule->getDiscount(),
84 'access_token' => $oauthToken[0]['token']
85 ]));
86 } catch (JobDoesNotExistException $e) {
87 var_dump($e->getMessage());
88 return $this->log($e);
89 } catch (WorkerDoesNotExistException $e) {
90 var_dump($e->getMessage());
91 return $this->log($e);
92 }
93 }