FormFields
2 years ago
FormTemplate
2 years ago
DonationGoal.php
2 years ago
DonationOptions.php
2 years ago
EmailSettings.php
2 years ago
FeeRecovery.php
2 years ago
FormFieldManager.php
2 years ago
FormFields.php
2 years ago
FormGrid.php
2 years ago
FormMeta.php
2 years ago
FormTitle.php
2 years ago
MigrateMeta.php
2 years ago
OfflineDonations.php
2 years ago
PaymentGateways.php
2 years ago
PdfSettings.php
2 years ago
RecurringDonationOptions.php
2 years ago
TermsAndConditions.php
2 years ago
DonationOptions.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\FormMigration\Steps; |
| 4 | |
| 5 | use Give\FormMigration\Contracts\FormMigrationStep; |
| 6 | |
| 7 | class DonationOptions extends FormMigrationStep |
| 8 | { |
| 9 | public function process() |
| 10 | { |
| 11 | $amountField = $this->fieldBlocks->findByName('givewp/donation-amount'); |
| 12 | |
| 13 | $priceOption = $this->getMetaV2('_give_price_option'); |
| 14 | $amountField->setAttribute('priceOption', $priceOption); |
| 15 | |
| 16 | if('set' === $priceOption) { |
| 17 | $amountField->setAttribute('setPrice', $this->getMetaV2('_give_set_price')); |
| 18 | } |
| 19 | |
| 20 | if('multi' === $priceOption) { |
| 21 | // @note $formV2->levels only returns a single level |
| 22 | $donationLevels = $this->getMetaV2('_give_donation_levels'); |
| 23 | // @note No corresponding setting in v3 for `_give_text` for Donation Levels. |
| 24 | $amountField->setAttribute('levels', |
| 25 | array_map([$this, 'roundAmount'], wp_list_pluck($donationLevels, '_give_amount'))); |
| 26 | } |
| 27 | |
| 28 | $isCustomAmountEnabled = $this->formV2->isCustomAmountOptionEnabled(); |
| 29 | $amountField->setAttribute('customAmount', $isCustomAmountEnabled); |
| 30 | |
| 31 | if ($isCustomAmountEnabled) { |
| 32 | $customAmountMin = $this->getMetaV2('_give_custom_amount_range_minimum'); |
| 33 | $customAmountMax = $this->getMetaV2('_give_custom_amount_range_maximum'); |
| 34 | |
| 35 | if ($customAmountMin) { |
| 36 | $amountField->setAttribute('customAmountMin', $this->roundAmount($customAmountMin)); |
| 37 | } |
| 38 | |
| 39 | if ($customAmountMax) { |
| 40 | $amountField->setAttribute('customAmountMax', $this->roundAmount($customAmountMax)); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | // @note No corresponding setting in v3 for "Custom Amount Text" |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @since 3.0.0 |
| 49 | */ |
| 50 | private function roundAmount($amount): float |
| 51 | { |
| 52 | return round((float)$amount, 2); |
| 53 | } |
| 54 | } |
| 55 |