Passed
Push — master ( bada6f...d61b94 )
by Aimeos
04:42
created

ServiceAddPerfData   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 90
dl 0
loc 139
c 1
b 0
f 0
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A after() 0 3 1
B up() 0 123 4
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2021
6
 */
7
8
9
namespace Aimeos\Upscheme\Task;
10
11
12
/**
13
 * Adds service performance records
14
 */
15
class ServiceAddPerfData extends Base
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 ['MShopAddTypeDataUnitperf', 'LocaleAddPerfData', 'MShopSetLocale'];
25
	}
26
27
28
	/**
29
	 * Insert product data.
30
	 */
31
	public function up()
32
	{
33
		$this->info( 'Adding service performance data', 'v' );
34
35
36
		$services = [
37
			'delivery' => [
38
				'pickup' => [
39
					'name' => 'Pickup',
40
					'short' => 'Pick-up at one of our local stores',
41
					'image' => 'https://demo.aimeos.org/media/service/pickup.png',
42
					'provider' => 'Standard',
43
					'costs' => '0.00',
44
				],
45
				'dhl' => [
46
					'name' => 'DHL',
47
					'short' => 'Delivery within three days by DHL',
48
					'image' => 'https://demo.aimeos.org/media/service/dhl.png',
49
					'provider' => 'Standard',
50
					'costs' => '3.90',
51
				],
52
				'fedex' => [
53
					'name' => 'Fedex',
54
					'short' => 'Delivery within two days by Fedex',
55
					'image' => 'https://demo.aimeos.org/media/service/fedex.png',
56
					'provider' => 'Standard',
57
					'costs' => '6.90',
58
				],
59
				'tnt' => [
60
					'name' => 'TNT',
61
					'short' => 'Delivery within one day by TNT',
62
					'image' => 'https://demo.aimeos.org/media/service/tnt.png',
63
					'provider' => 'Standard',
64
					'costs' => '9.90',
65
				],
66
			],
67
			'payment' => [
68
				'invoice' => [
69
					'name' => 'Invoice',
70
					'short' => 'Pay by invoice within 14 days',
71
					'image' => 'https://demo.aimeos.org/media/service/payment-in-advance.png',
72
					'provider' => 'PostPay',
73
					'costs' => '0.00',
74
				],
75
				'directdebit' => [
76
					'name' => 'Direct debit',
77
					'short' => 'Payment via your bank account',
78
					'image' => 'https://demo.aimeos.org/media/service/sepa.png',
79
					'provider' => 'PostPay',
80
					'costs' => '0.00',
81
				],
82
				'cash' => [
83
					'name' => 'Cash on delivery',
84
					'short' => 'Pay cash on delivery of the parcel',
85
					'image' => 'https://demo.aimeos.org/media/service/dhl-cod.png',
86
					'provider' => 'PrePay',
87
					'costs' => '8.00',
88
				],
89
				'prepay' => [
90
					'name' => 'Prepayment',
91
					'short' => 'Pay in advance before the parcel is shipped',
92
					'image' => 'https://demo.aimeos.org/media/service/payment-in-advance-alternative.png',
93
					'provider' => 'PrePay',
94
					'costs' => '0.00',
95
				],
96
			],
97
		];
98
99
		$numServices = $this->context()->getConfig()->get( 'setup/unitperf/max-services', 100 );
0 ignored issues
show
Bug introduced by
The method context() does not exist on Aimeos\Upscheme\Task\ServiceAddPerfData. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

99
		$numServices = $this->/** @scrutinizer ignore-call */ context()->getConfig()->get( 'setup/unitperf/max-services', 100 );
Loading history...
100
101
		$manager = \Aimeos\MShop::create( $this->context(), 'service' );
102
		$listManager = \Aimeos\MShop::create( $this->context(), 'service/lists' );
103
		$mediaManager = \Aimeos\MShop::create( $this->context(), 'media' );
104
		$priceManager = \Aimeos\MShop::create( $this->context(), 'price' );
105
		$textManager = \Aimeos\MShop::create( $this->context(), 'text' );
106
107
		$mListItem = $listManager->create()->setType( 'default' );
108
		$pListItem = $listManager->create()->setType( 'default' );
109
		$tListItem = $listManager->create()->setType( 'default' );
110
111
		$mediaItem = $mediaManager->create()->setType( 'icon' )->setMimeType( 'image/png' );
112
		$priceItem = $priceManager->create()->setType( 'default' )->setCurrencyId( 'EUR' );
113
		$textItem = $textManager->create()->setType( 'short' );
114
115
116
		$manager->begin();
117
118
		foreach( $services as $type => $list )
119
		{
120
			$pos = 0;
121
			$serviceItem = $manager->create()->setType( $type );
122
123
			for( $i = 0; $i < $numServices / 4; $i++ )
124
			{
125
				foreach( $list as $code => $entry )
126
				{
127
					$code = 'perf-pay-' . $code . '-' . str_pad( $i, 3, '0', STR_PAD_LEFT );
128
129
					$item = clone $serviceItem;
130
					$item->setLabel( $entry['name'] )
131
						->setProvider( $entry['provider'] )
132
						->setPosition( $pos++ )
133
						->setCode( $code )
134
						->setStatus( 1 );
135
136
					$media = clone $mediaItem;
137
					$media->setLabel( $entry['name'] )->setPreview( $entry['image'] )->setUrl( $entry['image'] );
138
					$item->addListItem( 'media', clone $mListItem, $media );
139
140
					$price = clone $priceItem;
141
					$price->setLabel( $entry['name'] )->setCosts( $entry['costs'] );
142
					$item->addListItem( 'price', clone $pListItem, $price );
143
144
					$text = clone $textItem;
145
					$text->setLabel( $entry['name'] )->setContent( $entry['short'] );
146
					$item->addListItem( 'text', clone $tListItem, $text );
147
148
					$manager->save( $item );
149
				}
150
			}
151
		}
152
153
		$manager->commit();
154
	}
155
}
156