Esempio n. 1
0
 /**
  * display home
  *
  * @return view
  */
 public function index()
 {
     //get data
     $APIProduct = new APIProduct();
     $datas['batik_wanita'] = $APIProduct->getIndex(['search' => ['recommended' => Session::has('whoami') ? Session::get('whoami')['id'] : 0, 'tags' => ['wanita']], 'sort' => ['name' => 'asc'], 'take' => 4, 'skip' => '']);
     $datas['batik_pria'] = $APIProduct->getIndex(['search' => ['recommended' => Session::has('whoami') ? Session::get('whoami')['id'] : 0, 'tags' => ['pria']], 'sort' => ['name' => 'asc'], 'take' => 4, 'skip' => '']);
     $datas['all'] = $APIProduct->getIndex(['search' => ['recommended' => Session::has('whoami') ? Session::get('whoami')['id'] : 0], 'take' => 4, 'skip' => 0]);
     $this->page_attributes->metas = ['og:type' => 'website', 'og:title' => 'BALIN.ID', 'og:description' => 'Fashionable and Modern Batik', 'og:url' => $this->balin['info']['url']['value'], 'og:image' => $this->balin['info']['logo']['value'], 'og:site_name' => 'balin.id', 'fb:app_id' => Config::get('fb_app.id')];
     $this->page_attributes->controller_name = $this->controller_name;
     $this->page_attributes->subtitle = 'Fashionable and Modern Batik';
     $this->page_attributes->data = $datas;
     if (isset($this->balin['banners'])) {
         $this->page_attributes->data['banners'] = $this->balin['banners'];
     } else {
         $this->page_attributes->data['banners'] = ['left_banner' => ['image_lg' => '', 'value' => json_encode(['button' => ['banner_button_url' => '']])], 'right_banner' => ['image_lg' => '', 'value' => json_encode(['button' => ['banner_button_url' => '']])], 'full_banner' => ['image_lg' => '', 'value' => json_encode(['button' => ['banner_button_url' => '']])]];
     }
     $this->page_attributes->source = $this->page_attributes->source . 'index';
     return $this->generateView();
 }
Esempio n. 2
0
 public function generateView()
 {
     //require
     if (!isset($this->page_attributes->breadcrumb)) {
         $this->page_attributes->breadcrumb = [];
     }
     if (!isset($this->page_attributes->title)) {
         $this->page_attributes->title = null;
     }
     if (!isset($this->page_attributes->subtitle)) {
         $this->page_attributes->subtitle = null;
     }
     if (!isset($this->page_attributes->data)) {
         $this->page_attributes->data = null;
     }
     if (!isset($this->page_attributes->paginator)) {
         $this->page_attributes->paginator = null;
     }
     if (!isset($this->page_attributes->type_form)) {
         $this->page_attributes->type_form = null;
     }
     if (!isset($this->page_attributes->metas)) {
         $this->page_attributes->metas = null;
     }
     if (!isset($this->page_attributes->controller_name)) {
         $this->page_attributes->controller_name = null;
     }
     if (!Session::has('carts') || is_null(Session::get('carts')) || empty(Session::get('carts'))) {
         if (!Session::has('whoami')) {
             $APIProduct = new APIProduct();
             $recommend = $APIProduct->getIndex(['search' => ['name' => Input::get('q'), 'recommended' => 0], 'sort' => ['name' => 'asc'], 'take' => 2, 'skip' => '']);
         } else {
             Session::set('API_token', Session::get('API_token_private'));
             $APIProduct = new APIProduct();
             $recommend = $APIProduct->getIndex(['search' => ['name' => Input::get('q'), 'recommended' => Session::get('whoami')['id']], 'sort' => ['name' => 'asc'], 'take' => 2, 'skip' => '']);
         }
     } else {
         $recommend = [];
     }
     $balin = $this->balin;
     //paginator
     $paging = $this->page_attributes->paginator;
     //initialize view
     $this->layout = view($this->page_attributes->source, compact('paging'))->with('breadcrumb', $this->page_attributes->breadcrumb)->with('page_title', $this->page_attributes->title)->with('page_subtitle', $this->page_attributes->subtitle)->with('data', $this->page_attributes->data)->with('balin', $balin)->with('recommend', $recommend)->with('metas', $this->page_attributes->metas)->with('controller_name', $this->page_attributes->controller_name)->with('type', $this->page_attributes->type_form);
     //optional data
     if (isset($this->page_attributes->search)) {
         $this->layout = $this->layout->with('searchResult', $this->page_attributes->search);
     }
     // return view
     return $this->layout;
 }
 public function show($id)
 {
     //get data category
     $APICategory = new APICategory();
     $category = $APICategory->getShow($id);
     $this->page_attributes->subtitle = $category['data']['name'];
     //search
     if (Input::has('q')) {
         $search = ['name' => Input::get('q'), 'categories' => str_replace(" ", "-", strtolower($category['data']['slug']))];
         $this->page_attributes->search = Input::get('q');
     } else {
         $search = ['categories' => str_replace(" ", "-", strtolower($category['data']['slug']))];
     }
     //sort
     if (Input::has('sort')) {
         $sort_item = explode('-', Input::get('sort'));
         $sort = [$sort_item[0] => $sort_item[1]];
     } else {
         $sort = [];
     }
     //get curent page
     if (is_null(Input::get('page'))) {
         $page = 1;
     } else {
         $page = Input::get('page');
     }
     //get product data
     $APIProduct = new APIProduct();
     $product = $APIProduct->getIndex(['search' => $search, 'sort' => $sort, 'take' => $this->take, 'skip' => ($page - 1) * $this->take]);
     //data paging
     $this->paginate(route('goods.category.show', ['id' => $category['data']['id']]), $product['data']['count'], $page);
     $category['data']['products'] = $product['data']['data'];
     //sorting
     $SortList = new SortList();
     $this->page_attributes->sorts = ['titles' => ['nama', 'harga', 'stok'], 'nama' => $SortList->getSortingList('nama'), 'harga' => $SortList->getSortingList('harga'), 'stok' => $SortList->getSortingList('stok')];
     // data here
     $this->page_attributes->data = $category['data'];
     //breadcrumb
     $breadcrumb = [$category['data']['name'] => route('goods.category.show', ['id' => $category['data']['name']])];
     //generate View
     $this->page_attributes->breadcrumb = array_merge($this->page_attributes->breadcrumb, $breadcrumb);
     $this->page_attributes->source = $this->page_attributes->source . 'show';
     return $this->generateView();
 }
 public function show($id = null)
 {
     //initialize
     $this->page_attributes->subtitle = ucwords(str_replace('_', ' ', $id));
     // filters
     if (Input::has('q')) {
         $this->page_attributes->search = Input::get('q');
     }
     //sort
     if (Input::has('sort')) {
         $sort_item = explode('-', Input::get('sort'));
         $sort = [$sort_item[0] => $sort_item[1]];
     } else {
         $sort = ['name' => 'asc'];
     }
     //get curent page
     if (is_null(Input::get('page'))) {
         $page = 1;
     } else {
         $page = Input::get('page');
     }
     // data here
     $APIProduct = new APIProduct();
     $product = $APIProduct->getIndex(['search' => ['labelname' => $id, 'name' => Input::get('q')], 'sort' => $sort, 'take' => $this->take, 'skip' => ($page - 1) * $this->take]);
     $SortList = new SortList();
     $this->page_attributes->sorts = ['titles' => ['nama', 'harga', 'stok'], 'nama' => $SortList->getSortingList('nama'), 'harga' => $SortList->getSortingList('harga'), 'stok' => $SortList->getSortingList('stok')];
     $this->page_attributes->data = ['id' => $id, 'name' => ucwords(str_replace('_', ' ', $id)), 'product' => $product['data']['data']];
     //paginate
     $this->paginate(route('goods.label.show', ['id' => $id]), $product['data']['count'], $page);
     //breadcrumb
     $breadcrumb = [ucwords(str_replace('_', ' ', $id)) => route('goods.label.show', $id)];
     //generate View
     $this->page_attributes->breadcrumb = array_merge($this->page_attributes->breadcrumb, $breadcrumb);
     $this->page_attributes->source = $this->page_attributes->source . 'show';
     return $this->generateView();
 }
Esempio n. 5
0
 /**
  * function to update an item to cart
  *
  * 1. Check existance of product
  * 2. Parsing data
  * 3. call add to cart function
  * 4. return response
  * @param slug, varian id
  */
 public function update($slug = null, $varian_id = null)
 {
     //1. Check existance of product
     $APIProduct = new APIProduct();
     $product = $APIProduct->getIndex(['search' => ['slug' => $slug]]);
     if ($product['data']['count'] < 1) {
         \App::abort(404);
     }
     //2. Parsing data
     $carts = Session::get('carts');
     $product_id = $product['data']['data'][0]['id'];
     $carts[$product_id]['varians'][$varian_id]['quantity'] = Input::get('qty');
     $varianids = [];
     $qtys = [];
     foreach ($carts[$product_id]['varians'] as $key => $value) {
         $varianids[$key] = $key;
         $qtys[$key] = $value['quantity'];
     }
     //3. call add to cart function
     $cart = $this->addToCart($carts, $product['data']['data'][0], $qtys, $varianids);
     Session::put('carts', $cart['data']);
     $carts = $cart['data'];
     if (count($carts) == 0) {
         Session::flash('carts', 'remove carts');
     }
     //4. return response
     if ($cart['status'] == 'success') {
         return Response::json(['carts' => $cart['data']], 200);
     }
     return Response::json(['carts' => $cart['data'], 'message' => $cart['message']], 200);
 }
 /**
  * Display all discount
  * 
  * 1. Check filter
  * 2. Check page
  * 3. Get data from API
  * 4. Generate paginator
  * 5. Generate breadcrumb
  * 6. Generate view
  * @param page, q
  * @return Object View
  */
 public function index()
 {
     //1. Check filter
     $search = ['discount' => true];
     if (Input::has('q')) {
         $search['name'] = Input::get('q');
         $this->page_attributes->search = Input::get('q');
     } else {
         $searchResult = null;
     }
     if (Input::has('category')) {
         $search['categories'] = str_replace(" ", "-", Input::get('category'));
     }
     if (Input::has('tag')) {
         $search['tags'] = str_replace(" ", "-", Input::get('tag'));
     }
     if (Input::has('label')) {
         $search['labelname'] = str_replace(" ", "_", Input::get('label'));
     }
     if (Input::has('sort')) {
         $sort_item = explode('-', Input::get('sort'));
         $sort = [$sort_item[0] => $sort_item[1]];
     } else {
         $sort = ['name' => 'asc'];
     }
     //2. Check page
     if (is_null(Input::get('page'))) {
         $page = 1;
     } else {
         $page = Input::get('page');
     }
     //3. Get data from API
     $APIProduct = new APIProduct();
     $product = $APIProduct->getIndex(['search' => $search, 'sort' => $sort, 'take' => $this->take, 'skip' => ($page - 1) * $this->take]);
     $this->page_attributes->data = ['product' => $product];
     //4. Generate paginator
     $this->paginate(route('promote.discount.index'), $product['data']['count'], $page);
     //5. Generate breadcrumb
     $breadcrumb = [];
     $this->page_attributes->breadcrumb = array_merge($this->page_attributes->breadcrumb, $breadcrumb);
     //6. Generate View
     $filterTitles = ['tag', 'kategori', 'label'];
     $filterTags = [];
     $filterCategories = [];
     $filterLabels = [];
     $APITag = new APITag();
     $tmpTag = $APITag->getIndex()['data']['data'];
     $key = 0;
     foreach ($tmpTag as $value) {
         if ($value['category_id'] != 0) {
             $filterTags[$key] = ucwords(str_replace("-", " ", $value['slug']));
             $key++;
         }
     }
     $APICategory = new APICategory();
     $tmpCategory = $APICategory->getIndex()['data']['data'];
     $key = 0;
     foreach ($tmpCategory as $value) {
         if ($value['category_id'] != 0) {
             $filterCategories[$key] = ucwords(str_replace("-", " ", $value['name']));
             $key++;
         }
     }
     $APILabel = new APILabel();
     $tmpLabel = $APILabel->getIndex()['data']['data'];
     $key = 0;
     foreach ($tmpLabel as $value) {
         $filterLabels[$key] = ucwords(str_replace("_", " ", $value['label']));
         $key++;
     }
     $SortList = new SortList();
     $this->page_attributes->sorts = ['titles' => ['nama', 'harga', 'promo', 'discount'], 'nama' => $SortList->getSortingList('nama'), 'harga' => $SortList->getSortingList('harga'), 'promo' => $SortList->getSortingList('promo'), 'discount' => $SortList->getSortingList('discount')];
     $this->page_attributes->filters = ['titles' => $filterTitles, 'tag' => $filterTags, 'kategori' => $filterCategories, 'label' => $filterLabels];
     $this->page_attributes->source = $this->page_attributes->source . 'index';
     return $this->generateView();
 }
Esempio n. 7
0
 /**
  * function to generate view and display spesific product of balin
  * 
  * @return view, redirect route
  */
 public function show($slug = null)
 {
     //1. Check product
     $API_product = new APIProduct();
     $product = $API_product->getIndex(['search' => ['slug' => $slug]]);
     if ($product['status'] != 'success') {
         $this->errors = $product['message'];
     } elseif ($product['data']['count'] < 1) {
         $this->errors = 'Tidak ada data.';
     } else {
         //2. Get Related product
         $related = $API_product->getIndex(['search' => ['name' => Input::get('q'), 'notid' => $product['data']['data'][0]['id']], 'sort' => ['name' => 'asc'], 'take' => 4]);
         $carts = Session::get('carts');
         //breadcrumb
         $breadcrumb = ['Produk' => route('balin.product.index'), $product['data']['data'][0]['name'] => route('balin.product.show', $product['data']['data'][0]['slug'])];
         //generate View
         $this->page_attributes->subtitle = $product['data']['data'][0]['name'];
         $this->page_attributes->controller_name = $this->controller_name;
         $this->page_attributes->data = ['product' => $product, 'related' => $related, 'carts' => $carts];
         $this->page_attributes->breadcrumb = array_merge($this->page_attributes->breadcrumb, $breadcrumb);
         $this->page_attributes->source = $this->page_attributes->source . 'show';
         return $this->generateView();
     }
     return $this->generateRedirectRoute('balin.product.index');
 }