예제 #1
0
 public static function getSmallestPrice($product, $includeSize = false)
 {
     $sizew = $sizeh = $bleed = 0;
     if (!isset($product->size_lists)) {
         $smallestSize = SizeList::where('product_id', $product->id)->cacheTags(['size_lists', 'products'])->orderBy('size_lists.sizew', 'asc')->orderBy('size_lists.sizeh', 'asc')->remember(30)->first();
         if (is_object($smallestSize)) {
             $sizew = $smallestSize->sizew;
             $sizeh = $smallestSize->sizeh;
         }
     } else {
         $min = [];
         foreach ($product->size_lists as $size_list) {
             if (!isset($min->sizew) || $min->sizew > $size_list->sizew) {
                 $min = $size_list;
             }
         }
     }
     $smallestDepth = ProductOption::select('name')->whereIn('id', function ($query) use($product) {
         $query->select('optionable_id')->from('optionables')->where('product_id', $product->id)->where('optionable_type', 'ProductOption');
     })->whereIn('option_group_id', function ($query) {
         $query->select('id')->from('option_groups')->where('key', 'depth');
     })->orderBy('key', 'asc')->first();
     if (is_object($smallestDepth)) {
         $bleed = (double) str_replace('" Box', '', $smallestDepth->name);
     }
     if ($sizew && $sizeh || $bleed) {
         $product->sizew = $sizew;
         $product->sizeh = $sizeh;
         $product->bleed = $bleed;
         $price = JTProduct::getPrice($product);
         $sellPrice = $price['sell_price'];
     } else {
         $sellPrice = JTProduct::getDefaultPrice($product);
     }
     if ($includeSize) {
         return ['sell_price' => $sellPrice, 'sizew' => $sizew, 'sizeh' => $sizeh];
     }
     return $sellPrice;
 }
예제 #2
0
 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;
 }