forked from aimeos/aimeos-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMShopAddAttributeData.php
56 lines (43 loc) · 1.12 KB
/
MShopAddAttributeData.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
* @copyright Aimeos (aimeos.org), 2017-2023
*/
namespace Aimeos\Upscheme\Task;
/**
* Adds default attribute
*/
class MShopAddAttributeData extends MShopAddDataAbstract
{
public function after() : array
{
return ['MShopAddTypeData'];
}
public function up()
{
}
/**
* Adds the default codes
*/
protected function process()
{
$site = $this->context()->locale()->getSiteItem()->getCode();
$this->info( sprintf( 'Adding default attribute data for site "%1$s"', $site ), 'vv' );
$ds = DIRECTORY_SEPARATOR;
$path = __DIR__ . $ds . 'default' . $ds . 'data' . $ds . 'attribute.php';
if( ( $data = include( $path ) ) == false ) {
throw new \RuntimeException( sprintf( 'No file "%1$s" found for default codes', $path ) );
}
$manager = \Aimeos\MShop::create( $this->context(), 'attribute' );
$item = $manager->create();
foreach( $data as $dataset )
{
try
{
$item = $item->setId( null )->fromArray( $dataset );
$manager->save( $item );
}
catch( \Exception $e ) { ; } // if attribute was already available
}
}
}