CustomerFieldsFactory.php
11 months ago
CustomerOrderFieldsFactory.php
1 year ago
CustomerReviewFieldsFactory.php
1 year ago
CustomerSubscriptionFieldsFactory.php
11 months ago
OrderFieldsFactory.php
2 months ago
TermOptionsBuilder.php
2 years ago
TermParentsLoader.php
1 year ago
index.php
3 years ago
CustomerFieldsFactory.php
160 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Automation\Integrations\WooCommerce\Fields; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Automation\Engine\Data\Field; |
| 9 | use MailPoet\Automation\Integrations\WooCommerce\Payloads\CustomerPayload; |
| 10 | |
| 11 | class CustomerFieldsFactory { |
| 12 | /** @var CustomerOrderFieldsFactory */ |
| 13 | private $customerOrderFieldsFactory; |
| 14 | |
| 15 | /** @var CustomerReviewFieldsFactory */ |
| 16 | private $customerReviewFieldsFactory; |
| 17 | |
| 18 | /** @var CustomerSubscriptionFieldsFactory */ |
| 19 | private $customerSubscriptionFieldsFactory; |
| 20 | |
| 21 | public function __construct( |
| 22 | CustomerOrderFieldsFactory $customerOrderFieldsFactory, |
| 23 | CustomerReviewFieldsFactory $customerReviewFieldsFactory, |
| 24 | CustomerSubscriptionFieldsFactory $customerSubscriptionFieldsFactory |
| 25 | ) { |
| 26 | $this->customerOrderFieldsFactory = $customerOrderFieldsFactory; |
| 27 | $this->customerReviewFieldsFactory = $customerReviewFieldsFactory; |
| 28 | $this->customerSubscriptionFieldsFactory = $customerSubscriptionFieldsFactory; |
| 29 | } |
| 30 | |
| 31 | /** @return Field[] */ |
| 32 | public function getFields(): array { |
| 33 | return array_merge( |
| 34 | [ |
| 35 | new Field( |
| 36 | 'woocommerce:customer:billing-company', |
| 37 | Field::TYPE_STRING, |
| 38 | __('Billing company', 'mailpoet'), |
| 39 | function (CustomerPayload $payload) { |
| 40 | return $payload->getBillingCompany(); |
| 41 | } |
| 42 | ), |
| 43 | new Field( |
| 44 | 'woocommerce:customer:billing-phone', |
| 45 | Field::TYPE_STRING, |
| 46 | __('Billing phone', 'mailpoet'), |
| 47 | function (CustomerPayload $payload) { |
| 48 | return $payload->getBillingPhone(); |
| 49 | } |
| 50 | ), |
| 51 | new Field( |
| 52 | 'woocommerce:customer:billing-city', |
| 53 | Field::TYPE_STRING, |
| 54 | __('Billing city', 'mailpoet'), |
| 55 | function (CustomerPayload $payload) { |
| 56 | return $payload->getBillingCity(); |
| 57 | } |
| 58 | ), |
| 59 | new Field( |
| 60 | 'woocommerce:customer:billing-postcode', |
| 61 | Field::TYPE_STRING, |
| 62 | __('Billing postcode', 'mailpoet'), |
| 63 | function (CustomerPayload $payload) { |
| 64 | return $payload->getBillingPostcode(); |
| 65 | } |
| 66 | ), |
| 67 | new Field( |
| 68 | 'woocommerce:customer:billing-state', |
| 69 | Field::TYPE_STRING, |
| 70 | __('Billing state/county', 'mailpoet'), |
| 71 | function (CustomerPayload $payload) { |
| 72 | return $payload->getBillingState(); |
| 73 | } |
| 74 | ), |
| 75 | new Field( |
| 76 | 'woocommerce:customer:billing-country', |
| 77 | Field::TYPE_ENUM, |
| 78 | __('Billing country', 'mailpoet'), |
| 79 | function (CustomerPayload $payload) { |
| 80 | return $payload->getBillingCountry(); |
| 81 | }, |
| 82 | [ |
| 83 | 'options' => $this->getBillingCountryOptions(), |
| 84 | ] |
| 85 | ), |
| 86 | new Field( |
| 87 | 'woocommerce:customer:shipping-company', |
| 88 | Field::TYPE_STRING, |
| 89 | __('Shipping company', 'mailpoet'), |
| 90 | function (CustomerPayload $payload) { |
| 91 | return $payload->getShippingCompany(); |
| 92 | } |
| 93 | ), |
| 94 | new Field( |
| 95 | 'woocommerce:customer:shipping-phone', |
| 96 | Field::TYPE_STRING, |
| 97 | __('Shipping phone', 'mailpoet'), |
| 98 | function (CustomerPayload $payload) { |
| 99 | return $payload->getShippingPhone(); |
| 100 | } |
| 101 | ), |
| 102 | new Field( |
| 103 | 'woocommerce:customer:shipping-city', |
| 104 | Field::TYPE_STRING, |
| 105 | __('Shipping city', 'mailpoet'), |
| 106 | function (CustomerPayload $payload) { |
| 107 | return $payload->getShippingCity(); |
| 108 | } |
| 109 | ), |
| 110 | new Field( |
| 111 | 'woocommerce:customer:shipping-postcode', |
| 112 | Field::TYPE_STRING, |
| 113 | __('Shipping postcode', 'mailpoet'), |
| 114 | function (CustomerPayload $payload) { |
| 115 | return $payload->getShippingPostcode(); |
| 116 | } |
| 117 | ), |
| 118 | new Field( |
| 119 | 'woocommerce:customer:shipping-state', |
| 120 | Field::TYPE_STRING, |
| 121 | __('Shipping state/county', 'mailpoet'), |
| 122 | function (CustomerPayload $payload) { |
| 123 | return $payload->getShippingState(); |
| 124 | } |
| 125 | ), |
| 126 | new Field( |
| 127 | 'woocommerce:customer:shipping-country', |
| 128 | Field::TYPE_ENUM, |
| 129 | __('Shipping country', 'mailpoet'), |
| 130 | function (CustomerPayload $payload) { |
| 131 | return $payload->getShippingCountry(); |
| 132 | }, |
| 133 | [ |
| 134 | 'options' => $this->getShippingCountryOptions(), |
| 135 | ] |
| 136 | ), |
| 137 | ], |
| 138 | $this->customerOrderFieldsFactory->getFields(), |
| 139 | $this->customerReviewFieldsFactory->getFields(), |
| 140 | $this->customerSubscriptionFieldsFactory->getFields() |
| 141 | ); |
| 142 | } |
| 143 | |
| 144 | private function getBillingCountryOptions(): array { |
| 145 | $options = []; |
| 146 | foreach (WC()->countries->get_allowed_countries() as $code => $name) { |
| 147 | $options[] = ['id' => $code, 'name' => $name]; |
| 148 | } |
| 149 | return $options; |
| 150 | } |
| 151 | |
| 152 | private function getShippingCountryOptions(): array { |
| 153 | $options = []; |
| 154 | foreach (WC()->countries->get_shipping_countries() as $code => $name) { |
| 155 | $options[] = ['id' => $code, 'name' => $name]; |
| 156 | } |
| 157 | return $options; |
| 158 | } |
| 159 | } |
| 160 |