CanDuplicate.php
1 year ago
CanFilter.php
2 weeks ago
CanFinalize.php
3 years ago
CanResendNotifications.php
1 year ago
HasAffiliation.php
2 years ago
HasAttributes.php
1 year ago
HasAutoFeeRules.php
5 months ago
HasBillingAddress.php
7 months ago
HasCharge.php
3 years ago
HasCheckout.php
3 years ago
HasCommissionStructure.php
2 years ago
HasCoupon.php
3 years ago
HasCustomer.php
3 years ago
HasDates.php
1 year ago
HasDiscount.php
1 year ago
HasDisputes.php
9 months ago
HasFees.php
11 months ago
HasImageSizes.php
2 years ago
HasInvoice.php
1 year ago
HasLicense.php
2 years ago
HasLineItem.php
2 years ago
HasOrder.php
3 years ago
HasPaymentFailures.php
1 year ago
HasPaymentInstrument.php
1 year ago
HasPaymentIntent.php
3 years ago
HasPaymentMethod.php
3 years ago
HasPayout.php
2 years ago
HasPayouts.php
2 years ago
HasPlatformFee.php
1 year ago
HasPrice.php
3 years ago
HasProcessorType.php
3 years ago
HasProduct.php
3 years ago
HasPromotion.php
1 year ago
HasPurchase.php
3 years ago
HasPurchases.php
3 years ago
HasReferral.php
2 years ago
HasReferralItems.php
2 years ago
HasReferrals.php
2 years ago
HasRefund.php
3 years ago
HasRefundItems.php
1 year ago
HasServiceFee.php
1 year ago
HasShippingAddress.php
7 months ago
HasShippingChoices.php
1 year ago
HasShippingMethod.php
1 year ago
HasSubscription.php
3 years ago
HasSubscriptions.php
3 years ago
HasSwap.php
1 year ago
SyncsCustomer.php
3 years ago
CanDuplicate.php
49 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Models\Traits; |
| 4 | |
| 5 | /** |
| 6 | * If the model has an attached customer. |
| 7 | */ |
| 8 | trait CanDuplicate { |
| 9 | /** |
| 10 | * Duplicate the model. |
| 11 | * |
| 12 | * @param string $id The ID of the model to duplicate. |
| 13 | * @return $this|\WP_Error |
| 14 | */ |
| 15 | protected function duplicate( $id = '' ) { |
| 16 | if ( $id && empty( $this->attributes['id'] ) ) { |
| 17 | $this->attributes['id'] = $id; |
| 18 | } |
| 19 | |
| 20 | if ( $this->fireModelEvent( 'duplicating' ) === false ) { |
| 21 | return false; |
| 22 | } |
| 23 | |
| 24 | if ( empty( $this->attributes['id'] ) ) { |
| 25 | return new \WP_Error( 'not_saved', 'Please create the model first.' ); |
| 26 | } |
| 27 | |
| 28 | $duplicated = \SureCart::request( |
| 29 | $this->endpoint . '/' . $this->attributes['id'] . '/duplicate/', |
| 30 | [ |
| 31 | 'method' => 'POST', |
| 32 | 'query' => $this->query, |
| 33 | ] |
| 34 | ); |
| 35 | |
| 36 | if ( is_wp_error( $duplicated ) ) { |
| 37 | return $duplicated; |
| 38 | } |
| 39 | |
| 40 | $this->resetAttributes(); |
| 41 | |
| 42 | $this->fill( $duplicated ); |
| 43 | |
| 44 | $this->fireModelEvent( 'duplicated' ); |
| 45 | |
| 46 | return $this; |
| 47 | } |
| 48 | } |
| 49 |