Skip to content

Instantly share code, notes, and snippets.

@mohsin
Last active August 30, 2020 14:43
Show Gist options
  • Save mohsin/54fa42e13c8124fb4f2b2526d396d2e2 to your computer and use it in GitHub Desktop.
Save mohsin/54fa42e13c8124fb4f2b2526d396d2e2 to your computer and use it in GitHub Desktop.
Code to make Mohsin.Social plugin with OFFLINE.Mall plugin of OctoberCMS
// Add code on the Code section of the layout file.
function onInit() {
Event::listen('rainlab.user.login', function($user) {
// If the user doesn't have a Customer model it was created via the backend.
// Make sure to add the Customer model now
if ( ! $user->customer && ! $user->is_guest) {
$customer = new \OFFLINE\Mall\Models\Customer();
$customer->firstname = $user->name;
$customer->lastname = $user->surname;
$customer->user_id = $user->id;
$customer->is_guest = false;
$customer->save();
$user->customer = $customer;
}
if ($user->customer->is_guest) {
Auth::logout();
throw new AuthException('offline.mall::lang.components.signup.errors.user_is_guest');
}
\OFFLINE\Mall\Models\Cart::transferSessionCartToCustomer($user->customer);
\OFFLINE\Mall\Models\Wishlist::transferToCustomer($user->customer);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment