PluginProbe
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.3.2
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.3.2
4.7.2 4.7.1 4.7.0 4.6.6 4.6.5 4.6.4 4.6.3 4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 All 281 releases
surecart / app / src / Middleware / PathRedirectMiddleware.php
PathRedirectMiddleware.php
69 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SureCart\Middleware;
4
5 use Closure;
6 use SureCartCore\Requests\RequestInterface;
7 use SureCartCore\Responses\RedirectResponse;
8
9 /**
10 * Middleware for handling model archiving.
11 */
12 class PathRedirectMiddleware {
13 /**
14 * Enqueue component assets.
15 *
16 * @param RequestInterface $request Request.
17 * @param Closure $next Next.
18 * @return function
19 */
20 public function handle( RequestInterface $request, Closure $next ) {
21 $path = $request->query( 'path' );
22 $customer_link_id = $request->query( 'customer_link_id' );
23
24 // need a path and a customer link id.
25 if ( empty( $path ) || empty( $customer_link_id ) ) {
26 return $next( $request );
27 }
28
29 $path = $request->query( 'path' );
30 return ( new RedirectResponse( $request ) )->to(
31 esc_url_raw( $this->buildUrl( untrailingslashit( get_home_url() ) . $path, $request ) )
32 );
33 }
34
35 /**
36 * Build the url.
37 *
38 * @return string
39 */
40 public function buildUrl( $url, RequestInterface $request ) {
41 if ( empty( $url ) ) {
42 return $url;
43 }
44
45 // add checkout id.
46 $id = $request->query( 'checkout_id' );
47 if ( $id ) {
48 $url = add_query_arg(
49 [
50 'checkout_id' => $id,
51 ],
52 $url
53 );
54 }
55
56 $promotion_code = $request->query( 'promotion_code' );
57 if ( $promotion_code ) {
58 $url = add_query_arg(
59 [
60 'coupon' => $promotion_code,
61 ],
62 $url
63 );
64 }
65
66 return $url;
67 }
68 }
69