user shops + shipping
This commit is contained in:
parent
ccc2af4bf7
commit
d4f6a774d0
53 changed files with 2326 additions and 814 deletions
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api;
|
|||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Input;
|
||||
use Session;
|
||||
use \SoapClient;
|
||||
|
||||
class KasController extends Controller
|
||||
|
|
@ -17,6 +18,7 @@ class KasController extends Controller
|
|||
private $session_lifetime = 600; // Gültigkeit des Tokens in Sek. bis zur neuen Authentifizierung
|
||||
private $session_update_lifetime = 'Y'; // bei N läuft die Session nach <$session_lifetime> Sekunden ab, bei Y verlängert sich die Session mit jeder Benutzung
|
||||
private $CredentialToken = false;
|
||||
private $kas_flood_delay = 2;
|
||||
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
|
|
@ -31,6 +33,7 @@ class KasController extends Controller
|
|||
|
||||
public function action($func, $para = array()){
|
||||
|
||||
$this->checkSession($func);
|
||||
try
|
||||
{
|
||||
$Params = array(); // Parameter für die API-Funktion
|
||||
|
|
@ -42,6 +45,8 @@ class KasController extends Controller
|
|||
'KasRequestType' => $func, // API-Funktion
|
||||
'KasRequestParams' => $para // Parameter an die API-Funktion
|
||||
)));
|
||||
Session::put('flood_protection.'.$func, time() + $this->kas_flood_delay + 0.2);
|
||||
|
||||
if(isset($req['Response']['ReturnString']) && $req['Response']['ReturnString'] == "TRUE"){
|
||||
return $req['Response']['ReturnInfo'];
|
||||
}
|
||||
|
|
@ -60,8 +65,11 @@ class KasController extends Controller
|
|||
|
||||
|
||||
private function login(){
|
||||
|
||||
$this->checkSession('auth');
|
||||
try
|
||||
{
|
||||
|
||||
$SoapLogon = new SoapClient('https://kasapi.kasserver.com/soap/wsdl/KasAuth.wsdl');
|
||||
$this->CredentialToken = $SoapLogon->KasAuth(json_encode(array(
|
||||
'KasUser' => $this->kas_user,
|
||||
|
|
@ -70,6 +78,8 @@ class KasController extends Controller
|
|||
'SessionLifeTime' => $this->session_lifetime,
|
||||
'SessionUpdateLifeTime' => $this->session_update_lifetime
|
||||
)));
|
||||
Session::put('flood_protection.auth', time() + $this->kas_flood_delay + 0.2);
|
||||
|
||||
}
|
||||
|
||||
// Fehler abfangen und ausgeben
|
||||
|
|
@ -83,7 +93,19 @@ class KasController extends Controller
|
|||
|
||||
}
|
||||
|
||||
private function checkSession($func)
|
||||
{
|
||||
$name = 'flood_protection.'.$func;
|
||||
|
||||
if(Session::exists($name)){
|
||||
$time_to_wait = (float)Session::get($name) - time();
|
||||
Session::forget($name);
|
||||
}else {
|
||||
$time_to_wait = 0;
|
||||
}
|
||||
if ( $time_to_wait >= 0 ) {
|
||||
usleep( intval( $time_to_wait*1000000 ) );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
104
app/Http/Controllers/ShippingController.php
Executable file
104
app/Http/Controllers/ShippingController.php
Executable file
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
|
||||
|
||||
|
||||
use App\Models\Shipping;
|
||||
use Input;
|
||||
use Illuminate\Http\Request;
|
||||
use Validator;
|
||||
|
||||
|
||||
class ShippingController extends Controller
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('superadmin');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data = [
|
||||
'values' => Shipping::all(),
|
||||
];
|
||||
return view('admin.shipping.index', $data);
|
||||
}
|
||||
|
||||
public function edit($shipping_id)
|
||||
{
|
||||
if($shipping_id == "new"){
|
||||
$shipping = new Shipping();
|
||||
$shipping->active = 1;
|
||||
|
||||
}else{
|
||||
$shipping = Shipping::findOrFail($shipping_id);
|
||||
|
||||
}
|
||||
$data = [
|
||||
'value' => $shipping,
|
||||
];
|
||||
return view('admin.shipping.edit', $data);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||
*/
|
||||
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);
|
||||
|
||||
}
|
||||
$data = Input::all();
|
||||
|
||||
$shipping->name = $data['name'];
|
||||
$shipping->free = $data['free'];
|
||||
$shipping->active = isset($data['active']) ? true : false;
|
||||
$shipping->save();
|
||||
|
||||
|
||||
\Session()->flash('alert-save', true);
|
||||
|
||||
return redirect(route('admin_shipping_edit', [$shipping->id]));
|
||||
|
||||
}
|
||||
|
||||
public function deleteShipping($shipping_id)
|
||||
{
|
||||
$shipping = Shipping::findOrFail($shipping_id);
|
||||
$shipping->delete();
|
||||
|
||||
\Session()->flash('alert-success', "Versandkosten gelöscht");
|
||||
return redirect('/admin/shippings');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers\Web;
|
|||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Product;
|
||||
use Util;
|
||||
use Yard;
|
||||
use Input;
|
||||
|
||||
|
|
@ -56,7 +57,10 @@ class CardController extends Controller
|
|||
}
|
||||
|
||||
public function showCard(){
|
||||
return view('web.templates.card');
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
return view('web.templates.card', $data);
|
||||
}
|
||||
|
||||
public function updateCard(){
|
||||
|
|
@ -73,11 +77,17 @@ class CardController extends Controller
|
|||
}
|
||||
|
||||
public function checkoutCard(){
|
||||
return view('web.templates.checkout');
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
return view('web.templates.checkout', $data);
|
||||
}
|
||||
|
||||
public function checkoutFinalCard(){
|
||||
return view('web.templates.checkout-final');
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
];
|
||||
return view('web.templates.checkout-final', $data);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use App\Http\Controllers\Controller;
|
|||
use App\Models\Category;
|
||||
use App\Models\Product;
|
||||
use Input;
|
||||
use Util;
|
||||
|
||||
class SiteController extends Controller
|
||||
{
|
||||
|
|
@ -22,7 +23,10 @@ class SiteController extends Controller
|
|||
|
||||
public function index()
|
||||
{
|
||||
return view('web.index');
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop()
|
||||
];
|
||||
return view('web.index', $data);
|
||||
}
|
||||
|
||||
public function site($site, $subsite = false, $product_slug = false)
|
||||
|
|
@ -35,6 +39,7 @@ class SiteController extends Controller
|
|||
if ($category && $product) {
|
||||
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'subsite' => $subsite,
|
||||
'categories' => Category::where('active', true)->orderBy('pos', 'ASC')->get(),
|
||||
'product' => $product,
|
||||
|
|
@ -51,6 +56,7 @@ class SiteController extends Controller
|
|||
$category = Category::where('slug', $subsite)->where('active', true)->first();
|
||||
if ($category) {
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'subsite' => $subsite,
|
||||
'categories' => Category::where('active', true)->orderBy('pos', 'ASC')->get(),
|
||||
'products' => Product::whereHas('categories', function ($query) use ($category) {
|
||||
|
|
@ -65,6 +71,7 @@ class SiteController extends Controller
|
|||
}
|
||||
}
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop(),
|
||||
'subsite' => 'alle-produkte',
|
||||
'categories' => Category::where('active', true)->orderBy('pos', 'ASC')->get(),
|
||||
'products' => Product::where('active', true)->orderBy('pos', 'ASC')->get(),
|
||||
|
|
@ -72,17 +79,19 @@ class SiteController extends Controller
|
|||
];
|
||||
return view('web.templates.'.$site, $data);
|
||||
}
|
||||
|
||||
$data = [
|
||||
'user_shop' => Util::getUserShop()
|
||||
];
|
||||
if($subsite){
|
||||
if(!view()->exists('web.templates.'.$subsite)){
|
||||
abort(404);
|
||||
}
|
||||
return view('web.templates.'.$subsite);
|
||||
return view('web.templates.'.$subsite, $data);
|
||||
}
|
||||
if(!view()->exists('web.templates.'.$site)){
|
||||
abort(404);
|
||||
}
|
||||
return view('web.templates.'.$site);
|
||||
return view('web.templates.'.$site, $data);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ class Kernel extends HttpKernel
|
|||
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
|
||||
'admin' => \App\Http\Middleware\Admin::class,
|
||||
'superadmin' => \App\Http\Middleware\SuperAdmin::class,
|
||||
'subdomain' => \App\Http\Middleware\Subdomain::class,
|
||||
'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
|
||||
'can' => \Illuminate\Auth\Middleware\Authorize::class,
|
||||
|
|
|
|||
35
app/Http/Middleware/Subdomain.php
Executable file
35
app/Http/Middleware/Subdomain.php
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\UserShop;
|
||||
use Closure;
|
||||
use Auth;
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Uses;
|
||||
use Util;
|
||||
|
||||
class Subdomain
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
|
||||
if(!empty($request->route('subdomain'))){
|
||||
$user_shop = UserShop::where('slug', $request->route('subdomain'))->where('active', 1)->first();
|
||||
$request->route()->forgetParameter('subdomain');
|
||||
Util::setPostRoute('user.');
|
||||
if($user_shop){
|
||||
\Session::put('user_shop', $user_shop);
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
return redirect(config('app.url'));
|
||||
|
||||
}
|
||||
}
|
||||
50
app/Models/Shipping.php
Normal file
50
app/Models/Shipping.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Shipping extends Model
|
||||
{
|
||||
protected $table = 'shippings';
|
||||
|
||||
protected $casts = [
|
||||
'trans_name' => 'array',
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'name', 'active', 'free'
|
||||
];
|
||||
|
||||
public function _format_number($value){
|
||||
return preg_replace("/[^0-9,]/", "", $value);
|
||||
}
|
||||
|
||||
public function setFreeAttribute( $value ) {
|
||||
if($value == ""){
|
||||
$this->attributes['free'] = null;
|
||||
}else{
|
||||
$value = $this->_format_number($value);
|
||||
$this->attributes['free'] = floatval(str_replace(',', '.', $value));
|
||||
}
|
||||
}
|
||||
public function getFormattedFree()
|
||||
{
|
||||
if($this->attributes['free'] === null) {
|
||||
return "";
|
||||
}
|
||||
if(\App::getLocale() == "en"){
|
||||
return number_format($this->attributes['free'], 2, '.', ',');
|
||||
}
|
||||
return number_format($this->attributes['free'], 2, ',', '.');
|
||||
}
|
||||
|
||||
|
||||
public function countries(){
|
||||
return $this->hasMany('App\Models\ShippingCountry', 'shipping_id', 'id');
|
||||
}
|
||||
|
||||
public function prices(){
|
||||
return $this->hasMany('App\Models\ShippingPrice', 'shipping_id', 'id');
|
||||
}
|
||||
}
|
||||
25
app/Models/ShippingCountry.php
Normal file
25
app/Models/ShippingCountry.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ShippingCountry extends Model
|
||||
{
|
||||
protected $table = 'shipping_countries';
|
||||
|
||||
|
||||
protected $fillable = [
|
||||
'shipping_id', 'country_id'
|
||||
];
|
||||
|
||||
public function shipping()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shipping', 'shipping_id');
|
||||
}
|
||||
|
||||
public function country()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Country', 'country_id');
|
||||
}
|
||||
}
|
||||
93
app/Models/ShippingPrice.php
Normal file
93
app/Models/ShippingPrice.php
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ShippingPrice extends Model
|
||||
{
|
||||
protected $table = 'shipping_prices';
|
||||
|
||||
protected $fillable = [
|
||||
'shipping_id', 'price', 'tax', 'factor', 'total_from', 'total_to', 'weight_from', 'weight_to',
|
||||
];
|
||||
|
||||
public function shipping()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Shipping', 'shipping_id');
|
||||
}
|
||||
|
||||
|
||||
public function _format_number($value){
|
||||
return preg_replace("/[^0-9,]/", "", $value);
|
||||
}
|
||||
|
||||
public function setPriceAttribute( $value ) {
|
||||
$value = $this->_format_number($value);
|
||||
$this->attributes['price'] = floatval(str_replace(',', '.', $value));
|
||||
}
|
||||
public function setFactorAttribute( $value ) {
|
||||
$value = $this->_format_number($value);
|
||||
$this->attributes['factor'] = floatval(str_replace(',', '.', $value));
|
||||
}
|
||||
public function setTaxAttribute( $value ) {
|
||||
$value = $this->_format_number($value);
|
||||
$this->attributes['tax'] = floatval(str_replace(',', '.', $value));
|
||||
}
|
||||
public function setPriceOldAttribute( $value ) {
|
||||
$value = $this->_format_number($value);
|
||||
$this->attributes['price_old'] = floatval(str_replace(',', '.', $value));
|
||||
}
|
||||
|
||||
public function setTotalFromAttribute( $value ) {
|
||||
$value = $this->_format_number($value);
|
||||
$this->attributes['total_from'] = floatval(str_replace(',', '.', $value));
|
||||
}
|
||||
public function setTotalToAttribute( $value ) {
|
||||
$value = $this->_format_number($value);
|
||||
$this->attributes['total_to'] = floatval(str_replace(',', '.', $value));
|
||||
}
|
||||
|
||||
|
||||
public function getFormattedPrice()
|
||||
{
|
||||
if(\App::getLocale() == "en"){
|
||||
return number_format($this->attributes['price'], 2, '.', ',');
|
||||
}
|
||||
return number_format($this->attributes['price'], 2, ',', '.');
|
||||
}
|
||||
public function getFormattedTax()
|
||||
{
|
||||
if(\App::getLocale() == "en"){
|
||||
return number_format($this->attributes['tax'], 2, '.', ',');
|
||||
}
|
||||
return number_format($this->attributes['tax'], 2, ',', '.');
|
||||
}
|
||||
|
||||
public function getFormattedFactor()
|
||||
{
|
||||
if(\App::getLocale() == "en"){
|
||||
return number_format($this->attributes['factor'], 2, '.', ',');
|
||||
}
|
||||
return number_format($this->attributes['factor'], 2, ',', '.');
|
||||
}
|
||||
|
||||
|
||||
public function getFormatTotalFrom()
|
||||
{
|
||||
if(\App::getLocale() == "en"){
|
||||
return number_format($this->attributes['total_from'], 2, '.', ',');
|
||||
}
|
||||
return number_format($this->attributes['total_from'], 2, ',', '.');
|
||||
}
|
||||
public function getFormattedTotalTo()
|
||||
{
|
||||
if(\App::getLocale() == "en"){
|
||||
return number_format($this->attributes['total_to'], 2, '.', ',');
|
||||
}
|
||||
return number_format($this->attributes['total_to'], 2, ',', '.');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -55,7 +55,7 @@ class UserShop extends Model
|
|||
|
||||
public function getSubdomainStatus()
|
||||
{
|
||||
if($this->is_online != NULL){
|
||||
if($this->is_online !== NULL){
|
||||
return $this->is_online;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ namespace App\Services;
|
|||
class Util
|
||||
{
|
||||
|
||||
private static $postRoute = 'base.';
|
||||
|
||||
public static function formatDate(){
|
||||
if(\App::getLocale() == "en"){
|
||||
|
|
@ -28,4 +29,30 @@ class Util
|
|||
}
|
||||
return 'd.m.Y - H:i';
|
||||
}
|
||||
public static function getPostRoute(){
|
||||
return self::$postRoute;
|
||||
}
|
||||
public static function setPostRoute($postRoute){
|
||||
self::$postRoute = $postRoute;
|
||||
}
|
||||
|
||||
public static function getUserShop(){
|
||||
if(\Session::has('user_shop')){
|
||||
if($user_shop = \Session::get('user_shop')){
|
||||
return $user_shop;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function addRoute($p = []){
|
||||
$b = [];
|
||||
if(\Session::has('user_shop')){
|
||||
if($user_shop = \Session::get('user_shop')){
|
||||
$b = ['subdomain' => $user_shop->slug];
|
||||
}
|
||||
}
|
||||
return array_merge($p, $b);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue