Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 853 | Revision 857 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
381 lars 1
<?php
2
 
383 lars 3
    namespace App\Http\Controllers;
381 lars 4
 
829 lars 5
    use App\Models\Item as ItemAlias;
817 lars 6
    use App\Http\Controllers\ShippingController;
719 lars 7
 
728 lars 8
    class BasketController extends Controller
383 lars 9
    {
713 lars 10
        public array $items         = array();
11
        public array $paymentInfo   = array();
12
        public array $shipmentCosts = array();
697 lars 13
 
714 lars 14
        public array $paymentMethods = array();
15
 
856 lars 16
        public float $weight = 0.00;
17
 
383 lars 18
        //
705 lars 19
        private function getPaymentInfo(): void
701 lars 20
        {
21
            $buffer = array(
22
                "itemAmt"      => array(
23
 
24
                    1 => 0.00,
25
                ),
26
                "itemAmtNetto" => array(
27
 
28
                    1 => 0.00,
29
                ),
30
                "itemTax"      => array(
31
 
32
                    1 => 0.00,
33
                ),
34
                "shipAmt"      => 0.00,
35
                "shipTax"      => array(
36
 
37
                    1 => 0.00,
38
                ),
39
                "Amt"          => 0.00,
40
                "Tax"          => 0.00,
41
                "Total"        => 0.00,
42
            );
43
            if ( $_SESSION["SHOP"]["BASKET"]->items )
44
            {
709 lars 45
                $Land = 47;
707 lars 46
                if ( ( isset( $_SESSION['SHOP']['Lieferadresse'] ) && $_SESSION['SHOP']['Lieferadresse'] == "true" ) || ( isset( $_GET["liefer"] ) && $_GET["liefer"] == 1 ) || isset( $_SESSION['SHOP']['buy']['Persdata']['liefer_Land'] ) )
701 lars 47
                {
48
                    $Land = $_SESSION['SHOP']['buy']['Persdata']['liefer_Land'];
49
                }
708 lars 50
                elseif ( isset( $_SESSION['SHOP']['buy']['Persdata']['Land'] ) )
701 lars 51
                {
52
                    $Land = $_SESSION['SHOP']['buy']['Persdata']['Land'];
53
                }
54
                if ( !isset( $GLOBALS["steuern"][$Land] ) )
55
                {
56
                    $Land = 47;
57
                }
58
                $taxArr = $GLOBALS["steuern"][$Land];
59
                foreach ( $_SESSION["SHOP"]["BASKET"]->items as $bItem )
60
                {
717 lars 61
                    if ( !$bItem->code )
701 lars 62
                    {
720 lars 63
                        $item = ItemAlias::find( $bItem->id );
701 lars 64
                        if ( !isset( $bItem->tax ) )
65
                        {
66
                            $bItem->tax = $item->tax1;
67
                        }
68
                        $tax = $taxArr[$bItem->tax];
69
                        $bPreis = $bItem->menge * $bItem->price;
70
                        $buffer["itemAmt"][$bItem->tax] += $bPreis;
71
                    }
72
                    else
73
                    {
74
                        $tax = 0;
75
                        $bPreis = $bItem->price;
76
                        $buffer["discount"] = $bPreis * -1;
77
                    }
725 lars 78
                    if ( isset( $GLOBALS["INI"]["netto_preise"] ) && $GLOBALS["INI"]["netto_preise"] )
701 lars 79
                    {
80
                        $buffer["itemTax"][$bItem->tax] += round( $bPreis * $tax / 100, 2 );
81
                    }
82
                    else
83
                    {
84
                        $buffer["itemTax"][$bItem->tax] += round( $bItem->price * $tax / ( 100 + $tax ), 2 ) * $bItem->menge;
85
                    }
86
                    $buffer["Amt"] += $bPreis;
87
                }
88
                if ( !( isset( $GLOBALS["INI"]["netto_preise"] ) && $GLOBALS["INI"]["netto_preise"] == 1 ) )
89
                {
90
                    foreach ( $buffer["itemTax"] as $tax => $amt )
91
                    {
92
                        $buffer["itemAmtNetto"][$tax] = $buffer["itemAmt"][$tax] - round( $amt, 2 );
93
                    }
94
                }
725 lars 95
                if ( isset( $_SESSION["SHOP"]["VERSAND"] ) && $_SESSION["SHOP"]["VERSAND"] )
701 lars 96
                {
97
                    $t = 1;
98
                    $bItem = $_SESSION["SHOP"]["VERSAND"];
99
                    $buffer["shipAmt"] = $bItem["preis"];
100
                    $buffer["Amt"] += $bItem["preis"];
101
                    if ( $GLOBALS["INI"]["netto_preise"] )
102
                    {
103
                        $netto = array_sum( $buffer["itemAmt"] );
104
                        $t = $buffer["itemAmt"][0] / $netto;
105
                    }
106
                    if ( !isset( $GLOBALS["steuern"][$Land] ) )
107
                    {
108
                        $Land = 47;
109
                    }
110
                    $taxArr = $GLOBALS["steuern"][$Land];
111
                    if ( $t == 1 )
112
                    {
113
                        $tax = $taxArr[0];
114
                        if ( $GLOBALS["INI"]["netto_preise"] )
115
                        {
116
                            $buffer["shipTax"][0] += $bItem->price * $tax / 100;
117
                        }
118
                        else
119
                        {
120
                            $buffer["shipTax"][0] += $bItem->price * $tax / ( 100 + $tax );
121
                        }
122
                    }
123
                    elseif ( $t == 0 )
124
                    {
125
                        $tax = $taxArr[1];
126
                        if ( $GLOBALS["INI"]["netto_preise"] )
127
                        {
128
                            $buffer["shipTax"][1] += $bItem->price * $tax / 100;
129
                        }
130
                        else
131
                        {
132
                            $buffer["shipTax"][1] += $bItem->price * $tax / ( 100 + $tax );
133
                        }
134
                    }
135
                    else
136
                    {
137
                        $tax = $taxArr[0];
725 lars 138
                        if ( isset( $GLOBALS["INI"]["netto_preise"] ) && $GLOBALS["INI"]["netto_preise"] )
701 lars 139
                        {
140
                            $buffer["shipTax"][0] += ( $bItem->price * $tax / 100 ) * $t;
141
                        }
142
                        else
143
                        {
144
                            $buffer["shipTax"][0] += ( $bItem->price * $tax / ( 100 + $tax ) ) * $t;
145
                        }
146
                        $tax = $taxArr[1];
725 lars 147
                        if ( isset( $GLOBALS["INI"]["netto_preise"] ) && $GLOBALS["INI"]["netto_preise"] )
701 lars 148
                        {
149
                            $buffer["shipTax"][1] += ( $bItem->price * $tax / 100 ) * ( 1 - $t );
150
                        }
151
                        else
152
                        {
153
                            $buffer["shipTax"][0] += ( $bItem->price * $tax / ( 100 + $tax ) ) * ( 1 - $t );
154
                        }
155
                    }
156
                }
157
                foreach ( $taxArr as $ind => $tax )
158
                {
159
                    $buffer["TaxRates"][$ind] = $tax;
160
                }
161
                $buffer["Tax"] = round( array_sum( $buffer["itemTax"] ) + array_sum( $buffer["shipTax"] ), 2 );
725 lars 162
                if ( isset( $GLOBALS["INI"]["netto_preise"] ) && $GLOBALS["INI"]["netto_preise"] )
701 lars 163
                {
164
                    $buffer["Total"] = round( $buffer["Amt"] + $buffer["Tax"], 2 );
165
                }
166
                else
167
                {
168
                    $buffer["Total"] = $buffer["Amt"];
169
                }
170
            }
705 lars 171
            $this->paymentInfo = $buffer;
701 lars 172
        }
383 lars 173
 
701 lars 174
        public function addItem()
656 lars 175
        {
668 lars 176
            $preis = 0;
705 lars 177
            if ( request( "preis" ) )
668 lars 178
            {
705 lars 179
                $preis = request( "preis" );
668 lars 180
            }
730 lars 181
            $bItem = new BasketItemController( \request( "Menge" ), $preis, \request( "item" ) );
670 lars 182
            $bItem->addinfo = "";
663 lars 183
            // addons aus konfigurator
705 lars 184
            $addon = \request( "addon" );
185
            if ( is_array( $addon ) )
663 lars 186
            {
705 lars 187
                foreach ( $addon as $itemID )
663 lars 188
                {
189
                    if ( $expl = explode( "#", $itemID ) )
190
                    {
191
                        if ( $expl[0] != 0 )
192
                        {
193
                            $itemID = $expl[0];
829 lars 194
                        }
195
                        $preis = 0;
741 lars 196
                        if ( $expl[1] != 0 )
197
                        {
198
                            $preis = $expl[1];
663 lars 199
                        }
200
                    }
201
                    if ( is_numeric( $itemID ) )
202
                    {
741 lars 203
                        $aItem = new BasketItemController( 1, $preis, $itemID );
829 lars 204
                        $bItem->addinfo .= "<br>" . $aItem->name;
205
                        $bItem->price += $preis;
663 lars 206
                    }
207
                }
208
            }
829 lars 209
            $key = sha1( $bItem->name . $bItem->addinfo );
738 lars 210
            if ( isset( $_SESSION["SHOP"]["BASKET"]->items[$key] ) )
211
            {
212
                $bItem->menge += $_SESSION["SHOP"]["BASKET"]->items[$key]->menge;
829 lars 213
            }
731 lars 214
            $_SESSION["SHOP"]["BASKET"]->items[$key] = $bItem;
705 lars 215
            $this->getPaymentInfo();
713 lars 216
            $this->getShipmentCosts();
856 lars 217
            $this->getBasketGewicht();
829 lars 218
        }
713 lars 219
 
829 lars 220
        public function editItem()
221
        {
222
            $key = request( "id" );
223
            $menge = request( "menge" );
746 lars 224
            $_SESSION["SHOP"]["BASKET"]->items[$key]->menge = $menge;
737 lars 225
            $this->getPaymentInfo();
829 lars 226
            $this->getShipmentCosts();
856 lars 227
            $this->getBasketGewicht();
829 lars 228
        }
737 lars 229
 
733 lars 230
        public function delItem()
231
        {
232
            $key = request( "id" );
233
            unset( $_SESSION["SHOP"]["BASKET"]->items[$key] );
736 lars 234
            $this->getPaymentInfo();
235
            $this->getShipmentCosts();
856 lars 236
            $this->getBasketGewicht();
733 lars 237
        }
238
 
713 lars 239
        private function getShipmentCosts()
829 lars 240
        {
241
            $sc = new ShippingController();
242
            $buffer = $sc->getShippingOptions();
843 lars 243
            $_SESSION["SHOP"]["BASKET"]->shipmentCosts = $buffer;
829 lars 244
        }
245
 
856 lars 246
        public function getBasketGewicht(): void
829 lars 247
        {
853 lars 248
            $gewicht = 0.00;
249
            foreach ( $_SESSION["SHOP"]["BASKET"]->items as $item )
829 lars 250
            {
853 lars 251
                $gewicht += $item->menge * $item->weight;
829 lars 252
            }
856 lars 253
            $_SESSION["SHOP"]["BASKET"]->weight = $gewicht;
829 lars 254
        }
383 lars 255
    }