.gitkeep
3 years ago
BuyPageController.php
2 years ago
DashboardController.php
3 years ago
ProductPageController.php
3 years ago
ProductTypePageController.php
3 years ago
PurchaseController.php
3 years ago
SubscriptionsController.php
3 years ago
WebhookController.php
2 years ago
ProductPageController.php
53 lines
| 1 | <?php |
| 2 | namespace SureCart\Controllers\Web; |
| 3 | |
| 4 | /** |
| 5 | * Handles webhooks |
| 6 | */ |
| 7 | class ProductPageController extends ProductTypePageController { |
| 8 | /** |
| 9 | * Show the product page |
| 10 | * |
| 11 | * @param \SureCartCore\Requests\RequestInterface $request Request. |
| 12 | * @param \SureCartCore\View $view View. |
| 13 | * @param string $id The id of the product. |
| 14 | * @return function |
| 15 | */ |
| 16 | public function show( $request, $view ) { |
| 17 | // get the product from the query var. |
| 18 | $id = get_query_var( 'sc_product_page_id' ); |
| 19 | |
| 20 | // fetch the product by id/slug. |
| 21 | $this->product = \SureCart\Models\Product::with( [ 'prices', 'image' ] )->find( $id ); |
| 22 | if ( is_wp_error( $this->product ) ) { |
| 23 | return $this->handleError( $this->product ); |
| 24 | } |
| 25 | |
| 26 | // if this product is a draft, check read permissions. |
| 27 | if ( 'draft' === $this->product->status && ! current_user_can( 'read_sc_products' ) ) { |
| 28 | return $this->notFound(); |
| 29 | } |
| 30 | |
| 31 | // slug changed or we are using the id, redirect. |
| 32 | if ( $this->product->slug !== $id ) { |
| 33 | return \SureCart::redirect()->to( $this->product->permalink ); |
| 34 | } |
| 35 | |
| 36 | set_query_var( 'sc_product_page_id', $this->product->id ); |
| 37 | |
| 38 | // add the filters. |
| 39 | $this->filters(); |
| 40 | |
| 41 | // handle block theme. |
| 42 | if ( wp_is_block_theme() ) { |
| 43 | global $_wp_current_template_content; |
| 44 | $_wp_current_template_content = $this->product->template->content ?? ''; |
| 45 | } |
| 46 | |
| 47 | // include the default view. |
| 48 | include $view; |
| 49 | |
| 50 | return \SureCart::response(); |
| 51 | } |
| 52 | } |
| 53 |