AdminRouteService.php
2 years ago
AdminRouteServiceProvider.php
3 years ago
AdminURLService.php
3 years ago
PermalinkService.php
3 years ago
PermalinkServiceProvider.php
3 years ago
PermalinkSettingService.php
3 years ago
PermalinksSettingsService.php
3 years ago
RouteConditionsServiceProvider.php
3 years ago
PermalinkServiceProvider.php
91 lines
| 1 | <?php |
| 2 | |
| 3 | namespace SureCart\Routing; |
| 4 | |
| 5 | use SureCartCore\ServiceProviders\ServiceProviderInterface; |
| 6 | |
| 7 | /** |
| 8 | * Provide custom route conditions. |
| 9 | * This is an example class so feel free to modify or remove it. |
| 10 | */ |
| 11 | class PermalinkServiceProvider implements ServiceProviderInterface { |
| 12 | /** |
| 13 | * Register all dependencies in the IoC container. |
| 14 | * |
| 15 | * @param \Pimple\Container $container Service container. |
| 16 | * @return void |
| 17 | */ |
| 18 | public function register( $container ) { |
| 19 | $container['surecart.settings.permalinks.product'] = function() { |
| 20 | return new PermalinkSettingService( |
| 21 | [ |
| 22 | 'slug' => 'product', |
| 23 | 'label' => __( 'SureCart Product Permalinks', 'surecart' ), |
| 24 | /* translators: %s: Home URL */ |
| 25 | 'description' => sprintf( __( 'If you like, you may enter custom structures for your product page URLs here. For example, using <code>products</code> would make your product buy links like <code>%sproducts/sample-product/</code>.', 'surecart' ), esc_url( home_url( '/' ) ) ), |
| 26 | 'options' => [ |
| 27 | [ |
| 28 | 'value' => 'products', |
| 29 | 'label' => __( 'Default', 'surecart' ), |
| 30 | ], |
| 31 | [ |
| 32 | 'value' => 'shop', |
| 33 | 'label' => __( 'Shop', 'surecart' ), |
| 34 | ], |
| 35 | ], |
| 36 | ] |
| 37 | ); |
| 38 | }; |
| 39 | |
| 40 | $container['surecart.settings.permalinks.buy'] = function() { |
| 41 | return new PermalinkSettingService( |
| 42 | [ |
| 43 | 'slug' => 'buy', |
| 44 | 'label' => __( 'SureCart Instant Checkout Permalinks', 'surecart' ), |
| 45 | /* translators: %s: Home URL */ |
| 46 | 'description' => sprintf( __( 'If you like, you may enter custom structures for your instant checkout URLs here. For example, using <code>buy</code> would make your product buy links like <code>%sbuy/sample-product/</code>.', 'surecart' ), esc_url( home_url( '/' ) ) ), |
| 47 | 'options' => [ |
| 48 | [ |
| 49 | 'value' => 'buy', |
| 50 | 'label' => __( 'Default', 'surecart' ), |
| 51 | ], |
| 52 | [ |
| 53 | 'value' => 'purchase', |
| 54 | 'label' => __( 'Purchase', 'surecart' ), |
| 55 | ], |
| 56 | ], |
| 57 | ] |
| 58 | ); |
| 59 | }; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Bootstrap any services if needed. |
| 64 | * |
| 65 | * @param \Pimple\Container $container Service container. |
| 66 | * @return void |
| 67 | */ |
| 68 | public function bootstrap( $container ) { |
| 69 | $container['surecart.settings.permalinks.product']->bootstrap(); |
| 70 | ( new PermalinkService() ) |
| 71 | ->params( [ 'sc_product_page_id' ] ) |
| 72 | ->url( untrailingslashit( \SureCart::settings()->permalinks()->getBase( 'product_page' ) ) . '/([a-z0-9-]+)[/]?$' ) |
| 73 | ->query( 'index.php?sc_product_page_id=$matches[1]' ) |
| 74 | ->create(); |
| 75 | |
| 76 | $container['surecart.settings.permalinks.buy']->bootstrap(); |
| 77 | ( new PermalinkService() ) |
| 78 | ->params( [ 'sc_checkout_product_id' ] ) |
| 79 | ->url( untrailingslashit( \SureCart::settings()->permalinks()->getBase( 'buy_page' ) ) . '/([a-z0-9-]+)[/]?$' ) |
| 80 | ->query( 'index.php?sc_checkout_product_id=$matches[1]' ) |
| 81 | ->create(); |
| 82 | |
| 83 | // Redirect. |
| 84 | ( new PermalinkService() ) |
| 85 | ->params( [ 'sc_redirect' ] ) |
| 86 | ->url( 'surecart/redirect' ) |
| 87 | ->query( 'index.php?sc_redirect=1' ) |
| 88 | ->create(); |
| 89 | } |
| 90 | } |
| 91 |