1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
||
5 | * @copyright Aimeos (aimeos.org), 2015-2018 |
||
6 | */ |
||
7 | |||
8 | |||
9 | namespace Aimeos\MW\Setup\Task; |
||
10 | |||
11 | |||
12 | /** |
||
13 | * Adds product test data |
||
14 | */ |
||
15 | class ProductAddTestData extends \Aimeos\MW\Setup\Task\BaseAddTestData |
||
16 | { |
||
17 | /** |
||
18 | * Returns the list of task names which this task depends on |
||
19 | * |
||
20 | * @return string[] List of task names |
||
21 | */ |
||
22 | public function getPreDependencies() |
||
23 | { |
||
24 | return ['AttributeAddTestData', 'TagAddTestData']; |
||
25 | } |
||
26 | |||
27 | |||
28 | /** |
||
29 | * Adds product test data |
||
30 | */ |
||
31 | public function migrate() |
||
32 | { |
||
33 | \Aimeos\MW\Common\Base::checkClass( \Aimeos\MShop\Context\Item\Iface::class, $this->additional ); |
||
34 | |||
35 | $this->msg( 'Adding product test data', 0 ); |
||
36 | |||
37 | $this->additional->setEditor( 'core:lib/mshoplib' ); |
||
38 | $this->process( $this->getData() ); |
||
39 | |||
40 | $this->status( 'done' ); |
||
41 | } |
||
42 | |||
43 | |||
44 | /** |
||
45 | * Returns the test data array |
||
46 | * |
||
47 | * @return array Multi-dimensional array of test data |
||
48 | */ |
||
49 | protected function getData() |
||
50 | { |
||
51 | $path = __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'product.php'; |
||
52 | |||
53 | if( ( $testdata = include( $path ) ) == false ) { |
||
54 | throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for product domain', $path ) ); |
||
55 | } |
||
56 | |||
57 | return $testdata; |
||
58 | } |
||
59 | |||
60 | |||
61 | /** |
||
62 | * Returns the manager for the current setup task |
||
63 | * |
||
64 | * @param string $domain Domain name of the manager |
||
65 | * @return \Aimeos\MShop\Common\Manager\Iface Manager object |
||
66 | */ |
||
67 | protected function getManager( $domain ) |
||
68 | { |
||
69 | if( $domain === 'product' ) { |
||
70 | return \Aimeos\MShop\Product\Manager\Factory::create( $this->additional, 'Standard' ); |
||
71 | } |
||
72 | |||
73 | return parent::getManager( $domain ); |
||
74 | } |
||
75 | |||
76 | |||
77 | /** |
||
78 | * Adds the product data from the given array |
||
79 | * |
||
80 | * @param array Multi-dimensional array of test data |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
81 | */ |
||
82 | protected function process( array $testdata ) |
||
83 | { |
||
84 | $manager = $this->getManager( 'product' ); |
||
85 | $listManager = $manager->getSubManager( 'lists' ); |
||
86 | $propManager = $manager->getSubManager( 'property' ); |
||
87 | |||
88 | $manager->begin(); |
||
89 | $this->storeTypes( $testdata, ['product/type', 'product/lists/type', 'product/property/type'] ); |
||
90 | $manager->commit(); |
||
91 | |||
92 | foreach( $testdata['product'] as $entry ) |
||
93 | { |
||
94 | $item = $manager->createItem()->fromArray( $entry ); |
||
95 | $item = $this->addListData( $listManager, $item, $entry ); |
||
96 | $item = $this->addPropertyData( $propManager, $item, $entry ); |
||
97 | |||
98 | $manager->saveItem( $item ); |
||
99 | } |
||
100 | } |
||
101 | } |
||
102 |