FreeShippingStoreEndpointData.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPDesk\FS\Blocks\FreeShipping; |
| 4 | |
| 5 | use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable; |
| 6 | |
| 7 | class FreeShippingStoreEndpointData implements Hookable { |
| 8 | |
| 9 | /** |
| 10 | * @var string |
| 11 | */ |
| 12 | private $integration_name; |
| 13 | |
| 14 | public function __construct( string $integration_name ) { |
| 15 | $this->integration_name = $integration_name; |
| 16 | } |
| 17 | |
| 18 | public function hooks() { |
| 19 | add_filter( 'octolize-checkout-block-integration-' . $this->integration_name . '-data', [ $this, 'integration_data' ] ); |
| 20 | add_filter( 'octolize-checkout-block-integration-' . $this->integration_name . '-schema', [ $this, 'integration_schema' ] ); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * @param array $data |
| 25 | * |
| 26 | * @return array <string, array<string, bool>> |
| 27 | */ |
| 28 | public function integration_data( $data ) { |
| 29 | return [ |
| 30 | 'page_type' => $this->get_page_type(), |
| 31 | ]; |
| 32 | } |
| 33 | |
| 34 | private function get_page_type() { |
| 35 | return is_checkout() ? 'checkout' : ( is_cart() ? 'cart' : 'other' ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @param array $schema |
| 40 | * |
| 41 | * @return array |
| 42 | */ |
| 43 | public function integration_schema( $schema ) { |
| 44 | $schema['page_type']['type'] = [ 'string' ]; |
| 45 | |
| 46 | return $schema; |
| 47 | } |
| 48 | |
| 49 | } |
| 50 |