/**
  * show all dishes for a specific store
  *
  * @param integer $id
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
  */
 public function getDishes($id)
 {
     if ($store = Store::find($id)) {
         return View::make('store.dishes', ['store' => $store]);
     }
     return Redirect::back();
 }
 public function getMenu($id)
 {
     $img = Store::find($id);
     $path = $img->menu;
     $mime = $img->mime;
     header("Content-Type: {$mime}");
     readfile($path);
     exit;
 }
 function getStores()
 {
     $brand_stores = array();
     $db_stores = $GLOBALS['DB']->query("SELECT stores.* FROM\n                brands JOIN brands_stores ON (brands.id = brands_stores.brand_id)\n                       JOIN stores ON (brands_stores.store_id = stores.id)\n                WHERE brands.id = {$this->getId()};");
     foreach ($db_stores as $store) {
         $found_store = Store::find($store['id']);
         array_push($brand_stores, $found_store);
     }
     return $brand_stores;
 }
Beispiel #4
0
 function testFind()
 {
     $name = "Clides";
     $test_store = new Store($name);
     $test_store->save();
     $name2 = "Marthas";
     $test_store2 = new Store($name2);
     $test_store2->save();
     $result = Store::find($test_store2->getId());
     $this->assertEquals($test_store2, $result);
 }
 public function detail($id)
 {
     $param['store'] = StoreModel::find($id);
     $param['servedCount'] = QueueModel::where('store_id', $id)->count();
     $userId = Session::has('user_id') ? Session::get('user_id') : 0;
     $queueNo = QueueModel::where('user_id', $userId)->where('store_id', $id)->whereRaw('DATE(created_at) = DATE(NOW())')->orderBy('created_at', 'DESC')->get();
     if (count($queueNo) > 0) {
         $queueNo = $queueNo[0]->queue_no;
     } else {
         $queueNo = null;
     }
     $param['queueNo'] = $queueNo;
     return View::make('user.store.detail')->with($param);
 }
 public function apply()
 {
     if (Input::has('store_id')) {
         $storeId = Input::get('store_id');
         $status = StatusModel::where('store_id', $storeId)->first();
         $queueNo = $status->last_queue_no;
         $status->last_queue_no = $queueNo + 1;
         $status->save();
         $store = StoreModel::find($storeId);
         return Response::json(['result' => 'success', 'msg' => '', 'queue_no' => $queueNo + 1, 'created_at' => $status->updated_at->format('Y-m-d H:i:s'), 'logo' => HTTP_PATH . "/assets/img/logo.png"]);
     } else {
         return Response::json(['result' => 'failed', 'msg' => 'Invalid Request']);
     }
 }
 public function detail()
 {
     if (Input::has('store_id') && Input::has('user_id')) {
         $storeId = Input::get('store_id');
         $userId = Input::get('user_id');
         $store = StoreModel::find($storeId);
         $queueNo = QueueModel::where('user_id', $userId)->where('store_id', $storeId)->whereRaw('DATE(created_at) = DATE(NOW())')->orderBy('created_at', 'DESC')->get();
         if (count($queueNo) > 0) {
             $queueNo = $queueNo[0]->queue_no;
         } else {
             $queueNo = null;
         }
         return Response::json(['result' => 'success', 'msg' => '', 'store_name' => $store->name, 'company_name' => $store->company->name, 'company_logo' => HTTP_LOGO_PATH . $store->company->setting->logo, 'company_created_at' => $store->company->created_at->format('Y-m-d H:i:s'), 'estimated_waiting' => count($store->activeAgent) == 0 ? '---' : ceil(($store->status->last_queue_no - $store->status->current_queue_no) / count($store->activeAgent)) * ($store->company->setting->waiting_time / 60) . 'min', 'next_number' => $store->status->last_queue_no, 'description' => str_replace('src="/assets', 'src="' . HTTP_PATH . '/assets', $store->description), 'category_name' => $store->company->category->name, 'city_name' => $store->company->city->name, 'address' => $store->address, 'total_customers_served' => QueueModel::where('store_id', $storeId)->count(), 'current_number' => $store->status->current_queue_no, 'queue_no' => $queueNo]);
     } else {
         return Response::json(['result' => 'failed', 'msg' => 'Invalid Request']);
     }
 }
 /**
  * create a delivery
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postCreate()
 {
     $nowDateTime = $this->getDateTimeAfterNow(5);
     $validator = Validator::make(Input::all(), array('store' => 'required|numeric|exists:stores,id', 'closing_time' => 'date_format:Y-m-d H:i:s|after:' . $nowDateTime->format('Y-m-d H:i:s')));
     if ($validator->passes() === false) {
         return Redirect::back()->withErrors($validator);
     }
     $storeId = Input::get('store');
     $closingTime = Input::get('closing_time');
     $store = Store::find($storeId);
     $delivery = new Delivery();
     $delivery->user()->associate(Auth::user());
     $delivery->store()->associate($store);
     $delivery->closing_time = $closingTime;
     $delivery->save();
     // push notification
     F4H\Pusher::push('delivery.created', array('user' => Auth::user()->email, 'store' => $store->name, 'closing_time' => $closingTime, 'delivery' => $delivery->getKey()));
     return Redirect::route('delivery.active');
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $file = $this->argument('file');
     $storeId = $this->argument('storeId');
     if (file_exists($file) === false || is_readable($file) === false) {
         $this->error('"' . $file . '" does not exist or is not readable.');
         return;
     }
     if (Store::find($storeId)->getKey() === null) {
         $this->error('A store with ID "' . $storeId . '" does not exist.');
         return;
     }
     $this->info('Importing dishes from "' . $file . '" to store with ID ' . $storeId . '...');
     $header = $this->readLine();
     while (($line = $this->readLine()) !== FALSE) {
         $dish = $this->getNewObject($this->mergeData($header, $line));
         $dish->save();
         $this->comment(' - "' . $dish->name . '" ID: ' . $dish->getKey());
     }
     $this->info('Importing stores completed.');
 }
Beispiel #10
0
 function test_find()
 {
     //Arrange
     $retailer = "Nordstrom";
     $address = "1234 SW Main Street";
     $phone = "123-456-7890";
     $id = null;
     $test_store = new Store($retailer, $address, $phone, $id);
     $test_store->save();
     $retailer2 = "Macys";
     $address2 = "400 SW 6th Avenue";
     $phone2 = "888-888-8888";
     $test_store2 = new Store($retailer2, $address2, $phone2, $id);
     $test_store2->save();
     //Act
     $result = Store::find($test_store2->getId());
     //Assert
     $this->assertEquals($test_store2, $result);
 }
Beispiel #11
0
 function test_find()
 {
     //Arrange
     $id = null;
     $store_name = "Fred Meyers";
     $test_store = new Store($id, $store_name);
     $test_store->save();
     $id2 = null;
     $store_name2 = "Walmart";
     $test_store2 = new Store($id2, $store_name2);
     $test_store2->save();
     //Act
     $result = Store::find($test_store->getId());
     //Assert
     $this->assertEquals($test_store, $result);
 }
Beispiel #12
0
 function testFind()
 {
     //Arrange
     $name = "shoe store";
     $location = "1234 nw 1st street";
     $id = 4;
     $test_store = new Store($name, $location, $id);
     $test_store->save();
     $name2 = "other store";
     $location2 = "5555 sw 2nd street";
     $id2 = 3;
     $test_store2 = new Store($name2, $location2, $id2);
     $test_store2->save();
     //Act
     $result = Store::find($test_store2->getId());
     //Assert
     $this->assertEquals($test_store2, $result);
 }
Beispiel #13
0
 function test_find()
 {
     //Arrange
     $store_name = "Portland Running Company";
     $id = null;
     $test_store = new Store($store_name, $id);
     $test_store->save();
     $store_name2 = "New Balance";
     $test_store2 = new Store($store_name2, $id);
     $test_store2->save();
     //Act
     $id = $test_store->getId();
     $result = Store::find($id);
     //Assert
     $this->assertEquals($test_store, $result);
 }
 public function save_store()
 {
     $id = Input::get('id');
     $white = Input::file('logo_white');
     $color = Input::file('logo');
     $store = Store::find($id);
     $cities = City::all();
     $zipcodes = array();
     foreach ($cities as $city) {
         array_push($zipcodes, $city->zipcode);
     }
     $flag = 0;
     if (!$store) {
         $store = new Store();
         $flag = 1;
     }
     $store->name = Input::get('name');
     $store->minimum_order_amount = Input::get('minimum_order_amount');
     $validator = Validator::make(array('white' => $white, 'color' => $color), array('white' => 'required|mimes:jpeg,bmp,png', 'color' => 'required|mimes:jpeg,bmp,png'));
     if ($validator->fails()) {
         $error_messages = $validator->messages();
         $response_array = array('success' => false, 'error' => 'Invalid Input', 'error_code' => 401);
         $response_code = 200;
         $message = "Invalid Input File";
         $type = "failed";
         return Redirect::to('/admin/stores')->with('type', $type)->with('message', $message);
     } else {
         if (Input::hasFile('logo')) {
             $store->logo_url = upload_image(Input::file('logo'));
         } else {
             if ($flag == 1) {
                 $store->logo_url = web_url() . "/uploads/default_store_logo.png";
             }
         }
         if (Input::hasFile('logo_white')) {
             $store->logo_white_url = upload_image(Input::file('logo_white'));
         } else {
             if ($flag == 1) {
                 $store->logo_white_url = web_url() . "/uploads/default_white_store_logo.png";
             }
         }
         $store->save();
         StoreLocation::where('store_id', $id)->delete();
         foreach ($zipcodes as $zipcode) {
             $store_location = new StoreLocation();
             $store_location->store_id = $store->id;
             $store_location->zipcode = $zipcode;
             $store_location->save();
         }
         $message = "Successfully updated the store";
         $type = "success";
         return Redirect::to('/admin/stores')->with('type', $type)->with('message', $message);
     }
 }
Beispiel #15
0
 function test_find()
 {
     //Arrange
     $name = "House of Shoes and Waffles";
     $address = "123 Street";
     $phone = "4-44";
     $test_store = new Store($name, $address, $phone);
     $test_store->save();
     $name2 = "Bob's Shoe Palace";
     $address2 = "456 Main Street";
     $phone2 = "1-800-NEW-SHOE";
     $test_store2 = new Store($name, $address, $phone);
     $test_store2->save();
     //Act
     $result = Store::find($test_store2->getId());
     //Assert
     $this->assertEquals($test_store2, $result);
 }
Beispiel #16
0
 function test_find()
 {
     //Arrange
     $store_name = "Flying Shoes";
     $id = 1;
     $test_store = new Store($store_name, $id);
     $test_store->save();
     //Act
     $result = Store::find($test_store->getId());
     //Assert
     $this->assertEquals($test_store, $result);
 }
Beispiel #17
0
$app->get('/store/{id}', function ($id) use($app) {
    $store = Store::find($id);
    return $app['twig']->render('store_edit.html.twig', array('store' => $store));
});
$app->patch('/stores/{id}', function ($id) use($app) {
    $store = Store::find($id);
    $store->update($_POST['name']);
    $brands = $store->getBrands();
    $all_brands = Brand::getAll();
    return $app['twig']->render('stores.html.twig', array('store' => $store, 'brands' => $brands, 'all_brands' => $all_brands));
});
$app->delete('/stores/{id}', function ($id) use($app) {
    $store = Store::find($id);
    $store->delete();
    return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll()));
});
$app->get('/brands/{id}', function ($id) use($app) {
    $brand = Brand::find($id);
    $stores = $brand->getStores();
    $all_stores = Store::getAll();
    return $app['twig']->render('brands.html.twig', array('brand' => $brand, 'stores' => $stores, 'all_stores' => $all_stores));
});
$app->post('/add_stores', function () use($app) {
    $brand = Brand::find($_POST['brand_id']);
    $store = Store::find($_POST['store_id']);
    $brand->addStore($store);
    $stores = $brand->getStores();
    $all_stores = Store::getAll();
    return $app['twig']->render('brands.html.twig', array('brand' => $brand, 'stores' => $stores, 'all_stores' => $all_stores));
});
return $app;
 public function checkout_step3()
 {
     // Processing Cart
     $cart_id = $this->cart_id;
     if (!$cart_id) {
         $cart_id = Input::get('cart_id');
     }
     $address_id = Input::get('address_id');
     $payment_id = Input::get('payment_id');
     $cart_products = DB::table('cart_products')->where('cart_id', $cart_id)->leftJoin('products', 'cart_products.product_id', '=', 'products.id')->leftJoin('users', 'cart_products.added_by', '=', 'users.id')->select('products.*', 'cart_products.quantity as cart_quantity', 'users.first_name as added_by')->orderBy('store_id')->get();
     $cart_users = DB::table('cart_users')->leftJoin('users', 'cart_users.user_id', '=', 'users.id')->select('users.*')->get();
     $response_array['cart'] = Cart::find($cart_id)->toArray();
     $response_array['cart']['total_amount'] = 0;
     $response_array['cart']['total_quantity'] = 0;
     $response_array['cart']['users'] = array();
     $response_array['cart']['stores'] = array();
     $store_id = 0;
     if ($cart_products) {
         $response_array['cart']['is_minimum_reached'] = 1;
         foreach ($cart_products as $cart_product) {
             if ($store_id != $cart_product->store_id) {
                 $store_id = $cart_product->store_id;
                 // Retriving Store
                 $store = Store::find($store_id)->toArray();
                 // Retriving Delivery Slot
                 $time = date("Y-m-d H:i:s");
                 $slot = Slot::where('store_id', $store_id)->where('start_time', '>', $time)->where('is_available', 1)->orderBy('start_time')->first();
                 if ($slot) {
                     $next_slot_start = date("D, jS M, H a", strtotime($slot->start_time));
                     $next_slot_end = date("h a", strtotime($slot->end_time));
                     $next_slot = $next_slot_start . " - " . $next_slot_end;
                 } else {
                     $next_slot = "No Slots available";
                 }
                 $store['slot'] = $next_slot;
                 $store['count'] = 1;
                 $store['sub_total'] = 0;
                 $response_array['cart']['stores'][$store_id] = $store;
                 $response_array['cart']['stores'][$store_id]['products'] = array();
             } else {
                 $response_array['cart']['stores'][$store_id]['count'] += 1;
             }
             $product = json_decode(json_encode($cart_product), true);
             $product['sub_total'] = $product['cart_quantity'] * $product['price'];
             $response_array['cart']['stores'][$store_id]['sub_total'] += $product['sub_total'];
             $response_array['cart']['total_amount'] += $product['sub_total'];
             $response_array['cart']['total_quantity']++;
             array_push($response_array['cart']['stores'][$store_id]['products'], $product);
         }
     }
     if ($cart_users) {
         foreach ($cart_users as $cart_user) {
             $product = json_decode(json_encode($cart_user), true);
             array_push($response_array['cart']['users'], $cart_user);
         }
     }
     foreach ($response_array['cart']['stores'] as $st) {
         if ($st['sub_total'] < $st['minimum_order_amount']) {
             $response_array['cart']['is_minimum_reached'] = 0;
         }
     }
     if (isset($response_array['cart']['is_minimum_reached']) && $response_array['cart']['is_minimum_reached'] == 1) {
         $order = new Order();
         $order->user_id = $this->user_id;
         $order->date = date("Y-m-d H:i:s");
         $order->total_products = $response_array['cart']['total_quantity'];
         $order->total_amount = $response_array['cart']['total_amount'];
         $order->payment_id = $payment_id;
         $order->address_id = $address_id;
         $payment = Payment::find($payment_id);
         $order->payment_customer_id = $payment->customer_id;
         $address = UserAddress::find($address_id);
         $order->address = $address->address . " " . $address->zipcode;
         $order->status = "Initiated";
         $order->save();
         foreach ($cart_products as $cart_product) {
             $order_product = new OrderProduct();
             $order_product->order_id = $order->id;
             $product = Product::find($cart_product->id);
             $product->total_sale += $cart_product->cart_quantity;
             $product->save();
             $order_product->price = $cart_product->price;
             $order_product->quantity = $cart_product->cart_quantity;
             $order_product->fulfilment_status = "Pending";
             $order_product->type = "Product";
             $order_product->parent_id = 0;
             $order_product->product_name = $product->name;
             $order_product->product_image_url = $product->image_url;
             $order_product->product_quantity = $product->quantity;
             $order_product->product_unit = $product->unit;
             $order_product->store_id = $product->store_id;
             $order_product->save();
         }
         // removing products from cart
         CartProduct::where('cart_id', $cart_id)->delete();
         // Order Placement Mail
         $user = User::find($this->user_id);
         Mail::send('emails.order_success', array('user' => $user, 'order' => $order), function ($message) use($user) {
             $message->to($user->email, $user->first_name)->subject('Thanks for placing the order!');
         });
         // Order Placement Mail to Admin
         $admin_email = Config::get('app.admin_email');
         Mail::send('emails.admin_order_success', array('user' => $user, 'order' => $order), function ($message) use($admin_email) {
             $message->to($admin_email, "Admin")->subject('New Order!');
         });
     } else {
         $message = "Minimum order amount not reached";
         if (Request::format() == 'html') {
             return View::make('checkout_step3')->with('store', $this->store)->with('departments', $this->departments)->with('zipcode', $this->zipcode)->with('city', $this->city)->with('stores1', $this->stores)->with('message', $message);
         } else {
             $response_array = array('success' => false, 'error_code' => 411, 'error' => $message);
             $response_code = 200;
             $response = Response::json($response_array, $response_code);
             return $response;
         }
     }
     if (Request::format() == 'html') {
         return View::make('checkout_step3')->with('store', $this->store)->with('departments', $this->departments)->with('zipcode', $this->zipcode)->with('city', $this->city)->with('stores1', $this->stores)->with('message', 'Thanks for placing your Order!!');
     } else {
         $response_array = array('success' => true);
         $response_code = 200;
         $response = Response::json($response_array, $response_code);
         return $response;
     }
 }
Beispiel #19
0
 function testFind()
 {
     $store_name = "Beacons Closet";
     $new_store = new Store($store_name);
     $new_store->save();
     $store_name2 = "Buffalo Exchange";
     $new_store2 = new Store($store_name);
     $new_store2->save();
     $result = Store::find($new_store->getId());
     $this->assertEquals($new_store, $result);
 }
Beispiel #20
0
 function testFind()
 {
     //Arrange
     $store_name = "Norstrom";
     $id = null;
     $test_store = new Store($store_name, $id);
     $test_store->save();
     $another_store = "Madewell";
     $test_store2 = new Store($another_store, $id);
     $test_store2->save();
     //Act
     $result = Store::find($test_store->getId());
     //Assert
     $this->assertEquals($test_store, $result);
 }
Beispiel #21
0
    return $app['twig']->render('store.html.twig', array('store' => $store, 'brands' => $store->getBrands(), 'form_check' => false, 'store_update' => false));
});
// This route deletes specific store
$app->delete("/delete_store/{id}", function ($id) use($app) {
    $id = $_POST['store_id'];
    $store = Store::find($id);
    $store->delete();
    return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'form_check' => false));
});
$app->get("/form_brand", function () use($app) {
    $store = Store::find($_GET['store_id']);
    return $app['twig']->render('store.html.twig', array('store' => $store, 'brands' => $store->getBrands(), 'form_check' => true, 'store_update' => false));
});
$app->post("/add_brand", function () use($app) {
    $name = $_POST['name'];
    $brand = new Brand($name, $id = null);
    $brand->save();
    $store_id = $_POST['store_id'];
    $store = Store::find($store_id);
    $store->addBrand($brand->getId());
    return $app['twig']->render('store.html.twig', array('store' => $store, 'brands' => $store->getBrands(), 'form_check' => false, 'store_update' => false));
});
// This route deletes a specific brand from a store
$app->delete("/delete_brand/{id}", function ($id) use($app) {
    $id = $_POST['brand_id'];
    $store_id = $_POST['store_id'];
    $store = Store::find($store_id);
    $store->deleteBrand($id);
    return $app['twig']->render('store.html.twig', array('store' => $store, 'brands' => $store->getBrands(), 'form_check' => false, 'store_update' => false));
});
return $app;
Beispiel #22
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
$store = new Store();
$projectionsMap = [GuestsArrivingProjection::class => new GuestsArrivingProjection($store), GuestNamesProjection::class => new GuestNamesProjection($store)];
$dispatcher = new Dispatcher($projectionsMap);
// -----------------------------------------------------------------
$guestRegisteredEvent = new GuestRegistered();
$guestRegisteredEvent->fullName = "Jon Doe";
$guestRegisteredEvent->guestId = "guest_1";
$event = new GuestBookedAppointment();
$event->appointmentId = '1';
$event->appointmentDateAndTime = new \DateTime();
$event->feelGoodPackageId = '2';
$event->guestId = 'guest_1';
$event->subsidiaryId = 'belgium';
$dispatcher->dispatch($guestRegisteredEvent);
$dispatcher->dispatch($event);
$guestsArriving = $store->find('1');
belgianAssert($guestsArriving !== null, 'not found');
belgianAssert($guestsArriving->guestId === 'guest_1', 'wrong guest value');
belgianAssert($guestsArriving->fullName === 'Jon Doe', 'wrong name of guest');
$guestName = $store->find('guest_1');
belgianAssert($guestName === 'Jon Doe', 'wrong guest name value');
function belgianAssert($condition, $message)
{
    if (!$condition) {
        throw new \Exception($message);
    }
}
var_dump($guestsArriving);
 public function delete($id)
 {
     try {
         StoreModel::find($id)->delete();
         $alert['msg'] = 'Store has been deleted successfully';
         $alert['type'] = 'success';
     } catch (\Exception $ex) {
         $alert['msg'] = 'This Store has been already used';
         $alert['type'] = 'danger';
     }
     return Redirect::route('company.store')->with('alert', $alert);
 }
 public function search_products()
 {
     $store_id = Request::segment(2);
     $this->store = Store::find($store_id);
     if (!$this->store) {
         if (Request::format() == 'html') {
             // Not Found Page
             die;
         } else {
             $response_array = array('success' => 'false', 'error_code' => '404', 'error' => 'Store not Found');
             $response_code = 200;
             $response = Response::json($response_array, $response_code);
             return $response;
         }
     }
     if (Input::has('per_page')) {
         $per_page = Input::get('per_page');
     } else {
         $per_page = 20;
     }
     if (Input::has('page')) {
         $page = Input::get('page');
     } else {
         $page = 0;
     }
     $shelf_data['products'] = array();
     $query = Product::where('store_id', $store_id);
     if (Input::has('q')) {
         $q = Input::get('q');
         $query = $query->where('products.name', 'LIKE', '%' . $q . '%');
     }
     $brands = $query->leftJoin('brands', 'products.brand_id', '=', 'brands.id')->select(DB::raw('distinct brands.*'))->get();
     $query = Product::where('store_id', $store_id);
     if (Input::has('q')) {
         $q = Input::get('q');
         $query = $query->where('products.name', 'LIKE', '%' . $q . '%');
     }
     $options = $query->leftJoin('product_tag', 'products.id', '=', 'product_tag.product_id')->Join('options', 'product_tag.option_id', '=', 'options.id')->select(DB::raw('distinct options.*'))->get();
     $query = Product::where('store_id', $store_id);
     $base_search_url = web_url() . "/store/" . $store_id . "/search?q=" . Input::get('q');
     if (Input::has('q')) {
         $q = Input::get('q');
         $query = $query->where('products.name', 'LIKE', '%' . $q . '%');
     }
     $base_search_url_options = $base_search_url;
     if (Input::has('options')) {
         $option_ids = Input::get('options');
         $query = $query->leftJoin('product_tag', 'products.id', '=', 'product_tag.product_id')->whereIn('product_tag.option_id', Input::get('options'));
         foreach (Input::get('options') as $option) {
             $base_search_url_options .= "&options[]=" . $option;
         }
     } else {
         $option_ids = array();
     }
     $base_search_url_brand = $base_search_url;
     if (Input::has('brand')) {
         $brand_id = Input::get('brand');
         $query = $query->where('brand_id', Input::get('brand'));
         $base_search_url_brand .= "&brand=" . Input::get('brand');
     } else {
         $brand_id = 0;
     }
     /*
     		if(Input::has('sort_by') && Input::get('sort_by') == 'price'){
     			$query = $query->orderBy('price');
     		} else {
     			$query = $query->orderBy('total_sale','desc');
     		} */
     $query = $query->orderBy('shelf_id');
     $products = $query->select('products.*')->distinct()->get();
     $shelves = array();
     $shelf_id = 0;
     foreach ($products as $product) {
         if ($product->shelf_id != $shelf_id) {
             $shelf = Shelf::find($product->shelf_id);
             $shelf_id = $product->shelf_id;
             $shelves[$shelf_id] = $shelf->toArray();
             $shelves[$shelf_id]['products'] = array();
         }
         $shelf_product = $product->toArray();
         array_push($shelves[$shelf_id]['products'], $shelf_product);
     }
     $response_array['shelves'] = $shelves;
     $response_array['brands'] = $brands->toArray();
     $response_array['options'] = $options->toArray();
     if (Request::format() == 'html' && $page == 0) {
         Session::put('store_id', $store_id);
         return View::make('search')->with('data', $response_array)->with('store', $this->store)->with('departments', $this->departments)->with('zipcode', $this->zipcode)->with('city', $this->city)->with('stores', $this->stores)->with('q', Input::get('q'))->with('base_search_url_brand', $base_search_url_brand)->with('base_search_url_options', $base_search_url_options)->with('option_ids', $option_ids)->with('brand_id', $brand_id);
     } else {
         $response_array['success'] = 'true';
         $response_code = 200;
         $response = Response::json($response_array, $response_code);
         return $response;
     }
 }
 function testFindById()
 {
     //Arrange
     $name = "Shoe Store 1";
     $id = 1;
     $test_store = new Store($name, $id);
     $test_store->save();
     $name2 = "Shoe Store 2";
     $id = 2;
     $test_store2 = new Store($name2, $id);
     $test_store2->save();
     //Act
     $search_id = $test_store->getId();
     $result = Store::find($search_id);
     //Assert
     $this->assertEquals($test_store, $result);
     var_dump($test_store);
     var_dump($result);
 }
Beispiel #26
0
 function test_find()
 {
     //Arrange
     $store_name = "jerrys shoes ";
     $test_store = new Store($store_name);
     $test_store->save();
     $store_name2 = "newmans shoes ";
     $test_store2 = new Store($store_name2);
     $test_store2->save();
     //Act
     $result = Store::find($test_store->getId());
     //Assert
     $this->assertEquals($test_store, $result);
 }
Beispiel #27
0
 function test_find()
 {
     $test_name = "Nordstrom";
     $test_id = 1;
     $test_store = new Store($test_name, $test_id);
     $test_store->save();
     $test_name2 = "Bloomingdales";
     $test_id2 = 2;
     $test_store2 = new Store($test_name2, $test_id2);
     $test_store2->save();
     $result = Store::find($test_store->getId());
     $this->assertEquals($test_store, $result);
 }
Beispiel #28
0
 function test_find()
 {
     //arrange
     $name = "A Shoe Store";
     $id = 1;
     $test_store1 = new Store($name, $id);
     $test_store1->save();
     $name2 = "Down by the riverside";
     $id2 = 2;
     $test_store2 = new Store($name2, $id2);
     $test_store2->save();
     //act
     $result = Store::find($test_store2->getId());
     //assert
     $this->assertEquals($test_store2, $result);
 }
