Get overall total from outside repeater

So I have this code to get the total but only gets the total of last product on the repeater
13 Replies
toeknee
toeknee2y ago
Get the repeater in a closure, then loop through and sum up the prices. ensure you typecast as closures tend to get strings.
Chrysippus
ChrysippusOP2y ago
this is my original conversation with the similar problem but I haven't getting any response https://discord.com/channels/883083792112300104/1123539135295127604
toeknee
toeknee2y ago
Firstly, on price you have: ->afterStateHydrated(function ($state, callable $set, callable $get) { $shippingFee = $get('../../shipping_fee'); $subtotal = $state * $get('product_quantity'); if($subtotal) { $set('../../total', $subtotal + $shippingFee); } }) ->afterStateHydrated(function ($state, callable $set, callable $get) { $shippingFee = $get('../../shipping_fee'); $subtotal = $state * $get('product_quantity'); if($subtotal) { $set('../../total', $subtotal + $shippingFee); } a duplicate
Chrysippus
ChrysippusOP2y ago
if i remove that it will remove the unit price when editing
toeknee
toeknee2y ago
It's duplicated You need a Hydrated and a Updated The perfromance for looping through a few objects in minimal, so instead of setting and getting constantly, I would just loop afterState updated through the items and calculate that way. It will be more precise
Chrysippus
ChrysippusOP2y ago
will that work on textInput? already did that only works on placeholder
toeknee
toeknee2y ago
Yes, you get the parent container items so why would it only work on a placeholder. DD after getting to ensure you get th evalues.
Chrysippus
ChrysippusOP2y ago
I have no idea how to do that
toeknee
toeknee2y ago
The same way you get total? but get orderItems
Chrysippus
ChrysippusOP2y ago
oh you want me to get collection insides repeater? Im sure I did that before and returns null didnt notice this one, I tried to dd collection('orderItems') but only works outside repeater
toeknee
toeknee2y ago
collect($get('../../orderItems'));
Chrysippus
ChrysippusOP2y ago
yeah I noticed that too, while typing lol. thanks this should work.
Want results from more Discord servers?
Add your server