API User Like

This commit is contained in:
Kevin Adametz 2021-12-25 02:59:15 +01:00
parent 80e6540f73
commit cc5c147c27
9 changed files with 46 additions and 26 deletions

View file

@ -264,7 +264,7 @@ class ShoppingUserController extends Controller
$shopping_user = ShoppingUser::create($data);
//Kundenhoheit prüfen
$priority = CustomerPriority::checkOne($shopping_user, true, false);
$priority = CustomerPriority::checkOne($shopping_user, true, false, true);
\App\Services\Shop::newUserOrder($shopping_user->number);
//exists //like //update
$user = $this->prepareForShow($shopping_user);

View file

@ -52,7 +52,6 @@ class HomepartyController extends Controller
$step = 10;
}
}
}
if($homeparty->homeparty_host){
$homeparty_user = $homeparty->homeparty_host;

View file

@ -145,7 +145,7 @@ class UserShopController extends Controller
return redirect(route('user_shop'));
}
catch (Exception $e) {
catch (\Exception $e) {
\Session()->flash('alert-danger', "Fehler".$e);
return redirect(route('user_shop'));
}
@ -230,7 +230,7 @@ class UserShopController extends Controller
return redirect(route('user_shop'));
}
catch (Exception $e) {
catch (\Exception $e) {
\Session()->flash('alert-danger', "Fehler".$e);
return redirect(route('user_shop'));
}
@ -262,12 +262,8 @@ class UserShopController extends Controller
/**
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function userShopRegisterForm(){
if(Request::get('shop_submit') == 'check'){
$rules = array(
'user_shop_name' => ' required|alpha_dash|profanity|unique:user_shops,name|min:4|max:20|full_word_check',
@ -282,10 +278,10 @@ class UserShopController extends Controller
if ($validator->fails()) {
\Session()->flash('shop-name-error', 'error');
return redirect()->back()->withErrors($validator)->withRequest();
return redirect()->back()->withErrors($validator)->withInput(Request::all());
}
\Session()->flash('shop-name-error', 'check');
return redirect(route('user_shop'))->withRequest();
return redirect(route('user_shop'))->withInput(Request::all());
}
if(Request::get('shop_submit') == 'action') {
@ -313,16 +309,15 @@ class UserShopController extends Controller
);
$validator = Validator::make(Request::all(), $rules);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator)->withRequest();
return redirect()->back()->withErrors($validator)->withInput(Request::all());
}
//all is right - save
$user = Auth::user();
$data = Request::all();
$slug = SlugService::createSlug(UserShop::class, 'slug', $data['user_shop_name']);
$user_shop = UserShop::create([
'user_id' => $user->id,
'name' => $data['user_shop_name'],
'name' => $slug,
'active' => true,
'active_date' => now(),
]

View file

@ -59,7 +59,6 @@ class CardController extends Controller
$image = $product->images->first()->slug;
}
$quantity = Request::get('quantity') ? Request::get('quantity') : 1;
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), $quantity, $product->price, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight]);
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), $quantity, $product->getPriceWith(Yard::instance('shopping')->getUserTaxFree(), false, Yard::instance('shopping')->getUserCountry()), ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight]);
if(Yard::instance('shopping')->getUserTaxFree()){
Yard::setTax($cartItem->rowId, 0);

View file

@ -50,8 +50,7 @@ class CheckoutController extends Controller
$is_for = isset($shopping_data['is_for']) ? $shopping_data['is_for'] : false;
$homeparty_id = isset($shopping_data['homeparty_id']) ? $shopping_data['homeparty_id'] : null;
$shopping_user = null;
/*if(!$this->getPayments('shopping_user_id') && Util::getAuthUser()){//$is_from !== 'shopping' && ){ //
$shopping_user = $this->shoppingUserAuthData($is_from, $is_for, $shopping_data);
@ -84,6 +83,7 @@ class CheckoutController extends Controller
$shopping_user = ShoppingUser::findOrFail($this->getPayments('shopping_user_id'));
$shopping_user->billing_state = Shop::getCountryShippingCountryId($shopping_user->billing_country_id);
$shopping_user->shipping_state = Shop::getCountryShippingCountryId($shopping_user->shipping_country_id);
$shopping_user->same_as_billing = $shopping_user->same_as_billing ? false : true; //reinvert
}
if($shopping_user->same_as_billing === NULL){
$shopping_user->same_as_billing = false;
@ -446,7 +446,6 @@ class CheckoutController extends Controller
$data['same_as_billing'] = isset($data['same_as_billing']) ? false : true; //reinvert
$data['accepted_data_checkbox'] = isset($data['accepted_data_checkbox']) ? true : false;
$shopping_user = false;
if($this->getPayments('shopping_user_id')){
$shopping_user = ShoppingUser::find($this->getPayments('shopping_user_id'));

View file

@ -29,10 +29,19 @@ class CustomerPriority
return $shopping_users;
}
public static function checkOne($shopping_user, $mail=false, $newCustomer = true){
public static function checkOne($shopping_user, $mail=false, $newCustomer = true, $entryExistsLike = false){
//look for entry
if(self::entryExists($shopping_user)){
return 'exists';
if($entryExistsLike){
if(self::entryExistsLike($shopping_user)){
if($mail){ //send mail
Mail::to(config('app.info_mail'))->send(new MailInfo($shopping_user, 'check_is_like_customer'));
}
return 'exists';
}
}else{
if(self::entryExists($shopping_user)){
return 'exists';
}
}
if(self::entryLike($shopping_user)){
if($mail){ //send mail
@ -117,11 +126,13 @@ class CustomerPriority
$change = [];
$ret = 'update';
//email geändert
if(isset($data['billing_email']) && $shopping_user->billing_email != $data['billing_email']){
$found = ShoppingUser::where('auth_user_id', '=', NULL)
->where('number', '!=', NULL) //has number
->where('id', '!=', $shopping_user->id)
->where('billing_email', '=', $data['billing_email'])
->where('member_id', '!=', $shopping_user->member_id)
->get()->pluck('number', 'id')->unique()->toArray();
if($found && count($found)){
foreach ($found as $key=>$val){
@ -139,6 +150,7 @@ class CustomerPriority
->where('id', '!=', $shopping_user->id)
->where('billing_lastname', '=', $data['billing_lastname'])
->where('billing_zipcode', '=', $data['billing_zipcode'])
->where('member_id', '!=', $shopping_user->member_id)
->get()->pluck('number', 'id')->unique()->toArray();
if($found && count($found)){
foreach ($found as $key=>$val){
@ -198,6 +210,23 @@ class CustomerPriority
return false;
}
private static function entryExistsLike($shopping_user)
{
$matches = ShoppingUser::where('auth_user_id', '=', NULL)
->where('number', '!=', NULL) //has number
->where('id', '!=', $shopping_user->id)
->where('member_id', '!=', $shopping_user->member_id)
->where('billing_email', '=', $shopping_user->billing_email)
->get()->pluck('number', 'id')->unique()->toArray();
if($matches && count($matches)){
$shopping_user->is_like = true;
$shopping_user->setNotice(self::$user_notice_key, $matches);
$shopping_user->save();
return true;
}
return false;
}
private static function entryLike($shopping_user){
//check same last name und PLZ
$matches = ShoppingUser::select('*')

View file

@ -1,4 +0,0 @@
<?php
phpinfo();
?>

View file

@ -75,7 +75,8 @@
<p>
<span class="text-muted">#{{$current->member->number}}</span><br>
{{$current->member->getFullName()}}<br>
{{$current->member->account->zipcode}} {{$current->member->account->city}}<br>
@if(isset($current->member->account->zipcode)){{$current->member->account->zipcode}} @endif
@if(isset($current->member->account->city)){{$current->member->account->city}} @endif <br>
@if($current->member->shop)
@if($current->member->isActive() && $current->member->isActiveShop())
<a href="{{$current->member->shop->getSubdomain(false)}}" class="badge badge-success" target="_blank">{{$current->member->shop->getSubdomain(false)}}</a>

View file

@ -419,6 +419,8 @@
</div>
</div>
@else
@if($is_from === 'user_order') {!! Form::hidden('same_as_billing', $shopping_user->same_as_billing) !!} @endif
<div class="row" @if($is_from === 'user_order') style="display: none" @endif>
<div class="col-lg-12 nomargin clearfix">
<hr>