1 | <?php |
||||||
2 | |||||||
3 | /** |
||||||
4 | * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
||||||
5 | * @copyright Metaways Infosystems GmbH, 2014 |
||||||
6 | * @copyright Aimeos (aimeos.org), 2015-2018 |
||||||
7 | */ |
||||||
8 | |||||||
9 | |||||||
10 | namespace Aimeos\MW\Setup\Task; |
||||||
11 | |||||||
12 | |||||||
13 | /** |
||||||
14 | * Adds demo records to coupon tables. |
||||||
15 | */ |
||||||
16 | class DemoAddCouponData extends \Aimeos\MW\Setup\Task\MShopAddDataAbstract |
||||||
17 | { |
||||||
18 | /** |
||||||
19 | * Returns the list of task names which this task depends on. |
||||||
20 | * |
||||||
21 | * @return string[] List of task names |
||||||
22 | */ |
||||||
23 | public function getPreDependencies() |
||||||
24 | { |
||||||
25 | return array( 'MShopAddLocaleDataDefault' ); |
||||||
26 | } |
||||||
27 | |||||||
28 | |||||||
29 | /** |
||||||
30 | * Returns the list of task names which depends on this task. |
||||||
31 | * |
||||||
32 | * @return array List of task names |
||||||
33 | */ |
||||||
34 | public function getPostDependencies() |
||||||
35 | { |
||||||
36 | return []; |
||||||
37 | } |
||||||
38 | |||||||
39 | |||||||
40 | /** |
||||||
41 | * Insert service data. |
||||||
42 | */ |
||||||
43 | public function migrate() |
||||||
44 | { |
||||||
45 | $this->msg( 'Processing coupon demo data', 0 ); |
||||||
46 | |||||||
47 | $context = $this->getContext(); |
||||||
48 | $value = $context->getConfig()->get( 'setup/default/demo', '' ); |
||||||
49 | |||||||
50 | if( $value === '' ) |
||||||
51 | { |
||||||
52 | $this->status( 'OK' ); |
||||||
53 | return; |
||||||
54 | } |
||||||
55 | |||||||
56 | |||||||
57 | $manager = \Aimeos\MShop::create( $context, 'coupon' ); |
||||||
58 | $search = $manager->createSearch(); |
||||||
59 | $search->setConditions( $search->compare( '=~', 'coupon.label', 'demo-' ) ); |
||||||
60 | $services = $manager->searchItems( $search ); |
||||||
61 | |||||||
62 | $manager->deleteItems( array_keys( $services ) ); |
||||||
63 | |||||||
64 | |||||||
65 | if( $value === '1' ) |
||||||
66 | { |
||||||
67 | $ds = DIRECTORY_SEPARATOR; |
||||||
68 | $path = __DIR__ . $ds . 'data' . $ds . 'demo-coupon.php'; |
||||||
69 | |||||||
70 | if( ( $data = include( $path ) ) == false ) { |
||||||
71 | throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for coupon domain', $path ) ); |
||||||
72 | } |
||||||
73 | |||||||
74 | foreach( $data as $entry ) |
||||||
75 | { |
||||||
76 | $item = $manager->createItem(); |
||||||
77 | $item->setLabel( $entry['label'] ); |
||||||
78 | $item->setProvider( $entry['provider'] ); |
||||||
0 ignored issues
–
show
|
|||||||
79 | $item->setDateStart( $entry['datestart'] ); |
||||||
0 ignored issues
–
show
The method
setDateStart() does not exist on Aimeos\MShop\Attribute\Item\Iface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
80 | $item->setDateEnd( $entry['dateend'] ); |
||||||
0 ignored issues
–
show
The method
setDateEnd() does not exist on Aimeos\MShop\Attribute\Item\Iface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
81 | $item->setConfig( $entry['config'] ); |
||||||
0 ignored issues
–
show
The method
setConfig() does not exist on Aimeos\MShop\Attribute\Item\Iface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
82 | $item->setStatus( $entry['status'] ); |
||||||
83 | |||||||
84 | $manager->saveItem( $item ); |
||||||
85 | |||||||
86 | $this->addCodes( $item->getId(), $entry['codes'] ); |
||||||
87 | } |
||||||
88 | |||||||
89 | $this->status( 'added' ); |
||||||
90 | } |
||||||
91 | else |
||||||
92 | { |
||||||
93 | $this->status( 'removed' ); |
||||||
94 | } |
||||||
95 | } |
||||||
96 | |||||||
97 | |||||||
98 | /** |
||||||
99 | * Adds the coupon codes to the database. |
||||||
100 | * |
||||||
101 | * @param string $couponId |
||||||
102 | * @param array $data |
||||||
103 | */ |
||||||
104 | protected function addCodes( $couponId, array $data ) |
||||||
105 | { |
||||||
106 | $manager = \Aimeos\MShop::create( $this->getContext(), 'coupon/code' ); |
||||||
107 | |||||||
108 | foreach( $data as $entry ) |
||||||
109 | { |
||||||
110 | $item = $manager->createItem(); |
||||||
111 | $item->setParentId( $couponId ); |
||||||
0 ignored issues
–
show
The method
setParentId() does not exist on Aimeos\MShop\Attribute\Item\Iface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
112 | $item->setCode( $entry['code'] ); |
||||||
113 | $item->setCount( $entry['count'] ); |
||||||
0 ignored issues
–
show
The method
setCount() does not exist on Aimeos\MShop\Attribute\Item\Iface .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
114 | $item->setDateStart( $entry['datestart'] ); |
||||||
115 | $item->setDateEnd( $entry['dateend'] ); |
||||||
116 | |||||||
117 | $manager->saveItem( $item ); |
||||||
118 | } |
||||||
119 | } |
||||||
120 | } |
||||||
121 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.