Skip to content

Commit f13ed43

Browse files
author
Dmytro Voskoboinikov
committed
MAGETWO-64547: Bundle Products - The options you selected are not available
1 parent 69b022c commit f13ed43

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

app/code/Magento/Bundle/Setup/UpgradeData.php

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,29 +79,49 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
7979

8080
// Updating data of the 'catalog_product_bundle_selection_price' table.
8181
$tableName = $setup->getTable('catalog_product_bundle_selection_price');
82-
$oldTableName = $setup->getTable('catalog_product_bundle_selection_price_old');
82+
$tmpTableName = $setup->getTable('catalog_product_bundle_selection_price_tmp');
8383

84-
$setup->getConnection()->renameTable($tableName, $oldTableName);
84+
$existingForeignKeys = $setup->getConnection()->getForeignKeys($tableName);
8585

86-
$tableCopy = $setup->getConnection()->createTableByDdl($oldTableName, $tableName);
86+
foreach ($existingForeignKeys as $key) {
87+
$setup->getConnection()->dropForeignKey($key['TABLE_NAME'], $key['FK_NAME']);
88+
}
89+
90+
$setup->getConnection()->createTable(
91+
$setup->getConnection()->createTableByDdl($tableName, $tmpTableName)
92+
);
8793

88-
foreach ($setup->getConnection()->getForeignKeys($oldTableName) as $key) {
89-
$setup->getConnection()->dropForeignKey($oldTableName, $key['FK_NAME']);
94+
foreach ($existingForeignKeys as $key) {
95+
$setup->getConnection()->addForeignKey(
96+
$key['FK_NAME'],
97+
$key['TABLE_NAME'],
98+
$key['COLUMN_NAME'],
99+
$key['REF_TABLE_NAME'],
100+
$key['REF_COLUMN_NAME'],
101+
$key['ON_DELETE']
102+
);
90103
}
91104

92-
$setup->getConnection()->createTable($tableCopy);
105+
$setup->getConnection()->query(
106+
$setup->getConnection()->insertFromSelect(
107+
$setup->getConnection()->select()->from($tableName),
108+
$tmpTableName
109+
)
110+
);
111+
112+
$setup->getConnection()->truncateTable($tableName);
93113

94114
$columnsToSelect = [];
95115

96-
foreach ($setup->getConnection()->describeTable($oldTableName) as $column) {
116+
foreach ($setup->getConnection()->describeTable($tmpTableName) as $column) {
97117
$alias = $column['COLUMN_NAME'] == 'parent_product_id' ? 'selections.' : 'prices.';
98118

99119
$columnsToSelect[] = $alias . $column['COLUMN_NAME'];
100120
}
101121

102122
$select = $setup->getConnection()->select()
103123
->from(
104-
['prices' => $oldTableName],
124+
['prices' => $tmpTableName],
105125
[]
106126
)->joinLeft(
107127
['selections' => $setup->getTable('catalog_product_bundle_selection')],
@@ -113,7 +133,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
113133
$setup->getConnection()->insertFromSelect($select, $tableName)
114134
);
115135

116-
$setup->getConnection()->dropTable($oldTableName);
136+
$setup->getConnection()->dropTable($tmpTableName);
117137
}
118138

119139
$setup->endSetup();

0 commit comments

Comments
 (0)