Beispiel #29
0
});
//POSTS (ADDS)
$app->post("/add_stores", function () use($app) {
    $store = Store::find($_POST['store_id']);
    $brand = Brand::find($_POST['brand_id']);
    $brand->addStore($store);
    return $app['twig']->render('brand.html.twig', array('brand' => $brand, 'brands' => Brand::getAll(), 'stores' => $brand->getStores(), 'all_stores' => Store::getAll()));
});
$app->post("/add_brands", function () use($app) {
    $store = Store::find($_POST['store_id']);
    $brand = Brand::find($_POST['brand_id']);
    $store->addBrand($brand);
    return $app['twig']->render('store.html.twig', array('store' => $store, 'stores' => Store::getAll(), 'brands' => $store->getBrands(), 'all_brands' => Brand::getAll()));
});
//GET AND EDIT AND DELETE STORE ROUTE
$app->get("/stores/{id}/edit", function ($id) use($app) {
    $store = Store::find($id);
    return $app['twig']->render('store-edit.html.twig', array('store' => $store, 'brands' => $store->getBrands()));
});
$app->patch("/stores/{id}", function ($id) use($app) {
    $store = Store::find($id);
    $new_name = $_POST['new_name'];
    $store->update($new_name);
    return $app['twig']->render('stores.html.twig', array('store' => $store, 'stores' => Store::getAll(), 'brands' => $store->getBrands()));
});
$app->delete("/stores/{id}", function ($id) use($app) {
    $store = Store::find($id);
    $store->delete();
    return $app['twig']->render('stores.html.twig', array('stores' => Store::getAll()));
});
return $app;
Beispiel #30
0
    $user = User::find("id", $user_id);
    $store = Store::find("id", $store_id);
    return $app['twig']->render('store.html.twig', array('store' => $store[0], 'user' => $user[0], 'beers' => $store[0]->getBeers(), 'all_beers' => Beer::getAll()));
});
//from store
//add beer to store
//show store
$app->post("/{user_id}/store/{store_id}", function ($user_id, $store_id) use($app) {
    $store = Store::find("id", $store_id);
    $beer = Beer::find("id", $_POST['beer_id']);
    $store[0]->addBeer($beer[0]->getId());
    $user = User::find("id", $user_id);
    return $app['twig']->render('store.html.twig', array('store' => $store[0], 'user' => $user[0], 'beers' => $store[0]->getBeers(), 'all_beers' => Beer::getAll()));
});
//--------------------------------------------- Begin Review Functionality ----------------------------------------
$app->get("/{user_id}/review/{beer_id}", function ($user_id, $beer_id) use($app) {
    $user = User::find("id", $user_id);
    $beer = Beer::find("id", $beer_id);
    return $app['twig']->render('review.html.twig', array('user' => $user[0], 'beer' => $beer[0]));
});
$app->post("/{user_id}/review/{beer_id}", function ($user_id, $beer_id) use($app) {
    $user = User::find("id", $user_id);
    $review = Review::findReview($beer_id, $user_id);
    $review[0]->update($_POST['beer_review'], $_POST['review_date']);
    $reviews = Review::find("user_id", $user[0]->getId());
    $new_beers = User::findBeerStyle($user[0]->getId(), $user[0]->getPreferredStyle());
    $local_stores = Store::find("region", $user[0]->getRegion());
    return $app['twig']->render('profile.html.twig', array('user' => $user[0], 'reviews' => $reviews, 'new_beers' => $new_beers, 'local_stores' => $local_stores));
});
return $app;
//End of app, do not code below here