|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2024 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Upscheme\Task; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Adds demo records to supplier tables. |
|
14
|
|
|
*/ |
|
15
|
|
|
class DemoAddSupplierData extends MShopAddDataAbstract |
|
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 after() : array |
|
23
|
|
|
{ |
|
24
|
|
|
return ['Supplier', 'Media', 'Text', 'MShopAddTypeDataDefault', 'MShopAddCodeDataDefault']; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Returns the list of task names which depends on this task. |
|
30
|
|
|
* |
|
31
|
|
|
* @return array List of task names |
|
32
|
|
|
*/ |
|
33
|
|
|
public function before() : array |
|
34
|
|
|
{ |
|
35
|
|
|
return ['DemoRebuildIndex']; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Insert service data. |
|
41
|
|
|
*/ |
|
42
|
|
|
public function up() |
|
43
|
|
|
{ |
|
44
|
|
|
$context = $this->context(); |
|
|
|
|
|
|
45
|
|
|
$value = $context->config()->get( 'setup/default/demo', '' ); |
|
46
|
|
|
|
|
47
|
|
|
if( $value === '' ) { |
|
48
|
|
|
return; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
$this->info( 'Processing supplier demo data', 'vv' ); |
|
53
|
|
|
|
|
54
|
|
|
$manager = \Aimeos\MShop::create( $context, 'supplier' ); |
|
55
|
|
|
|
|
56
|
|
|
$search = $manager->filter(); |
|
57
|
|
|
$search->setConditions( $search->compare( '=~', 'supplier.code', 'demo-' ) ); |
|
58
|
|
|
$services = $manager->search( $search ); |
|
59
|
|
|
|
|
60
|
|
|
$manager->delete( $services->toArray() ); |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
if( $value === '1' ) |
|
64
|
|
|
{ |
|
65
|
|
|
$ds = DIRECTORY_SEPARATOR; |
|
66
|
|
|
$path = __DIR__ . $ds . 'data' . $ds . 'demo-supplier.php'; |
|
67
|
|
|
|
|
68
|
|
|
if( ( $data = include( $path ) ) == false ) { |
|
69
|
|
|
throw new \RuntimeException( sprintf( 'No file "%1$s" found for supplier domain', $path ) ); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$this->saveItems( $data ); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Stores the supplier items |
|
79
|
|
|
* |
|
80
|
|
|
* @param array $data List of arrays containing the supplier properties |
|
81
|
|
|
*/ |
|
82
|
|
|
protected function saveItems( array $data ) |
|
83
|
|
|
{ |
|
84
|
|
|
$manager = \Aimeos\MShop::create( $this->context(), 'supplier' ); |
|
85
|
|
|
|
|
86
|
|
|
foreach( $data as $idx => $entry ) |
|
87
|
|
|
{ |
|
88
|
|
|
$item = $manager->create()->fromArray( $entry, true ); |
|
89
|
|
|
|
|
90
|
|
|
$item = $this->addRefItems( $item, $entry, $idx ); |
|
91
|
|
|
$item = $this->addAddressItems( $item, $entry ); |
|
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
$manager->save( $item ); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Adds the referenced product items from the given entry data. |
|
100
|
|
|
* |
|
101
|
|
|
* @param \Aimeos\MShop\Common\Item\AddressRef\Iface $item Item with list items |
|
102
|
|
|
* @param array $entry Associative list of data with product section |
|
103
|
|
|
* @return \Aimeos\MShop\Common\Item\Iface $item Updated item |
|
104
|
|
|
*/ |
|
105
|
|
|
protected function addAddressItems( \Aimeos\MShop\Common\Item\AddressRef\Iface $item, array $entry ) |
|
106
|
|
|
{ |
|
107
|
|
|
$manager = \Aimeos\MShop::create( $this->context(), 'supplier/address' ); |
|
108
|
|
|
|
|
109
|
|
|
foreach( $entry['address'] ?? [] as $addr ) { |
|
110
|
|
|
$item->addAddressItem( $manager->create()->fromArray( $addr, true ) ); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
return $item; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|