-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working Dynamic Shopify Data Source Block Registration
- Loading branch information
Showing
9 changed files
with
87 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace RemoteDataBlocks\Config; | ||
|
||
trait DynamicDatasource { | ||
private string $slug; | ||
private string $uuid; | ||
|
||
public function set_slug( string $slug ): void { | ||
$this->slug = $slug; | ||
} | ||
|
||
public function get_slug(): string { | ||
return $this->slug; | ||
} | ||
|
||
public function set_uuid( string $uuid ): void { | ||
$this->uuid = $uuid; | ||
} | ||
|
||
public function get_uuid(): string { | ||
return $this->uuid; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
inc/config/shopify-datasource/class-shopify-datasource.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace RemoteDataBlocks\Config; | ||
|
||
use RemoteDataBlocks\Config\HttpDatasource; | ||
use function plugins_url; | ||
|
||
class ShopifyDatasource extends HttpDatasource { | ||
use DynamicDatasource; | ||
|
||
public function __construct( private string $access_token, private string $store_name ) {} | ||
|
||
public function get_store_name(): string { | ||
return $this->store_name; | ||
} | ||
|
||
public function get_endpoint(): string { | ||
return 'https://' . $this->store_name . '.myshopify.com/api/2024-04/graphql.json'; | ||
} | ||
|
||
public function get_request_headers(): array { | ||
return [ | ||
'Content-Type' => 'application/json', | ||
'X-Shopify-Storefront-Access-Token' => $this->access_token, | ||
]; | ||
} | ||
|
||
public function get_image_url(): string { | ||
return plugins_url( '../../assets/shopify_logo_black.png', __FILE__ ); | ||
} | ||
} |
4 changes: 1 addition & 3 deletions
4
...eries/class-shopify-get-product-query.php → ...ource/class-shopify-get-product-query.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletions
4
...s/class-shopify-search-products-query.php → ...e/class-shopify-search-products-query.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,5 @@ | ||
<?php | ||
|
||
namespace RemoteDataBlocks\Config; | ||
|
||
use RemoteDataBlocks\Config\HttpDatasource; | ||
use function plugins_url; | ||
|
||
class ShopifyDatasource extends HttpDatasource { | ||
public function __construct( private string $access_token, private string $store_name ) {} | ||
|
||
public function get_endpoint(): string { | ||
return 'https://' . $this->store_name . '.myshopify.com/api/2024-04/graphql.json'; | ||
} | ||
|
||
public function get_request_headers(): array { | ||
return [ | ||
'Content-Type' => 'application/json', | ||
'X-Shopify-Storefront-Access-Token' => $this->access_token, | ||
]; | ||
} | ||
|
||
public function get_image_url(): string { | ||
return plugins_url( '../../assets/shopify_logo_black.png', __FILE__ ); | ||
} | ||
} | ||
require_once __DIR__ . '/class-shopify-datasource.php'; | ||
require_once __DIR__ . '/class-shopify-get-product-query.php'; | ||
require_once __DIR__ . '/class-shopify-search-products-query.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters