コード例 #1
0
 public function getShopDetails($where)
 {
     try {
         $result = Shops::whereRaw($where['rawQuery'], isset($where['bindParams']) ? $where['bindParams'] : array())->join('users', 'users.id', '=', 'shops.user_id')->select(['shop_id', 'shop_name', 'users.name', 'users.last_name', 'shop_status'])->get();
         return $result;
     } catch (\Exception $e) {
         return $e->getMessage();
     }
 }
 /**
  * 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]);
     }
 }