@@ -27,59 +27,63 @@ public function calculate()
27
27
return false ;
28
28
}
29
29
30
- $ shippingMethods = [];
30
+ $ shippingRates = [];
31
31
32
32
$ cart = Cart::getCart ();
33
33
34
34
$ address = $ cart ->shipping_address ;
35
35
36
- $ data = app ('Webkul\UpsShipping\Helpers\ShippingMethodHelper ' )->getAllCartProducts ($ address );
36
+ $ shippingMethodHelper = app (ShippingMethodHelper::class);
37
+
38
+ $ cartProductsShippingData = $ shippingMethodHelper ->getAllCartProducts ($ address );
37
39
38
- if (! $ data ) {
40
+ if (! $ cartProductsShippingData ) {
39
41
return false ;
40
42
}
41
43
42
- foreach ($ data as $ key => $ fedexServices ) {
44
+ foreach ($ cartProductsShippingData as $ sellerId => $ shippingMethods ) {
43
45
$ totalShippingCost = 0 ;
46
+
47
+ $ sellerRates = [];
44
48
45
- $ rates = [];
46
-
47
- foreach ($ fedexServices as $ methods => $ upsRate ) {
48
- $ itemShippingCost = $ upsRate ['rate ' ] * $ upsRate ['itemQuantity ' ];
49
- $ sellerId = $ upsRate ['marketplace_seller_id ' ];
49
+ foreach ($ shippingMethods as $ methodCode => $ methodData ) {
50
+ $ itemShippingCost = $ methodData ['rate ' ] * $ methodData ['itemQuantity ' ];
51
+ $ marketplaceSellerId = $ methodData ['marketplace_seller_id ' ];
50
52
51
- $ rates [ $ sellerId ] = [
53
+ $ sellerRates [ $ marketplaceSellerId ] = [
52
54
'amount ' => core ()->convertPrice ($ itemShippingCost ),
53
55
'base_amount ' => $ itemShippingCost ,
54
56
];
55
57
56
58
$ totalShippingCost += $ itemShippingCost ;
57
59
}
58
60
59
- $ object = new CartShippingRate ;
61
+ $ cartShippingRate = new CartShippingRate ;
60
62
61
- $ object ->carrier = 'mpups ' ;
63
+ $ cartShippingRate ->carrier = 'mpups ' ;
62
64
63
- $ object ->carrier_title = $ this ->getConfigData ('title ' );
65
+ $ cartShippingRate ->carrier_title = $ this ->getConfigData ('title ' );
64
66
65
- $ object ->method = 'mpups_ ' . $ key ;
67
+ $ cartShippingRate ->method = 'mpups_ ' . $ sellerId ;
66
68
67
- $ object ->method_title = $ this ->getConfigData ('title ' );
69
+ $ cartShippingRate ->method_title = $ this ->getConfigData ('title ' );
68
70
69
- $ object ->method_description = $ key ;
71
+ $ cartShippingRate ->method_description = $ sellerId ;
70
72
71
- $ object ->price = core ()->convertPrice ($ totalShippingCost );
73
+ $ cartShippingRate ->price = core ()->convertPrice ($ totalShippingCost );
72
74
73
- $ object ->base_price = $ totalShippingCost ;
75
+ $ cartShippingRate ->base_price = $ totalShippingCost ;
74
76
75
- $ shippingMethods [] = $ object ;
77
+ $ shippingRates [] = $ cartShippingRate ;
78
+
76
79
// Store rates in session
77
80
$ marketplaceShippingRates = session ()->get ('marketplace_shipping_rates ' , []);
78
81
79
- $ marketplaceShippingRates ['mpupsshipping ' ][$ key ] = $ rates ;
82
+ $ marketplaceShippingRates ['mpupsshipping ' ][$ sellerId ] = $ sellerRates ;
83
+
80
84
session ()->put ('marketplace_shipping_rates ' , $ marketplaceShippingRates );
81
85
}
82
86
83
- return $ shippingMethods ;
87
+ return $ shippingRates ;
84
88
}
85
89
}
0 commit comments