public function flashsaleAjaxHandler(Request $request)
 {
     $inputData = $request->input();
     $method = $inputData['method'];
     $objCategoryModel = ProductCategory::getInstance();
     switch ($method) {
         case 'getActiveCategories':
             $where = ['rawQuery' => 'category_status = ? AND parent_category_id = ?', 'bindParams' => [1, 0]];
             echo '<pre>';
             print_r($where);
             die("dx");
             $allactiveproducts = $objCategoryModel->getAllMainCategories($where);
             if (!empty($allactiveproducts)) {
                 echo json_encode($allactiveproducts);
             } else {
                 echo 0;
             }
             break;
     }
 }
 /**
  * Edit category action
  * @param Request $request
  * @param $id Category id
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  * @throws \FlashSale\Http\Modules\Admin\Models\Exception
  * @since 20-12-2015
  * @author Dinanath Thakur <*****@*****.**>
  */
 public function editCategory(Request $request, $id)
 {
     $objCategoryModel = ProductCategory::getInstance();
     if ($request->isMethod('post')) {
         Validator::extend('word_count', function ($field, $value, $parameters) {
             if (count(explode(' ', $value)) > 10) {
                 return false;
             }
             return true;
         }, 'Meta keywords should not contain more than 10 words.');
         $rules = array('category_name' => 'required|max:50|unique:product_categories,category_name,' . $id . ',category_id', 'category_desc' => 'max:255', 'status' => 'required', 'seo_name' => 'max:100', 'page_title' => 'max:70', 'meta_desc' => 'max:160', 'meta_keywords' => 'word_count');
         $validator = Validator::make($request->all(), $rules);
         if ($validator->fails()) {
             return Redirect::back()->with(["status" => 'error', 'msg' => 'Please correct the following errors.'])->withErrors($validator)->withInput();
         } else {
             if (Input::hasFile('category_image')) {
                 $filePath = uploadImageToStoragePath(Input::file('category_image'), 'category');
                 if ($filePath) {
                     $dataToUpdate['category_banner_url'] = $filePath;
                 }
             }
             $dataToUpdate['category_name'] = $request->input('category_name');
             $dataToUpdate['category_desc'] = $request->input('category_desc');
             $dataToUpdate['category_status'] = $request->input('status');
             $dataToUpdate['is_visible'] = $request->input('is_visible');
             $dataToUpdate['parent_category_id'] = $request->input('parent_category');
             $dataToUpdate['page_title'] = $request->input('page_title');
             $dataToUpdate['meta_description'] = $request->input('meta_desc');
             $dataToUpdate['meta_keywords'] = $request->input('meta_keywords');
             $whereForUpdate = ['rawQuery' => 'category_id =?', 'bindParams' => [$id]];
             $updateResult = $objCategoryModel->updateCategoryWhere($dataToUpdate, $whereForUpdate);
             if ($updateResult > 0) {
                 if (isset($filePath)) {
                     deleteImageFromStoragePath($request->input('old_image'));
                 }
                 return Redirect::back()->with(['status' => 'success', 'msg' => 'Category details has been updated.']);
             } else {
                 return Redirect::back()->with(['status' => 'info', 'msg' => 'Nothing to update.']);
             }
         }
     }
     $where = ['rawQuery' => 'category_id =?', 'bindParams' => [$id]];
     $categoryDetails = $objCategoryModel->getCategoryDetailsWhere($where);
     $allCategories = '';
     if ($categoryDetails) {
         //            $where = ['rawQuery' => 'category_status =?', 'bindParams' => [1]];
         $where = ['rawQuery' => '1'];
         $allCategories = $objCategoryModel->getAllCategoriesWhere($where);
         //            foreach ($allCategories as $key => $value) {
         //                $allCategories[$key]->display_name = $this->getCategoryDisplayName($value->category_id);
         //            }
     }
     return view('Admin/Views/category/editCategory', ['categoryDetails' => $categoryDetails, 'allCategories' => $allCategories]);
 }
 /**
  * To get string for tree view of categories (Ex.|--|--)
  * Used for tree view of category
  * @param $id Category id, for which we want to generate string
  * @return string
  * @throws Exception
  * @since 21-12-2015
  * @author Dinanath Thakur <*****@*****.**>
  */
 public function getCategoryDisplayName($id)
 {
     if ($id == 0) {
         return '';
     } else {
         $objCategoryModel = ProductCategory::getInstance();
         $where = ['rawQuery' => 'category_id = ?', 'bindParams' => [$id]];
         $parentCategory = $objCategoryModel->getCategoryDetailsWhere($where);
         if ($parentCategory->parent_category_id != 0) {
             return $this->getCategoryDisplayName($parentCategory->parent_category_id);
             // . '&brvbar;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
         } else {
             return '';
         }
     }
 }
 public function editProduct(Request $request, $productId)
 {
     $temp = ["cacheid" => "testcacheid1", "testsdata" => [["lessonid" => "1", "drills" => [["drillid" => "1", "result_ids" => "1,2,3"], ["drillid" => "2", "result_ids" => "4"]]], ["lessonid" => "2", "drills" => [["drillid" => "1", "result_ids" => "1,2,3"], ["drillid" => "2", "result_ids" => "4"]]]]];
     dd(json_encode($temp, true));
     die;
     //GET from product            //GET from productmeta
     $objModelProducts = Products::getInstance();
     $whereForProduct = ['rawQuery' => 'products.product_id = ?', 'bindParams' => [$productId]];
     $productData = json_decode($objModelProducts->getProductWhere($whereForProduct), true);
     if (!empty($productData['data'])) {
         $objModelCategory = ProductCategory::getInstance();
         $objModelFeatures = ProductFeatures::getInstance();
         $objModelProductMeta = ProductMeta::getInstance();
         $objModelProductImage = ProductImage::getInstance();
         $objModelProductOption = ProductOption::getInstance();
         $objModelProductOptionVariant = ProductOptionVariant::getInstance();
         $objModelProductOptionVariantRelation = ProductOptionVariantRelation::getInstance();
         $objModelProductFeatureVariantRelation = ProductFeatureVariantRelation::getInstance();
         $objModelProductOptVarCombination = ProductOptionVariantsCombination::getInstance();
         $objModelProductFeature = ProductFeatures::getInstance();
         $userId = Session::get('fs_admin')['id'];
         $whereForCat = ['rawQuery' => 'category_status =?', 'bindParams' => [1]];
         $allCategories = $objModelCategory->getAllCategoriesWhere($whereForCat);
         $whereForFeatureGroup = ['rawQuery' => 'group_flag =? and status = ?', 'bindParams' => [1, 1]];
         $allFeatureGroups = $objModelFeatures->getAllFeaturesWhere($whereForFeatureGroup);
         //GET from product_feature_variant_relation
         $catId = (int) $productData['data']['category_id'];
         $catFlag = true;
         $parentCategory = array();
         $count = 1;
         $bindParamsForFeature = array();
         $queryForFeature = "";
         $queryForFeatureGroup = "";
         while ($catFlag) {
             if ($count == 1) {
                 $queryForFeatureGroup = '(product_features.group_flag = 1) and (product_features.for_categories LIKE ? OR product_features.for_categories LIKE ? OR product_features.for_categories LIKE ? OR product_features.for_categories LIKE ?';
                 $queryForFeature = '(group_flag = 0 and parent_id = 0) and (for_categories LIKE ? OR for_categories LIKE ? OR for_categories LIKE ? OR for_categories LIKE ?';
             } else {
                 $count++;
                 $catId = $parentCategory['category_id'];
                 $queryForFeatureGroup .= 'OR product_features.for_categories LIKE ? OR product_features.for_categories LIKE ? OR product_features.for_categories LIKE ? OR product_features.for_categories LIKE ?';
                 $queryForFeature .= 'OR for_categories LIKE ? OR for_categories LIKE ? OR for_categories LIKE ? OR for_categories LIKE ?';
             }
             array_push($bindParamsForFeature, "%,{$catId}");
             array_push($bindParamsForFeature, "%,{$catId},%");
             array_push($bindParamsForFeature, "{$catId},%");
             array_push($bindParamsForFeature, "{$catId}");
             $parentCategory = array();
             $whereForCat = ['rawQuery' => 'parent_category_id = ?', "bindParams" => [$catId]];
             $parentCategory = $objModelCategory->getCategoryDetailsWhere($whereForCat);
             if (!$parentCategory) {
                 $catFlag = false;
             }
         }
         $queryForFeature .= ")";
         $queryForFeatureGroup .= ")";
         $whereForFeature = ['rawQuery' => $queryForFeature, 'bindParams' => $bindParamsForFeature];
         $featureDetails = json_decode($objModelProductFeature->getAllFeaturesWithVariantsWhere($whereForFeature), true);
         //            $featureDetails = json_decode($objModelProductFeature->getAllFeaturesWithFVRelationWhere($whereForFeature), true);
         $whereForFeatureGroup = ['rawQuery' => $queryForFeatureGroup, 'bindParams' => $bindParamsForFeature];
         $featureGroups = json_decode($objModelProductFeature->getAllFGsWithFsWhere($whereForFeatureGroup), true);
         foreach ($featureGroups['data'] as $keyFG => $valueFG) {
             $whereForFs = ['rawQuery' => "product_features.parent_id IN (?)", "bindParams" => [$valueFG['feature_ids']]];
             $featureGroups['data'][$keyFG]['featureDetails'] = json_decode($objModelProductFeature->getAllFeaturesWithVariantsWhere($whereForFs), true)['data'];
         }
         $whereForFVRelation = ['rawQuery' => "product_id = ?", 'bindParams' => [$productId]];
         $fvRelations = $objModelProductFeatureVariantRelation->getAllFeatureVariantRelationsWhere($whereForFVRelation);
         //            dd($fvRelations);
         $response['code'] = $featureDetails['code'];
         $response['message'] = $featureDetails['message'];
         $response['data']['featureDetails'] = $featureDetails['data'];
         $response['data']['featureGroupDetails'] = $featureGroups['data'];
         //GET from options
         $whereForOptions = ['rawQuery' => 'status = 1'];
         $allOptions = $objModelProductOption->getAllOptionsWhere($whereForOptions);
         //GET from option_variants
         //            $objModelProductOptionVariant->getVariants
         //GET from option_variant_relation
         $whereForOptVar = ['rawQuery' => "1"];
         //product_id = ?", 'bindParams' => [$productId]];
         $whereForJoin = ['column' => 'product_id', 'condition' => '=', 'value' => "{$productId}"];
         $dataOptVarWithRelations = json_decode($objModelProductOptionVariant->getOptionVarWithRelationsWhere($whereForOptVar, ['*'], $whereForJoin), true);
         //            dd(json_decode($dataOptVarWithRelations, true));//$objModelProductOptionVariantRelation
         //GET from option_variants_combination
         $whereForOptVarCombinations = ['rawQuery' => "product_id = ?", 'bindParams' => [$productId]];
         $dataOptVarCombs = json_decode($objModelProductOptVarCombination->getAllCombinationsWhere($whereForOptVarCombinations), true);
         //            dd(json_decode($dataOptVarCombs, true));//$objModelProductOptionVariantRelation
         //GET from product_images
         $whereForImages = ['rawQuery' => 'for_product_id = ? and for_combination_id = ?', 'bindParams' => [$productId, 0]];
         $dataDefaultImages = json_decode($objModelProductImage->getAllImagesWhere($whereForImages), true);
         //            dd($dataImages);
         if ($request->isMethod('post')) {
             dd($request);
             //            $inputData = $request->input('product_data');//Excludes image
             $inputData = $request->all()['product_data'];
             //Includes image
             //            print_a($inputData['options']);
             //            print_a($_FILES);
             $returnData = ['code' => 400, "message" => "Nothing to update.", "data" => null];
             if (isset($inputData['updateFormName'])) {
                 $updateFormName = $inputData['updateFormName'];
                 $errors = array();
                 switch ($updateFormName) {
                     case "general":
                         $rules = ['product_name' => 'required', 'price' => 'required', 'in_stock' => 'required', 'comment' => 'max:100'];
                         $messages = array();
                         $validator = Validator::make($inputData, $rules, $messages);
                         if ($validator->fails()) {
                             return Redirect::back()->with(["code" => 400, "status" => 'error', 'message' => 'Please correct the following errors.'])->withErrors($validator)->withInput();
                         } else {
                             $productData = array();
                             $productData['product_name'] = trim($inputData['product_name']);
                             $productData['for_shop_id'] = $inputData['shop_id'];
                             if (array_key_exists('product_type', $inputData)) {
                                 $productData['product_type'] = 1;
                             }
                             $productData['min_qty'] = $inputData['minimum_order_quantity'];
                             $productData['max_qty'] = $inputData['maximum_order_quantity'];
                             $productData['category_id'] = $inputData['category_id'];
                             $productData['for_gender'] = $inputData['for_gender'];
                             $productData['price_total'] = $inputData['price'];
                             $productData['list_price'] = $inputData['list_price'];
                             $productData['in_stock'] = $inputData['in_stock'];
                             $productData['added_date'] = time();
                             $productData['added_by'] = $userId;
                             $productData['status_set_by'] = $userId;
                             $returnData = $objModelProducts->updateProductsWhere($productData);
                             //                                $returnData['code'] = 200;
                             //                                $returnData['message'] = "General details saved successfully";
                             //                                $returnData['data'] = null;
                         }
                         //--------------------------PRODUCT-METADATA----------------------------//
                         $productMetaData['product_id'] = $productId;
                         $productMetaData['full_description'] = trim($inputData['full_description']);
                         $productMetaData['short_description'] = trim($inputData['short_description']);
                         $productMetaData['weight'] = $inputData['shipping_properties']['weight'];
                         $productMetaData['shipping_freight'] = $inputData['shipping_properties']['shipping_freight'];
                         $shippingParams = array();
                         $shippingParams['min_items'] = $inputData['shipping_properties']['min_items'];
                         $shippingParams['max_items'] = $inputData['shipping_properties']['min_items'];
                         if (array_key_exists('box_length', $inputData['shipping_properties'])) {
                             $shippingParams['box_length'] = $inputData['shipping_properties']['box_length'];
                         }
                         if (array_key_exists('box_width', $inputData['shipping_properties'])) {
                             $shippingParams['box_width'] = $inputData['shipping_properties']['box_width'];
                         }
                         if (array_key_exists('box_height', $inputData['shipping_properties'])) {
                             $shippingParams['box_height'] = $inputData['shipping_properties']['box_height'];
                         }
                         $productMetaData['shipping_params'] = json_encode($shippingParams);
                         $productMetaData['quantity_discount'] = json_encode($inputData['quantity_discount']);
                         $productMetaData['product_tabs'] = json_encode($inputData['product_tabs']);
                         $insertedProductMetaId = $objModelProductMeta->addProductMetaData($productMetaData);
                         if (!$insertedProductMetaId) {
                             $errors[] = 'Sorry, some of the product data were not added, please update the same on the edit section.';
                         }
                         //--------------------------END PRODUCT-METADATA----------------------------//
                         //------------------------PRODUCT FEATURES START HERE---------------------//
                         if (array_key_exists('features', $inputData)) {
                             $productDataFeatures = $inputData['features'];
                             $fvrDataToInsert = array();
                             foreach ($productDataFeatures as $keyPDF => $valuePDF) {
                                 if (array_key_exists("single", $productDataFeatures[$keyPDF])) {
                                     //                            $fvrDataToInsert[] = ['product_id' => $insertedProductId, 'feature_id' => $keyPDF, 'variant_ids' => 0, 'display_status' => $productDataFeatures[$keyPDF]['status']];
                                     $objModelProductFeatureVariantRelation->addFeatureVariantRelation(['product_id' => $insertedProductId, 'feature_id' => $keyPDF, 'variant_ids' => 0, 'display_status' => $productDataFeatures[$keyPDF]['status']]);
                                 } else {
                                     if (array_key_exists("muliple", $productDataFeatures[$keyPDF])) {
                                         //                            $fvrDataToInsert[] = ['product_id' => $insertedProductId, 'feature_id' => $keyPDF, 'variant_ids' => implode(",", array_keys($valuePDF['multiple'])), 'display_status' => $valuePDF['status']];
                                         $objModelProductFeatureVariantRelation->addFeatureVariantRelation(['product_id' => $insertedProductId, 'feature_id' => $keyPDF, 'variant_ids' => implode(",", array_keys($valuePDF['multiple'])), 'display_status' => $valuePDF['status']]);
                                     } else {
                                         if (array_key_exists("select", $productDataFeatures[$keyPDF])) {
                                             //                            $fvrDataToInsert[] = ['product_id' => $insertedProductId, 'feature_id' => $keyPDF, 'variant_ids' => $valuePDF['select'], 'display_status' => $valuePDF['status']];
                                             $objModelProductFeatureVariantRelation->addFeatureVariantRelation(['product_id' => $insertedProductId, 'feature_id' => $keyPDF, 'variant_ids' => "" . $valuePDF['select'], 'display_status' => $valuePDF['status']]);
                                         }
                                     }
                                 }
                             }
                             //                    $objModelProductFeatureVariantRelation->addFeatureVariantRelation($fvrDataToInsert);
                         }
                         //------------------------PRODUCT FEATURES END HERE---------------------//
                         break;
                         //TODO update main image here
                     //TODO update main image here
                     case "images":
                         $rules = ['mainimage' => 'image|mimes:jpeg,bmp,png|max:1000'];
                         $messages['mainimage.image'] = 'Only jpg, jpeg, gif images allowed for upload.';
                         $validator = Validator::make($inputData, $rules, $messages);
                         if ($validator->fails()) {
                             return Redirect::back()->with(["code" => 400, "status" => 'error', 'message' => 'Please correct the following errors.'])->withErrors($validator)->withInput();
                         } else {
                             //TODO update otherimages here
                             //----------------------------PRODUCT-IMAGES------------------------------//
                             $productImages = $_FILES['product_data'];
                             $imageData = array();
                             if ($productImages['error']['mainimage'] == 0) {
                                 $mainImageURL = uploadImageToStoragePath($productImages['tmp_name']['mainimage'], 'product_' . $insertedProductId, 'product_' . $insertedProductId . '_0_' . time() . '.jpg', 724, 1024);
                                 if ($mainImageURL) {
                                     $mainImageData['for_product_id'] = $insertedProductId;
                                     $mainImageData['image_type'] = 0;
                                     $mainImageData['image_upload_type'] = 0;
                                     $mainImageData['image_url'] = $mainImageURL;
                                     $imageData[] = $mainImageData;
                                 }
                             } else {
                                 $errors[] = 'Sorry, something went wrong. Main image could not be uploaded, You can upload it on edit section.';
                             }
                             if (array_key_exists('otherimages', $productImages['name'])) {
                                 foreach ($productImages['tmp_name']['otherimages'] as $otherImageKey => $otherImage) {
                                     if ($otherImage != '') {
                                         $otherImageURL = uploadImageToStoragePath($otherImage, 'product_' . $insertedProductId, 'product_' . $insertedProductId . '_' . ($otherImageKey + 1) . '_' . time() . '.jpg', 724, 1024);
                                         if ($otherImageURL) {
                                             $otherImageData['for_product_id'] = $insertedProductId;
                                             $otherImageData['image_type'] = 1;
                                             $otherImageData['image_upload_type'] = 0;
                                             $otherImageData['image_url'] = $otherImageURL;
                                             $imageData[] = $otherImageData;
                                         }
                                     }
                                 }
                             }
                             if (!empty($imageData)) {
                                 $objModelProductImage->addNewImage($imageData);
                             }
                             //--------------------------END PRODUCT-IMAGES----------------------------//
                             $returnData['code'] = 200;
                             $returnData['message'] = "Images updated successfully";
                             $returnData['data'] = null;
                         }
                         break;
                     case "options":
                         $rules = ['mainimage' => 'image|mimes:jpeg,bmp,png|max:1000'];
                         $messages['mainimage.image'] = 'Only jpg, jpeg, gif images allowed for upload.';
                         $validator = Validator::make($inputData, $rules, $messages);
                         if ($validator->fails()) {
                             return Redirect::back()->with(["code" => 400, "status" => 'error', 'message' => 'Please correct the following errors.'])->withErrors($validator)->withInput();
                         } else {
                             //TODO options code here
                             if (array_key_exists('options', $inputData)) {
                                 $finalOptionVariantRelationData = array();
                                 $varDataForCombinations = array();
                                 foreach ($inputData['options'] as $key => $optionValue) {
                                     $optionVariantRelationData['product_id'] = $insertedProductId;
                                     $optionVariantRelationData['option_id'] = $optionValue['option_id'];
                                     $optionVariantRelationData['status'] = $optionValue['status'];
                                     $tempOptionVariantData = array();
                                     $variantIds = array();
                                     //-------------------------OLD OPTION VARIANT START-----------------------//
                                     /*
                                     if (array_key_exists('variantData', $optionValue)) {
                                         foreach ($optionValue['variantData'] as $variantKey => $variantValue) {
                                             $temp = array();
                                             if ($variantValue['variant_id'] == 0) {
                                                 $variantData['option_id'] = $optionValue['option_id'];
                                                 $variantData['variant_name'] = $variantValue['variant_name'];
                                                 $variantData['added_by'] = $userId;
                                                 $variantData['status'] = $variantValue['status'];
                                                 $variantData['created_at'] = NULL;
                                     
                                                 $insertedVariantId = $objModelProductOptionVariant->addNewVariantAndGetID($variantData);
                                                 if ($insertedVariantId > 0) {
                                                     array_push($variantIds, $insertedVariantId);
                                                     $temp['VID'] = $insertedVariantId;
                                                     $temp['VN'] = $variantValue['variant_name'];
                                                     $temp['PM'] = $variantValue['price_modifier'];
                                                     $temp['PMT'] = $variantValue['price_modifier_type'];
                                                     $temp['WM'] = $variantValue['weight_modifier'];
                                                     $temp['WMT'] = $variantValue['weight_modifier_type'];
                                                     $temp['STTS'] = $variantValue['status'];
                                                 }
                                             } else {
                                                 array_push($variantIds, $variantValue['variant_id']);
                                                 $temp['VID'] = $variantValue['variant_id'];
                                                 $temp['VN'] = $variantValue['variant_name'];
                                                 $temp['PM'] = $variantValue['price_modifier'];
                                                 $temp['PMT'] = $variantValue['price_modifier_type'];
                                                 $temp['WM'] = $variantValue['weight_modifier'];
                                                 $temp['WMT'] = $variantValue['weight_modifier_type'];
                                                 $temp['STTS'] = $variantValue['status'];
                                             }
                                             $tempOptionVariantData[] = $temp;
                                         }
                                         if (!empty($variantIds) && !empty($tempOptionVariantData)) {
                                             $optionVariantRelationData['variant_ids'] = implode(',', $variantIds);
                                             $optionVariantRelationData['variant_data'] = json_encode($tempOptionVariantData);
                                         }
                                     }
                                     */
                                     //-------------------------OLD OPTION VARIANT END-----------------------//
                                     //-------------------------NEW OPTION VARIANT START---------------------//
                                     if (array_key_exists('variantData', $optionValue)) {
                                         foreach ($optionValue['variantData'] as $variantKey => $variantValue) {
                                             $temp = array();
                                             array_push($variantIds, $variantValue['variant_id']);
                                             $temp['VID'] = $variantValue['variant_id'];
                                             $temp['VN'] = $variantValue['variant_name'];
                                             $temp['PM'] = $variantValue['price_modifier'];
                                             $temp['PMT'] = $variantValue['price_modifier_type'];
                                             $temp['WM'] = $variantValue['weight_modifier'];
                                             $temp['WMT'] = $variantValue['weight_modifier_type'];
                                             $temp['STTS'] = $variantValue['status'];
                                             $tempOptionVariantData[] = $temp;
                                         }
                                     }
                                     if (array_key_exists('variantDataNew', $optionValue)) {
                                         foreach ($optionValue['variantDataNew'] as $variantKey => $variantValue) {
                                             $temp = array();
                                             $variantData['option_id'] = $optionValue['option_id'];
                                             $variantData['variant_name'] = $variantValue['variant_name'];
                                             $variantData['added_by'] = $userId;
                                             $variantData['status'] = $variantValue['status'];
                                             $variantData['created_at'] = NULL;
                                             $insertedVariantId = $objModelProductOptionVariant->addNewVariantAndGetID($variantData);
                                             if ($insertedVariantId > 0) {
                                                 $varDataForCombinations[$variantValue['variant_id']] = $insertedVariantId;
                                                 array_push($variantIds, $insertedVariantId);
                                                 $temp['VID'] = $insertedVariantId;
                                                 $temp['VN'] = $variantValue['variant_name'];
                                                 $temp['PM'] = $variantValue['price_modifier'];
                                                 $temp['PMT'] = $variantValue['price_modifier_type'];
                                                 $temp['WM'] = $variantValue['weight_modifier'];
                                                 $temp['WMT'] = $variantValue['weight_modifier_type'];
                                                 $temp['STTS'] = $variantValue['status'];
                                             }
                                             $tempOptionVariantData[] = $temp;
                                         }
                                     }
                                     if (!empty($variantIds) && !empty($tempOptionVariantData)) {
                                         $optionVariantRelationData['variant_ids'] = implode(',', $variantIds);
                                         $optionVariantRelationData['variant_data'] = json_encode($tempOptionVariantData);
                                     }
                                     //-------------------------NEW OPTION VARIANT END---------------------//
                                     $finalOptionVariantRelationData[] = $optionVariantRelationData;
                                 }
                                 if (!empty($finalOptionVariantRelationData)) {
                                     $objModelProductOptionVariantRelation->addNewOptionVariantRelation($finalOptionVariantRelationData);
                                 }
                                 //------------------------PRODUCT OPTION COMBINATIONS START HERE---------------------//
                                 foreach ($inputData['opt_combination'] as $keyCombination => $valueCombination) {
                                     $flags = explode("_", $valueCombination['newflag']);
                                     $combinationVarIds = explode("_", $keyCombination);
                                     $flagKeys = array_keys($flags, "1");
                                     foreach ($flagKeys as $keyFK => $valueFK) {
                                         $combinationVarIds[$keyFK] = $varDataForCombinations[$combinationVarIds[[$keyFK]]];
                                     }
                                     //TODO ADD BARCODE, shippig info and image data for the combination here
                                     $dataCombinations['product_id'] = $insertedProductId;
                                     $dataCombinations['variant_ids'] = implode("_", $combinationVarIds);
                                     $dataCombinations['quantity'] = $valueCombination['quantity'];
                                     $dataCombinations['exception_flag'] = 0;
                                     if (isset($valueCombination['excludeflag']) && $valueCombination['excludeflag'] == 'on') {
                                         $dataCombinations['exception_flag'] = 1;
                                     }
                                     $objModelProductOptVarCombination->addNewOptionVariantsCombination($dataCombinations);
                                 }
                                 //------------------------PRODUCT OPTION COMBINATIONS END HERE---------------------//
                             }
                             $returnData['code'] = 200;
                             $returnData['message'] = "Options saved successfully";
                             $returnData['data'] = null;
                         }
                         break;
                         /* case "features":
                            $returnData['code'] = 200;
                            $returnData['message'] = "Features saved successfully";
                            $returnData['data'] = null;
                            break; */
                     /* case "features":
                        $returnData['code'] = 200;
                        $returnData['message'] = "Features saved successfully";
                        $returnData['data'] = null;
                        break; */
                     case "filters":
                         $rules = ['mainimage' => 'image|mimes:jpeg,bmp,png|max:1000'];
                         $messages['mainimage.image'] = 'Only jpg, jpeg, gif images allowed for upload.';
                         $validator = Validator::make($inputData, $rules, $messages);
                         if ($validator->fails()) {
                             return Redirect::back()->with(["code" => 400, "status" => 'error', 'message' => 'Please correct the following errors.'])->withErrors($validator)->withInput();
                         } else {
                             $returnData['code'] = 200;
                             $returnData['message'] = "Filters saved successfully";
                             $returnData['data'] = null;
                         }
                         break;
                     case "tabs":
                         $rules = ['mainimage' => 'image|mimes:jpeg,bmp,png|max:1000'];
                         $messages['mainimage.image'] = 'Only jpg, jpeg, gif images allowed for upload.';
                         $validator = Validator::make($inputData, $rules, $messages);
                         if ($validator->fails()) {
                             return Redirect::back()->with(["code" => 400, "status" => 'error', 'message' => 'Please correct the following errors.'])->withErrors($validator)->withInput();
                         } else {
                             $returnData['code'] = 200;
                             $returnData['message'] = "Tab details saved successfully";
                             $returnData['data'] = null;
                         }
                         break;
                     default:
                         break;
                 }
             }
         }
         foreach ($allCategories as $key => $value) {
             $allCategories[$key]->display_name = $this->getCategoryDisplayName($value->category_id);
         }
         return view('Admin/Views/product/editProduct', ['code' => '', 'allCategories' => $allCategories, 'allOptions' => $allOptions, 'featureGroups' => json_decode($allFeatureGroups, true), 'productData' => $productData['data'], 'dataOptVarWithRelations' => $dataOptVarWithRelations, 'dataOptVarCombs' => $dataOptVarCombs, 'dataDefaultImages' => $dataDefaultImages]);
     } else {
         return view('Admin/Views/product/editProduct', ['code' => '400', 'message' => 'No such product exists.', 'productData' => array()]);
     }
 }
 /**
  * Add New Shop
  * @param Request $request
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  * @since 13-05-2016
  * @author Vini Dubey <*****@*****.**>
  */
 public function addNewShop(Request $request)
 {
     $objCategoryModel = ProductCategory::getInstance();
     $objLocationModel = Location::getInstance();
     $objShopModel = Shops::getInstance();
     $objShopMetadataModel = ShopMetadata::getInstance();
     $userId = Session::get('fs_admin')['id'];
     $whereforCategory = ['rawQuery' => 'category_status =? and parent_category_id =?', 'bindParams' => [1, 0]];
     $allCategories = $objCategoryModel->getAllCategoriesWhere($whereforCategory);
     $whereforCountry = ['rawQuery' => 'is_visible =? and location_type =?', 'bindParams' => [0, 0]];
     $allCountry = $objLocationModel->getAllLocationsWhere($whereforCountry);
     $whereforShop = ['rawQuery' => 'user_id =?', 'bindParams' => [$userId]];
     $allShop = $objShopModel->getAllshopsWhere($whereforShop);
     //        print_a($allShop);
     //echo "<pre>";print_r($allShop);die;
     /////////////////////////////Flag Set By admin side///////////////Todo- Flag Set By admin side
     $multiple_store_flag = 1;
     // Value 1 if flag is set
     $sub_store_flag = 1;
     // Value 1 if flag is set
     $parent_category_flag = 1;
     // Value 1 if flag is set
     /////////////////////////////////////////////////////////////////
     $flag['multiple_store_flag'] = $multiple_store_flag;
     $flag['sub_store_flag'] = $sub_store_flag;
     $flag['parent_category_flag'] = $parent_category_flag;
     $data['allCategories'] = $allCategories;
     $data['Country'] = $allCountry;
     $data['Shop'] = $allShop;
     if (!empty($allShop) && $multiple_store_flag != 1) {
         //Error msg if multiple shop not allowed and shopeady added
         return view("Supplier/Views/supplier/addNewShop", ['multiple_store_err' => "Shop already added, Can not add Multiple Shop"]);
     } else {
         $parentCategoryId = 0;
         if (isset($request['parent_category']) && !empty($request['parent_category'])) {
             $parentCategoryId = $request['parent_category'];
         }
         $parentShopId = "";
         if (isset($request['parent_shop']) && !empty($request['parent_shop'])) {
             $parentShopId = $request['parent_shop'];
         }
         if ($request->isMethod('post')) {
             if ($parentShopId == '') {
                 //Sub store flag is not set
                 $rules = array('shop_name' => 'required');
             } else {
                 //Sub store flag is set
                 $rules = array();
             }
             $validator = Validator::make($request->all(), $rules);
             if ($validator->fails()) {
                 return Redirect::back()->withErrors($validator)->withInput();
             } else {
                 try {
                     $addressLine1 = "";
                     if (isset($request['address_line_1'])) {
                         $addressLine1 = $request['address_line_1'];
                     }
                     $addressLine2 = "";
                     if (isset($request['address_line_2'])) {
                         $addressLine2 = $request['address_line_2'];
                     }
                     $country = "";
                     if (isset($request['country'])) {
                         $country = $request['country'];
                     }
                     $state = "";
                     if (isset($request['state'])) {
                         $state = $request['state'];
                     }
                     $city = "";
                     if (isset($request['city'])) {
                         $city = $request['city'];
                     }
                     $zipcode = "";
                     if (isset($request['zipcode'])) {
                         $zipcode = $request['zipcode'];
                     }
                     $shop_flag = 1;
                     if (isset($request['shop_flag'])) {
                         $shop_flag = $request['shop_flag'];
                     }
                     $show_shop = 2;
                     if (isset($request['show_shop'])) {
                         $show_shop = $request['show_shop'];
                     }
                     ////////////Upload Shop Banner Start///////////////////////
                     if (isset($_FILES["shop_banner"]["name"]) && !empty($_FILES["shop_banner"]["name"])) {
                         $bannerFilePath = uploadImageToStoragePath(Input::file('shop_banner'), 'shopbanner', 'shopbanner_' . $userId . '_' . time() . ".jpg");
                     } else {
                         $bannerFilePath = uploadImageToStoragePath($_SERVER['DOCUMENT_ROOT'] . "/assets/images/no-image.png", 'shopbanner', 'shopbanner_' . $userId . '_' . time() . ".jpg");
                     }
                     ////////////Upload Shop banner End///////////////////////
                     ////////////Upload Shop Logo Start///////////////////////
                     if (isset($_FILES["shop_logo"]["name"]) && !empty($_FILES["shop_logo"]["name"])) {
                         $logoFilePath = uploadImageToStoragePath(Input::file('shop_logo'), 'shoplogo', 'shoplogo_' . $userId . '_' . time() . ".jpg");
                     } else {
                         $logoFilePath = uploadImageToStoragePath($_SERVER['DOCUMENT_ROOT'] . "/assets/images/no-image.png", 'shoplogo', 'shoplogo_' . $userId . '_' . time() . ".jpg");
                     }
                     ////////////Upload Shop Logo End///////////////////////
                     if ($parentShopId == "") {
                         //Sub store flag is not set
                         $shopdata = array('user_id' => $userId, 'shop_name' => $request['shop_name'], 'shop_banner' => $bannerFilePath, 'shop_logo' => $logoFilePath, 'parent_category_id' => $parentCategoryId, 'shop_flag' => $shop_flag);
                         $addShop = $objShopModel->addShop($shopdata);
                         $shop_id = $addShop;
                         $shopType = "0";
                     } else {
                         //Sub store flag is set
                         $shopType = "1";
                         $shop_id = $parentShopId;
                     }
                     $shopMatadata = array('shop_id' => $shop_id, 'shop_type' => $shopType, 'address_line_1' => $addressLine1, 'address_line_2' => $addressLine2, 'city' => $city, 'state' => $state, 'country' => $country, 'zipcode' => $zipcode, 'added_date' => time(), 'show_shop_address' => $show_shop, 'shop_metadata_status' => 1);
                     $addShop = $objShopMetadataModel->addShopMetadata($shopMatadata);
                     if ($addShop) {
                         if ($parentShopId == "") {
                             return redirect()->back()->with('shop_success_msg', 'Shop Added Successfully, Waiting for Admin Approval.');
                         } else {
                             return redirect()->back()->with('shop_success_msg', 'Shop Added Successfully.');
                         }
                     }
                 } catch (\Exception $ex) {
                     return redirect()->back()->with('exception', 'An exception occurred, please reload the page and try again.');
                 }
             }
         }
         return view("Admin/Views/shop/addNewShop", ['data' => $data], ['flag' => $flag]);
     }
 }
 /**
  * Edit Wholesale Campaign
  * @param Request $request
  * @param $campaign_id
  * @param $added_by
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  * @throws \Exception
  * @author Vini Dubey
  */
 public function editWholesale(Request $request, $campaign_id, $added_by)
 {
     $objProductCategory = ProductCategory::getInstance();
     $objCampaignModel = Campaigns::getInstance();
     $objProductModel = Products::getInstance();
     if ($request->isMethod('post')) {
         $rules = array('campaign_name' => 'unique:campaigns,campaign_name,' . $campaign_id . ',campaign_id', 'wholesale_image' => 'image');
         $validator = Validator::make($request->all(), $rules);
         if ($validator->fails()) {
             return Redirect::back()->withErrors($validator)->withInput();
         }
         if (Input::hasFile('wholesale_image')) {
             $filePath = uploadImageToStoragePath(Input::file('wholesale_image'), 'wholesale', 'wholesale_' . $added_by . '_' . time() . ".jpg");
             $data['campaign_banner'] = $filePath;
         }
         $postData = $request->all();
         $data['campaign_name'] = $postData['campaign_name'];
         $data['discount_type'] = '2';
         $data['discount_value'] = $postData['percentagediscount'];
         $categ = $postData['productcategories'];
         if (isset($postData['productsubcategories'])) {
             $subcat = $postData['productsubcategories'];
         } else {
             $subcat = [];
         }
         $tmp = [];
         foreach ($categ as $index => $item) {
             $tmp[$item] = array_values(array_filter(array_map(function ($cat) use($item) {
                 if (explode('_', $cat)[0] == $item) {
                     return explode('_', $cat)[1];
                 }
             }, $subcat)));
         }
         $data['for_category_ids'] = json_encode($tmp);
         $data['by_user_id'] = $added_by;
         $data['for_product_ids'] = implode(",", $postData['product']);
         $where = ['rawQuery' => 'campaign_id = ?', 'bindParams' => [$campaign_id]];
         $campaigns = 'Wholesale';
         $campaignUpdate = $objCampaignModel->updateFlashsaleStatus($data, $where);
         if ($campaignUpdate) {
             if (isset($filePath)) {
                 deleteImageFromStoragePath($postData['oldImage']);
             }
             return Redirect::back()->with(['status' => 'success', 'msg' => $campaigns . ' ' . 'Updated Successfully.']);
         } else {
             return Redirect::back()->with(['status' => 'error', 'msg' => $campaigns . ' ' . 'Some Error try again.']);
         }
     }
     $where = ['rawQuery' => 'campaign_id = ?  AND by_user_id = ?', 'bindParams' => [$campaign_id, $added_by]];
     $selectedColumn = ['campaigns.*', 'users.username'];
     $wholesaleInfo = $objCampaignModel->getAllFlashsaleDetails($where, $selectedColumn);
     if (isset($wholesaleInfo) && !empty($wholesaleInfo)) {
         foreach ($wholesaleInfo as $flashkey => $flashval) {
             $categoryIds = json_decode($flashval->for_category_ids, true);
             $categoryMerg = array_merge(array_keys($categoryIds));
             $categoryMergee = array_merge(array_flatten($categoryIds));
             $categoryMerge = array_merge(array_keys($categoryIds), array_flatten($categoryIds));
             $where = ['rawQuery' => 'category_id IN(' . implode(",", $categoryMerge) . ')'];
             $selectedColumn = [DB::raw('GROUP_CONCAT(DISTINCT category_name) AS category_name'), DB::raw('GROUP_CONCAT(DISTINCT category_id) AS category_id')];
             $getcategory = $objProductCategory->getCategoryNameById($where, $selectedColumn);
             foreach ($getcategory as $catkey => $catval) {
                 $wholesaleInfo[$flashkey]->category = $catval->category_name;
                 $wholesaleInfo[$flashkey]->category_ids = $catval->category_id;
             }
             $whereProduct = ['rawQuery' => 'product_id IN(' . $flashval->for_product_ids . ')'];
             $selectedColumn = [DB::raw('GROUP_CONCAT(DISTINCT product_name) AS product_name'), DB::raw('GROUP_CONCAT(DISTINCT product_id) AS product_id')];
             $getproduct = $objProductModel->getProductNameById($whereProduct, $selectedColumn);
             foreach ($getproduct as $prodkey => $prodval) {
                 $wholesaleInfo[$flashkey]->product_name = $prodval->product_name;
                 $wholesaleInfo[$flashkey]->product_id = $prodval->product_id;
             }
         }
         $where = ['rawQuery' => 'category_status = ? AND parent_category_id = ?', 'bindParams' => [1, 0]];
         $selectedColumn = ['category_id', 'category_name', 'category_status', 'for_shop_id'];
         $allactivecategories = $objProductCategory->getAllCategoriesWhere($where, $selectedColumn);
         $where = ['rawQuery' => 'category_status = ?', 'bindParams' => [1]];
         $selectedColumn = ['product_categories.*', DB::raw('GROUP_CONCAT(category_id)AS main_category_id'), DB::raw('GROUP_CONCAT(category_name)AS main_category_name')];
         $allActiveSubcategories = $objProductCategory->getSubCategoriesForMaincategory($where, $selectedColumn);
         $mainCategory = array_filter(array_map(function ($category) {
             if ($category->parent_category_id == 0) {
                 return $category;
             }
         }, $allActiveSubcategories))[0];
         $finalCatData = [];
         foreach (explode(',', $mainCategory->main_category_id) as $index => $mainCatID) {
             foreach ($allActiveSubcategories as $subCatKey => $allActiveSubcategory) {
                 if ($allActiveSubcategory->parent_category_id == $mainCatID) {
                     $allActiveSubcategory->main_cat_name = explode(',', $mainCategory->main_category_name)[$index];
                     $finalCatData[$mainCatID] = $allActiveSubcategory;
                 }
             }
         }
         $where = ['rawQuery' => 'added_by = ? AND product_type = ?', 'bindParams' => [$added_by, 1]];
         $selectedColumn = ['product_id', 'product_name'];
         $allproducts = $objProductModel->getAllSupplierProducts($where, $selectedColumn);
         return view('Admin/Views/campaign/editWholesale', ['wholesaleDetails' => $wholesaleInfo[0], 'activeCategory' => $allactivecategories, 'allProducts' => $allproducts, 'allcategories' => $finalCatData]);
     } else {
         return view('Admin/Views/campaign/editWholesale');
     }
 }
 public function editFeature(Request $request, $featureId)
 {
     $objModelFeatures = ProductFeatures::getInstance();
     $objModelCategory = ProductCategory::getInstance();
     $objModelFeatureVariants = ProductFeatureVariants::getInstance();
     $whereForFeatureGroup = ['rawQuery' => 'group_flag =? and status = ?', 'bindParams' => [1, 1]];
     $allFeatureGroups = $objModelFeatures->getAllFeaturesWhere($whereForFeatureGroup);
     $whereForFeature = ['rawQuery' => 'feature_id = ? and group_flag=?', 'bindParams' => [$featureId, 0]];
     $featureDetails = $objModelFeatures->getFeatureWhere($whereForFeature);
     $whereForCat = ['rawQuery' => 'category_status =?', 'bindParams' => [1]];
     $allCategories = $objModelCategory->getAllCategoriesWhere($whereForCat);
     $whereForFV = ['rawQuery' => 'feature_id = ?', 'bindParams' => [$featureId]];
     $fvData = $objModelFeatureVariants->getAllFeatureVariantsWhere($whereForFV);
     if ($request->isMethod('post')) {
         //            echo "<pre>"; print_r($request->input()); die;
         $dataUpdateFeature = array();
         $dataUpdateFeature['parent_id'] = (string) json_decode($featureDetails, true)['data']['parent_id'];
         if ($request->input('parent_id') != null) {
             $dataUpdateFeature['parent_id'] = $request->input('parent_id');
         }
         $rulesEditdFeature = ['feature_name' => 'required|regex:/(^[A-Za-z0-9 ]+$)+/|max:255|unique:product_features,feature_name,' . $featureId . ',feature_id,parent_id,' . $dataUpdateFeature['parent_id'] . ',group_flag,0', 'full_description' => 'max:255', 'feature_type' => 'required', 'for_categories' => 'required'];
         $messagesEditFeature = ['feature_name.required' => 'Please enter a name', 'feature_name.alpha_num' => 'Please enter a valid name', 'full_description.max' => 'Description should not exceed 255 characters', 'feature_type.required' => 'Please select a feature type', 'for_categories.required' => 'Please select atleast one category'];
         $featureVariants = $request->input('feature_variant')['name'];
         $featureVariantsDesc = $request->input('feature_variant')['description'];
         $featureVariantIds = $request->input('feature_variant')['variant_id'];
         //            echo '<pre>'; print_r($featureVariantIds); die;
         foreach ($featureVariants as $keyFV => $valueFV) {
             //NEED MORE VALIDATION HERE
             $rulesEditdFeature['feature_variant.name.' . $keyFV] = 'regex:/(^[A-Za-z0-9 ]+$)+/|max:255|unique:product_feature_variants,variant_name,' . (isset($featureVariantIds[$keyFV]) ? $featureVariantIds[$keyFV] : 'NULL') . ',variant_id,feature_id,' . $featureId;
             $rulesEditdFeature['feature_variant.description.' . $keyFV] = 'regex:/(^[A-Za-z0-9 ]+$)+/|max:255';
             $messagesEditFeature['feature_variant.name.' . $keyFV . '.regex'] = 'Name can contain alphanumeric characters and spaces only';
             $messagesEditFeature['feature_variant.name.' . $keyFV . '.max'] = 'Name is too long to use. 255 characters max.';
             $messagesEditFeature['feature_variant.name.' . $keyFV . '.unique'] = 'Variant name already in use.';
             $messagesEditFeature['feature_variant.description.' . $keyFV . '.regex'] = 'Invalid description.';
         }
         //            $this->validate($request, $rulesEditdFeature, $messagesEditFeature);
         $validator = Validator::make($request->all(), $rulesEditdFeature, $messagesEditFeature);
         if ($validator->fails()) {
             return Redirect::back()->with(["code" => '400', 'message' => 'Please correct the following errors.'])->withErrors($validator)->withInput();
         } else {
             $dataUpdateFeature['feature_name'] = $request->input('feature_name');
             $dataUpdateFeature['full_description'] = $request->input('full_description');
             $dataUpdateFeature['feature_type'] = $request->input('feature_type');
             $selectedCategories = $request->input('for_categories');
             $dataUpdateFeature['for_categories'] = implode(',', array_keys($selectedCategories));
             $dataUpdateFeature['display_on_product'] = 0;
             if ($request->input('display_on_product') != null) {
                 $dataUpdateFeature['display_on_product'] = 1;
             }
             $dataUpdateFeature['display_on_catalog'] = 0;
             if ($request->input('display_on_catalog') != null) {
                 $dataUpdateFeature['display_on_catalog'] = 1;
             }
             $dataUpdateFeature['group_flag'] = 0;
             $whereForFeatureUpdate = ['rawQuery' => 'feature_id = ?', 'bindParams' => [$featureId]];
             $updatedFeature = json_decode($objModelFeatures->updateFeatureWhere($dataUpdateFeature, $whereForFeatureUpdate), true);
             //CODE TO INSERT VARIANTS HERE
             $whereForVariantId = ['rawQuery' => 'feature_id =?', 'bindParams' => [$featureId]];
             $selectedVariantColumn = array(DB::raw('GROUP_CONCAT(variant_id) AS variant_ids'));
             $oldVariantIds = explode(',', json_decode($objModelFeatureVariants->getFeatureVariantWhere($whereForVariantId, $selectedVariantColumn), true)['data']['variant_ids']);
             $inputVariantIds = array();
             $updateVariantResultFlag = false;
             $newVariantResultFlag = false;
             $deletedVariantResultFlag = false;
             $variantIdsToDelete = $oldVariantIds;
             if ($dataUpdateFeature['feature_type'] != 0) {
                 foreach ($featureVariants as $keyFV => $valueFV) {
                     if ($valueFV != '') {
                         if (isset($featureVariantIds[$keyFV]) && in_array($featureVariantIds[$keyFV], $oldVariantIds)) {
                             //UPDATE VARIANT DETAILS
                             $inputVariantIds[] = $featureVariantIds[$keyFV];
                             $updateVariantData = '';
                             $updateVariantData['variant_name'] = $valueFV;
                             $updateVariantData['description'] = $featureVariantsDesc[$keyFV];
                             $whereForUpdateVariant = ['rawQuery' => 'variant_id =?', 'bindParams' => [$featureVariantIds[$keyFV]]];
                             $updateVariantResult = $objModelFeatureVariants->updateFeatureVariantWhere($updateVariantData, $whereForUpdateVariant);
                             if ($updateVariantResult) {
                                 $updateVariantResultFlag = true;
                             }
                         } else {
                             //ADD NEW VARIANT DETAILS
                             $newVariantData['feature_id'] = $featureId;
                             $newVariantData['variant_name'] = $valueFV;
                             //                            $newVariantData['added_by'] = $userId;
                             $newVariantData['description'] = $featureVariantsDesc[$keyFV];
                             $newInsertedVariantId = $objModelFeatureVariants->addFeatureVariant($newVariantData);
                             if ($newInsertedVariantId) {
                                 $newVariantResultFlag = true;
                             }
                         }
                     }
                 }
                 $variantIdsToDelete = array_diff($oldVariantIds, $inputVariantIds);
             }
             if (!empty($variantIdsToDelete)) {
                 $whereForDeleteVariant = ['rawQuery' => 'variant_id IN (?)', 'bindParams' => [implode(',', $variantIdsToDelete)]];
                 $deletedVariantResult = $objModelFeatureVariants->deleteFeatureVariantWhere($whereForDeleteVariant);
                 if ($deletedVariantResult) {
                     $deletedVariantResultFlag = true;
                 }
             }
             if (isset($updatedFeature) && $updatedFeature['code'] == 200 || isset($updateVariantResultFlag) && $updateVariantResultFlag || isset($newVariantResultFlag) && $newVariantResultFlag || isset($deletedVariantResultFlag) && $deletedVariantResultFlag) {
                 //ALL DETAILS UPDATED
                 return Redirect::back()->with(['code' => '200', 'message' => 'Changes saved successfully.']);
             } else {
                 //NOTHING TO UPDATE
                 return Redirect::back()->with(['code' => '200', 'message' => 'Nothing to update.']);
             }
         }
     }
     return view('Admin/Views/features/editFeature', ['code' => '', 'featureGroups' => json_decode($allFeatureGroups, true), 'allCategories' => $allCategories, 'featureDetails' => json_decode($featureDetails, true), 'fvData' => json_decode($fvData, true)]);
     //, ['successMsg' => $successMsg, 'errMsg' => $errMsg]
 }
 /**
  * Edit category action
  * @param Request $request
  * @param $id Category id
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  * @throws \FlashSale\Http\Modules\Admin\Models\Exception
  * @since 20-12-2015
  * @author Dinanath Thakur <*****@*****.**>
  */
 public function editCategory(Request $request, $id)
 {
     $objCategoryModel = ProductCategory::getInstance();
     if ($request->isMethod('post')) {
         Validator::extend('word_count', function ($field, $value, $parameters) {
             if (count(explode(' ', $value)) > 10) {
                 return false;
             }
             return true;
         }, 'Meta keywords should not contain more than 10 words.');
         $rules = array('category_name' => 'required|max:50|unique:product_categories,category_name,' . $id . ',category_id', 'category_desc' => 'max:255', 'status' => 'required', 'seo_name' => 'max:100', 'page_title' => 'max:70', 'meta_desc' => 'max:160', 'meta_keywords' => 'word_count');
         $validator = Validator::make($request->all(), $rules);
         if ($validator->fails()) {
             return Redirect::back()->with(["status" => 'error', 'msg' => 'Please correct the following errors.'])->withErrors($validator)->withInput();
         } else {
             if (Input::hasFile('category_image')) {
                 $destinationPath = 'assets/uploads/categories/';
                 $filename = 'category_' . time() . ".jpg";
                 File::makeDirectory($destinationPath, 0777, true, true);
                 $filePath = '/' . $destinationPath . $filename;
                 $imageResult = Image::make(Input::file('category_image'))->resize($this->imageWidth, $this->imageHeight, function ($constraint) {
                     $constraint->aspectRatio();
                 })->save($destinationPath . $filename, 80);
                 if ($imageResult) {
                     $dataToUpdate['category_banner_url'] = $filePath;
                 }
             }
             $dataToUpdate['category_name'] = $request->input('category_name');
             $dataToUpdate['category_desc'] = $request->input('category_desc');
             $dataToUpdate['category_status'] = $request->input('status');
             $dataToUpdate['parent_category_id'] = $request->input('parent_category');
             $dataToUpdate['page_title'] = $request->input('page_title');
             $dataToUpdate['meta_description'] = $request->input('meta_desc');
             $dataToUpdate['meta_keywords'] = $request->input('meta_keywords');
             $whereForUpdate = ['rawQuery' => 'category_id =?', 'bindParams' => [$id]];
             $updateResult = $objCategoryModel->updateCategoryWhere($dataToUpdate, $whereForUpdate);
             if ($updateResult) {
                 return Redirect::back()->with(['status' => 'success', 'msg' => 'Category details has been updated.']);
             } else {
                 return Redirect::back()->with(['status' => 'info', 'msg' => 'Nothing to update.']);
             }
         }
     }
     $where = ['rawQuery' => 'category_id =?', 'bindParams' => [$id]];
     $categoryDetails = $objCategoryModel->getCategoryDetailsWhere($where);
     $allCategories = '';
     if ($categoryDetails) {
         $where = ['rawQuery' => 'category_status =?', 'bindParams' => [1]];
         $allCategories = $objCategoryModel->getAllCategoriesWhere($where);
         foreach ($allCategories as $key => $value) {
             $allCategories[$key]->display_name = $this->getCategoryDisplayName($value->category_id);
         }
     }
     return view('Admin/Views/category/editCategory', ['categoryDetails' => $categoryDetails, 'allCategories' => $allCategories]);
 }