23-01-2026
This commit is contained in:
parent
a939cd51ef
commit
a8b395e20d
248 changed files with 29342 additions and 4805 deletions
|
|
@ -6,7 +6,8 @@ use Carbon;
|
|||
use App\Models\UserAbo;
|
||||
use App\Services\AboHelper;
|
||||
|
||||
class AboRepository extends BaseRepository {
|
||||
class AboRepository extends BaseRepository
|
||||
{
|
||||
|
||||
|
||||
public function __construct()
|
||||
|
|
@ -15,75 +16,99 @@ class AboRepository extends BaseRepository {
|
|||
}
|
||||
|
||||
|
||||
public function setModel(UserAbo $model){
|
||||
public function setModel(UserAbo $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
public function update($data)
|
||||
{
|
||||
if(isset($data['action'])){
|
||||
if($data['action'] === 'abo_update_settings'){
|
||||
if($this->validate($data)){
|
||||
if (isset($data['action'])) {
|
||||
if ($data['action'] === 'abo_update_settings') {
|
||||
if ($this->validate($data)) {
|
||||
$this->updateStatus($data);
|
||||
$this->model->abo_interval = $data['abo_interval'];
|
||||
$this->model->next_date = AboHelper::setNextDate(now(), $data['abo_interval']);
|
||||
$this->model ->save();
|
||||
$this->model->save();
|
||||
\Session()->flash('alert-success', 'Einstellungen gespeichert');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function create($data){
|
||||
public function create($data) {}
|
||||
|
||||
}
|
||||
|
||||
private function updateStatus($data){
|
||||
private function updateStatus($data)
|
||||
{
|
||||
// Handle cancellation
|
||||
if (isset($data['abo_cancel']) && $data['abo_cancel'] == 'true') {
|
||||
// Status 4 = abo_cancel (storniert/gekündigt)
|
||||
$this->model->status = 4;
|
||||
$this->model->active = false;
|
||||
$this->model->cancel_date = now();
|
||||
$this->model->save();
|
||||
return;
|
||||
}
|
||||
|
||||
$active = (isset($data['abo_is_active']) && $data['abo_is_active']) ? true : false;
|
||||
//if status is active and active is false, set status to inactive
|
||||
if($this->model->active && !$active){
|
||||
if($this->model->status = 2){ //okay
|
||||
$this->model->status = 6; //
|
||||
if ($this->model->active && !$active) {
|
||||
if ($this->model->status == 2) { //okay
|
||||
$this->model->status = 6; //inactive
|
||||
$this->model->active = false;
|
||||
$this->model->save();
|
||||
}
|
||||
}
|
||||
if(!$this->model->active && $active){
|
||||
if($this->model->status = 6){ //inactive
|
||||
if (!$this->model->active && $active) {
|
||||
if ($this->model->status = 6) { //inactive
|
||||
$this->model->status = 2; //okay
|
||||
$this->model->active = true;
|
||||
$this->model->save();
|
||||
}
|
||||
}
|
||||
$this->model->active = $active;
|
||||
return;
|
||||
}
|
||||
|
||||
private function validate($data){
|
||||
if($data['view'] !== 'admin'){
|
||||
if($this->model->is_for === 'me' && $this->model->user_id !== \Auth::user()->id){
|
||||
private function validate($data)
|
||||
{
|
||||
if ($data['view'] !== 'admin') {
|
||||
if ($this->model->is_for === 'me' && $this->model->user_id !== \Auth::user()->id) {
|
||||
\Session()->flash('alert-error', 'Unauthorized action. User ID does not match.');
|
||||
return false;
|
||||
}
|
||||
if($this->model->is_for === 'ot' && $this->model->member_id !== \Auth::user()->id){
|
||||
if ($this->model->is_for === 'ot' && $this->model->member_id !== \Auth::user()->id) {
|
||||
\Session()->flash('alert-error', 'Unauthorized action. User ID does not match.');
|
||||
return false;
|
||||
}
|
||||
if($data['view'] === 'me' && $this->model->is_for !== 'me'){
|
||||
if ($data['view'] === 'me' && $this->model->is_for !== 'me') {
|
||||
\Session()->flash('alert-error', 'Unauthorized action. Is not for me');
|
||||
return false;
|
||||
}
|
||||
if($data['view'] === 'ot' && $this->model->is_for !== 'ot'){
|
||||
if ($data['view'] === 'ot' && $this->model->is_for !== 'ot') {
|
||||
\Session()->flash('alert-error', 'Unauthorized action. Is not your customer');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(!in_array($data['abo_interval'], \App\Models\UserAbo::$aboDeliveryDays)){
|
||||
if (!in_array($data['abo_interval'], \App\Models\UserAbo::$aboDeliveryDays)) {
|
||||
//to check if user is not admin
|
||||
\Session()->flash('alert-error', __('abo.error_abo_interval'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Prüfung: Wenn das Abo diesen Monat noch nicht ausgeführt wurde (oder noch nie),
|
||||
// darf das Abo-Intervall nicht auf einen Tag gesetzt werden, der bereits vergangen ist (oder heute ist),
|
||||
// da setNextDate das nächste Ausführungsdatum sonst auf den nächsten Monat setzt und dieser Monat übersprungen wird.
|
||||
$executedThisMonth = $this->model->last_date && \Carbon\Carbon::parse($this->model->last_date)->isCurrentMonth();
|
||||
|
||||
if (!$executedThisMonth && $data['abo_interval'] <= now()->day) {
|
||||
\Session()->flash('alert-error', __('abo.error_abo_interval_in_the_past'));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ use App\Models\ShoppingOrderItem;
|
|||
use Illuminate\Support\Collection;
|
||||
|
||||
|
||||
class CheckoutRepository extends BaseRepository {
|
||||
class CheckoutRepository extends BaseRepository
|
||||
{
|
||||
|
||||
private $session;
|
||||
private $instance;
|
||||
|
|
@ -26,11 +27,12 @@ class CheckoutRepository extends BaseRepository {
|
|||
$this->instance = 'checkout';
|
||||
}
|
||||
|
||||
public function makeShoppingOrder($shopping_user, $data){
|
||||
public function makeShoppingOrder($shopping_user, $data)
|
||||
{
|
||||
|
||||
$user_shop = Util::getUserShop();
|
||||
|
||||
if($shopping_user->is_from === 'homeparty'){
|
||||
if ($shopping_user->is_from === 'homeparty') {
|
||||
//get data
|
||||
$homeparty = Homeparty::find($shopping_user->homeparty_id);
|
||||
//set Data!
|
||||
|
|
@ -50,37 +52,37 @@ class CheckoutRepository extends BaseRepository {
|
|||
'subtotal_ws' => 0,
|
||||
'tax' => $total - $homeparty->order['ek_price_net'],
|
||||
'total_shipping' => Yard::instance($this->instance)->totalWithShipping(2, '.', ''),
|
||||
'points' => $homeparty->order['points'] - $homeparty->order['bonus_points_diff'],
|
||||
'points' => round($homeparty->order['points'] - $homeparty->order['bonus_points_diff'], 2),
|
||||
'weight' => 0,
|
||||
'txaction' => 'prev',
|
||||
'mode' => Util::getUserShoppingMode(),
|
||||
];
|
||||
}elseif($shopping_user->is_from === 'collection'){
|
||||
//get data
|
||||
$ShoppingCollectOrder = ShoppingCollectOrder::find($shopping_user->shopping_collect_order_id);
|
||||
//set Data!
|
||||
$total = Yard::instance($this->instance)->total(2, '.', ''); //ek_price
|
||||
$data = [
|
||||
'shopping_user_id' => $shopping_user->id,
|
||||
'auth_user_id' => $shopping_user->auth_user_id,
|
||||
'country_id' => Yard::instance($this->instance)->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
'user_shop_id' => $user_shop->id,
|
||||
'payment_for' => $shopping_user->getOrderPaymentFor(),
|
||||
'total' => $total,
|
||||
'subtotal' => $ShoppingCollectOrder->price_total_net,
|
||||
'shipping' => 0,
|
||||
'shipping_net' => 0,
|
||||
'subtotal_ws' => $ShoppingCollectOrder->price_total_net,
|
||||
'tax' => $ShoppingCollectOrder->tax_total,
|
||||
'tax_split' => $ShoppingCollectOrder->tax_split,
|
||||
'total_shipping' => Yard::instance($this->instance)->totalWithShipping(2, '.', ''),
|
||||
'points' => $ShoppingCollectOrder->points,
|
||||
'weight' => 0,
|
||||
'txaction' => 'prev',
|
||||
'mode' => Util::getUserShoppingMode(),
|
||||
];
|
||||
}else{
|
||||
} elseif ($shopping_user->is_from === 'collection') {
|
||||
//get data
|
||||
$ShoppingCollectOrder = ShoppingCollectOrder::find($shopping_user->shopping_collect_order_id);
|
||||
//set Data!
|
||||
$total = Yard::instance($this->instance)->total(2, '.', ''); //ek_price
|
||||
$data = [
|
||||
'shopping_user_id' => $shopping_user->id,
|
||||
'auth_user_id' => $shopping_user->auth_user_id,
|
||||
'country_id' => Yard::instance($this->instance)->getShippingCountryId(),
|
||||
'language' => \App::getLocale(),
|
||||
'user_shop_id' => $user_shop->id,
|
||||
'payment_for' => $shopping_user->getOrderPaymentFor(),
|
||||
'total' => $total,
|
||||
'subtotal' => $ShoppingCollectOrder->price_total_net,
|
||||
'shipping' => 0,
|
||||
'shipping_net' => 0,
|
||||
'subtotal_ws' => $ShoppingCollectOrder->price_total_net,
|
||||
'tax' => $ShoppingCollectOrder->tax_total,
|
||||
'tax_split' => $ShoppingCollectOrder->tax_split,
|
||||
'total_shipping' => Yard::instance($this->instance)->totalWithShipping(2, '.', ''),
|
||||
'points' => round($ShoppingCollectOrder->points, 2),
|
||||
'weight' => 0,
|
||||
'txaction' => 'prev',
|
||||
'mode' => Util::getUserShoppingMode(),
|
||||
];
|
||||
} else {
|
||||
$data = [
|
||||
'shopping_user_id' => $shopping_user->id,
|
||||
'auth_user_id' => $shopping_user->auth_user_id,
|
||||
|
|
@ -95,7 +97,7 @@ class CheckoutRepository extends BaseRepository {
|
|||
'subtotal_ws' => Yard::instance($this->instance)->subtotalWithShipping(2, '.', ''),
|
||||
'tax' => Yard::instance($this->instance)->taxWithShipping(2, '.', ''),
|
||||
'total_shipping' => Yard::instance($this->instance)->totalWithShipping(2, '.', ''),
|
||||
'points' => Yard::instance($this->instance)->points(),
|
||||
'points' => round(Yard::instance($this->instance)->points(), 2),
|
||||
'weight' => Yard::instance($this->instance)->weight(),
|
||||
'is_abo' => isset($data['is_abo']) ? $data['is_abo'] : false,
|
||||
'abo_interval' => isset($data['abo_interval']) ? $data['abo_interval'] : null,
|
||||
|
|
@ -104,60 +106,60 @@ class CheckoutRepository extends BaseRepository {
|
|||
];
|
||||
}
|
||||
|
||||
$shopping_order= false;
|
||||
if($this->getSessionPayments('shopping_order_id')){
|
||||
$shopping_order = false;
|
||||
if ($this->getSessionPayments('shopping_order_id')) {
|
||||
$shopping_order = ShoppingOrder::find($this->getSessionPayments('shopping_order_id'));
|
||||
if($shopping_order){
|
||||
if ($shopping_order) {
|
||||
$shopping_order->fill($data);
|
||||
$shopping_order->save();
|
||||
}
|
||||
}
|
||||
if(!$shopping_order){
|
||||
if (!$shopping_order) {
|
||||
$shopping_order = ShoppingOrder::create($data);
|
||||
if($shopping_user->is_from === 'collection' && $ShoppingCollectOrder){
|
||||
if ($shopping_user->is_from === 'collection' && $ShoppingCollectOrder) {
|
||||
$ShoppingCollectOrder->shopping_order_id = $shopping_order->id;
|
||||
$ShoppingCollectOrder->save();
|
||||
}
|
||||
}
|
||||
$this->putSessionPayments('shopping_order_id', $shopping_order->id);
|
||||
|
||||
$items = Yard::instance($this->instance)->getContentByOrder();
|
||||
$shopping_order->shopping_order_items()->each(function($model) use ($items, $shopping_order, $shopping_user) {
|
||||
foreach ($items as $item) {
|
||||
if ($model->row_id === $item->rowId) {
|
||||
$price_net = Yard::instance($this->instance)->rowPriceNet($item, 2, '.', '');
|
||||
$tax = $item->price - $price_net;
|
||||
$data = [
|
||||
'shopping_order_id' => $shopping_order->id,
|
||||
'row_id' => $item->rowId,
|
||||
'product_id' => $item->id,
|
||||
'comp' => $item->options->comp,
|
||||
'qty' => $item->qty,
|
||||
'price' => $item->price,
|
||||
'price_net' => $price_net,
|
||||
'tax_rate' => $item->taxRate,
|
||||
'tax' => $tax,
|
||||
'price_vk_net' => $shopping_order->getPriceVkNetBy($item->id),
|
||||
'discount' => $item->options->no_commission ? 0 : $shopping_order->getUserDiscount(),
|
||||
'points' => $item->options->points,
|
||||
'slug' => $item->options->slug,
|
||||
];
|
||||
if($shopping_user->is_from === 'homeparty'){
|
||||
$data['homeparty_id'] = (int) $shopping_user->homeparty_id;
|
||||
$data['product_id'] = null;
|
||||
}
|
||||
if($shopping_user->is_from === 'collection'){
|
||||
$data['shopping_collect_order_id'] = (int) $shopping_user->shopping_collect_order_id;
|
||||
$data['product_id'] = null;
|
||||
}
|
||||
$model->fill($data)->save();
|
||||
return false;
|
||||
$items = Yard::instance($this->instance)->getContentByOrder();
|
||||
$shopping_order->shopping_order_items()->each(function ($model) use ($items, $shopping_order, $shopping_user) {
|
||||
foreach ($items as $item) {
|
||||
if ($model->row_id === $item->rowId) {
|
||||
$price_net = Yard::instance($this->instance)->rowPriceNet($item, 2, '.', '');
|
||||
$tax = $item->price - $price_net;
|
||||
$data = [
|
||||
'shopping_order_id' => $shopping_order->id,
|
||||
'row_id' => $item->rowId,
|
||||
'product_id' => $item->id,
|
||||
'comp' => $item->options->comp,
|
||||
'qty' => $item->qty,
|
||||
'price' => $item->price,
|
||||
'price_net' => $price_net,
|
||||
'tax_rate' => $item->taxRate,
|
||||
'tax' => $tax,
|
||||
'price_vk_net' => $shopping_order->getPriceVkNetBy($item->id),
|
||||
'discount' => $item->options->no_commission ? 0 : $shopping_order->getUserDiscount(),
|
||||
'points' => $item->options->points,
|
||||
'slug' => $item->options->slug,
|
||||
];
|
||||
if ($shopping_user->is_from === 'homeparty') {
|
||||
$data['homeparty_id'] = (int) $shopping_user->homeparty_id;
|
||||
$data['product_id'] = null;
|
||||
}
|
||||
if ($shopping_user->is_from === 'collection') {
|
||||
$data['shopping_collect_order_id'] = (int) $shopping_user->shopping_collect_order_id;
|
||||
$data['product_id'] = null;
|
||||
}
|
||||
$model->fill($data)->save();
|
||||
return false;
|
||||
}
|
||||
return $model->delete();
|
||||
}
|
||||
return $model->delete();
|
||||
});
|
||||
foreach ($items as $item) {
|
||||
if (!ShoppingOrderItem::where('shopping_order_id', $shopping_order->id)->where('row_id', $item->rowId)->count()){
|
||||
if (!ShoppingOrderItem::where('shopping_order_id', $shopping_order->id)->where('row_id', $item->rowId)->count()) {
|
||||
|
||||
$price_net = Yard::instance($this->instance)->rowPriceNet($item, 2, '.', '');
|
||||
$tax = $item->price - $price_net;
|
||||
|
|
@ -178,12 +180,12 @@ class CheckoutRepository extends BaseRepository {
|
|||
'slug' => $item->options->slug
|
||||
];
|
||||
|
||||
if($shopping_user->is_from === 'homeparty'){
|
||||
if ($shopping_user->is_from === 'homeparty') {
|
||||
$data['homeparty_id'] = (int) $shopping_user->homeparty_id;
|
||||
$data['price_vk_net'] = 0;
|
||||
$data['product_id'] = null;
|
||||
}
|
||||
if($shopping_user->is_from === 'collection'){
|
||||
if ($shopping_user->is_from === 'collection') {
|
||||
$data['price_vk_net'] = 0;
|
||||
$data['shopping_collect_order_id'] = (int) $shopping_user->shopping_collect_order_id;
|
||||
$data['product_id'] = null;
|
||||
|
|
@ -191,29 +193,30 @@ class CheckoutRepository extends BaseRepository {
|
|||
$shopping_order_item = ShoppingOrderItem::create($data);
|
||||
}
|
||||
}
|
||||
if($shopping_user->is_from === 'homeparty'){
|
||||
if ($shopping_user->is_from === 'homeparty') {
|
||||
$shopping_order->makeHomepartyTaxSplit();
|
||||
}elseif($shopping_user->is_from === 'collection'){
|
||||
} elseif ($shopping_user->is_from === 'collection') {
|
||||
//is set on create / filll.
|
||||
}else{
|
||||
} else {
|
||||
$shopping_order->makeTaxSplit();
|
||||
}
|
||||
return $shopping_order;
|
||||
}
|
||||
public function makeShoppingUser($data){
|
||||
public function makeShoppingUser($data)
|
||||
{
|
||||
|
||||
$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->getSessionPayments('shopping_user_id')){
|
||||
if ($this->getSessionPayments('shopping_user_id')) {
|
||||
$shopping_user = ShoppingUser::find($this->getSessionPayments('shopping_user_id'));
|
||||
if($shopping_user){
|
||||
if ($shopping_user) {
|
||||
$shopping_user->fill($data);
|
||||
$shopping_user->mode = null;
|
||||
$shopping_user->save();
|
||||
}
|
||||
}
|
||||
if(!$shopping_user){
|
||||
if (!$shopping_user) {
|
||||
$shopping_user = ShoppingUser::create($data);
|
||||
}
|
||||
$this->putSessionPayments('shopping_user_id', $shopping_user->id);
|
||||
|
|
@ -221,53 +224,55 @@ class CheckoutRepository extends BaseRepository {
|
|||
return $shopping_user;
|
||||
}
|
||||
|
||||
public function getPaymentsMethods($is_from, $is_abo = false){
|
||||
public function getPaymentsMethods($is_from, $is_abo = false)
|
||||
{
|
||||
$payment_methods = [];
|
||||
if($is_from !== 'shopping' && Util::getAuthUser()){
|
||||
if ($is_from !== 'shopping' && Util::getAuthUser()) {
|
||||
$user = Util::getAuthUser();
|
||||
$payment_methods['default'] = $user->payment_methods;
|
||||
$payment_methods['data'] = $user->account->payment_data;
|
||||
}else{
|
||||
} else {
|
||||
$payment_methods['default'] = PaymentMethod::getDefaultAsArray($is_abo)->toArray();
|
||||
$payment_methods['data'] = false;
|
||||
}
|
||||
if($is_abo){
|
||||
$payment_methods['active'] = \App\Models\PaymentMethod::where('active', true)->where('is_abo', true)->get()->pluck( 'id', 'short')->toArray();
|
||||
}else{
|
||||
$payment_methods['active'] = \App\Models\PaymentMethod::where('active', true)->get()->pluck( 'id', 'short')->toArray();
|
||||
if ($is_abo) {
|
||||
$payment_methods['active'] = \App\Models\PaymentMethod::where('active', true)->where('is_abo', true)->get()->pluck('id', 'short')->toArray();
|
||||
} else {
|
||||
$payment_methods['active'] = \App\Models\PaymentMethod::where('active', true)->get()->pluck('id', 'short')->toArray();
|
||||
}
|
||||
return $payment_methods;
|
||||
}
|
||||
|
||||
public function isPaymentsMethodsActive($payment_method, $is_from, $is_abo = false){
|
||||
public function isPaymentsMethodsActive($payment_method, $is_from, $is_abo = false)
|
||||
{
|
||||
$payment_names = ['wlt#PPE' => 'PP', 'cc' => 'CC', 'sb#PNT' => 'SB', 'elv' => 'SEPA', 'vor' => 'VOR', 'fnc#MIV' => 'FNC'];
|
||||
$payment_methods = $this->getPaymentsMethods($is_from, $is_abo);
|
||||
if(isset($payment_names[$payment_method])){
|
||||
if (isset($payment_names[$payment_method])) {
|
||||
$payment_with = $payment_names[$payment_method];
|
||||
if(array_key_exists($payment_with, $payment_methods['active']) && in_array($payment_methods['active'][$payment_with], $payment_methods['default'])){
|
||||
return true;
|
||||
if (array_key_exists($payment_with, $payment_methods['active']) && in_array($payment_methods['active'][$payment_with], $payment_methods['default'])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
abort(404);
|
||||
}
|
||||
|
||||
public function makeCustomerShoppingUser($shopping_data, $is_for, $is_from){
|
||||
public function makeCustomerShoppingUser($shopping_data, $is_for, $is_from)
|
||||
{
|
||||
// $shopping_user = ShoppingUser::findOrFail($shopping_data['shopping_user_id']);
|
||||
$shopping_user = new ShoppingUser();
|
||||
$shopping_user->fill($shopping_data);
|
||||
$shopping_user->faker_mail = false;
|
||||
$shopping_user->auth_user_id = null;
|
||||
$shopping_user->homeparty_id = null;
|
||||
$shopping_user->same_as_billing = $shopping_user->same_as_billing ? false : true; //reinvert
|
||||
// $shopping_user->id = null;
|
||||
$shopping_user->accepted_data_checkbox = 1;
|
||||
$shopping_user->is_for = $is_for;
|
||||
$shopping_user->is_from = $is_from;
|
||||
$shopping_user->mode = 'prev';
|
||||
$shopping_user->language = \App::getLocale();
|
||||
return $shopping_user;
|
||||
|
||||
}
|
||||
$shopping_user = new ShoppingUser();
|
||||
$shopping_user->fill($shopping_data);
|
||||
$shopping_user->faker_mail = false;
|
||||
$shopping_user->auth_user_id = null;
|
||||
$shopping_user->homeparty_id = null;
|
||||
$shopping_user->same_as_billing = $shopping_user->same_as_billing ? false : true; //reinvert
|
||||
// $shopping_user->id = null;
|
||||
$shopping_user->accepted_data_checkbox = 1;
|
||||
$shopping_user->is_for = $is_for;
|
||||
$shopping_user->is_from = $is_from;
|
||||
$shopping_user->mode = 'prev';
|
||||
$shopping_user->language = \App::getLocale();
|
||||
return $shopping_user;
|
||||
}
|
||||
|
||||
public function initShoppingUser($is_for, $is_from, $homeparty_id = null)
|
||||
{
|
||||
|
|
@ -275,11 +280,11 @@ class CheckoutRepository extends BaseRepository {
|
|||
$shopping_user->homeparty_id = $homeparty_id;
|
||||
$shopping_user->language = \App::getLocale();
|
||||
//eingeloggter Kunde
|
||||
if(\Auth::guard('customers')->check()){
|
||||
if (\Auth::guard('customers')->check()) {
|
||||
$shopping_user = $this->shoppingUserByAuthCustomer(\Auth::guard('customers')->user());
|
||||
}
|
||||
//eingeloggter User Berater
|
||||
if(\Auth::guard('user')->check()){
|
||||
if (\Auth::guard('user')->check()) {
|
||||
$shopping_user = $this->shoppingUserByAuthUser(\Auth::guard('user')->user(), $is_from, $is_for);
|
||||
}
|
||||
$shopping_user->mode = 'prev';
|
||||
|
|
@ -288,29 +293,31 @@ class CheckoutRepository extends BaseRepository {
|
|||
return $shopping_user;
|
||||
}
|
||||
|
||||
public function shoppingUserByAuthCustomer(\App\Models\Customer $user){
|
||||
public function shoppingUserByAuthCustomer(\App\Models\Customer $user)
|
||||
{
|
||||
|
||||
//clone shopping user!
|
||||
if($user->shopping_user_id){
|
||||
if ($user->shopping_user_id) {
|
||||
$find_shopping_user = ShoppingUser::find($user->shopping_user_id);
|
||||
if($find_shopping_user){
|
||||
if ($find_shopping_user) {
|
||||
$shopping_user = $find_shopping_user->replicate();
|
||||
$shopping_user->billing_country_id = null;
|
||||
$shopping_user->shipping_country_id = null;
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
$shopping_user = new ShoppingUser();
|
||||
$shopping_user->language = \App::getLocale();
|
||||
}
|
||||
|
||||
|
||||
return $shopping_user;
|
||||
}
|
||||
|
||||
public function shoppingUserByAuthUser(\App\User $user, $is_from, $is_for){
|
||||
public function shoppingUserByAuthUser(\App\User $user, $is_from, $is_for)
|
||||
{
|
||||
|
||||
$shopping_user = new ShoppingUser();
|
||||
$shopping_user->language = \App::getLocale();
|
||||
|
||||
|
||||
$shopping_user->billing_salutation = $user->account->salutation;
|
||||
$shopping_user->billing_company = $user->account->company;
|
||||
$shopping_user->billing_firstname = $user->account->first_name;
|
||||
|
|
@ -327,7 +334,7 @@ class CheckoutRepository extends BaseRepository {
|
|||
|
||||
$shopping_user->accepted_data_checkbox = 1;
|
||||
|
||||
|
||||
|
||||
//Lieferadresse
|
||||
$shopping_user->same_as_billing = $user->account->same_as_billing ? false : true;
|
||||
$shopping_user->shipping_salutation = $user->account->shipping_salutation;
|
||||
|
|
@ -340,19 +347,21 @@ class CheckoutRepository extends BaseRepository {
|
|||
$shopping_user->shipping_city = $user->account->shipping_city;
|
||||
//$shopping_user->shipping_country_id = $user->account->shipping_country_id;
|
||||
$shopping_user->shipping_phone = $user->account->shipping_phone;
|
||||
|
||||
$shopping_user->shipping_postnumber = $user->account->shipping_postnumber;
|
||||
|
||||
|
||||
return $shopping_user;
|
||||
}
|
||||
|
||||
public function shoppingUserAuthData($is_from, $is_for, $data = []){
|
||||
public function shoppingUserAuthData($is_from, $is_for, $data = [])
|
||||
{
|
||||
|
||||
$user = Util::getAuthUser();
|
||||
$shopping_user = new ShoppingUser();
|
||||
$shopping_user->auth_user_id = $user->id;
|
||||
$shopping_user->mode = 'prev';
|
||||
$shopping_user->language = \App::getLocale();
|
||||
|
||||
|
||||
$shopping_user->billing_salutation = $user->account->salutation;
|
||||
$shopping_user->billing_company = $user->account->company;
|
||||
$shopping_user->billing_firstname = $user->account->first_name;
|
||||
|
|
@ -374,10 +383,10 @@ class CheckoutRepository extends BaseRepository {
|
|||
$shopping_user->shopping_collect_order_id = isset($data['shopping_collect_order_id']) ? $data['shopping_collect_order_id'] : null;
|
||||
|
||||
//Lieferadresse
|
||||
if($is_from === 'user_order'){
|
||||
if(isset($data['shopping_user_id']) && strpos($data['is_for'], 'ot') !== false){
|
||||
if ($is_from === 'user_order') {
|
||||
if (isset($data['shopping_user_id']) && strpos($data['is_for'], 'ot') !== false) {
|
||||
$s_user = ShoppingUser::findOrFail($data['shopping_user_id']);
|
||||
/* $shopping_user->billing_salutation = $s_user->billing_salutation;
|
||||
/* $shopping_user->billing_salutation = $s_user->billing_salutation;
|
||||
$shopping_user->billing_company = $s_user->billing_company;
|
||||
$shopping_user->billing_firstname = $s_user->billing_firstname;
|
||||
$shopping_user->billing_lastname = $s_user->billing_lastname;
|
||||
|
|
@ -390,7 +399,7 @@ class CheckoutRepository extends BaseRepository {
|
|||
$shopping_user->billing_email = $s_user->billing_email;
|
||||
;*/
|
||||
$shopping_user->faker_mail = $s_user->faker_mail;
|
||||
if(!$s_user->faker_mail){
|
||||
if (!$s_user->faker_mail) {
|
||||
$shopping_user->shipping_email = $s_user->billing_email;
|
||||
}
|
||||
$shopping_user->shopping_user_id = $data['shopping_user_id'];
|
||||
|
|
@ -407,8 +416,8 @@ class CheckoutRepository extends BaseRepository {
|
|||
$shopping_user->shipping_city = isset($data['shipping_city']) ? $data['shipping_city'] : '';
|
||||
$shopping_user->shipping_country_id = Yard::instance($this->instance)->getShippingCountryCountryId();
|
||||
$shopping_user->shipping_phone = isset($data['shipping_phone']) ? $data['shipping_phone'] : '';
|
||||
|
||||
}else{
|
||||
$shopping_user->shipping_postnumber = isset($data['shipping_postnumber']) ? $data['shipping_postnumber'] : '';
|
||||
} else {
|
||||
$shopping_user->same_as_billing = $user->account->same_as_billing ? false : true;
|
||||
$shopping_user->shipping_salutation = $user->account->shipping_salutation;
|
||||
$shopping_user->shipping_company = $user->account->shipping_company;
|
||||
|
|
@ -420,22 +429,24 @@ class CheckoutRepository extends BaseRepository {
|
|||
$shopping_user->shipping_city = $user->account->shipping_city;
|
||||
$shopping_user->shipping_country_id = $user->account->shipping_country_id;
|
||||
$shopping_user->shipping_phone = $user->account->shipping_phone;
|
||||
$shopping_user->shipping_postnumber = $user->account->shipping_postnumber;
|
||||
}
|
||||
|
||||
return $shopping_user;
|
||||
}
|
||||
|
||||
public function putSessionPayments($key, $value){
|
||||
public function putSessionPayments($key, $value)
|
||||
{
|
||||
$content = $this->getContent();
|
||||
$content->put($key, $value);
|
||||
$this->session->put($this->instance, $content);
|
||||
|
||||
}
|
||||
|
||||
public function getSessionPayments($key){
|
||||
public function getSessionPayments($key)
|
||||
{
|
||||
|
||||
$content = $this->getContent();
|
||||
if ($content->has($key)){
|
||||
if ($content->has($key)) {
|
||||
return $content->get($key);
|
||||
}
|
||||
return false;
|
||||
|
|
@ -443,10 +454,10 @@ class CheckoutRepository extends BaseRepository {
|
|||
|
||||
public function sessionDestroy($with_shopping = false)
|
||||
{
|
||||
if($with_shopping){
|
||||
if(session('user_shop_payment') === 1){ //ShoppingInstance payment 1 = webshop
|
||||
if ($with_shopping) {
|
||||
if (session('user_shop_payment') === 1) { //ShoppingInstance payment 1 = webshop
|
||||
Yard::instance('webshop')->destroy();
|
||||
}else{
|
||||
} else {
|
||||
Yard::instance('shopping')->destroy();
|
||||
}
|
||||
}
|
||||
|
|
@ -460,4 +471,4 @@ class CheckoutRepository extends BaseRepository {
|
|||
}
|
||||
return $this->session->get($this->instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
namespace App\Repositories;
|
||||
|
||||
class CustomerRepository extends BaseRepository {
|
||||
use App\Models\ShoppingUser;
|
||||
|
||||
class CustomerRepository extends BaseRepository
|
||||
{
|
||||
|
||||
|
||||
public function __construct()
|
||||
|
|
@ -10,7 +13,42 @@ class CustomerRepository extends BaseRepository {
|
|||
//$this->model = $model;
|
||||
}
|
||||
|
||||
public function deleteCustomer(ShoppingUser $shopping_user)
|
||||
{
|
||||
if ($shopping_user->shopping_orders->count() > 0) {
|
||||
return false;
|
||||
}
|
||||
$shopping_user->auth_user_id = null;
|
||||
$shopping_user->member_id = null;
|
||||
$shopping_user->billing_salutation = null;
|
||||
$shopping_user->billing_company = null;
|
||||
$shopping_user->billing_firstname = 'Deleted';
|
||||
$shopping_user->billing_lastname = 'User';
|
||||
$shopping_user->billing_address = 'Deleted';
|
||||
$shopping_user->billing_address_2 = null;
|
||||
$shopping_user->billing_zipcode = '00000';
|
||||
$shopping_user->billing_city = 'Deleted';
|
||||
$shopping_user->billing_phone = null;
|
||||
$shopping_user->billing_email = 'deleted_' . $shopping_user->id . '@deleted.com';
|
||||
|
||||
$shopping_user->shipping_salutation = null;
|
||||
$shopping_user->shipping_company = null;
|
||||
$shopping_user->shipping_firstname = 'Deleted';
|
||||
$shopping_user->shipping_lastname = 'User';
|
||||
$shopping_user->shipping_address = 'Deleted';
|
||||
$shopping_user->shipping_address_2 = null;
|
||||
$shopping_user->shipping_zipcode = '00000';
|
||||
$shopping_user->shipping_city = 'Deleted';
|
||||
$shopping_user->shipping_phone = null;
|
||||
$shopping_user->shipping_email = 'deleted_' . $shopping_user->id . '@deleted.com';
|
||||
|
||||
$shopping_user->remarks = null;
|
||||
$shopping_user->notice = null;
|
||||
$shopping_user->faker_mail = true;
|
||||
|
||||
$shopping_user->save();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update($data)
|
||||
{
|
||||
|
|
@ -44,9 +82,10 @@ class CustomerRepository extends BaseRepository {
|
|||
return true;
|
||||
}
|
||||
|
||||
public function create($data){
|
||||
public function create($data)
|
||||
{
|
||||
|
||||
/* $this->model = User::create([
|
||||
/* $this->model = User::create([
|
||||
'email' => $data['email'],
|
||||
'password' => Hash::make($data['password']),
|
||||
]);
|
||||
|
|
@ -66,6 +105,4 @@ class CustomerRepository extends BaseRepository {
|
|||
|
||||
return $this->model;*/
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,24 +2,21 @@
|
|||
|
||||
namespace App\Repositories;
|
||||
|
||||
|
||||
|
||||
use App\Models\CountryPrice;
|
||||
use App\Models\Product;
|
||||
use App\Models\ProductAttribute;
|
||||
use App\Models\ProductBundle;
|
||||
use App\Models\ProductCategory;
|
||||
use App\Models\ProductImage;
|
||||
use App\Models\ProductIngredient;
|
||||
|
||||
class ProductRepository extends BaseRepository {
|
||||
|
||||
|
||||
class ProductRepository extends BaseRepository
|
||||
{
|
||||
public function __construct(Product $model)
|
||||
{
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* refresh.
|
||||
*/
|
||||
|
|
@ -34,34 +31,33 @@ class ProductRepository extends BaseRepository {
|
|||
$data['sponsor_buying_points'] = isset($data['sponsor_buying_points']) ? 1 : 0;
|
||||
$data['show_on'] = isset($data['show_on']) ? $data['show_on'] : null;
|
||||
|
||||
if($data['id'] === "new"){
|
||||
if ($data['id'] === 'new') {
|
||||
$this->model = Product::create($data);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$this->model = $this->getById($data['id']);
|
||||
$this->model->slug = null;
|
||||
$this->model->fill($data);
|
||||
$this->model->save();
|
||||
}
|
||||
|
||||
$this->updateCategories(isset($data['categories']) ? $data['categories'] : array());
|
||||
$this->updateAttributes(isset($data['attributes']) ? $data['attributes'] : array());
|
||||
$this->updateIngredients(isset($data['product_ingredients']) ? $data['product_ingredients'] : array());
|
||||
$this->updateCategories(isset($data['categories']) ? $data['categories'] : []);
|
||||
$this->updateAttributes(isset($data['attributes']) ? $data['attributes'] : []);
|
||||
$this->updateIngredients(isset($data['product_ingredients']) ? $data['product_ingredients'] : []);
|
||||
$this->updateBundles(isset($data['product_bundles']) ? $data['product_bundles'] : []);
|
||||
$this->updateBundleQuantities(isset($data['bundle_quantities']) ? $data['bundle_quantities'] : []);
|
||||
$this->updateCountryPrices($data);
|
||||
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
|
||||
public function updateIngredients($data = array())
|
||||
public function updateIngredients($data = [])
|
||||
{
|
||||
$ProductIngredient = $this->model->p_ingredients()->pluck('ingredient_id')->toArray();
|
||||
//set attr
|
||||
if(is_array($data)){
|
||||
// set attr
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $id) {
|
||||
//not use
|
||||
if(!in_array($id, $ProductIngredient)){
|
||||
// not use
|
||||
if (! in_array($id, $ProductIngredient)) {
|
||||
ProductIngredient::create([
|
||||
'product_id' => $this->model->id,
|
||||
'ingredient_id' => $id,
|
||||
|
|
@ -69,20 +65,99 @@ class ProductRepository extends BaseRepository {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function updateCategories($data = array())
|
||||
/**
|
||||
* Aktualisiert Bundle-Produkte (Set/Kit-Inhalte)
|
||||
* Fügt nur neue Bundle-Items hinzu, löscht keine bestehenden
|
||||
*
|
||||
* @param array $data Array von Produkt-IDs die zum Bundle hinzugefügt werden sollen
|
||||
* @return bool
|
||||
*/
|
||||
public function updateBundles($data = [])
|
||||
{
|
||||
$existingBundleIds = $this->model->bundleItems()->pluck('bundle_product_id')->toArray();
|
||||
|
||||
if (is_array($data)) {
|
||||
$pos = count($existingBundleIds);
|
||||
foreach ($data as $bundleProductId) {
|
||||
// Nur hinzufügen wenn noch nicht vorhanden und nicht das Produkt selbst
|
||||
if (! in_array($bundleProductId, $existingBundleIds) && $bundleProductId != $this->model->id) {
|
||||
ProductBundle::create([
|
||||
'product_id' => $this->model->id,
|
||||
'bundle_product_id' => $bundleProductId,
|
||||
'quantity' => 1,
|
||||
'pos' => $pos++,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualisiert die Menge eines Bundle-Items
|
||||
*
|
||||
* @param int $bundleProductId ID des enthaltenen Produkts
|
||||
* @param int $quantity Neue Menge
|
||||
* @return bool
|
||||
*/
|
||||
public function updateBundleQuantity($bundleProductId, $quantity)
|
||||
{
|
||||
$bundle = ProductBundle::where('product_id', $this->model->id)
|
||||
->where('bundle_product_id', $bundleProductId)
|
||||
->first();
|
||||
|
||||
if ($bundle) {
|
||||
$bundle->quantity = max(1, intval($quantity));
|
||||
$bundle->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualisiert die Mengen aller Bundle-Items
|
||||
*
|
||||
* @param array $data Array mit bundle_product_id => quantity Zuordnungen
|
||||
* @return bool
|
||||
*/
|
||||
public function updateBundleQuantities($data = [])
|
||||
{
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $bundleProductId => $item) {
|
||||
if (isset($item['qty']) && isset($item['id'])) {
|
||||
$bundle = ProductBundle::where('product_id', $this->model->id)
|
||||
->where('bundle_product_id', $item['id'])
|
||||
->first();
|
||||
|
||||
if ($bundle) {
|
||||
$bundle->quantity = max(1, intval($item['qty']));
|
||||
$bundle->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function updateCategories($data = [])
|
||||
{
|
||||
foreach ($this->model->categories as $category) {
|
||||
if(($pos = array_search($category->category_id, $data)) !== FALSE){
|
||||
if (($pos = array_search($category->category_id, $data)) !== false) {
|
||||
unset($data[$pos]);
|
||||
}else{
|
||||
} else {
|
||||
$category->delete();
|
||||
}
|
||||
}
|
||||
//set attr
|
||||
if(is_array($data)){
|
||||
// set attr
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $id) {
|
||||
ProductCategory::create([
|
||||
'product_id' => $this->model->id,
|
||||
|
|
@ -90,20 +165,21 @@ class ProductRepository extends BaseRepository {
|
|||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function updateAttributes($data = array())
|
||||
public function updateAttributes($data = [])
|
||||
{
|
||||
foreach ($this->model->attributes as $attribute) {
|
||||
if(($pos = array_search($attribute->attribute_id, $data)) !== FALSE){
|
||||
if (($pos = array_search($attribute->attribute_id, $data)) !== false) {
|
||||
unset($data[$pos]);
|
||||
}else{
|
||||
} else {
|
||||
$attribute->delete();
|
||||
}
|
||||
}
|
||||
//set attr
|
||||
if(is_array($data)){
|
||||
// set attr
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $id) {
|
||||
ProductAttribute::create([
|
||||
'product_id' => $this->model->id,
|
||||
|
|
@ -111,92 +187,79 @@ class ProductRepository extends BaseRepository {
|
|||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function updateCountryPrices($data)
|
||||
{
|
||||
if(!isset($data['country_prices']) || !is_array($data['country_prices'])){
|
||||
if (! isset($data['country_prices']) || ! is_array($data['country_prices'])) {
|
||||
return false;
|
||||
}
|
||||
foreach ($data['country_prices'] as $k => $country_id) {
|
||||
$cp = CountryPrice::updateOrCreate([
|
||||
'country_id' => $country_id,
|
||||
'product_id' => $this->model->id,
|
||||
],
|
||||
[
|
||||
'c_price' => isset($data['c_price'][$country_id]) ? reFormatNumber($data['c_price'][$country_id]) : null,
|
||||
'c_tax' => isset($data['c_tax'][$country_id]) ? reFormatNumber($data['c_tax'][$country_id]) : null,
|
||||
'c_price_old' => isset($data['c_price_old'][$country_id]) ? reFormatNumber($data['c_price_old'][$country_id]) : null,
|
||||
'c_currency' => isset($data['c_currency'][$country_id]) ? reFormatNumber($data['c_currency'][$country_id]) : null,
|
||||
]);
|
||||
|
||||
$cp = CountryPrice::updateOrCreate(
|
||||
[
|
||||
'country_id' => $country_id,
|
||||
'product_id' => $this->model->id,
|
||||
],
|
||||
[
|
||||
'c_price' => isset($data['c_price'][$country_id]) ? reFormatNumber($data['c_price'][$country_id]) : null,
|
||||
'c_tax' => isset($data['c_tax'][$country_id]) ? reFormatNumber($data['c_tax'][$country_id]) : null,
|
||||
'c_price_old' => isset($data['c_price_old'][$country_id]) ? reFormatNumber($data['c_price_old'][$country_id]) : null,
|
||||
'c_currency' => isset($data['c_currency'][$country_id]) ? reFormatNumber($data['c_currency'][$country_id]) : null,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public function copy($model)
|
||||
{
|
||||
$this->model = $model->replicate();
|
||||
$this->model->name = "Kopie: ".$this->model->name;
|
||||
$this->model->name = 'Kopie: ' . $this->model->name;
|
||||
$this->model->wp_number = null;
|
||||
$this->model->save();
|
||||
|
||||
//categories
|
||||
foreach ($model->categories as $category){
|
||||
// categories
|
||||
foreach ($model->categories as $category) {
|
||||
ProductCategory::create([
|
||||
'product_id' => $this->model->id,
|
||||
'category_id' => $category->category_id,
|
||||
]);
|
||||
}
|
||||
|
||||
//attributes
|
||||
foreach ($model->attributes as $attribute){
|
||||
// attributes
|
||||
foreach ($model->attributes as $attribute) {
|
||||
ProductAttribute::create([
|
||||
'product_id' => $this->model->id,
|
||||
'attribute_id' => $attribute->attribute_id,
|
||||
]);
|
||||
}
|
||||
|
||||
//images
|
||||
foreach ($model->images as $image){
|
||||
// images
|
||||
foreach ($model->images as $image) {
|
||||
$name = \App\Services\Slim::sanitizeFileName($image->original_name);
|
||||
$name = uniqid() . '_' . $name;
|
||||
|
||||
//copy
|
||||
// copy
|
||||
$data = \Storage::disk('public')->copy(
|
||||
'images/product/'.$image->product_id.'/'.$image->filename,
|
||||
'images/product/'.$this->model->id.'/'.$name
|
||||
'images/product/' . $image->product_id . '/' . $image->filename,
|
||||
'images/product/' . $this->model->id . '/' . $name
|
||||
);
|
||||
|
||||
|
||||
ProductImage::create([
|
||||
'product_id' => $this->model->id,
|
||||
'filename' => $name,
|
||||
'original_name' => $image->original_name,
|
||||
'ext' => $image->ext,
|
||||
'mine' => $image->mine,
|
||||
'size' => $image->size
|
||||
'size' => $image->size,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function delete()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public function delete() {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue