Term_Mapper
Summary
No summary available.Source
File: src/BigCommerce/Import/Mappers/Term_Mapper.php
abstract class Term_Mapper { /** * @var string The name of the taxonomy to map. Should be set in the extending class. */ protected $taxonomy; public function __construct() { if ( empty( $this->taxonomy ) ) { throw new \RuntimeException( __( 'Unable to map terms without a taxonomy', 'bigcommerce' ) ); } } /** * Map a BigCommerce term ID to the equivalent WP term ID * * @param int $bc_id * * @return int */ public function map( $bc_id ) { if ( empty( $bc_id ) ) { return 0; } $local = $this->find_existing_term( $bc_id ); if ( $local ) { return $local; } return 0; // don't import it right now, presume it will be imported on the next importer run } /** * Find an already-imported term in the WP database * * @param int $bc_id * * @return int The ID of the found term. 0 on failure. */ protected function find_existing_term( $bc_id ) { $terms = get_terms( [ 'taxonomy' => $this->taxonomy, 'hide_empty' => false, 'meta_query' => [ [ 'key' => 'bigcommerce_id', 'value' => $bc_id, 'compare' => '=', ], ], ] ); if ( ! empty( $terms ) ) { return (int) reset( $terms )->term_id; } return 0; } }
Methods
- __construct
- map — Map a BigCommerce term ID to the equivalent WP term ID