Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 958 | Revision 1340 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php

    namespace App\Http\Controllers;

    use App\Models\WebSetting;
    use Illuminate\Http\Request;
    use App\Models\User;
    use App\Models\OrderAddress;
    use App\Models\OrderItem;
    use App\Models\Order;

    class OrderController extends Controller
    {
        //
        private int       $shipAddrId;
        private int       $billAddrId;
        private Order     $order;
        private int       $orderId;
        private OrderItem $orderItem;
        private array     $orderItems;

        public function create()
        {
            $this->billAddr = new OrderAddress();
            if ( !( isset( $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] ) && $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] ) )
            {
                $_SESSION["SHOP"]["buy"]["Persdata"]["ID"] = 1;
            }
            $this->billAddr->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
            $this->billAddr->name = $_SESSION["SHOP"]["buy"]["Persdata"]["Vorname"];
            $this->billAddr->lastname = $_SESSION["SHOP"]["buy"]["Persdata"]["Nachname"];
            if ( $_SESSION["SHOP"]["buy"]["Persdata"]["Firma"] )
            {
                $this->billAddr->company = $_SESSION["SHOP"]["buy"]["Persdata"]["Firma"];
            }
            $this->billAddr->street = $_SESSION["SHOP"]["buy"]["Persdata"]["Strasse"];
            $this->billAddr->houseno = $_SESSION["SHOP"]["buy"]["Persdata"]["Hausnummer"];
            $this->billAddr->zip = $_SESSION["SHOP"]["buy"]["Persdata"]["PLZ"];
            $this->billAddr->city = $_SESSION["SHOP"]["buy"]["Persdata"]["Ort"];
            $this->billAddr->country_id = $_SESSION["SHOP"]["buy"]["Persdata"]["Land"];
            $this->billAddr->phone = $_SESSION["SHOP"]["buy"]["Persdata"]["Telefon"];
            $this->billAddr->email = $_SESSION["SHOP"]["buy"]["Persdata"]["email"];
            $this->billAddr->save();
            $this->billAddrId = $this->billAddr->id;

            if ( $_SESSION["SHOP"]["Lieferadresse"] == "packstation" )
            {
                $this->shipAddr = new OrderAddress();
                $this->shipAddr->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
                $this->shipAddr->name = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Vorname_pst"];
                $this->shipAddr->lastname = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Nachname_pst"];
                if ( $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma_pst"] )
                {
                    $this->shipAddr->company = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma_pst"];
                }
                $this->shipAddr->street = $_SESSION["SHOP"]["buy"]["Persdata"]["lieferStrasse_pst"];
                $this->shipAddr->houseno = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Hausnummer_pst"];
                $this->shipAddr->zip = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_PLZ_pst"];
                $this->shipAddr->city = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Ort_pst"];
                $this->shipAddr->country_id = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Land_pst"];
                $this->shipAddr->phone = $_SESSION["SHOP"]["buy"]["Persdata"]["Telefon"];
                $this->shipAddr->email = $_SESSION["SHOP"]["buy"]["Persdata"]["email"];
                $this->shipAddr->save();
                $this->shipAddrId = $this->billAddr->id;
            }
            else
            {
                $this->shipAddr = new OrderAddress();
                $this->shipAddr->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
                $this->shipAddr->name = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Vorname"];
                if ( $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma"] )
                {
                    $this->shipAddr->company = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Firma"];
                }
                $this->shipAddr->lastname = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Nachname"];
                $this->shipAddr->street = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Strasse"];
                $this->shipAddr->houseno = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Hausnummer"];
                $this->shipAddr->zip = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_PLZ"];
                $this->shipAddr->city = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Ort"];
                $this->shipAddr->country_id = $_SESSION["SHOP"]["buy"]["Persdata"]["liefer_Land"];
                $this->shipAddr->phone = $_SESSION["SHOP"]["buy"]["Persdata"]["Telefon"];
                $this->shipAddr->email = $_SESSION["SHOP"]["buy"]["Persdata"]["email"];
                $this->shipAddr->save();
                $this->shipAddrId = $this->billAddr->id;
            }
            $this->order = new Order();
            $this->order->shop_id = $GLOBALS["INI"]["shops_ID"];
            $this->order->user_id = $_SESSION["SHOP"]["buy"]["Persdata"]["ID"];
            $this->order->order_type_id = 1;
            $this->order->ship_addr_id = $this->shipAddrId;
            $this->order->bill_addr_id = $this->billAddrId;
            $this->order->created_by = "(Bestellung)";
            $this->order->save();
            $this->orderId = $this->order->id;
            $this->orderItems = array();
            foreach ( $_SESSION["SHOP"]["BASKET"]->items as $item )
            {
                $this->orderItem = new OrderItem();
                $this->orderItem->name = $item->name;
                $this->orderItem->item_id = $item->id;
                $this->orderItem->price = $item->price;
                $this->orderItem->amount = $item->menge;
                $this->orderItem->option_input = $item->addinfo;
                $this->orderItem->save();
                $this->orderItems[] = $this->orderItem;
            }
            return $this->orderId;
        }

        public function mail()
        {
            $webSettings = WebSetting::where( 'shop_id', '=', $this->order->shop_id )->where( 'order_type_id', '=', $this->order->order_type_id )->whereIn( 'id', [ 11, 12, 13, 14, 17, 18, 1000, ] )->get();
            foreach ( $webSettings as $webSetting )
            {
                switch ( $webSetting->id )
                {
                    case 11:
                        $fromEmail = $webSetting->content;
                        break;
                    case 12:
                        $customerSubject = $webSetting->content;
                        break;
                    case 13:
                        $customerBody = $webSetting->content;
                        break;
                    case 14:
                        $bccAddress = $webSetting->content;
                        break;
                    case 17:
                        $shopSubject = $webSetting->content;
                        break;
                    case 18:
                        $shopBody = $webSetting->content;
                        break;
                    case 1000:
                        $template = $webSetting->content;
                        break;
                }
            }

        }
    }