public function listProductOptionGroup() { if (!Request::ajax()) { return App::abort(404); } $start = Input::has('start') ? (int) Input::get('start') : 0; $length = Input::has('length') ? Input::get('length') : 10; $search = Input::has('search') ? Input::get('search') : []; $productOptionGroups = ProductOptionGroup::select('id', 'name', 'key', 'description'); if (!empty($search)) { foreach ($search as $key => $value) { if (empty($value)) { continue; } $value = ltrim(rtrim($value)); $productOptionGroups->where($key, 'like', '%' . $value . '%'); } } $order = Input::has('order') ? Input::get('order') : []; if (!empty($order)) { $columns = Input::has('columns') ? Input::get('columns') : []; foreach ($order as $value) { $column = $value['column']; if (!isset($columns[$column]['name']) || empty($columns[$column]['name'])) { continue; } $productOptionGroups->orderBy($columns[$column]['name'], $value['dir'] == 'asc' ? 'asc' : 'desc'); } } $count = $productOptionGroups->count(); if ($length > 0) { $productOptionGroups = $productOptionGroups->skip($start)->take($length); } $arrOptionGroups = $productOptionGroups->get()->toArray(); $arrReturn = ['draw' => Input::has('draw') ? Input::get('draw') : 1, 'recordsTotal' => ProductOptionGroup::count(), 'recordsFiltered' => $count, 'data' => []]; if (!empty($arrOptionGroups)) { foreach ($arrOptionGroups as $optionGroup) { $arrReturn['data'][] = array(++$start, $optionGroup['id'], $optionGroup['name'], $optionGroup['key'], $optionGroup['description']); } } $response = Response::json($arrReturn); $response->header('Content-Type', 'application/json'); return $response; }
public function caculatePrice() { $sku = Input::has('sku') ? Input::get('sku') : 'ROL-663'; $sizew = Input::has('sizew') ? Input::get('sizew') : 0; $sizeh = Input::has('sizeh') ? Input::get('sizeh') : 0; $quantity = Input::has('order_qty') ? Input::get('order_qty') : 1; $product = new VIImage(); $product->sizew = $sizew; $product->sizeh = $sizeh; $groups = ProductOptionGroup::select('id', 'name', 'key')->get(); foreach ($groups as $value) { $option_key = Input::has($value->key) ? Input::get($value->key) : ''; if ($option_key != '') { //echo 'option_key: '.$option_key.'<br/>'; $obj_option = ProductOption::where('key', $option_key)->first(); $option = floatval($obj_option->name); if ($value->key == 'depth') { $product->bleed = $option; } else { $key = $value->key; $product->{$key} = $option; } } } // echo '<pre>'; // print_r($product); // echo '</pre>'; // exit; $product->quantity = $quantity; $product->sku = $sku; $price = JTProduct::getPrice($product); if ($product->margin_up) { $biggerPrice = $price['sell_price'] * (1 + $product->margin_up / 100); $arrReturn = ['sell_price' => $price['sell_price'], 'bigger_price' => VIImage::viFormat($biggerPrice), 'amount' => $price['sub_total']]; } else { $arrReturn = ['sell_price' => $price['sell_price'], 'amount' => $price['sub_total']]; } if (Request::ajax()) { $arrReturn = ['status' => 'ok', 'message' => '', 'data' => $arrReturn]; $response = Response::json($arrReturn); $response->header('Content-Type', 'application/json'); return $response; } return false; }