Standard-Shop fuer jeden Berater: Kundenbestellung ohne Shop crashte nicht mehr

Berater ohne UserShop liefen bei Kundenbestellungen (abo-ot-customer) in
"Attempt to read property id on null". Shops werden jetzt bei Freischaltung
und bei Bedarf automatisch angelegt (Name aus Vor-/Nachname, bei Belegung
-2, -3, ...). Nachtrag fuer Bestandsberater: php artisan user:ensure-shops.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin 2026-09-28 08:13:29 +00:00
parent 2381bbe3b9
commit 083d643220
7 changed files with 306 additions and 7 deletions

View file

@ -12,6 +12,7 @@ use App\Models\ShoppingOrderItem;
use App\Models\ShoppingUser;
use App\Services\CustomerPriority;
use App\Services\Shop;
use App\Services\UserShopService;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@ -638,7 +639,7 @@ class ShoppingUserController extends Controller
'auth_user_id' => $shopping_user->auth_user_id,
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
'language' => \App::getLocale(),
'user_shop_id' => auth()->user()->user_sponsor->shop->id,
'user_shop_id' => UserShopService::ensureForUser(auth()->user()->user_sponsor)->id,
'payment_for' => 7,
'member_id' => $shopping_user->member_id,
'total' => Yard::instance('shopping')->total(2, '.', ''),

View file

@ -14,6 +14,7 @@ use App\Repositories\UserRepository;
use App\Services\HTMLHelper;
use App\Services\SysLog;
use App\Services\UserService;
use App\Services\UserShopService;
use App\User;
use Auth;
use Carbon\Carbon;
@ -344,6 +345,7 @@ class LeadController extends Controller
$user->confirmation_code_to = null;
$user->confirmation_code_remider = 0;
$user->save();
UserShopService::ensureForUser($user);
// mail with code to user?
Mail::to($user->email)->locale($user->getLocale())->send(new MailAccountActive($user));

View file

@ -17,6 +17,7 @@ use App\Services\Payment;
use App\Services\ProductOrderContext;
use App\Services\Shop;
use App\Services\UserService;
use App\Services\UserShopService;
use App\Services\Util;
use App\User;
use Auth;
@ -306,11 +307,12 @@ class OrderController extends Controller
private function processCustomerPayment($user, $identifier, $data, $id, $for)
{
$shopping_user = ShoppingUser::find($id);
$user_shop = UserShopService::ensureForUser($user);
$shopping_instance = ShoppingInstance::create([
'identifier' => $identifier,
'user_shop_id' => $user->shop->id,
'user_shop_id' => $user_shop->id,
'payment' => 6, // Berater Shop to Customer Shop
'subdomain' => $user->shop->getSubdomain(),
'subdomain' => $user_shop->getSubdomain(),
'country_id' => Yard::instance('shopping')->getShippingCountryId(),
'language' => $shopping_user->getLocale(), // hier wird die Sprache des Kunden verwendet
'amount' => Yard::instance('shopping')->totalWithShipping(2, '.', ''),

View file

@ -15,6 +15,7 @@ use App\Repositories\ContractPDFRepository;
use App\Repositories\FileRepository;
use App\Repositories\UserRepository;
use App\Services\UserService;
use App\Services\UserShopService;
use App\Services\Util;
use App\User;
use Auth;
@ -416,6 +417,7 @@ class WizardController extends Controller
$user->confirmation_code_to = null;
$user->confirmation_code_remider = 0;
$user->save();
UserShopService::ensureForUser($user);
// mail with code to user?
if ($user->isTestMode()) {
@ -604,7 +606,7 @@ class WizardController extends Controller
if ($product->images->count()) {
$image = $product->images->first()->slug;
}
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->getPriceWith(\App\Services\UserService::getTaxFree(), false, \App\Services\UserService::$user_country), false, false, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'no_free_shipping' => $product->no_free_shipping, 'free_shipping_consultant' => $product->free_shipping_consultant, 'show_on' => $product->show_on]);
$cartItem = Yard::instance('shopping')->add($product->id, $product->getLang('name'), 1, $product->getPriceWith(UserService::getTaxFree(), false, UserService::$user_country), false, false, ['image' => $image, 'slug' => $product->slug, 'weight' => $product->weight, 'points' => $product->points, 'no_commission' => $product->no_commission, 'no_free_shipping' => $product->no_free_shipping, 'free_shipping_consultant' => $product->free_shipping_consultant, 'show_on' => $product->show_on]);
if ($cartItem->qty > 1) {
Yard::instance('shopping')->update($cartItem->rowId, 1);
}
@ -613,10 +615,10 @@ class WizardController extends Controller
Yard::instance('shopping')->remove($existingItem->rowId);
}
}
if (\App\Services\UserService::getTaxFree()) {
if (UserService::getTaxFree()) {
Yard::setTax($cartItem->rowId, 0);
} else {
Yard::setTax($cartItem->rowId, $product->getTaxWith(\App\Services\UserService::$user_country));
Yard::setTax($cartItem->rowId, $product->getTaxWith(UserService::$user_country));
}
do {
@ -626,7 +628,7 @@ class WizardController extends Controller
$data = [];
$data['is_from'] = 'wizard';
$data['is_for'] = 'me';
$data['user_price_infos'] = \App\Services\UserService::getUserPriceInfos();
$data['user_price_infos'] = UserService::getUserPriceInfos();
ShoppingInstance::create([
'identifier' => $identifier,