ClassesBigCommerceImportProcessorsCategory Import

Category_Import

Abstract class for processing term imports.

This class provides common functionality for importing terms into WordPress. It interacts with BigCommerce’s API and uses GraphQL data for creating or updating terms.

Methods

taxonomy

Get the taxonomy name for this import.

protected taxonomy(): string

This method returns the taxonomy name used for categorization, which is the product category.

Return Value:

The taxonomy name for product categories.


running_state

Get the current running state for this import.

protected running_state(): string

This method returns the state representing the update process for categories.

Return Value:

The running state constant for category updating.


completed_state

Get the completed state for this import.

protected completed_state(): string

This method returns the state representing the successful completion of the category import.

Return Value:

The completed state constant for category update.


get_fallback_terms

Get fallback terms when GraphQL request fails.

protected get_fallback_terms(): array|null

If GraphQL fails, this method fetches categories using the REST API as a fallback. It handles pagination and logging for both successful and failed attempts.

Return Value:

An array of categories or null if no categories are retrieved.


get_source_data

Get category data using GraphQL.

public get_source_data(string $cursor = ''): array

This method retrieves category tree data via GraphQL, handling the response and returning the result.

Parameters:

ParameterTypeDescription
$cursorstringThe cursor for pagination, default is an empty string.

Return Value:

The processed category data from GraphQL response.

Throws:

Throws an exception if GraphQL request fails.


parse_gql_term

Parse a term (category) for GraphQL.

protected parse_gql_term(mixed $term = null): array

This method processes a single term, extracting the image URL and setting the parent ID before recursively parsing any children of the term.

Parameters:

ParameterTypeDescription
$termmixedThe term (category) to parse.

Return Value:

An array of GQL_Term_Model objects representing the term and its children.


parse_term_children

Parse child terms (categories).

protected parse_term_children(array& $result, mixed $children, int $parent_id): mixed

This method recursively processes child categories for a given parent term. It sets the image URL and parent ID for each child before adding it to the result.

Parameters:

ParameterTypeDescription
$resultarrayAn array that will contain parsed terms.
$childrenmixedThe child terms to parse.
$parent_idintThe ID of the parent term.

get_category_data

Get category data by ID.

public get_category_data(int $category_id): \BigCommerce\Api\v3\Model\CategoryResponse

This method retrieves category data by ID using the Catalog API.

Parameters:

ParameterTypeDescription
$category_idintThe ID of the category to retrieve.

Return Value:

The category data response.

Throws:

Throws an exception if API request fails.


Inherited methods

get_option

protected get_option(string $option, bool $default = false): mixed

Parameters:

ParameterTypeDescription
$optionstring
$defaultbool

update_option

protected update_option(string $option, mixed $value, bool $autoload = false): bool

Parameters:

ParameterTypeDescription
$optionstring
$valuemixed
$autoloadbool

add_option

protected add_option(string $option, mixed $value, bool $autoload = false): bool

Parameters:

ParameterTypeDescription
$optionstring
$valuemixed
$autoloadbool

delete_option

protected delete_option(string $option): bool

Parameters:

ParameterTypeDescription
$optionstring

__construct

Constructor for the Term_Import class.

public __construct(\BigCommerce\Api\v3\Api\CatalogApi $catalog_api, \BigCommerce\GraphQL\GraphQL_Processor $gql_processor, int $batch_size): mixed

Parameters:

ParameterTypeDescription
$catalog_api\BigCommerce\Api\v3\Api\CatalogApiInstance of the Catalog API client.
$gql_processor\BigCommerce\GraphQL\GraphQL_ProcessorInstance of the GraphQL processor.
$batch_sizeintNumber of terms to process in a single batch.

taxonomy

Get the name of the taxonomy being updated.

protected taxonomy(): string
  • This method is abstract.

Return Value:

The taxonomy name.


get_fallback_terms

Get fallback terms in case the main source data is unavailable.

protected get_fallback_terms(): array
  • This method is abstract.

Return Value:

An array of fallback terms.


running_state

Get the state name to set while the import is running.

protected running_state(): string
  • This method is abstract.

Return Value:

The running state name.


completed_state

Get the state name to set when the import is complete.

protected completed_state(): string
  • This method is abstract.

Return Value:

The completed state name.


run

Execute the term import process.

public run(): void

This method fetches terms from the source, processes them, and updates the import status as it progresses.


do_term_import

Process and import a single term.

protected do_term_import(\StdClass $term, bool $fallback = false): void

Parameters:

ParameterTypeDescription
$term\StdClassThe term object to import.
$fallbackboolWhether to use fallback data for this import.

get_source_data

Fetch term data from the source.

public get_source_data(string $cursor = ''): array
  • This method is abstract.

Parameters:

ParameterTypeDescription
$cursorstringOptional. A cursor for paginated results.

Return Value:

The API response object.

Throws:

If the API request fails.


parse_gql_term

Parse a GraphQL term object into an array format.

protected parse_gql_term(\StdClass|null $term = null): array
  • This method is abstract.

Parameters:

ParameterTypeDescription
$term\StdClass|nullThe GraphQL term object.

Return Value:

The parsed term data.


handle_graph_ql_response

Parse a GraphQL response and handle pagination if necessary.

protected handle_graph_ql_response(string $raw_response = ''): array|mixed

Parameters:

ParameterTypeDescription
$raw_responsestringThe raw GraphQL response.

Return Value:

Parsed term data or a cursor for the next page of results.


get_page

Get the current page for the import process.

protected get_page(): int

Return Value:

The current page number.


set_page

Set the current page for the import process.

protected set_page(int $page): void

Parameters:

ParameterTypeDescription
$pageintThe page number to set.

get_msf_categories

Get the categories in the MSF category tree.

public get_msf_categories(\BigCommerce\Api\v3\Api\CatalogApi $api, array $params = []): \BigCommerce\Api\v3\Model\CategoryCollectionResponse|array

This method retrieves categories within the MSF category tree by fetching the tree ID, then requesting a batch of categories from the BigCommerce API.

Parameters:

ParameterTypeDescription
$api\BigCommerce\Api\v3\Api\CatalogApiThe BigCommerce Catalog API instance.
$paramsarrayAdditional parameters for the category query (optional).

Return Value:

A collection of categories or an empty array.

Throws:

Throws an exception if the API request fails.


get_trees

Get all category trees associated with a given channel.

public get_trees(\BigCommerce\Api\v3\Api\CatalogApi $api): array

This method fetches category trees from BigCommerce by retrieving the channel ID associated with the primary connection and querying the BigCommerce API for available category trees.

Parameters:

ParameterTypeDescription
$api\BigCommerce\Api\v3\Api\CatalogApiThe BigCommerce Catalog API instance.

Return Value:

An array of category trees.

Throws:

Throws an exception if the API request fails.



Automatically generated on 2025-01-21