Skip to content

Commit

Permalink
Merge pull request #9 from florent-maissiat-smile/add-foreign-key
Browse files Browse the repository at this point in the history
Add foreign key on quote and order tables for column 'seller_id'.
  • Loading branch information
Fanny DECLERCK authored Apr 29, 2019
2 parents 85b10b5 + 3ef47ef commit cab9599
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
38 changes: 37 additions & 1 deletion Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
{
$setup->startSetup();

if (version_compare($context->getVersion(), '1.0.2', '<')) {
$this->addColumns($setup);
}
if (version_compare($context->getVersion(), '1.0.3', '<')) {
$this->addForeignKey($setup);
}

$setup->endSetup();
}

/**
* Add 'seller_id' and 'pickup_date' columns on quote and order tables.
*
* @param SchemaSetupInterface $setup Module Setup.
*/
protected function addColumns(SchemaSetupInterface $setup)
{
$tables = [$setup->getTable('quote'), $setup->getTable('sales_order')];

foreach ($tables as $currentTable) {
Expand All @@ -60,7 +77,26 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
]
);
}
}

$setup->endSetup();
/**
* Add foreign key on quote and order tables for column 'seller_id'.
*
* @param SchemaSetupInterface $setup Module Setup.
*/
protected function addForeignKey(SchemaSetupInterface $setup)
{
$tables = [$setup->getTable('quote'), $setup->getTable('sales_order')];

foreach ($tables as $currentTable) {
$setup->getConnection()->addForeignKey(
$setup->getFkName($currentTable, 'seller_id', 'smile_seller_entity', 'entity_id'),
$currentTable,
'seller_id',
$setup->getTable('smile_seller_entity'),
'entity_id',
\Magento\Framework\DB\Ddl\Table::ACTION_SET_NULL
);
}
}
}
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Smile_Offer" setup_version="1.0.2">
<module name="Smile_Offer" setup_version="1.0.3">
<sequence>
<module name="Smile_ElasticsuiteCatalog" />
<module name="Magento_Catalog" />
Expand Down

0 comments on commit cab9599

Please sign in to comment.