FormFields
2 years ago
FormTemplate
2 years ago
ActiveCampaign.php
2 years ago
ConstantContact.php
2 years ago
ConvertKit.php
2 years ago
CurrencySwitcher.php
2 years ago
DonationGoal.php
2 years ago
DonationOptions.php
2 years ago
DoubleTheDonation.php
2 years ago
EmailSettings.php
2 years ago
FeeRecovery.php
2 years ago
FormExcerpt.php
2 years ago
FormFeaturedImage.php
2 years ago
FormFieldManager.php
2 years ago
FormFields.php
2 years ago
FormGrid.php
2 years ago
FormMeta.php
2 years ago
FormTaxonomies.php
1 year ago
FormTitle.php
2 years ago
FundsAndDesignations.php
2 years ago
GiftAid.php
2 years ago
Mailchimp.php
2 years ago
MigrateMeta.php
2 years ago
OfflineDonations.php
2 years ago
PaymentGateways.php
2 years ago
PdfSettings.php
2 years ago
PerFormGateways.php
2 years ago
RazorpayPerFormSettings.php
1 year ago
RecurringDonationOptions.php
2 years ago
TermsAndConditions.php
2 years ago
DonationOptions.php
68 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\FormMigration\Steps; |
| 4 | |
| 5 | use Give\FormMigration\Contracts\FormMigrationStep; |
| 6 | use Give\Framework\Blocks\BlockModel; |
| 7 | |
| 8 | class DonationOptions extends FormMigrationStep |
| 9 | { |
| 10 | public function process() |
| 11 | { |
| 12 | /** @var BlockModel $amountField */ |
| 13 | $amountField = $this->fieldBlocks->findByName('givewp/donation-amount'); |
| 14 | |
| 15 | $priceOption = $this->getMetaV2('_give_price_option'); |
| 16 | $amountField->setAttribute('priceOption', $priceOption); |
| 17 | |
| 18 | if('set' === $priceOption) { |
| 19 | $amountField->setAttribute('setPrice', $this->getMetaV2('_give_set_price')); |
| 20 | } |
| 21 | |
| 22 | if('multi' === $priceOption) { |
| 23 | // @note $formV2->levels only returns a single level |
| 24 | $donationLevels = $this->getMetaV2('_give_donation_levels'); |
| 25 | |
| 26 | $isDescriptionEnabled = false; |
| 27 | $amountField->setAttribute('levels', |
| 28 | array_map(function ($donationLevel) use (&$isDescriptionEnabled) { |
| 29 | $isDescriptionEnabled = $isDescriptionEnabled || ! empty($donationLevel['_give_text']); |
| 30 | |
| 31 | return [ |
| 32 | 'value' => $this->roundAmount($donationLevel['_give_amount']), |
| 33 | 'label' => $donationLevel['_give_text'], |
| 34 | 'checked' => isset($donationLevel['_give_default']) && $donationLevel['_give_default'] === 'default', |
| 35 | ]; |
| 36 | }, $donationLevels) |
| 37 | ); |
| 38 | $amountField->setAttribute('descriptionsEnabled', $isDescriptionEnabled); |
| 39 | } |
| 40 | |
| 41 | $isCustomAmountEnabled = $this->formV2->isCustomAmountOptionEnabled(); |
| 42 | $amountField->setAttribute('customAmount', $isCustomAmountEnabled); |
| 43 | |
| 44 | if ($isCustomAmountEnabled) { |
| 45 | $customAmountMin = $this->getMetaV2('_give_custom_amount_range_minimum'); |
| 46 | $customAmountMax = $this->getMetaV2('_give_custom_amount_range_maximum'); |
| 47 | |
| 48 | if ($customAmountMin) { |
| 49 | $amountField->setAttribute('customAmountMin', $this->roundAmount($customAmountMin)); |
| 50 | } |
| 51 | |
| 52 | if ($customAmountMax) { |
| 53 | $amountField->setAttribute('customAmountMax', $this->roundAmount($customAmountMax)); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // @note No corresponding setting in v3 for "Custom Amount Text" |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @since 3.0.0 |
| 62 | */ |
| 63 | private function roundAmount($amount): float |
| 64 | { |
| 65 | return round((float)$amount, 2); |
| 66 | } |
| 67 | } |
| 68 |