class CategoriesTerm in Commerce Migrate 3.0.x
Same name and namespace in other branches
- 8.2 modules/woocommerce/src/Plugin/migrate/source/woo3/CategoriesTerm.php \Drupal\commerce_migrate_woocommerce\Plugin\migrate\source\woo3\CategoriesTerm
- 3.1.x modules/woocommerce/src/Plugin/migrate/source/woo3/CategoriesTerm.php \Drupal\commerce_migrate_woocommerce\Plugin\migrate\source\woo3\CategoriesTerm
Yields each taxonomy term in the Categories column.
The cell containing the WooCommerce 3 categories is a comma separated list of the categories assigned to the product variation in this row. Each category is a string of categories with a greater than sign delimiter. The term on the left of the > is the parent of the term on the right side. The depth of the hierarchy is increased by adding '> child' strings, as many as is needed.
Example:
Clothing > Hoodies, Clothing > Hoodies > Pocket, Clothing > Hoodies > Zip
In this case, the term 'Clothing' is the parent of 'Hoodies' which is the parent of 'Pocket' and the parent of 'Zip'.
Plugin annotation
@MigrateSource(
id = "woo3_categories_term_csv"
)
Hierarchy
- class \Drupal\commerce_migrate_woocommerce\Plugin\migrate\source\woo3\CategoriesTerm extends \Drupal\migrate_source_csv\Plugin\migrate\source\CSV
Expanded class hierarchy of CategoriesTerm
File
- modules/
woocommerce/ src/ Plugin/ migrate/ source/ woo3/ CategoriesTerm.php, line 27
Namespace
Drupal\commerce_migrate_woocommerce\Plugin\migrate\source\woo3View source
class CategoriesTerm extends CSV {
/**
* {@inheritdoc}
*/
public function initializeIterator() {
$file = parent::initializeIterator();
return $this
->getYield($file);
}
/**
* Prepare one row per taxonomy term field in the source.
*
* @param \Generator $file
* The source CSV file object.
*
* @codingStandardsIgnoreStart
*
* @return \Generator
* A new row with a taxonomy term and it's parent.
*
* @codingStandardsIgnoreEnd
*/
public function getYield(\Generator $file) {
foreach ($file as $row) {
$new_row = $row;
$categorySet = explode(',', $row['Categories']);
foreach ($categorySet as $category) {
$names = explode('>', $category);
$previous_name = 0;
// Build a row for each term name.
foreach ($names as $name) {
$new_row['parent'] = $previous_name;
$previous_name = trim($name);
$new_row['name'] = trim($name);
(yield $new_row);
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CategoriesTerm:: |
public | function | Prepare one row per taxonomy term field in the source. | |
CategoriesTerm:: |
public | function |