# fluent-cart/trunk/app/Services/Report/Concerns/CanParseAddressField.php

FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler, version trunk. 48 lines.

- Page: https://pluginprobe.com/plugins/fluent-cart/trunk/code/app/Services/Report/Concerns/CanParseAddressField.php
- Raw: https://pluginprobe.com/plugins/fluent-cart/trunk/raw/app/Services/Report/Concerns/CanParseAddressField.php
- Modified: 2025-10-14T16:36:46+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-cart/trunk/code/app/Services/Report/Concerns/CanParseAddressField.php#L10-L20`.

```php
<?php

namespace FluentCart\App\Services\Report\Concerns;

use FluentCart\App\Services\Report\ReportService;
use FluentCart\Framework\Support\Arr;
use FluentCart\Framework\Support\DateTime;

trait CanParseAddressField
{

    /**
     * Parse Address value from given data
     *
     * @param mixed $item
     * @param string $groupKey The name of the group
     * @return string
     */
    protected function parseAddressField($item, string $groupKey): string
    {
        $allowedKeys = [
            'shipping_country',
            'billing_country',
            'shipping_city',
            'billing_city',
            'shipping_state',
            'billing_state'
        ];

        if (!in_array($groupKey, $allowedKeys)) {
            return __('Unknown', 'fluent-cart');
        }

        list($addressType, $field) = explode('_', $groupKey);
        // Check if order_addresses exist
        if (Arr::exists($item, 'order_addresses')) {
            foreach ($item['order_addresses'] as $address) {
                // Check if the address type matches (billing or shipping)
                if (Arr::get($address, 'type') === $addressType) {
                    // Return the requested field if it exists, otherwise return 'Unknown'
                    return Arr::get($address, $field, __('Unknown', 'fluent-cart'));
                }
            }
        }

        return __('Unknown', 'fluent-cart'); // Fallback if no matching address or field found
    }
}
```
