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
Get the repeater in a closure, then loop through and sum up the prices.
ensure you typecast as closures tend to get strings.
this is my original conversation with the similar problem but I haven't getting any response
https://discord.com/channels/883083792112300104/1123539135295127604
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
if i remove that it will remove the unit price
when editing
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
will that work on textInput?
already did that only works on placeholder
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.
I have no idea how to do that
The same way you get total?
but get orderItems
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
collect($get('../../orderItems'));
yeah I noticed that too, while typing lol.
thanks this should work.