1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2021-2024 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Upscheme\Task; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class OrderAddProductParentid extends Base |
13
|
|
|
{ |
14
|
|
|
public function after() : array |
15
|
|
|
{ |
16
|
|
|
return ['Product']; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
public function before() : array |
21
|
|
|
{ |
22
|
|
|
return ['Order']; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
public function up() |
27
|
|
|
{ |
28
|
|
|
$db = $this->db( 'db-order' ); |
29
|
|
|
|
30
|
|
|
if( !$db->hasColumn( 'mshop_order_base_product', 'parentprodid' ) ) { |
31
|
|
|
return; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$this->info( 'Separate product ID and parent ID in order base product table', 'vv' ); |
35
|
|
|
|
36
|
|
|
$table = $db->table( 'mshop_order_base_product' ); |
37
|
|
|
$table->refid( 'parentprodid' )->up(); |
38
|
|
|
|
39
|
|
|
$db->stmt()->update( 'mshop_order_base_product' ) |
40
|
|
|
->set( 'parentprodid', 'prodid' ) |
41
|
|
|
->where( 'type = \'select\'' ) |
42
|
|
|
->executeStatement(); |
43
|
|
|
|
44
|
|
|
$result = $db->stmt()->select( 'siteid', 'prodcode' ) |
45
|
|
|
->from( 'mshop_order_base_product' ) |
46
|
|
|
->where( 'type = \'select\'' ) |
47
|
|
|
->executeQuery(); |
48
|
|
|
|
49
|
|
|
$used = []; |
50
|
|
|
$db2 = $this->db( 'db-order', true ); |
51
|
|
|
$proddb = $this->db( 'db-product' ); |
52
|
|
|
|
53
|
|
|
while( $row = $result->fetchAssociative() ) |
54
|
|
|
{ |
55
|
|
|
if( isset( $used[$row['siteid']][$row['code']] ) ) { |
56
|
|
|
continue; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$rows = $proddb->select( 'mshop_product', ['siteid' => $row['siteid'], 'code' => $row['prodcode']] ); |
60
|
|
|
|
61
|
|
|
foreach( $rows as $product ) |
62
|
|
|
{ |
63
|
|
|
$db2->stmt()->update( 'mshop_order_base_product' ) |
64
|
|
|
->set( 'prodid', '?' ) |
65
|
|
|
->where( 'siteid = ?' )->andWhere( 'prodcode = ?' ) |
66
|
|
|
->setParameters( [$product['id'], $product['siteid'], $product['code']] ) |
67
|
|
|
->executeStatement(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
$used[$row['siteid']][$row['code']] = true; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|