PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.1
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.1
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
fluent-cart / app / Services / Report / Concerns / CanParseAddressField.php

CanParseAddressField.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.5.1, at app/Services/Report/Concerns/CanParseAddressField.php

48 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Services\Report\Concerns;
4
5 use FluentCart\App\Services\Report\ReportService;
6 use FluentCart\Framework\Support\Arr;
7 use FluentCart\Framework\Support\DateTime;
8
9 trait CanParseAddressField
10 {
11
12 /**
13 * Parse Address value from given data
14 *
15 * @param mixed $item
16 * @param string $groupKey The name of the group
17 * @return string
18 */
19 protected function parseAddressField($item, string $groupKey): string
20 {
21 $allowedKeys = [
22 'shipping_country',
23 'billing_country',
24 'shipping_city',
25 'billing_city',
26 'shipping_state',
27 'billing_state'
28 ];
29
30 if (!in_array($groupKey, $allowedKeys)) {
31 return __('Unknown', 'fluent-cart');
32 }
33
34 list($addressType, $field) = explode('_', $groupKey);
35 // Check if order_addresses exist
36 if (Arr::exists($item, 'order_addresses')) {
37 foreach ($item['order_addresses'] as $address) {
38 // Check if the address type matches (billing or shipping)
39 if (Arr::get($address, 'type') === $addressType) {
40 // Return the requested field if it exists, otherwise return 'Unknown'
41 return Arr::get($address, $field, __('Unknown', 'fluent-cart'));
42 }
43 }
44 }
45
46 return __('Unknown', 'fluent-cart'); // Fallback if no matching address or field found
47 }
48 }