1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Migration for Commerce Products used in DFS WEM. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
class DFSWEMProducts extends DemoFrameworkBaseProducts { |
9
|
|
|
|
10
|
|
View Code Duplication |
public function __construct($arguments) { |
|
|
|
|
11
|
|
|
parent::__construct($arguments); |
12
|
|
|
$this->description = t('Import DFS WEM products.'); |
13
|
|
|
|
14
|
|
|
// Create a map object for tracking the relationships between source rows |
15
|
|
|
$this->map = new MigrateSQLMap($this->machineName, |
16
|
|
|
array( |
17
|
|
|
'sku' => array( |
18
|
|
|
'type' => 'varchar', |
19
|
|
|
'length' => 32, |
20
|
|
|
'not null' => TRUE, |
21
|
|
|
), |
22
|
|
|
), |
23
|
|
|
MigrateDestinationEntityAPI::getKeySchema('commerce_product', 'wem_product') |
24
|
|
|
); |
25
|
|
|
|
26
|
|
|
$this->destination = new MigrateDestinationEntityAPI('commerce_product', 'wem_product'); |
27
|
|
|
|
28
|
|
|
// Define a default import path. |
29
|
|
|
$import_path = drupal_get_path('module', 'dfs_wem') . '/import/'; |
30
|
|
|
|
31
|
|
|
// Create a MigrateSource object. |
32
|
|
|
$this->source = new MigrateSourceCSV($import_path . 'dfs_wem.products.csv', $this->csvcolumns(), array('header_rows' => 1)); |
33
|
|
|
|
34
|
|
|
$this->addFieldMapping('field_images:source_dir')->defaultValue($import_path . 'images'); |
35
|
|
|
|
36
|
|
|
$this->addFieldMapping('field_wem_product_interests', 'interests'); |
37
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
function csvcolumns() { |
|
|
|
|
41
|
|
|
$columns[0] = array('title', 'Title'); |
|
|
|
|
42
|
|
|
$columns[1] = array('sku', 'SKU'); |
43
|
|
|
$columns[2] = array('commerce_price', 'Price'); |
44
|
|
|
$columns[3] = array('images', 'Images'); |
45
|
|
|
$columns[4] = array('interests', 'Interests'); |
46
|
|
|
return $columns; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
function prepareRow($row) { |
|
|
|
|
50
|
|
|
$row->images = explode(', ', $row->images); |
51
|
|
|
$row->uid = 1; |
52
|
|
|
$row->language = LANGUAGE_NONE; |
53
|
|
|
$row->status = 1; |
54
|
|
|
$row->interests = explode(", ", $row->interests); |
55
|
|
|
return TRUE; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.