public function dailyspecialDetails(Request $request)
 {
     $postData = $request->all();
     $response = new stdClass();
     $objUserModel = new User();
     if ($postData) {
         $userId = '';
         if (isset($postData['id'])) {
             $userId = $postData['id'];
         }
         $mytoken = '';
         $authflag = false;
         if (isset($postData['mytoken'])) {
             $mytoken = $postData['mytoken'];
             if ($mytoken == env("API_TOKEN")) {
                 $authflag = true;
             } else {
                 if ($userId != '') {
                     $whereForloginToken = $userId;
                     DB::setFetchMode(PDO::FETCH_ASSOC);
                     $Userscredentials = $objUserModel->getUsercredsWhere($whereForloginToken);
                     if ($mytoken == $Userscredentials['login_token']) {
                         $authflag = true;
                     }
                 }
             }
         }
         if ($authflag) {
             //LOGIN TOKEN
             DB::setFetchMode(PDO::FETCH_ASSOC);
             $objCampaingsModel = new Campaigns();
             $dailyDetails = $objCampaingsModel->getDailyspecialDetail();
             if ($dailyDetails) {
                 $data = $dailyDetails;
                 $response->code = 200;
                 $response->message = "Success";
                 $response->data = $data;
             } else {
                 $response->code = 100;
                 $response->message = "Something went Wrong. No Product Details found.";
                 $response->data = null;
             }
         } else {
             $response->code = 401;
             $response->message = "Access Denied";
             $response->data = null;
         }
     } else {
         $response->code = 401;
         $response->message = "Invalid request";
         $response->data = null;
     }
     echo json_encode($response, true);
 }
 /**
  * Flashsale Ajax Handler
  * @param Request $request
  * @author: Vini Dubey<*****@*****.**>
  */
 public function flashsaleAjaxHandler(Request $request)
 {
     $method = $request->input('method');
     $objUserModel = new User();
     $objCategoryModel = ProductCategories::getInstance();
     $objProductModel = Products::getInstance();
     $objOptionVariant = ProductOptionVariants::getInstance();
     $objCampaigns = Campaigns::getInstance();
     if ($method != "") {
         switch ($method) {
             case 'optionVariantDetails':
                 $postData = $request->all();
                 $response = new stdClass();
                 if ($postData) {
                     $userId = '';
                     if (isset($postData['id'])) {
                         $userId = $postData['id'];
                     }
                     $productId = '';
                     if (isset($postData['variant_id'])) {
                         $variantId = $postData['variant_id'];
                     }
                     if (isset($postData['product_id'])) {
                         $productId = $postData['product_id'];
                     }
                     if (isset($postData['selectedCombination'])) {
                         $selectedCombination = $postData['selectedCombination'];
                     }
                     $mytoken = '';
                     $authflag = false;
                     if (isset($postData['api_token'])) {
                         $mytoken = $postData['api_token'];
                         if ($mytoken == env("API_TOKEN")) {
                             $authflag = true;
                         } else {
                             if ($userId != '') {
                                 $whereForloginToken = $userId;
                                 $Userscredentials = $objUserModel->getUsercredsWhere($whereForloginToken);
                                 if ($mytoken == $Userscredentials['login_token']) {
                                     $authflag = true;
                                 }
                             }
                         }
                     }
                     $variantDetails = '';
                     if ($authflag) {
                         $where = ['rawQuery' => 'product_option_variants_combination.product_id = ? AND product_option_variants_combination.variant_ids IN("' . $selectedCombination . '","' . strrev($selectedCombination) . '")', 'bindParams' => [$productId]];
                         $selectedColumn = ['product_option_variants.*', 'product_images.*', 'product_option_variants_combination.*', 'product_option_variant_relation.*', DB::raw('GROUP_CONCAT(
                 CASE
                 WHEN ((SELECT COUNT(pi_id) FROM product_images  WHERE product_images.for_combination_id !="0")!=0)
                 THEN
                     CASE
                         WHEN (product_images.image_type =1 AND (product_images.for_combination_id!=0 OR product_images.for_combination_id!=""))
                         THEN product_images.image_type
                      END
                  ELSE  product_images.image_type
                 END) AS image_types'), DB::raw('GROUP_CONCAT(DISTINCT
                 CASE
                 WHEN ((SELECT COUNT(pi_id) FROM product_images  WHERE product_images.for_combination_id !="0")!=0)
                 THEN
                     CASE
                         WHEN (product_images.image_type =1 AND (product_images.for_combination_id!=0 OR product_images.for_combination_id!=""))
                         THEN product_images.image_url
                      END
                  ELSE  product_images.image_url
                 END) AS image_urls'), DB::raw('GROUP_CONCAT(DISTINCT product_option_variants_combination.variant_ids) AS variant_ids_combination'), DB::raw('GROUP_CONCAT(DISTINCT product_option_variant_relation.variant_ids) AS variant_id')];
                         $optionVariantDetailsForPopUp = $objOptionVariant->getOptionVariantDetailsForPopup($where, $selectedColumn);
                         //  echo'<pre>';print_r($optionVariantDetailsForPopUp);die("fchb");
                         if ($optionVariantDetailsForPopUp[0]) {
                             $response->code = 200;
                             $response->message = "Success";
                             $response->data = $optionVariantDetailsForPopUp[0];
                         } else {
                             $response->code = 100;
                             $response->message = "Something went Wrong. No Product Details found.";
                             $response->data = null;
                         }
                     } else {
                         $response->code = 401;
                         $response->message = "Access Denied";
                         $response->data = null;
                     }
                 } else {
                     $response->code = 401;
                     $response->message = "Invalid request";
                     $response->data = null;
                 }
                 echo json_encode($response, true);
             case 'getCampaignsForMenu':
                 $postData = $request->all();
                 $response = new stdClass();
                 if ($postData) {
                     $userId = '';
                     if (isset($postData['id'])) {
                         $userId = $postData['id'];
                     }
                     $mytoken = '';
                     $authflag = false;
                     if (isset($postData['api_token'])) {
                         $mytoken = $postData['api_token'];
                         if ($mytoken == env("API_TOKEN")) {
                             $authflag = true;
                         } else {
                             if ($userId != '') {
                                 $whereForloginToken = $userId;
                                 $Userscredentials = $objUserModel->getUsercredsWhere($whereForloginToken);
                                 if ($mytoken == $Userscredentials['login_token']) {
                                     $authflag = true;
                                 }
                             }
                         }
                     }
                     $variantDetails = '';
                     if ($authflag) {
                         $where = ['rawQuery' => 'available_from < ? AND available_upto > ? AND campaign_status = ?', 'bindParams' => [time(), time(), 1]];
                         $selectedColumns = ['Campaigns.*'];
                         $campaignDetails = $objCampaigns->getFlashsaleDetail($where, $selectedColumns);
                         $campData = [];
                         foreach ([1 => 'DS', 2 => 'FS'] as $index => $item) {
                             $campData[$item] = implode(",", array_unique(array_flatten(array_filter(array_map(function ($camp) use($index) {
                                 if ($camp->campaign_type == $index) {
                                     return array_unique(array_merge(array_keys(json_decode($camp->for_category_ids, true)), array_flatten(json_decode($camp->for_category_ids, true))));
                                 } else {
                                     return null;
                                 }
                             }, $campaignDetails)))));
                         }
                         foreach ([1 => 'DS', 2 => 'FS'] as $index => $item) {
                             $campDatasForCampaignName[$item] = implode(",", array_unique(array_flatten(array_filter(array_map(function ($campDatasForCampaignName) use($index) {
                                 if ($campDatasForCampaignName->campaign_type == $index) {
                                     //                                        return array_unique(array_merge(array_keys(json_decode($camp->for_category_ids, true)), array_flatten(json_decode($camp->for_category_ids, true))));
                                     return $campDatasForCampaignName->campaign_banner;
                                 } else {
                                     return null;
                                 }
                             }, $campaignDetails)))));
                         }
                         $where = ['rawQuery' => 'category_status = ? AND category_id IN(' . implode(',', array_unique(explode(',', implode(',', $campData)))) . ')', 'bindParams' => [1]];
                         $selectColumn = ['product_categories.*'];
                         $categoryInfo = $objCategoryModel->getCategoryWhere($where, $selectColumn);
                         $final['categoryInfo'] = $categoryInfo;
                         $final['campaignCatId'] = $campData;
                         $final['campName'] = $campDatasForCampaignName;
                         //                            echo'<pre>';print_r($final);die("fgvj");
                         if ($final) {
                             $response->code = 200;
                             $response->message = "Success";
                             $response->data = $final;
                         } else {
                             $response->code = 100;
                             $response->message = "Something went Wrong. No Product Details found.";
                             $response->data = null;
                         }
                     } else {
                         $response->code = 401;
                         $response->message = "Access Denied";
                         $response->data = null;
                     }
                 } else {
                     $response->code = 401;
                     $response->message = "Invalid request";
                     $response->data = null;
                 }
                 echo json_encode($response, true);
         }
     }
 }
 public function flashsaleDetails(Request $request)
 {
     $postData = $request->all();
     $response = new stdClass();
     $objUserModel = new User();
     if ($postData) {
         $userId = '';
         if (isset($postData['id'])) {
             $userId = $postData['id'];
         }
         $mytoken = '';
         $authflag = false;
         if (isset($postData['mytoken'])) {
             $mytoken = $postData['mytoken'];
             if ($mytoken == env("API_TOKEN")) {
                 $authflag = true;
             } else {
                 if ($userId != '') {
                     $whereForloginToken = $userId;
                     DB::setFetchMode(PDO::FETCH_ASSOC);
                     $Userscredentials = $objUserModel->getUsercredsWhere($whereForloginToken);
                     if ($mytoken == $Userscredentials['login_token']) {
                         $authflag = true;
                     }
                 }
             }
         }
         if ($authflag) {
             //LOGIN TOKEN
             DB::setFetchMode(PDO::FETCH_ASSOC);
             $objCampaingsModel = new Campaigns();
             $objProductCategoryModel = new ProductCategories();
             $objProductsModel = new Products();
             $currenttime = time();
             $campaignDetails = $objCampaingsModel->getFlashsaleDetail();
             if ($campaignDetails) {
                 //            foreach ($campaignDetails as $campaignkey => $campaignval) {
                 //                $productcategoryId = array($campaignval['for_category_ids']);
                 //                $productproductId = array($campaignval['for_product_ids']);
                 //
                 //            }
                 //            $categoryId = explode(",", $productcategoryId[0]);
                 //            $productId = explode(",", $productproductId[0]);
                 //            if ($categoryId != '' && $productId != '') {
                 //                $category = $objProductCategoryModel->getCategoriesWhere($categoryId);
                 //                $products = $objProductsModel->getProductWhere($productId);
                 $data = $campaignDetails;
                 //                $data['categoryId'] = $category;
                 //                $data['productId'] = $products;
                 $response->code = 200;
                 $response->message = "Success";
                 $response->data = $data;
             } else {
                 $response->code = 100;
                 $response->message = "Something went Wrong. No Product Details found.";
                 $response->data = null;
             }
         } else {
             $response->code = 401;
             $response->message = "Access Denied";
             $response->data = null;
         }
     } else {
         $response->code = 401;
         $response->message = "Invalid request";
         $response->data = null;
     }
     echo json_encode($response, true);
 }
 /**
  * Service for product details
  * @param Request $request
  * @author Vini Dubey
  * @since  31-03-2016
  */
 public function productDetails(Request $request)
 {
     $objProductModel = Products::getInstance();
     $objProductmetaModel = Productmeta::getInstance();
     $objProductImagesModel = ProductImages::getInstance();
     $objUserModel = User::getInstance();
     $objCampaignModel = Campaigns::getInstance();
     $objProductTag = ProductTags::getInstance();
     $postData = $request->all();
     $response = new stdClass();
     if ($postData) {
         $userId = '';
         if (isset($postData['id'])) {
             $userId = $postData['id'];
         }
         $productId = '';
         if (isset($postData['product_id'])) {
             $productId = $postData['product_id'];
         }
         $mytoken = 0;
         $authflag = false;
         if (isset($postData['api_token'])) {
             $mytoken = $postData['api_token'];
             if ($mytoken == env("API_TOKEN")) {
                 $authflag = true;
             } else {
                 if ($userId != '') {
                     $whereForloginToken = $userId;
                     $Userscredentials = $objUserModel->getUsercredsWhere($whereForloginToken);
                     if ($mytoken == $Userscredentials['login_token']) {
                         $authflag = true;
                     }
                 }
             }
         }
         if ($authflag) {
             if ($productId != '') {
                 $whereProductName = $productId;
                 $productDetails = $objProductModel->getProductDetailsWhere($whereProductName);
                 //                    $productDetails = (array)$productDetails;
                 //                    $productmaterial = array($productDetails[0]['material_ids']);
                 //                    $productpatternId = array($productDetails[0]['pattern_ids']);
                 //                    $producttagsId = array($productDetails[0]['tag_ids']);
                 //                    $materialId = explode(",", $productmaterial[0]);
                 //                    $patternId = explode(",", $productpatternId[0]);
                 //                    $tagId = explode(",", $producttagsId[0]);
                 ////                    $productmaterial = $objProductMaterial->getProductMaterialWhere($materialId);
                 ////                    $productpattern = $objProductPattern->getProductPatternWhere($patternId);
                 //                    $producttags = $objProductTag->getProductTagWhere($tagId);
                 //                    //  $campaigns = $objCampaignModel->getCampaignProduct($whereProductName);
                 //                    if ($productDetails[0]) {
                 //                        if ($productDetails[0]['product_id'] != '') {
                 //                            $productsizeDetails = $objProductmetaModel->getProductsizeDetails($productDetails[0]['product_id']);
                 ////                            echo"<pre>";print_r($productsizeDetails);die("zxdsg");
                 //                            $whereProductId = $productDetails[0]['product_id'];
                 //                            $productimages = $objProductImagesModel->getProductimagesWhere($whereProductId);
                 //
                 //                            $data['productDetails'] = $productDetails[0];
                 //                            //  $data['productsizes'] = $productsizeDetails;
                 //                            $data['productimages'] = $productimages;
                 //                            $data['productmaterials'] = $productmaterial;
                 //                            $data['productpatterns'] = $productpattern;
                 //                            $data['producttags'] = $producttags;
                 //                            $data['productUrl'] = env('WEB_URL') . "/product-details/" . $productId;
                 //                            $presentTime = time();
                 //                            $productDetails[0]['discountFlag'] = 0;
                 //                            if ($productDetails[0]['discount_value'] > 0) {
                 //
                 //                                $disountFlag = TRUE;
                 //                                if ($productDetails[0]['available_from'] != '' || $productDetails[0]['available_upto'] != '') {
                 //                                    if ($productDetails[0]['available_from'] != '' && $productDetails[0]['available_from'] > $presentTime) {
                 //
                 //                                        $disountFlag = FALSE;
                 //                                    }
                 //                                    if ($productDetails[0]['available_upto'] != '' && $productDetails[0]['available_upto'] < $presentTime) {
                 //
                 //                                        $disountFlag = FALSE;
                 //                                    }
                 //                                }
                 //                                if ($disountFlag) {
                 //                                    $discountedValue = 0;
                 //                                    $productPrice = (int)$productDetails[0]['price'];
                 //                                    if ($productDetails[0]['discount_type'] == 1) {
                 //                                        $discountedValue = $productPrice - (int)$productDetails[0]['discount_value'];
                 //                                    }
                 //                                    if ($productDetails[0]['discount_type'] == 2) {
                 //                                        $discountedValue = $productPrice - (int)($productPrice * ((int)$productDetails[0]['discount_value'] / 100));
                 //                                    }
                 //
                 //                                    $data['productDetails']['discountedprice'] = $discountedValue;
                 //                                    $data['productDetails']['discountFlag'] = 1;
                 //                                }
                 //                            }
                 //                            $response->code = 200;
                 //                            $response->message = "Success";
                 //                            $response->data = $data;
                 //                        } else {
                 //                            $response->code = 100;
                 //                            $response->message = "Something went Wrong. No Product Details found.";
                 //                            $response->data = null;
                 //                        }
                 //                    } else {
                 //                        $response->code = 100;
                 //                        $response->message = "No such Product Available.";
                 //                        $response->data = null;
                 //                    }
                 //                } else {
                 //                    $response->code = 100;
                 //                    $response->message = "You missed Something.";
                 //                    $response->data = null;
             }
         } else {
             $response->code = 401;
             $response->message = "Access Denied";
             $response->data = null;
         }
     } else {
         $response->code = 401;
         $response->message = "Invalid request";
         $response->data = null;
     }
     echo json_encode($response, true);
 }