Skip to content

Commit

Permalink
Merge pull request #367 from magento-folks/2.1.3_bugs_pr
Browse files Browse the repository at this point in the history
Fixed issues:
- MAGETWO-56397: Unable to Upgrade with Split Databases
- MAGETWO-57387: Unable to print Invoices and Credit memo from Sales>Orders
- MAGETWO-58064: Unable to upgrade with split databases. Part 2 
- MAGETWO-58036: Reloading page on checkout causes shipping method to go "undefined"
  • Loading branch information
MomotenkoNatalia authored Sep 12, 2016
2 parents e5cf9f4 + 6a90c6a commit 3bc378c
Show file tree
Hide file tree
Showing 28 changed files with 537 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ define(
}

if (!availableRate && window.checkoutConfig.selectedShippingMethod) {
availableRate = true;
availableRate = window.checkoutConfig.selectedShippingMethod;
selectShippingMethodAction(window.checkoutConfig.selectedShippingMethod);
}

Expand Down
26 changes: 18 additions & 8 deletions app/code/Magento/OfflineShipping/Setup/InstallSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
*/
class InstallSchema implements InstallSchemaInterface
{
/**
* @var string
*/
private static $quoteConnectionName = 'checkout';

/**
* @var string
*/
private static $salesConnectionName = 'sales';

/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
Expand Down Expand Up @@ -105,32 +115,32 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
['unsigned' => true, 'nullable' => false, 'default' => '0'],
'Simple Free Shipping'
);
$installer->getConnection()->addColumn(
$installer->getTable('sales_order_item'),
$installer->getConnection(self::$salesConnectionName)->addColumn(
$installer->getTable('sales_order_item', self::$salesConnectionName),
'free_shipping',
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
null,
['unsigned' => true, 'nullable' => false, 'default' => '0'],
'Free Shipping'
);
$installer->getConnection()->addColumn(
$installer->getTable('quote_address'),
$installer->getConnection(self::$quoteConnectionName)->addColumn(
$installer->getTable('quote_address', self::$quoteConnectionName),
'free_shipping',
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
null,
['unsigned' => true, 'nullable' => false, 'default' => '0'],
'Free Shipping'
);
$installer->getConnection()->addColumn(
$installer->getTable('quote_item'),
$installer->getConnection(self::$quoteConnectionName)->addColumn(
$installer->getTable('quote_item', self::$quoteConnectionName),
'free_shipping',
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
null,
['unsigned' => true, 'nullable' => false, 'default' => '0'],
'Free Shipping'
);
$installer->getConnection()->addColumn(
$installer->getTable('quote_address_item'),
$installer->getConnection(self::$quoteConnectionName)->addColumn(
$installer->getTable('quote_address_item', self::$quoteConnectionName),
'free_shipping',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
null,
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/OfflineShipping/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
"magento/module-backend": "100.1.*",
"magento/module-shipping": "100.1.*",
"magento/module-catalog": "101.0.*",
"magento/module-sales": "100.1.*",
"magento/module-sales-rule": "100.1.*",
"magento/module-directory": "100.1.*",
"magento/module-quote": "100.1.*",
"magento/framework": "100.1.*"
},
"suggest": {
"magento/module-checkout": "100.1.*",
"magento/module-sales": "100.1.*",
"magento/module-offline-shipping-sample-data": "Sample Data version:100.1.*"
},
"type": "magento2-module",
Expand Down
9 changes: 7 additions & 2 deletions app/code/Magento/Persistent/Setup/InstallSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
*/
class InstallSchema implements InstallSchemaInterface
{
/**
* @var string
*/
private static $connectionName = 'checkout';

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -97,8 +102,8 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
* Alter quote table with is_persistent flag
*
*/
$installer->getConnection()->addColumn(
$installer->getTable('quote'),
$installer->getConnection(self::$connectionName)->addColumn(
$installer->getTable('quote', self::$connectionName),
'is_persistent',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
Expand Down
39 changes: 39 additions & 0 deletions app/code/Magento/Quote/Model/Product/Plugin/RemoveQuoteItems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Quote\Model\Product\Plugin;

class RemoveQuoteItems
{
/**
* @var \Magento\Quote\Model\Product\QuoteItemsCleanerInterface
*/
private $quoteItemsCleaner;

/**
* @param \Magento\Quote\Model\Product\QuoteItemsCleanerInterface $quoteItemsCleaner
*/
public function __construct(\Magento\Quote\Model\Product\QuoteItemsCleanerInterface $quoteItemsCleaner)
{
$this->quoteItemsCleaner = $quoteItemsCleaner;
}

/**
* @param \Magento\Catalog\Model\ResourceModel\Product $subject
* @param \Closure $proceed
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @return \Magento\Catalog\Model\ResourceModel\Product
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundDelete(
\Magento\Catalog\Model\ResourceModel\Product $subject,
\Closure $proceed,
\Magento\Catalog\Api\Data\ProductInterface $product
) {
$result = $proceed($product);
$this->quoteItemsCleaner->execute($product);
return $result;
}
}
33 changes: 33 additions & 0 deletions app/code/Magento/Quote/Model/Product/QuoteItemsCleaner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Quote\Model\Product;

class QuoteItemsCleaner implements \Magento\Quote\Model\Product\QuoteItemsCleanerInterface
{
/**
* @var \Magento\Quote\Model\ResourceModel\Quote\Item
*/
private $itemResource;

/**
* @param \Magento\Quote\Model\ResourceModel\Quote\Item $itemResource
*/
public function __construct(\Magento\Quote\Model\ResourceModel\Quote\Item $itemResource)
{
$this->itemResource = $itemResource;
}

/**
* {@inheritdoc}
*/
public function execute(\Magento\Catalog\Api\Data\ProductInterface $product)
{
$this->itemResource->getConnection()->delete(
$this->itemResource->getMainTable(),
'product_id = ' . $product->getId()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Quote\Model\Product;

use Magento\Catalog\Api\Data\ProductInterface;

interface QuoteItemsCleanerInterface
{
/**
* @param ProductInterface $product
* @return void
*/
public function execute(ProductInterface $product);
}
6 changes: 0 additions & 6 deletions app/code/Magento/Quote/Setup/InstallSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -964,12 +964,6 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
$installer->getTable('quote_item'),
'item_id',
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
)->addForeignKey(
$installer->getFkName('quote_item', 'product_id', 'catalog_product_entity', 'entity_id'),
'product_id',
$installer->getTable('catalog_product_entity'),
'entity_id',
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
)->addForeignKey(
$installer->getFkName('quote_item', 'quote_id', 'quote', 'entity_id'),
'quote_id',
Expand Down
20 changes: 15 additions & 5 deletions app/code/Magento/Quote/Setup/QuoteSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class QuoteSetup extends EavSetup
*/
protected $_encryptor;

/**
* @var string
*/
private static $connectionName = 'checkout';

/**
* @param ModuleDataSetupInterface $setup
* @param Context $context
Expand Down Expand Up @@ -70,8 +75,11 @@ public function __construct(
*/
protected function _flatTableExist($table)
{
$tablesList = $this->getSetup()->getConnection()->listTables();
return in_array(strtoupper($this->getSetup()->getTable($table)), array_map('strtoupper', $tablesList));
$tablesList = $this->getSetup()->getConnection(self::$connectionName)->listTables();
return in_array(
strtoupper($this->getSetup()->getTable($table, self::$connectionName)),
array_map('strtoupper', $tablesList)
);
}

/**
Expand Down Expand Up @@ -107,13 +115,15 @@ public function addAttribute($entityTypeId, $code, array $attr)
*/
protected function _addFlatAttribute($table, $attribute, $attr)
{
$tableInfo = $this->getSetup()->getConnection()->describeTable($this->getSetup()->getTable($table));
$tableInfo = $this->getSetup()
->getConnection(self::$connectionName)
->describeTable($this->getSetup()->getTable($table, self::$connectionName));
if (isset($tableInfo[$attribute])) {
return $this;
}
$columnDefinition = $this->_getAttributeColumnDefinition($attribute, $attr);
$this->getSetup()->getConnection()->addColumn(
$this->getSetup()->getTable($table),
$this->getSetup()->getConnection(self::$connectionName)->addColumn(
$this->getSetup()->getTable($table, self::$connectionName),
$attribute,
$columnDefinition
);
Expand Down
73 changes: 0 additions & 73 deletions app/code/Magento/Quote/Setup/Recurring.php

This file was deleted.

25 changes: 19 additions & 6 deletions app/code/Magento/Quote/Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
*/
class UpgradeSchema implements UpgradeSchemaInterface
{
/**
* @var string
*/
private static $connectionName = 'checkout';

/**
* {@inheritdoc}
*/
Expand All @@ -22,16 +27,16 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
$setup->startSetup();

if (version_compare($context->getVersion(), '2.0.1', '<')) {
$setup->getConnection()->addIndex(
$setup->getTable('quote_id_mask'),
$setup->getIdxName('quote_id_mask', ['masked_id']),
$setup->getConnection(self::$connectionName)->addIndex(
$setup->getTable('quote_id_mask', self::$connectionName),
$setup->getIdxName('quote_id_mask', ['masked_id'], '', self::$connectionName),
['masked_id']
);
}

if (version_compare($context->getVersion(), '2.0.2', '<')) {
$setup->getConnection()->changeColumn(
$setup->getTable('quote_address'),
$setup->getConnection(self::$connectionName)->changeColumn(
$setup->getTable('quote_address', self::$connectionName),
'street',
'street',
[
Expand All @@ -41,7 +46,15 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
]
);
}

//drop foreign key for single DB case
if (version_compare($context->getVersion(), '2.0.3', '<')
&& $setup->tableExists($setup->getTable('quote_item'))
) {
$setup->getConnection()->dropForeignKey(
$setup->getTable('quote_item'),
$setup->getFkName('quote_item', 'product_id', 'catalog_product_entity', 'entity_id')
);
}
$setup->endSetup();
}
}
Loading

0 comments on commit 3bc378c

Please sign in to comment.