shipping costs
This commit is contained in:
parent
d4f6a774d0
commit
22a2b4710a
20 changed files with 797 additions and 457 deletions
|
|
@ -6,6 +6,8 @@ namespace App\Http\Controllers;
|
|||
|
||||
|
||||
use App\Models\Shipping;
|
||||
use App\Models\ShippingCountry;
|
||||
use App\Models\ShippingPrice;
|
||||
use Input;
|
||||
use Illuminate\Http\Request;
|
||||
use Validator;
|
||||
|
|
@ -55,50 +57,94 @@ class ShippingController extends Controller
|
|||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = Input::all();
|
||||
if ($data['id'] == "new") {
|
||||
$shipping = new Shipping();
|
||||
$rules = array(
|
||||
'name' => 'required',
|
||||
);
|
||||
|
||||
} else {
|
||||
$shipping = Shipping::findOrFail($data['id']);
|
||||
$rules = array(
|
||||
'name' => 'required',
|
||||
);
|
||||
}
|
||||
$data = [
|
||||
'value' => $shipping,
|
||||
];
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return view('admin.shipping.edit', $data)->withErrors($validator);
|
||||
|
||||
}
|
||||
$shipping = false;
|
||||
$data = Input::all();
|
||||
|
||||
$shipping->name = $data['name'];
|
||||
$shipping->free = $data['free'];
|
||||
$shipping->active = isset($data['active']) ? true : false;
|
||||
$shipping->save();
|
||||
if($data['action'] == 'shipping'){
|
||||
if ($data['id'] == "new") {
|
||||
$shipping = new Shipping();
|
||||
$rules = array('name' => 'required');
|
||||
} else {
|
||||
$shipping = Shipping::findOrFail($data['id']);
|
||||
$rules = array('name' => 'required');
|
||||
}
|
||||
$ret = ['value' => $shipping];
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return view('admin.shipping.edit', $ret)->withErrors($validator);
|
||||
}
|
||||
$data = Input::all();
|
||||
$shipping->name = $data['name'];
|
||||
$shipping->free = $data['free'];
|
||||
$shipping->active = isset($data['active']) ? true : false;
|
||||
$shipping->save();
|
||||
}
|
||||
|
||||
if($data['action'] == 'price'){
|
||||
$shipping = Shipping::findOrFail($data['shipping_id']);
|
||||
$rules = array('price' => 'required');
|
||||
$ret = ['value' => $shipping];
|
||||
$validator = Validator::make(Input::all(), $rules);
|
||||
if ($validator->fails()) {
|
||||
return view('admin.shipping.edit', $ret)->withErrors($validator);
|
||||
}
|
||||
if ($data['id'] == "new") {
|
||||
$price = ShippingPrice::create($data);
|
||||
} else {
|
||||
$price = ShippingPrice::findOrFail($data['id']);
|
||||
if($price->shipping_id != $shipping->id){
|
||||
abort(404);
|
||||
}
|
||||
$price->fill($data);
|
||||
$price->save();
|
||||
}
|
||||
|
||||
\Session()->flash('alert-save', true);
|
||||
}
|
||||
if($data['action'] == 'country'){
|
||||
$shipping = Shipping::findOrFail($data['shipping_id']);
|
||||
foreach($data['country_ids'] as $country_id){
|
||||
if(ShippingCountry::where('country_id', $country_id)->count() == 0){
|
||||
ShippingCountry::create([
|
||||
'shipping_id' => $shipping->id,
|
||||
'country_id' => $country_id
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return redirect(route('admin_shipping_edit', [$shipping->id]));
|
||||
if($shipping){
|
||||
\Session()->flash('alert-save', true);
|
||||
return redirect(route('admin_shipping_edit', [$shipping->id]));
|
||||
}
|
||||
return redirect(route('admin_shippings'));
|
||||
|
||||
}
|
||||
|
||||
public function deleteShipping($shipping_id)
|
||||
{
|
||||
$shipping = Shipping::findOrFail($shipping_id);
|
||||
$shipping->delete();
|
||||
|
||||
public function deleteShipping($id)
|
||||
{
|
||||
$model = Shipping::findOrFail($id);
|
||||
$model->delete();
|
||||
\Session()->flash('alert-success', "Versandkosten gelöscht");
|
||||
return redirect('/admin/shippings');
|
||||
}
|
||||
|
||||
public function deletePrice($id)
|
||||
{
|
||||
$model = ShippingPrice::findOrFail($id);
|
||||
$shipping = $model->shipping;
|
||||
$model->delete();
|
||||
\Session()->flash('alert-success', "Preis gelöscht");
|
||||
return redirect(route('admin_shipping_edit', [$shipping->id]));
|
||||
}
|
||||
|
||||
public function deleteCountry($id)
|
||||
{
|
||||
$model = ShippingCountry::findOrFail($id);
|
||||
$shipping = $model->shipping;
|
||||
$model->delete();
|
||||
\Session()->flash('alert-success', "Preis gelöscht");
|
||||
return redirect(route('admin_shipping_edit', [$shipping->id]));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue