AbandonedCheckoutProtocolController.php
2 years ago
AbandonedCheckoutsController.php
3 years ago
AccountController.php
2 years ago
ActivationsController.php
3 years ago
AffiliationProductsController.php
2 years ago
AffiliationProtocolController.php
2 years ago
AffiliationRequestsController.php
2 years ago
AffiliationsController.php
2 years ago
BalanceTransactionsController.php
3 years ago
BrandController.php
2 years ago
BumpsController.php
3 years ago
CancellationActsController.php
3 years ago
CancellationReasonsController.php
3 years ago
ChargesController.php
2 years ago
CheckEmailController.php
2 years ago
CheckoutsController.php
1 year ago
ClicksController.php
2 years ago
CouponsController.php
3 years ago
CustomerController.php
1 year ago
CustomerNotificationProtocolController.php
2 years ago
DownloadsController.php
3 years ago
DraftCheckoutsController.php
2 years ago
ExportsController.php
2 years ago
FulfillmentsController.php
3 years ago
IncomingWebhooksController.php
2 years ago
IntegrationProvidersController.php
3 years ago
IntegrationsController.php
2 years ago
InvoicesController.php
1 year ago
LicensesController.php
3 years ago
LineItemsController.php
2 years ago
LoginController.php
2 years ago
ManualPaymentMethodsController.php
3 years ago
MediasController.php
3 years ago
OrderController.php
3 years ago
OrderProtocolController.php
2 years ago
PaymentIntentsController.php
2 years ago
PaymentMethodsController.php
2 years ago
PayoutGroupsController.php
2 years ago
PayoutsController.php
2 years ago
PeriodsController.php
3 years ago
PortalProtocolController.php
2 years ago
PricesController.php
1 year ago
ProcessorController.php
3 years ago
ProductCollectionsController.php
2 years ago
ProductGroupsController.php
3 years ago
ProductMediaController.php
1 year ago
ProductsController.php
1 year ago
PromotionsController.php
3 years ago
ProvisionalAccountController.php
3 years ago
PurchasesController.php
3 years ago
ReferralItemsController.php
2 years ago
ReferralsController.php
2 years ago
RefundsController.php
3 years ago
RegisteredWebhookController.php
2 years ago
RestController.php
1 year ago
ReturnItemsController.php
2 years ago
ReturnReasonsController.php
2 years ago
ReturnRequestsController.php
2 years ago
SettingsController.php
1 year ago
ShippingMethodController.php
3 years ago
ShippingProfileController.php
3 years ago
ShippingProtocolController.php
3 years ago
ShippingRateController.php
3 years ago
ShippingZoneController.php
3 years ago
StatisticsController.php
2 years ago
SubscriptionProtocolController.php
2 years ago
SubscriptionsController.php
2 years ago
TaxOverrideController.php
2 years ago
TaxProtocolController.php
2 years ago
TaxRegistrationController.php
3 years ago
TaxZoneController.php
3 years ago
UploadsController.php
3 years ago
UpsellFunnelsController.php
2 years ago
UpsellsController.php
2 years ago
VariantOptionsController.php
2 years ago
VariantValuesController.php
2 years ago
VariantsController.php
2 years ago
VerificationCodeController.php
2 years ago
WebhookController.php
3 years ago
PricesController.php
37 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Controllers\Rest; |
| 4 | |
| 5 | use SureCart\Models\Price; |
| 6 | use SureCart\Models\Product; |
| 7 | |
| 8 | /** |
| 9 | * Handle Price requests through the REST API |
| 10 | */ |
| 11 | class PricesController extends RestController { |
| 12 | /** |
| 13 | * Class to make the requests. |
| 14 | * |
| 15 | * @var string |
| 16 | */ |
| 17 | protected $class = Price::class; |
| 18 | |
| 19 | /** |
| 20 | * Run some middleware to run before request. |
| 21 | * |
| 22 | * @param \SureCart\Models\Model $class Model class instance. |
| 23 | * @param \WP_REST_Request $request Request object. |
| 24 | * |
| 25 | * @return \SureCart\Models\Model |
| 26 | */ |
| 27 | protected function middleware( $class, \WP_REST_Request $request ) { |
| 28 | // get the expands from the product for syncing. |
| 29 | $expands = array_merge( [ 'product' ], array_map( fn( $expand ) => strpos( $expand, '.' ) !== false ? $expand : 'product.' . $expand, Product::getSyncExpands() ) ); |
| 30 | // If we are updating or creating, always return the product for syncing. |
| 31 | if ( in_array( $request->get_method(), [ 'POST', 'PUT', 'PATCH', 'DELETE' ] ) ) { |
| 32 | $class->with( array_unique( array_filter( array_merge( $expands, $request['expand'] ?? [] ) ) ) ); |
| 33 | } |
| 34 | return parent::middleware( $class, $request ); |
| 35 | } |
| 36 | } |
| 37 |