Term_Saver

Provides functionality for saving terms into WordPress, including term data, term metadata, and term images. This class implements the Import_Strategy interface, allowing it to be used within an import process. It contains methods for handling terms in BigCommerce and saving them in WordPress.

Constants

ConstantVisibilityTypeValue
DATA_HASH_META_KEYpublic’bigcommerce_data_hash’
IMPORTER_VERSION_META_KEYpublic’bigcommerce_importer_version’

Properties

bc_term

protected \ArrayAccess $bc_term

taxonomy

protected string $taxonomy

term_id

protected int $term_id

Methods

__construct

Term_Saver constructor.

public __construct(\ArrayAccess $bc_term, string $taxonomy, int $term_id): mixed

Initializes the Term_Saver with the provided BigCommerce term, taxonomy, and optional term ID.

Parameters:

ParameterTypeDescription
$bc_term\ArrayAccessThe BigCommerce term data.
$taxonomystringThe taxonomy the term belongs to.
$term_idintThe term ID in WordPress (default is 0).

do_import

Imports the term into WordPress, saving term data, term metadata, and images.

public do_import(): int

Return Value:

The imported term ID.


get_term_bc_id

Returns the BigCommerce ID of the term.

public get_term_bc_id(\ArrayAccess $bc_term): int|null

Parameters:

ParameterTypeDescription
$bc_term\ArrayAccessThe BigCommerce term data.

Return Value:

The BigCommerce ID or category ID.


save_wp_term

Saves the term in WordPress.

protected save_wp_term(\ArrayAccess $bc_term): int
  • This method is abstract.

Parameters:

ParameterTypeDescription
$bc_term\ArrayAccessThe BigCommerce term data.

Return Value:

The ID of the created or updated term.


save_wp_termmeta

Saves the term metadata in WordPress.

protected save_wp_termmeta(\ArrayAccess $bc_term): mixed
  • This method is abstract.

Parameters:

ParameterTypeDescription
$bc_term\ArrayAccessThe BigCommerce term data.

term_name

Returns the name of the term, sanitized for WordPress.

protected term_name(\ArrayAccess $bc_term): string

Parameters:

ParameterTypeDescription
$bc_term\ArrayAccessThe BigCommerce term data.

Return Value:

The sanitized term name.


term_slug

Returns the slug for the term, either from the custom URL or generated from the name.

protected term_slug(\ArrayAccess $bc_term): string

Parameters:

ParameterTypeDescription
$bc_term\ArrayAccessThe BigCommerce term data.

Return Value:

The term slug.


sanitize_int

Sanitizes an integer value.

protected sanitize_int(mixed $value): int

Parameters:

ParameterTypeDescription
$valuemixedThe value to sanitize.

Return Value:

The sanitized integer value.


sanitize_string

Sanitizes a string value.

protected sanitize_string(mixed $value): string

Parameters:

ParameterTypeDescription
$valuemixedThe value to sanitize.

Return Value:

The sanitized string value.


get_term_args

Returns the arguments for the term, including the slug, description, and parent ID.

protected get_term_args(\ArrayAccess $bc_term): array

Parameters:

ParameterTypeDescription
$bc_term\ArrayAccessThe BigCommerce term data.

Return Value:

The arguments for the term.


determine_parent_term_id

Determines the parent term ID for the given BigCommerce term.

protected determine_parent_term_id(\ArrayAccess $bc_term): int

Parameters:

ParameterTypeDescription
$bc_term\ArrayAccessThe BigCommerce term data.

Return Value:

The parent term ID.


import_image

Imports the image for the term, either by finding an existing image or importing a new one.

protected import_image(\ArrayAccess $bc_term): mixed

Parameters:

ParameterTypeDescription
$bc_term\ArrayAccessThe BigCommerce term data.

hash

Calculates a hash for the given term data.

public static hash(\ArrayAccess $bc_term): string
  • This method is static.

Parameters:

ParameterTypeDescription
$bc_term\ArrayAccessThe BigCommerce term data.

Return Value:

The calculated hash.



Automatically generated on 2025-01-21