# How to check if total of 1 particular field in structure equals 0

**URL:** <https://forum.getkirby.com/t/how-to-check-if-total-of-1-particular-field-in-structure-equals-0/20544>\
**Category:** Questions\
**Tags:** v3\
**Created:** [December 28, 2020, 10:52am UTC](https://forum.getkirby.com/t/how-to-check-if-total-of-1-particular-field-in-structure-equals-0/20544 "2020-12-28T10:52:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiahr](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kiahr/32/7169_2.png) [@kiahr](https://forum.getkirby.com/u/kiahr)\
**Post date:** [December 28, 2020, 10:52am UTC](https://forum.getkirby.com/t/how-to-check-if-total-of-1-particular-field-in-structure-equals-0/20544/1 "2020-12-28T10:52:16Z")

</div>

Hello,

In my blueprints I have the below structure field. The field “inventory\_quantity” will have a number input between 0-10. I would like to check if the total of the field “inventory\_quantity” for all items in the structure equals 0. The end goal is to create an If Statement so that when the total is 0, I can add a sold out banner.

```
shopifyVariants:
        label: Variants
        type: structure
        fields:
          title:
            label: Title
            type: text
          price:
            label: Price
            type: text
          compare_at_price:
            label: Compare at price
            type: text
          inventory_quantity:
            label: Inventory
            type: text
          sku:
            label: SKU
            type: text

```

I am just getting very stuck at the moment…

Any help is greatly appreciated!

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [December 28, 2020, 11:03am UTC](https://forum.getkirby.com/t/how-to-check-if-total-of-1-particular-field-in-structure-equals-0/20544/2 "2020-12-28T11:03:38Z")

</div>

```auto
$inventory_quantity = array_sum($page->shopifyVariants()->toStructure()->pluck('inventory_quantity', ','));

```

`$page->shopifyVariants()->toStructure()->pluck('inventory_quantity', ',')` plucks all the `inventory_quantity` values from the structure , `array_sum` then sums up all the values in that array.

Consider using a [number field](https://getkirby.com/docs/reference/panel/fields/number) instead of a text field, so that only numbers can be added. It also allows you to set a min and max value.

If this doesn’t work because the array contains strings instead of numbers, then we have to first cast to number before summing up. Edit: seems to work, though.

---

<div class="post-metadata">

**Author:** ![kiahr](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/kiahr/32/7169_2.png) [@kiahr](https://forum.getkirby.com/u/kiahr)\
**Post date:** [December 29, 2020, 4:04am UTC](https://forum.getkirby.com/t/how-to-check-if-total-of-1-particular-field-in-structure-equals-0/20544/3 "2020-12-29T04:04:29Z")

</div>

Thanks a lot @texnixe, that worked perfectly. I will go ahead and mark it solved.
