Esempio n. 1
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $model = \App\Models\Offer::findOrFail($id);
     $model->update($request->all());
     $model->catalogs()->sync($request->get('catalogs', []));
     return redirect('/admin/offer');
 }
Esempio n. 2
0
@extends('admin.layout')

@section('form_footer')

    <?php 
if (isset($model_id) and $model_id > 0) {
    $use_catalogs_ids_arr = \App\Models\Offer::findOrFail($model_id)->getCatalogsIdsArr();
} else {
    $use_catalogs_ids_arr = [];
}
?>

    <div class="form-group">
        <label>Каталоги</label>
        @foreach(\Auth::user()->catalogs()->get() as $catalog)
            <div class="checkbox">
                <label>
                    <input type="checkbox" name="catalogs[]" value="{{ $catalog->id }}"{{ in_array($catalog->id, $use_catalogs_ids_arr) ? ' checked' : '' }}>
                    {{ $catalog->name }}
                </label>
            </div>
        @endforeach
    </div>

@endsection

@section('content')
    @include('admin.common.edit_form')
@endsection
 function offer($id)
 {
     return view('offer')->with(['offer' => Offer::findOrFail($id), 'locations' => Location::all()]);
 }
Esempio n. 4
0
 /**
  * Возвращает актуальные товарные предложения
  */
 public function getActualProductOffers()
 {
     $sql = "select co.offer_id, po.id as product_offer_id\n                from offers ofr\n                join catalog_offer co on co.offer_id = ofr.id\n                join catalogs ct on co.catalog_id = ct.id\n                join products_offers po on po.catalog_id = ct.id\n                join " . self::TABLE_NAME . " p on po.product_id = p.id\n                where ofr.status = 1 and ct.status = 1 and po.status = 1 and po.product_id = :product_id";
     $result = \DB::select($sql, ['product_id' => $this->id]);
     if (!$result) {
         return [];
     }
     $output_arr = [];
     foreach ($result as $row) {
         $obj = new \stdClass();
         /**
          * @var \App\Models\Offer $offer_model
          * @var \App\Models\ProductOffer $product_offer_model
          */
         $offer_model = \App\Models\Offer::findOrFail($row->offer_id);
         $product_offer_model = \App\Models\ProductOffer::findOrFail($row->product_offer_id);
         $obj->offer = $offer_model;
         $obj->product_offer = $product_offer_model;
         $obj->price = $product_offer_model->getPrice();
         if ($offer_model->margin_percent > 0) {
             $obj->price += $obj->price * $offer_model->margin_percent / 100;
         }
         $obj->price = round($obj->price, 2);
         $output_arr[] = $obj;
     }
     return $output_arr;
 }