nebukad

checkout

Jan 5th, 2017
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 39.43 KB | None | 0 0
  1. <?php
  2.  
  3. namespace ORORI\FrontendBundle\Controller;
  4.  
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\HttpFoundation\Request;
  7.  
  8. class CartController extends MainController
  9. {
  10.    
  11.     private $diamondPromo = [
  12.     ];
  13.     private $clearencePromo = [
  14.         'WP-1014',
  15.         'WP-1041',
  16.         'WP-1029',
  17.         'WP-1033',
  18.         'WP-1026',
  19.         'WP-1028',
  20.         'WP-1024',
  21.         'WP-1032',
  22.         'WP-1067',
  23.         'WR-1023',
  24.         'WR-1033',
  25.         'WR-1028',
  26.         'WR-1026',
  27.         'WR-1060',
  28.         'WR-1021',
  29.         'WR-1025',
  30.         'WR-1010',
  31.         'WR-1031',
  32.         'WR-1034',
  33.         'WR-1040',
  34.         'WR-1050',
  35.         'WR-1065'
  36.     ];
  37.     private $satujutavoucherPromo = [
  38.         'VC-FLASH-1000-GOLD'
  39.     ];
  40.    
  41.    
  42.     protected function rateLimitAccess()
  43.     {
  44.         $session = $this->get('session');
  45.  
  46.         $rateLimitQuota = $session->get('rate_limit_quota', null);   // quota of api call
  47.         $rateLimitRefresh = $session->get('rate_limit_refresh', null); // time to refresh quota
  48.  
  49.         $rateLimitWindow = 1 * 60; // minutes
  50.         $rateLimitMaxQuota = 5;      // 5 max requests per $rateLimitWindow
  51.  
  52.         if ($rateLimitQuota === null) {
  53.             $rateLimitQuota = $rateLimitMaxQuota;
  54.             $rateLimitRefresh = time() + $rateLimitWindow;
  55.         } else {
  56.             if ($rateLimitQuota == 0) {
  57.                 if ($rateLimitRefresh > time()) {
  58.                     return false;
  59.                 } else {
  60.                     $rateLimitRefresh = time() + $rateLimitWindow;
  61.                     $rateLimitQuota = $rateLimitMaxQuota;
  62.                 }
  63.             } else {
  64.                 --$rateLimitQuota;
  65.             }
  66.         }
  67.  
  68.         $session->set('rate_limit_quota',   $rateLimitQuota);
  69.         $session->set('rate_limit_refresh', $rateLimitRefresh);
  70.  
  71.         return true; // all good
  72.     }
  73.  
  74.     protected function checkVoucherAction(Request $request)
  75.     {
  76.         if ($this->rateLimitAccess() == false) {
  77.             return new JsonResponse(['status' => 'error', 'message' => 'Too many request'], 429);
  78.         }
  79.  
  80.         $request->request->set('method', 'GET');
  81.         $request->request->set('url', '/frontend/voucher/'.$request->query->get('voucher'));
  82.         $request->request->set('param', [
  83.             'shopping_cart_id' => $request->query->get('shoppingcart_id'),
  84.             'value' => $request->query->get('value'),
  85.         ]);
  86.  
  87.         $result = $this->apiAction($request);
  88.  
  89.         if ($result->getStatusCode() == 200) {
  90.             $response = json_decode($result->getContent());
  91.  
  92.             return new JsonResponse(['status' => 'success', 'voucher' => $response->voucher]);
  93.         } elseif ($result->getStatusCode() == 400) {
  94.             $response = json_decode($result->getContent());
  95.             $message = isset($response->error->user_message) ? $response->error->user_message : 'Invalid voucher'; // alias for 'server error'
  96.  
  97.             return new JsonResponse(['status' => 'error', 'message' => $message]);
  98.         } else {
  99.             return new JsonResponse([]);
  100.         }
  101.     }
  102.  
  103.     protected function deleteAction(Request $request)
  104.     {
  105.         $shop_id = array();
  106.         $ac = $request->query->get('ac');
  107.         $pg = $request->query->get('pg');
  108.  
  109.         $shoppingcart = $this->getShoppingCart($request, $ac, $pg);
  110.  
  111.         if (!$shoppingcart) {
  112.             return $this->redirect('/');
  113.         }
  114.         $x = 0;
  115.         foreach ($shoppingcart as $row) {
  116.             $shop_id[$x] = $row->id;
  117.             ++$x;
  118.         }
  119.  
  120.         return $this->render('ORORIFrontendBundle:Page:shopping-cart-thanks.html.twig', array(
  121.             'title' => 'Shopping Cart',
  122.             'id' => $shop_id,
  123.             'access_token' => $ac,
  124.             'page_cookie' => $pg,
  125.             'active' => 'cart',
  126.         ));
  127.     }
  128.  
  129.     protected function initializeShoppingcart(Request $request, $customer = null)
  130.     {
  131.         $shoppingCarts = $this->getShoppingCart($request, $request->cookies->get('access_token'), $request->cookies->get('pg'));
  132.  
  133.         if (!empty($shoppingCarts->shoppingcart)) {
  134.             $apply = false;
  135.             $isDiamondPromo = false;
  136.  
  137.             $payment_methode = [
  138.                 'transfer'      => true,
  139.                 'cc'            => true,
  140.                 'bca_cicilan'   => true,
  141.                 'cimb'          => true,
  142.                 'klikbca'       => true,
  143.                 'klikpay'       => true,
  144.                 'mandiriclickpay' => true,
  145.                 'mandirisms'    => false,
  146.                 'virtual'           => true,
  147.                 'edc'           => true
  148.             ];
  149.  
  150. //            $applyProductCategoryPrefix = ['custom_earring','custom_ring','custom_pendant', 'diamond'];
  151.             //https://app.asana.com/0/36113108136077/140737874362676
  152.             $applyProductCategoryPrefix = ['custom_earring','custom_ring','custom_pendant'];
  153.             $type_free = [
  154.                 'custom',
  155.                 'ring',
  156.                 'bridal',
  157.                 'rolletto',
  158.                 'signa',
  159.                 'diamondjewelry',
  160.                 'mensring',
  161.                 'goldjewelry',
  162.                 'engagement',
  163.                 'package',
  164.                 'customring',
  165.                 'dmo_ring',
  166.                 'ubs_fashion',
  167.                 'ubs_gold',
  168.                 'ubs_mensring',
  169.                 'ubs_womensring',
  170.                 'diamond'
  171.             ];
  172.             $bca_cicilan_except = [
  173.                 'gold_antam',
  174.                 'gold_pamp',
  175.                 'gold_dowry',
  176.                 'custom',
  177. //                'diamond',
  178.                 //'box',
  179.                 //'cleaning'
  180.             ];
  181.             $cc_except = [
  182.                 'gold_antam',
  183.                 'gold_pamp',
  184.                 'gold_dowry',
  185.                 //'box',
  186.                 //'cleaning'
  187.             ];
  188.             $bca_klikpay_except = [
  189.                 'gold_antam',
  190.                 'gold_pamp',
  191.                 'gold_dowry',
  192.                 //'box',
  193.                 //'cleaning'
  194.             ];
  195.             $titleExcept = ['diamond', 'gift', 'gold_antam', 'gold_pamp', 'gold_pendant_alphabet', 'bridal', 'rolletto', 'signa'];
  196.             $titleMapper = array(
  197.                 'box'               => 'Kotak',
  198.                 'cleaning'          => 'Pembersih',
  199.                 'custom_customer'   => 'Custom',
  200.                 'custom_for_customer'     => 'Custom',
  201.                 'customer_for_customer'   => 'Custom',
  202.                 'custom'            => 'My Custom Design',
  203.                 'custom_earring'    => 'Rangka Anting',
  204.                 'custom_pendant'    => 'Rangka Liontin',
  205.                 'custom_ring'       => 'Rangka Cincin',
  206.                 'custom_voucher'    => 'Voucher',
  207.                 'diamond_men_ring'  => 'Cincin Pria',
  208.                 'diamond_women_ring'      => 'Cincin Wanita',
  209.                 'diamond_pendant'   => 'Liontin Berlian',
  210.                 'diamond_earring'   => 'Anting Berlian',
  211.                 'diamond_religious' => 'Liontin Religius',
  212.                 'diamond_bracelet'      => 'Gelang Berlian',
  213.                 'alphabet_frame'    => 'Rangka Liontin',
  214.                 'alphabet_frame_yellow' => 'Rangka Liontin',
  215.                 'alphabet_frame_rose'   => 'Rangka Liontin',
  216.                 'gold_ankle_bracelet'   => 'Gelang Kaki',
  217.                 'gold_bracelet'     => 'Gelang Emas',
  218.                 'gold_earring'      => 'Anting Emas',
  219.                 'gold_necklace'     => 'Kalung Emas',
  220.                 'gold_pendant'      => 'Liontin Emas',
  221.                 'package'           => 'Paket Perhiasan',
  222.                 'solitaire_ring'    => 'Love Ring',
  223.                 'solitaire_pendant' => 'Love Charm',
  224.                 'solitaire_earring' => 'Love Mee',
  225.                 'bestvalue'         => 'Cincin Kawin',
  226.                 'beauty'            => 'Cincin Kawin',
  227.                 'design'            => 'Cincin Kawin',
  228.                 'simply'            => 'Cincin Kawin',
  229.                 'ethnic'            => 'Cincin Kawin',
  230.                 'bridal'            => 'Bridal',
  231.                 'rolletto'          => 'Rolletto',
  232.                 'signa'             => 'Signa',
  233.                 'ubs_necklace'      => 'Kalung UBS',
  234.                 'ubs_earring'       => 'Anting UBS',
  235.                 'ubs_bracelet'      => 'Gelang UBS',
  236.                 'ubs_bangle'        => 'Gelang UBS',
  237.                 'ubs_pendant'       => 'Liontin UBS',
  238.                 'ubs_women_ring'    => 'Cincin Wanita UBS',
  239.                 'ubs_men_ring'      => 'Cincin Pria UBS',
  240.                 'ubs_kids'          => 'Perhiasan Anak UBS',
  241.                 'diamond_threestone' => 'Diamond Threestone',
  242.             );
  243.  
  244.             // Gold Bar, Loose Diamond, DMO, Jewelry Accessories, dan Alphabet pendant update
  245.             // email from marcella , Ketentuan Promo Bank ( 11-01-2016 11:23 )
  246. //            $ccExcept = array(
  247. //                'gold_antam',
  248. //                'gold_pamp',
  249. //                'gold_dowry',
  250. //                'gold_pendant_alphabet',
  251. //                'package',
  252. //                'box',
  253. //                'cleaning',
  254. //                'diamond',
  255. //                'custom_earring',
  256. //                'custom_pendant',
  257. //                'custom_ring',
  258. //                'custom'
  259. //            );
  260.  
  261.  
  262.             //- Gold Bar
  263.             //- Loose Diamond
  264.             //- DMO
  265.             //- Pendant Alphabet
  266.             //- promo sept
  267.  
  268.             $now = date('Y-m-d');
  269.             $cart_count = 0;
  270.  
  271. //            $productGarage = $this->container->getParameter('orori.garage.product');
  272. //            $garage_start = $this->container->getParameter('orori.garage.start');
  273. //            $garage_end = $this->container->getParameter('orori.garage.end');
  274.  
  275.             $bank_start = $this->container->getParameter('orori.bank.start');
  276.             $bank_end = $this->container->getParameter('orori.bank.end');
  277.  
  278.             $promo_bank_type = [
  279.                 'diamondjewelry',
  280.                 'mensring',
  281.                 'engagement'
  282.             ];
  283.  
  284.             $cookieFlashsale = ($request->cookies->get('flash-sale')) ? $request->cookies->get('flash-sale') : 0;
  285.  
  286.             $voucher_gold   = 0;
  287.             $voucher_free   = 0;
  288.             $hide_voucher   = 0;
  289.             $hide_cicilan   = 0;
  290.             $hide_goldpoint = 0;
  291.             $freeshipping   = 0;
  292.             $cc             = 0;
  293.             $box            = 0;
  294.             $point          = ($customer) ? $customer->point : 0;
  295.             $discount       = 0;
  296.             $subtotal       = 0;
  297.             $goldbar        = 0;
  298.             $sameday        = 0;
  299.             $issameday      = 0;
  300.             $notsameday     = 0;
  301.             $isgoldbar      = 0;
  302.             $isdiamond      = 0;
  303.             $isspecial      = 0;
  304.             $isnoinstallment= 0;
  305.             $isinstallment3 = 0;
  306.             $isinstallment6 = 0;
  307.             $isGroupbuy     = false;
  308.             $cartid         = array();
  309.             $promo          = array();
  310.             $container      = array();
  311.  
  312.             // promo variable exist
  313.             $promo_bank  = 0;
  314.             $promo_group_buy  = 0;
  315.             $isClearencePromo = false;
  316.             $isSatujutavoucherPromo = false;
  317.  
  318.             foreach ($shoppingCarts->shoppingcart as $key => $shoppingCart) {
  319.                 ++$cart_count;
  320.                 // surcharge checking
  321.                 if ($shoppingCart->product->category) {
  322.                     if (in_array($shoppingCart->product->category, $applyProductCategoryPrefix) || in_array($shoppingCart->product->sub_category, $applyProductCategoryPrefix) || $shoppingCart->product->type == 'customring') {
  323.                         $apply = true;
  324.                     }
  325.                 }
  326.                 // special promo checking
  327.                 if($shoppingCart->product->is_special_promo){
  328.                     ++$isspecial;
  329.                 }
  330.                 // allowed installment checking
  331.                 if($shoppingCart->product->is_allowed_installment_3){
  332.                     ++$isinstallment3;
  333.                 }
  334.                 if($shoppingCart->product->is_allowed_installment_6){
  335.                     ++$isinstallment6;
  336.                 }
  337.                 // no installment checking
  338.                 if(!$shoppingCart->product->is_allowed_installment_3 && !$shoppingCart->product->is_allowed_installment_6){
  339.                     ++$isnoinstallment;
  340.                 }
  341. //                // cashback checking
  342. //                if(!in_array($shoppingCart->product->category, $ccExcept) && $shoppingCart->product->final_price >=5000000){
  343. //                    ++$iscashback;
  344. //                    $promo['cashback'] = 500000;
  345. //                }
  346.                 // freeshipping checking
  347.                 if (in_array($shoppingCart->product->type, $type_free)) {
  348.                     ++$freeshipping;
  349.                 }
  350.                 // diamond promo check
  351.                 if (in_array($shoppingCart->product->code, $this->diamondPromo)) {
  352.                     $isDiamondPromo = true;
  353.                 }
  354.                 // clearence promo check
  355.                 if (in_array(strtoupper($shoppingCart->product->code), $this->clearencePromo)) {
  356.                     $isClearencePromo = true;
  357.                 }
  358.                 if (in_array(strtoupper($shoppingCart->product->code), $this->satujutavoucherPromo)) {
  359.                     $isSatujutavoucherPromo = true;
  360.                 }
  361.                 // group buy promo checking
  362.                 if($shoppingCart->product->groupbuy_discount_value > 0){
  363.                     ++$promo_group_buy;
  364.                 }
  365.                 // box shipping price exception
  366.                 if($shoppingCart->product->type=='box'){
  367.                     $total_box = $shoppingCart->count * $shoppingCart->product->final_price;
  368.                     $box += ($total_box);
  369.                     // box freeshipping
  370.                     if($total_box >= 3000000){
  371. //                        ++$freeshipping;
  372.                     }
  373.                 }
  374.                 // cleaning shipping price exception
  375.                 if($shoppingCart->product->type=='cleaning'){
  376.                     $total_cleaning = $shoppingCart->count * $shoppingCart->product->final_price;
  377.                     // cleaning freeshipping
  378.                     if($total_cleaning >= 3000000){
  379. //                        ++$freeshipping;
  380.                     }
  381.                 }
  382.                 // payment except
  383.                 if (in_array($shoppingCart->product->category, $bca_cicilan_except)) {
  384.                     $payment_methode['bca_cicilan'] =  false;
  385.                 }
  386.                 if (in_array($shoppingCart->product->category, $cc_except)) {
  387.                     $payment_methode['cc'] =  false;
  388.                     ++$cc;
  389.                 }
  390.                 if (in_array($shoppingCart->product->category, $bca_klikpay_except)) {
  391.                     $payment_methode['klikpay'] =  false;
  392.                 }
  393.                 // enable installment for mahar / dowry
  394.                 if($shoppingCart->product->category == 'gold_dowry'){
  395.                     $payment_methode['cc'] =  true;
  396.                     $payment_methode['bca_cicilan'] =  true;
  397.                     $cc=0;
  398.                 }
  399.                 // goldbar counter
  400.                 if ($shoppingCart->product->category == 'gold_antam' || $shoppingCart->product->category == 'gold_dowry' || $shoppingCart->product->category == 'gold_pamp') {
  401.                     ++$goldbar;
  402.                     if($shoppingCart->product->category == 'gold_antam') {
  403.                         ++$isgoldbar;
  404.                         if ($shoppingCart->product->code == 'antam-100gr-new' || $shoppingCart->product->code == 'antam-50gr-new') {
  405.                             ++$sameday;
  406.                         } else {
  407.                             ++$notsameday;
  408.                         }
  409.                     }
  410.                 }
  411.                 // diamond counter
  412.                 if ($shoppingCart->product->type == 'diamond') {
  413.                     ++$isdiamond;
  414.                 }
  415.                 // voucher gold 500 checking
  416.                 if($shoppingCart->product->code == 'VC-FLASH-500-GOLD'){
  417.                     ++$voucher_gold;
  418.                     $promo['voucher_gold'] = $voucher_gold;
  419.                 }
  420.                 if($shoppingCart->product->code == 'VC-FLASH-500' || $shoppingCart->product->code == 'VC-FLASH-1000'){
  421.                     ++$voucher_free;
  422.                     $promo['voucher_free'] = $voucher_free;
  423.                 }
  424.  
  425.                 // promo bank 1 april 2016 - 30 juni 2016
  426.                 if ($now >= $bank_start && $now <= $bank_end) {
  427.                     if (in_array($shoppingCart->product->type, $promo_bank_type) && $shoppingCart->product->is_special_promo == 0) {
  428.                         $promo_bank += $shoppingCart->product->final_price;
  429.                         $promo['bank'] = $promo_bank;
  430.                     }
  431.                 }
  432.                
  433.                 // Groupbuy checking
  434.                 if ($shoppingCart->product->groupbuy_discount > 0) {
  435.                     $isGroupbuy = true;
  436.                 }
  437.  
  438.                 // generate title
  439.                 if (in_array($shoppingCart->product->category, $titleExcept)) {
  440.                     if($shoppingCart->product->category == 'diamond'){
  441.                         $exp = explode('\\N', $shoppingCart->product->name);
  442.                         $title = $exp[0];
  443.                     }else{
  444.                         $title = $shoppingCart->product->name;
  445.                     }
  446.                 }else{
  447.                     $explode_code = explode('-', $shoppingCart->product->code);
  448.                     if(isset($explode_code[1])){
  449.                         $codes = ' ( '. $explode_code[1]. ' )';
  450.                     }else{
  451.                         $codes = '';
  452.                     }
  453.                     $title = $titleMapper[$shoppingCart->product->category].$codes;
  454.                 }
  455.  
  456.                 $subtotal += $shoppingCart->product->final_price * $shoppingCart->count;
  457.                 $discount += $shoppingCart->product->total_discount * $shoppingCart->count;
  458.                 $container[$key] = array(
  459.                     'id'    => $shoppingCart->id,
  460.                     'title' => $title,
  461.                     'image' => $this->getImageSize($shoppingCart->product->main_image,'s'),
  462.                     'quantity' => $shoppingCart->count,
  463.                     'price' => $shoppingCart->product->final_price,
  464.                     'category' => $shoppingCart->product->category
  465.                 );
  466.                 $cartid[$key] = $shoppingCart->id;
  467.             }
  468.             $total = array(
  469.                 'count'         => $cart_count,
  470.                 'sub_total'     => $subtotal,
  471.                 'discount'      => $discount,
  472.                 'shipping_box'  => $box
  473.             );
  474.  
  475. //            if($subtotal < 20000000) {
  476. //                $shipping = array(
  477. //                    array('id' => 11, 'text' => 'RPX Economy Package ( ECP ) (no extra insurance)'),
  478. //                    array('id' => 12, 'text' => 'RPX Next Day Package ( NDP ) (no extra insurance)')
  479. //                );
  480. //            }else{
  481. //                $shipping = array(
  482. //                    array('id' => 16, 'text' => 'RPX Economy Package ( ECP ) (extra insurance)'),
  483. //                    array('id' => 17, 'text' => 'RPX Next Day Package ( NDP ) (extra insurance)')
  484. //                );
  485. //            }
  486. //            if($goldbar == 0) {
  487. //                $shipping_methode = array_merge($shipping, $shipping_methode);
  488. //            }else{
  489. //                $shipping_methode = $shipping;
  490. //            }
  491.  
  492.             // sameday service
  493.             if($customer && $sameday == $cart_count && strtoupper($customer->shipping_province)=='DKI JAKARTA'){
  494. //            if(checkoutProcess.goldbarnew > 0 && provinsi.toUpperCase()=='DKI JAKARTA' && checkoutProcess.notsameDay == 0){
  495.                 $now    = date('Y-m-d',strtotime($shoppingCarts->timestamp->date));
  496.                 $night  = strtotime($now . ' 00:00:00');
  497.                 $day    = strtotime($now . ' 11:00:00');
  498.                 $today  = strtotime($shoppingCarts->timestamp->date);
  499.  
  500.                 // make sure time for sameday
  501.                 if($today > $night && $today < $day){
  502. //                    $same_shipping = array(
  503. //                        array('id' => 21, 'text' => 'SAME DAY SHIPPING ( Dikirim hari ini )')
  504. //                    );
  505.                     $issameday = 1;
  506. //                    $shipping_methode = array_merge($same_shipping, $shipping_methode);
  507.                 }
  508.             }
  509.  
  510.             // freeshipping except
  511. //            if($freeshipping > 0 && $subtotal < 3000000){
  512. //                if($voucher_free > 0 && $subtotal >= 3000000 && $cookieFlashsale == 0){
  513. //                    $freeshipping = 1;
  514. //                }else {
  515. //                    $freeshipping = 0;
  516. //                }
  517. //            }else{
  518. //                if($subtotal < 3000000) {
  519. //                    $freeshipping = 0;
  520. //                }
  521. //            }
  522.  
  523.             if($voucher_free == $cart_count) {
  524.                 $freeshipping = 1;
  525.             }
  526.  
  527. //            if($customer && strtoupper($customer->shipping_province)=='DKI JAKARTA' && $subtotal >= 2500000 && $cookieFlashsale == 0){
  528. //                $kurir = array(
  529. //                    array('id' => 0, 'text' => 'Kurir (Khusus Jakarta)')
  530. //                );
  531. //                $shipping_methode = array_merge($kurir, $shipping_methode);
  532. //            }
  533. //
  534. //            if($customer && strtoupper($customer->shipping_province)=='DKI JAKARTA' && $subtotal <= 1000000){
  535. //                $popbox = array(
  536. //                    array('id' => 31, 'text' => 'Pop Box (Khusus Jakarta)')
  537. //                );
  538. //                $shipping_methode = array_merge($popbox, $shipping_methode);
  539. //            }
  540.  
  541.             if(($freeshipping > 0 && $goldbar==0 && $subtotal >= 3000000 && $cookieFlashsale == 0) || ( $freeshipping > 0 && $voucher_free > 0 )){
  542. //            if(($isgoldbar==0 && $subtotal >= 3000000 && $cookieFlashsale == 0) || ( $voucher_free > 0 )){
  543.                 $freeshipping = 1;
  544.             }else{
  545.                 $freeshipping = 0;
  546.             }
  547.  
  548.             // no freeshipping for box & cleaning
  549. //            if($total_box > 0 || $total_cleaning > 0){
  550. //                $freeshipping = 0;
  551. //            }
  552.  
  553.             if($subtotal < 500000){
  554.                 $payment_methode['bca_cicilan'] = false;
  555.             }
  556.  
  557.             if($cookieFlashsale) {
  558.                 $payment_methode = [
  559.                     'transfer' => true,
  560.                     'cc' => true,
  561.                     'bca_cicilan' => false,
  562.                     'cimb' => true,
  563.                     'klikbca' => true,
  564.                     'klikpay' => true,
  565.                     'mandiriclickpay' => true,
  566.                     'mandirisms' => false,
  567.                     'virtual' => true,
  568.                     'edc' => true
  569.                 ];
  570.                 $apply = true;
  571.             }
  572.  
  573.             if($cc > 0) {
  574.                 $payment_methode['cc'] = false;
  575.             }
  576.  
  577.             $now = date('Y-m-d');
  578.             $flash_start = $this->container->getParameter('orori.flashsale.start');
  579.             $flash_end = $this->container->getParameter('orori.flashsale.end');
  580.             $cookieFlashsale = $request->cookies->get('flash-sale');
  581.  
  582.             // promo flashsale 27 nov 2015 - 29 nov 2015
  583.             // flashsale check customer
  584.             $error = '';
  585.             if ($now >= $flash_start && $now <= $flash_end && $cookieFlashsale) {
  586.                 if($customer) {
  587.                     $cek = $this->checkFlashSale($request, $customer->id);
  588.                     if(isset($cek->error)){
  589.                         $error = $cek->error;
  590.                     }
  591.                 }
  592.             }
  593.  
  594.             // overide installment
  595.             if($isnoinstallment > 0){
  596.                 $isinstallment3 = 0;
  597.                 $isinstallment6 = 0;
  598.                 $payment_methode['bca_cicilan'] =  false;
  599.             }else{
  600.                 if($isinstallment3 > $isinstallment6) {
  601.                     $isinstallment6 = 0;
  602.                 }
  603.             }
  604. //            echo '$isnoinstallment : '.$isnoinstallment.'<br>';
  605. //            echo '$isinstallment3 : '.$isinstallment3.'<br>';
  606. //            echo '$isinstallment6 : '.$isinstallment6.'<br>';
  607. //            echo '$cart_count : '.$cart_count.'<br>';
  608.  
  609.             if($isspecial>0){
  610. //                $iscashback = 0;
  611.                 $promo = array();
  612.             }
  613.  
  614.             if ($isDiamondPromo) {
  615.                 $payment_methode = [
  616.                     'transfer'      => true,
  617.                     'cc'            => false,
  618.                     'bca_cicilan'   => false,
  619.                     'cimb'          => false,
  620.                     'klikbca'       => true,
  621.                     'klikpay'       => false,
  622.                     'mandiriclickpay' => false,
  623.                     'mandirisms'    => false,
  624.                     'virtual'       => false,
  625.                     'edc'           => false
  626.                 ];
  627.             }
  628.  
  629.             // Hide for a while because still error
  630.             $payment_methode['bca_cicilan'] =  false;
  631.  
  632.             // For special product can use voucher promo
  633.             $startSpecialVoucher = \DateTime::createFromFormat('Y-m-d H:i:s', '2016-05-17 00:00:00');
  634.             $endSpecialVoucher   = \DateTime::createFromFormat('Y-m-d H:i:s', '2016-05-20 23:59:59');
  635.             $nowVoucher          = new \DateTime();
  636.             if ($startSpecialVoucher <= $nowVoucher && $nowVoucher <= $endSpecialVoucher) {
  637.                 $hide_voucher = 0;
  638.                 $eternity  = ['WR-1097','WR-1098','WR-1099','WR-1100','WR-1101',
  639.                               'WR-1102','WR-1103','WR-1104','WR-1105','WR-1106',];
  640.                
  641.                 foreach ($shoppingCarts->shoppingcart as $key => $cart) {
  642.                     if (in_array($cart->product->code , $eternity)) {
  643.                         $hide_voucher = 1;
  644.                         break;
  645.                     } else if (!in_array(strtolower($cart->product->category), ['solitaire_ring','solitaire_earring','solitaire_pendant','diamond_women_ring',
  646.                         'diamond_men_ring','diamond_pendant','diamond_earring','diamond_religious']) && $cart->product->type !== 'ring') {
  647.                         $hide_voucher = 1;
  648.                         break;
  649.                     }
  650.                 }
  651.             }
  652.            
  653.             // Hide VA on production
  654.             $env = $this->get('kernel')->getEnvironment();
  655.             if ($env == 'prod')
  656.                 $payment_methode['virtual'] = false;
  657.  
  658.             // freeshipping all item
  659.             $startFreeshipping = \DateTime::createFromFormat('Y-m-d H:i:s', '2016-06-08 00:00:00');
  660.             $endFreeshipping   = \DateTime::createFromFormat('Y-m-d H:i:s', '2016-06-16 23:59:59');
  661.             $nowVoucher          = new \DateTime();
  662.             if ($startFreeshipping <= $nowVoucher && $nowVoucher <= $endFreeshipping) {
  663.                 if($customer && strtoupper($customer->shipping_province)!='DKI JAKARTA') {
  664.                     if($isgoldbar + $isdiamond == $cart_count){
  665.                         $freeshipping = 0;
  666.                     }else{
  667.                         $freeshipping = 1;
  668.                     }
  669.                 }else{
  670.                     $freeshipping = 1;
  671.                     $isgoldbar = 0;
  672.                 }
  673.             }
  674.             $now = date('Y-m-d');
  675.             $error = '';
  676.             $flash_start = $this->container->getParameter('orori.flashsale.start');
  677.             $flash_end = $this->container->getParameter('orori.flashsale.end');
  678.             $access_token = $request->cookies->get('access_token');
  679.             $cookieFlashsale = $request->cookies->get('flash-sale');
  680.  
  681.             // promo flashsale 27 nov 2015 - 29 nov 2015
  682.             if ($now >= $flash_start && $now <= $flash_end && $cookieFlashsale) {
  683.                 if($access_token && $customer) {
  684.                     $freeshipping = 0;
  685.                 }
  686.             }
  687.  
  688.             if($promo_group_buy > 0) {
  689.                 if(isset($customer) && isset($customer->email) && ($customer->email === '[email protected]' || $customer->email === '[email protected]')) {
  690.                     $payment_methode = [
  691.                         'transfer' => true,
  692.                         'cc' => true,
  693.                         'bca_cicilan' => false,
  694.                         'cimb' => true,
  695.                         'klikbca' => true,
  696.                         'klikpay' => true,
  697.                         'mandiriclickpay' => true,
  698.                         'mandirisms' => false,
  699.                         'virtual' => true,
  700.                         'edc' => true
  701.                     ];
  702.                 }else {
  703.                     $payment_methode = [
  704.                         'transfer' => true,
  705.                         'cc' => false,
  706.                         'bca_cicilan' => false,
  707.                         'cimb' => false,
  708.                         'klikbca' => false,
  709.                         'klikpay' => false,
  710.                         'mandiriclickpay' => false,
  711.                         'mandirisms' => false,
  712.                         'virtual' => false,
  713.                         'edc' => false
  714.                     ];
  715.                 }
  716.                 $hide_voucher = 1;
  717.                 $hide_cicilan = 1;
  718.                 $hide_goldpoint = 1;
  719.             }
  720.  
  721.             if($isClearencePromo) {
  722.                 $payment_methode = [
  723.                     'transfer'  => true,
  724.                     'cc'        => false,
  725.                     'bca_cicilan' => false,
  726.                     'cimb'      => false,
  727.                     'klikbca'   => false,
  728.                     'klikpay'   => false,
  729.                     'mandiriclickpay' => false,
  730.                     'mandirisms'=> false,
  731.                     'virtual'   => false,
  732.                     'edc'       => false
  733.                 ];
  734.             }
  735.            
  736.             if($isSatujutavoucherPromo) {
  737.                 $hide_voucher = 1;
  738.             }
  739.  
  740.             if($isspecial > 0){
  741.                 $hide_voucher = 1;
  742.             }
  743.  
  744.             $cc_installment = array();
  745.             if ($apply){
  746.                 if ($hide_cicilan > 0) {
  747.                     $cc_installment['full'] = 'Full Payment';
  748.                 }else{
  749.                     $cc_installment['full'] = 'Full Payment';
  750.                     if ($isinstallment3 && $isinstallment3 > 0 && $subtotal >= 500000) {
  751.                         $cc_installment['anz-3'] = 'ANZ 3 bulan(5 %)';
  752.                         $cc_installment['cimb-3'] = 'CIMB 3 bulan(6 %)';
  753.                         $cc_installment['sc-3'] = 'Standard Chartered 3 bulan(4.5 %)';
  754.                     }
  755.                 }
  756.             }else {
  757.                 if ($hide_cicilan > 0) {
  758.                     $cc_installment['full'] = 'Full Payment';
  759.                 } else {
  760.                     $cc_installment['full'] = 'Full Payment';
  761.                     if ($isinstallment3 && $isinstallment3 > 0 && $subtotal >= 500000) {
  762.                         $cc_installment['anz-3'] = 'ANZ 3 bulan(0 %)';
  763.                         $cc_installment['cimb-3'] = 'CIMB 3 bulan(0 %)';
  764.                         $cc_installment['sc-3'] = 'Standard Chartered 3 bulan(0 %)';
  765.                         $cc_installment['mandiri-3'] = 'Mandiri 3 bulan(0 %)';
  766.                         $cc_installment['bca-3'] = 'BCA 3 bulan(0 %)';
  767.                     }
  768.                     if ($isinstallment6 && $isinstallment6 > 0 && $subtotal >= 500000) {
  769.                         $cc_installment['hsbc-6'] = 'HSBC 6 bulan(0 %)';
  770.                         $cc_installment['anz-6'] = 'ANZ 6 bulan(0 %)';
  771.                         $cc_installment['cimb-6'] = 'CIMB 6 bulan(0 %)';
  772.                         $cc_installment['sc-6'] = 'Standard Chartered 6 bulan(0 %)';
  773.                         $cc_installment['mandiri-6'] = 'Mandiri 6 bulan(0 %)';
  774.                     }
  775.                 }
  776.             }
  777.            
  778. //            echo "".$isgoldbar."<br>";
  779. //            echo "".$isdiamond."<br>";
  780. //            echo "".$cart_count."<br>";
  781. //            echo "".$freeshipping."<br>";
  782. //            echo "".$customer->shipping_province."<br>";
  783. //            die;
  784.            
  785.             return [
  786.                 'apply'             => $apply,
  787.                 'total'             => $total,
  788.                 'freeshipping'      => $freeshipping,
  789.                 'payment_methode'   => $payment_methode,
  790. //                'shipping_methode'  => $shipping_methode,
  791.                 'promo'             => $promo,
  792.                 'cart'              => $container,
  793.                 'cartid'            => $cartid,
  794.                 'customer'          => $customer,
  795.                 'sameday'           => $issameday,
  796.                 'point'             => $point,
  797.                 'error'             => $error,
  798.                 'is_diamond'        => $isdiamond,
  799.                 'is_goldbar'        => $isgoldbar,
  800.                 'is_special'        => $isspecial,
  801.                 'installment'       => $cc_installment,
  802.                 'flashsale'         => ($cookieFlashsale) ? $cookieFlashsale : 0,
  803.                 'hide_voucher'      => $hide_voucher,
  804.                 'hide_cicilan'      => $hide_cicilan,
  805.                 'hide_goldpoint'      => $hide_goldpoint
  806.             ];
  807.         }
  808.         return [];
  809.     }
  810.  
  811.     public function getImageSize($src, $size)
  812.     {
  813.         $img = explode('/', $src);
  814.         if ($img[0]) {
  815.             $imgname = end($img);
  816.             $split = explode('.', $imgname);
  817.             $path = explode($imgname, $src);
  818.             $result = $path[0].$split[0].'_'.$size.'.'.$split[1];
  819.         } else {
  820.             $result = '';
  821.         }
  822.  
  823.         return $result;
  824.     }
  825.  
  826.     public function generateURLs($category, $code, $meta, $id=0){
  827.         $mapper = array(
  828.             'simply'                => 'wedding',
  829.             'beauty'                => 'wedding',
  830.             'design'                => 'wedding',
  831.             'palladium'             => 'wedding',
  832.             'silver'                => 'wedding',
  833.             'bestvalue'             => 'wedding',
  834.             'best_design'           => 'wedding',
  835.             'exclusive'             => 'wedding',
  836.             'solitaire_ring'        => 'solitaire',
  837.             'solitaire_earring'     => 'solitaire',
  838.             'solitaire_pendant'     => 'solitaire',
  839.             'diamond_women_ring'    => 'jewelry',
  840.             'diamond_men_ring'      => 'jewelry',
  841.             'diamond_earring'       => 'jewelry',
  842.             'diamond_bracelet'      => 'jewelry',
  843.             'diamond_pendant'       => 'jewelry',
  844.             'diamond_religious'     => 'jewelry',
  845.             'diamond_religious_moslem'     => 'jewelry',
  846.             'gold_ring'             => 'jewelry',
  847.             'gold_pendant'          => 'jewelry',
  848.             'gold_bracelet'         => 'jewelry',
  849.             'gold_earring'          => 'jewelry',
  850.             'gold_necklace'         => 'jewelry',
  851.             'gold_pendant_alphabet' => 'jewelry',
  852.             'alphabet_frame'        => 'jewelry',
  853.             'gold_ankle_bracelet'   => 'jewelry',
  854.             'box'                   => 'jewelry',
  855.             'cleaning'              => 'jewelry',
  856.             'others'                => 'jewelry',
  857.             'custom'                => 'jewelry',
  858.             'custom_customer'       => 'jewelry',
  859.             'custom_for_customer'     => 'jewelry',
  860.             'customer_for_customer'   => 'jewelry',
  861.             'custom_earring'        => 'jewelry',
  862.             'custom_pendant'        => 'jewelry',
  863.             'custom_ring'           => 'jewelry',
  864.             'custom_voucher'        => 'jewelry',
  865.             'package'               => 'package',
  866.             'diamond'               => 'diamond',
  867.             'bridal'                => 'bridal-detail',
  868.             'rolletto'              => 'rolletto-detail',
  869.             'signa'                 => 'signa-detail',
  870.             'gold_dowry'            => 'goldbar',
  871.             'gold_antam'            => 'antam-goldbar',
  872.             'gold_pamp'             => 'pamp-goldbar',
  873.             'ubs_necklace'          => 'jewelry',
  874.             'ubs_earring'           => 'jewelry',
  875.             'ubs_bracelet'          => 'jewelry',
  876.             'ubs_bangle'            => 'jewelry',
  877.             'ubs_pendant'           => 'jewelry',
  878.             'ubs_women_ring'        => 'jewelry',
  879.             'ubs_men_ring'          => 'jewelry',
  880.             'diamond_threestone'    => 'engagement'
  881.         );
  882.  
  883.         $paramMeta = http_build_query($meta);
  884.         if ($category == 'diamond') {
  885.             $url = '/' . $mapper[$category] . '/product/' . $category . '/' . $id;
  886.         } else {
  887.             if($category == 'gold_pendant_alphabet'){
  888.                 $code_split = explode('-', $code);
  889.  
  890.                 if(array_pop($code_split) == 'Y') $code = implode('-', $code_split).'-W';
  891.             }
  892.             $url = '/' . $mapper[$category] . '/product/' . $category . '/' . $code . '?' . $paramMeta;
  893.  
  894.         }
  895.         if ($category == 'bridal' || $category == 'rolletto' || $category == 'signa') {
  896.             $url = '/' . $mapper[$category] . '?' . $paramMeta;
  897.         }
  898.         if ($category == 'gold_antam') {
  899.             $url = '/' . $mapper[$category] . '?' . $paramMeta;
  900.         }
  901.         if ($category == 'gold_pamp') {
  902.             $url = '/' . $mapper[$category];
  903.         }
  904.  
  905.         return $url;
  906.     }
  907.  
  908.     public function getUserInfo(Request $request)
  909.     {
  910.         $me = null;
  911.  
  912.         if ($request->cookies->has('access_token')) {
  913.             // get '/me'
  914.             $request->request->set('method', 'GET');
  915.             $request->request->set('url', '/me');
  916.  
  917.             $result = $this->apiAction($request);
  918.  
  919.             if ($result->getStatusCode() == 200) {
  920.                 $response = json_decode($result->getContent());
  921.  
  922.                 $me = $response->customer;
  923.             } else {
  924.                 $me = $result->getStatusCode();
  925.                 $request->cookies->remove('access_token');
  926.             }
  927.         }
  928.  
  929.         return $me;
  930.     }
  931.  
  932.     public function calculateGoldPoint(Request $request, $type, $value)
  933.     {
  934.         $me = 0;
  935.  
  936.         $request->request->set('method', 'GET');
  937.         $request->request->set('url', '/gold-point/calculate');
  938.         $request->request->set('param', [
  939.             'type' => $type,
  940.             'value' => $value,
  941.         ]);
  942.         $result = $this->apiAction($request);
  943.  
  944.         if ($result->getStatusCode() == 200) {
  945.             $response = json_decode($result->getContent());
  946.  
  947.             $me = $response;
  948.         } else {
  949.             $request->cookies->remove('access_token');
  950.         }
  951.  
  952.         return $me;
  953.     }
  954.  
  955.     public function checkFlashSale($request, $id)
  956.     {
  957.         $me = null;
  958.  
  959.         // get
  960.         $request->request->set('method', 'GET');
  961.         $request->request->set('url', '/promotion/flash-sales/check-customer/' .$id);
  962.  
  963.         $result = $this->apiAction($request);
  964.  
  965.         if ($result->getStatusCode() == 200) {
  966.             $response = json_decode($result->getContent());
  967.  
  968.             $me = $response;
  969.         }else{
  970.             $response = json_decode($result->getContent());
  971.  
  972.             $me = $response;
  973.         }
  974.  
  975.         return $me;
  976.     }
  977. }
Advertisement
Add Comment
Please, Sign In to add comment