diff --git a/app/code/Magento/Checkout/view/frontend/web/js/model/checkout-data-resolver.js b/app/code/Magento/Checkout/view/frontend/web/js/model/checkout-data-resolver.js
index edbca0a510b19..0fd1a4967f836 100644
--- a/app/code/Magento/Checkout/view/frontend/web/js/model/checkout-data-resolver.js
+++ b/app/code/Magento/Checkout/view/frontend/web/js/model/checkout-data-resolver.js
@@ -165,7 +165,7 @@ define(
}
if (!availableRate && window.checkoutConfig.selectedShippingMethod) {
- availableRate = true;
+ availableRate = window.checkoutConfig.selectedShippingMethod;
selectShippingMethodAction(window.checkoutConfig.selectedShippingMethod);
}
diff --git a/app/code/Magento/OfflineShipping/Setup/InstallSchema.php b/app/code/Magento/OfflineShipping/Setup/InstallSchema.php
index 8ce77e6098b43..0c2b62f908894 100644
--- a/app/code/Magento/OfflineShipping/Setup/InstallSchema.php
+++ b/app/code/Magento/OfflineShipping/Setup/InstallSchema.php
@@ -15,6 +15,16 @@
*/
class InstallSchema implements InstallSchemaInterface
{
+ /**
+ * @var string
+ */
+ private static $quoteConnectionName = 'checkout';
+
+ /**
+ * @var string
+ */
+ private static $salesConnectionName = 'sales';
+
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -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,
diff --git a/app/code/Magento/OfflineShipping/composer.json b/app/code/Magento/OfflineShipping/composer.json
index 83c687f08fd0b..d803af8f7c952 100644
--- a/app/code/Magento/OfflineShipping/composer.json
+++ b/app/code/Magento/OfflineShipping/composer.json
@@ -8,7 +8,6 @@
"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.*",
@@ -16,6 +15,7 @@
},
"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",
diff --git a/app/code/Magento/Persistent/Setup/InstallSchema.php b/app/code/Magento/Persistent/Setup/InstallSchema.php
index 940133fcf5dd7..89e7d88fbd066 100644
--- a/app/code/Magento/Persistent/Setup/InstallSchema.php
+++ b/app/code/Magento/Persistent/Setup/InstallSchema.php
@@ -15,6 +15,11 @@
*/
class InstallSchema implements InstallSchemaInterface
{
+ /**
+ * @var string
+ */
+ private static $connectionName = 'checkout';
+
/**
* {@inheritdoc}
*/
@@ -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,
diff --git a/app/code/Magento/Quote/Model/Product/Plugin/RemoveQuoteItems.php b/app/code/Magento/Quote/Model/Product/Plugin/RemoveQuoteItems.php
new file mode 100644
index 0000000000000..314ed2fed8a55
--- /dev/null
+++ b/app/code/Magento/Quote/Model/Product/Plugin/RemoveQuoteItems.php
@@ -0,0 +1,39 @@
+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;
+ }
+}
diff --git a/app/code/Magento/Quote/Model/Product/QuoteItemsCleaner.php b/app/code/Magento/Quote/Model/Product/QuoteItemsCleaner.php
new file mode 100644
index 0000000000000..ec0e6809c48f7
--- /dev/null
+++ b/app/code/Magento/Quote/Model/Product/QuoteItemsCleaner.php
@@ -0,0 +1,33 @@
+itemResource = $itemResource;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function execute(\Magento\Catalog\Api\Data\ProductInterface $product)
+ {
+ $this->itemResource->getConnection()->delete(
+ $this->itemResource->getMainTable(),
+ 'product_id = ' . $product->getId()
+ );
+ }
+}
diff --git a/app/code/Magento/Quote/Model/Product/QuoteItemsCleanerInterface.php b/app/code/Magento/Quote/Model/Product/QuoteItemsCleanerInterface.php
new file mode 100644
index 0000000000000..1691efab5e541
--- /dev/null
+++ b/app/code/Magento/Quote/Model/Product/QuoteItemsCleanerInterface.php
@@ -0,0 +1,17 @@
+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',
diff --git a/app/code/Magento/Quote/Setup/QuoteSetup.php b/app/code/Magento/Quote/Setup/QuoteSetup.php
index 2608580cf8fa3..1ef5f4b0dae2e 100644
--- a/app/code/Magento/Quote/Setup/QuoteSetup.php
+++ b/app/code/Magento/Quote/Setup/QuoteSetup.php
@@ -29,6 +29,11 @@ class QuoteSetup extends EavSetup
*/
protected $_encryptor;
+ /**
+ * @var string
+ */
+ private static $connectionName = 'checkout';
+
/**
* @param ModuleDataSetupInterface $setup
* @param Context $context
@@ -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)
+ );
}
/**
@@ -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
);
diff --git a/app/code/Magento/Quote/Setup/Recurring.php b/app/code/Magento/Quote/Setup/Recurring.php
deleted file mode 100644
index 03fe30bf80272..0000000000000
--- a/app/code/Magento/Quote/Setup/Recurring.php
+++ /dev/null
@@ -1,73 +0,0 @@
-metadataPool = $metadataPool;
- $this->externalFKSetup = $externalFKSetup;
- }
-
- /**
- * {@inheritdoc}
- */
- public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
- {
- $installer = $setup;
- $installer->startSetup();
-
- $this->addExternalForeignKeys($installer);
-
- $installer->endSetup();
- }
-
- /**
- * Add external foreign keys
- *
- * @param SchemaSetupInterface $installer
- * @return void
- * @throws \Exception
- */
- protected function addExternalForeignKeys(SchemaSetupInterface $installer)
- {
- $metadata = $this->metadataPool->getMetadata(ProductInterface::class);
- $this->externalFKSetup->install(
- $installer,
- $metadata->getEntityTable(),
- $metadata->getIdentifierField(),
- 'quote_item',
- 'product_id'
- );
- }
-}
diff --git a/app/code/Magento/Quote/Setup/UpgradeSchema.php b/app/code/Magento/Quote/Setup/UpgradeSchema.php
index 602f93e0445f0..0ea04377eaa39 100644
--- a/app/code/Magento/Quote/Setup/UpgradeSchema.php
+++ b/app/code/Magento/Quote/Setup/UpgradeSchema.php
@@ -14,6 +14,11 @@
*/
class UpgradeSchema implements UpgradeSchemaInterface
{
+ /**
+ * @var string
+ */
+ private static $connectionName = 'checkout';
+
/**
* {@inheritdoc}
*/
@@ -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',
[
@@ -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();
}
}
diff --git a/app/code/Magento/Quote/Test/Unit/Model/Product/Plugin/RemoveQuoteItemsTest.php b/app/code/Magento/Quote/Test/Unit/Model/Product/Plugin/RemoveQuoteItemsTest.php
new file mode 100644
index 0000000000000..083722f3a1bb3
--- /dev/null
+++ b/app/code/Magento/Quote/Test/Unit/Model/Product/Plugin/RemoveQuoteItemsTest.php
@@ -0,0 +1,38 @@
+quoteItemsCleanerMock = $this->getMock(\Magento\Quote\Model\Product\QuoteItemsCleanerInterface::class);
+ $this->model = new \Magento\Quote\Model\Product\Plugin\RemoveQuoteItems($this->quoteItemsCleanerMock);
+ }
+
+ public function testAroundDelete()
+ {
+ $productResourceMock = $this->getMock(\Magento\Catalog\Model\ResourceModel\Product::class, [], [], '', false);
+ $productMock = $this->getMock(\Magento\Catalog\Api\Data\ProductInterface::class);
+ $closure = function () use ($productResourceMock) {
+ return $productResourceMock;
+ };
+
+ $this->quoteItemsCleanerMock->expects($this->once())->method('execute')->with($productMock);
+ $result = $this->model->aroundDelete($productResourceMock, $closure, $productMock);
+ $this->assertEquals($result, $productResourceMock);
+ }
+}
diff --git a/app/code/Magento/Quote/Test/Unit/Model/Product/QuoteItemsCleanerTest.php b/app/code/Magento/Quote/Test/Unit/Model/Product/QuoteItemsCleanerTest.php
new file mode 100644
index 0000000000000..d6bb3e5ae31a8
--- /dev/null
+++ b/app/code/Magento/Quote/Test/Unit/Model/Product/QuoteItemsCleanerTest.php
@@ -0,0 +1,45 @@
+itemResourceMock = $this->getMock(
+ \Magento\Quote\Model\ResourceModel\Quote\Item::class,
+ [],
+ [],
+ '',
+ false
+ );
+ $this->model = new \Magento\Quote\Model\Product\QuoteItemsCleaner($this->itemResourceMock);
+ }
+
+ public function testExecute()
+ {
+ $tableName = 'table_name';
+ $productMock = $this->getMock(\Magento\Catalog\Api\Data\ProductInterface::class);
+ $productMock->expects($this->once())->method('getId')->willReturn(1);
+
+ $connectionMock = $this->getMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
+ $this->itemResourceMock->expects($this->once())->method('getConnection')->willReturn($connectionMock);
+ $this->itemResourceMock->expects($this->once())->method('getMainTable')->willReturn($tableName);
+
+ $connectionMock->expects($this->once())->method('delete')->with($tableName, 'product_id = 1');
+ $this->model->execute($productMock);
+ }
+}
diff --git a/app/code/Magento/Quote/etc/di.xml b/app/code/Magento/Quote/etc/di.xml
index e3192f1c1d58e..384f5ca143b86 100644
--- a/app/code/Magento/Quote/etc/di.xml
+++ b/app/code/Magento/Quote/etc/di.xml
@@ -40,7 +40,6 @@
-
@@ -90,4 +89,8 @@
+
+
+
+
diff --git a/app/code/Magento/Quote/etc/module.xml b/app/code/Magento/Quote/etc/module.xml
index 8350b4c4f87ea..281cde9eeb9d1 100644
--- a/app/code/Magento/Quote/etc/module.xml
+++ b/app/code/Magento/Quote/etc/module.xml
@@ -6,6 +6,6 @@
*/
-->
-
+
diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/PdfDocumentsMassAction.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/PdfDocumentsMassAction.php
new file mode 100644
index 0000000000000..5396a1d69bc5b
--- /dev/null
+++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/PdfDocumentsMassAction.php
@@ -0,0 +1,52 @@
+filter->getCollection($this->getOrderCollection()->create());
+ return $this->massAction($collection);
+ } catch (\Exception $e) {
+ $this->messageManager->addError($e->getMessage());
+ /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
+ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
+ return $resultRedirect->setPath($this->redirectUrl);
+ }
+ }
+
+ /**
+ * Get Order Collection Factory
+ *
+ * @return \Magento\Sales\Model\ResourceModel\Order\CollectionFactory
+ * @deprecated
+ */
+ private function getOrderCollection()
+ {
+ if ($this->orderCollectionFactory === null) {
+ $this->orderCollectionFactory = \Magento\Framework\App\ObjectManager::getInstance()->get(
+ \Magento\Sales\Model\ResourceModel\Order\CollectionFactory::class
+ );
+ }
+ return $this->orderCollectionFactory;
+ }
+}
diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php
index 119333e85f325..9b2e62ed96ea9 100644
--- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php
+++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfcreditmemos.php
@@ -21,7 +21,7 @@
* Class Pdfcreditmemos
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
-class Pdfcreditmemos extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction
+class Pdfcreditmemos extends \Magento\Sales\Controller\Adminhtml\Order\PdfDocumentsMassAction
{
/**
* @var FileFactory
diff --git a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php
index 8085f8fa406db..4eb93fb332f9e 100644
--- a/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php
+++ b/app/code/Magento/Sales/Controller/Adminhtml/Order/Pdfinvoices.php
@@ -20,7 +20,7 @@
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
-class Pdfinvoices extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction
+class Pdfinvoices extends \Magento\Sales\Controller\Adminhtml\Order\PdfDocumentsMassAction
{
/**
* @var FileFactory
@@ -79,7 +79,7 @@ protected function massAction(AbstractCollection $collection)
return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl());
}
return $this->fileFactory->create(
- sprintf('packingslip%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')),
+ sprintf('invoice%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')),
$this->pdfInvoice->getPdf($invoicesCollection->getItems())->render(),
DirectoryList::VAR_DIR,
'application/pdf'
diff --git a/app/code/Magento/Sales/Setup/SalesSetup.php b/app/code/Magento/Sales/Setup/SalesSetup.php
index d0c73fdc69eb4..4a766213d711c 100644
--- a/app/code/Magento/Sales/Setup/SalesSetup.php
+++ b/app/code/Magento/Sales/Setup/SalesSetup.php
@@ -15,6 +15,7 @@
/**
* Setup Model of Sales Module
* @codeCoverageIgnore
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class SalesSetup extends \Magento\Eav\Setup\EavSetup
{
@@ -28,6 +29,11 @@ class SalesSetup extends \Magento\Eav\Setup\EavSetup
*/
protected $encryptor;
+ /**
+ * @var string
+ */
+ private static $connectionName = 'sales';
+
/**
* @param ModuleDataSetupInterface $setup
* @param Context $context
@@ -85,8 +91,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)
+ );
}
/**
@@ -123,13 +132,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
);
@@ -149,8 +160,8 @@ protected function _addGridAttribute($table, $attribute, $attr, $entityTypeId)
{
if (in_array($entityTypeId, $this->_flatEntitiesGrid) && !empty($attr['grid'])) {
$columnDefinition = $this->_getAttributeColumnDefinition($attribute, $attr);
- $this->getSetup()->getConnection()->addColumn(
- $this->getSetup()->getTable($table . '_grid'),
+ $this->getSetup()->getConnection(self::$connectionName)->addColumn(
+ $this->getSetup()->getTable($table . '_grid', self::$connectionName),
$attribute,
$columnDefinition
);
diff --git a/app/code/Magento/Sales/Setup/UpgradeSchema.php b/app/code/Magento/Sales/Setup/UpgradeSchema.php
index b82756c126d84..b977cb28596ea 100644
--- a/app/code/Magento/Sales/Setup/UpgradeSchema.php
+++ b/app/code/Magento/Sales/Setup/UpgradeSchema.php
@@ -8,13 +8,17 @@
use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
-use Magento\Framework\DB\Adapter\AdapterInterface;
/**
* @codeCoverageIgnore
*/
class UpgradeSchema implements UpgradeSchemaInterface
{
+ /**
+ * @var string
+ */
+ private static $connectionName = 'sales';
+
/**
* {@inheritdoc}
*/
@@ -23,36 +27,39 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
$installer = $setup;
$installer->startSetup();
if (version_compare($context->getVersion(), '2.0.2', '<')) {
- $connection = $installer->getConnection();
+ $connection = $installer->getConnection(self::$connectionName);
//sales_bestsellers_aggregated_daily
$connection->dropForeignKey(
- $installer->getTable('sales_bestsellers_aggregated_daily'),
+ $installer->getTable('sales_bestsellers_aggregated_daily', self::$connectionName),
$installer->getFkName(
'sales_bestsellers_aggregated_daily',
'product_id',
'catalog_product_entity',
- 'entity_id'
+ 'entity_id',
+ self::$connectionName
)
);
//sales_bestsellers_aggregated_monthly
$connection->dropForeignKey(
- $installer->getTable('sales_bestsellers_aggregated_monthly'),
+ $installer->getTable('sales_bestsellers_aggregated_monthly', self::$connectionName),
$installer->getFkName(
'sales_bestsellers_aggregated_monthly',
'product_id',
'catalog_product_entity',
- 'entity_id'
+ 'entity_id',
+ self::$connectionName
)
);
//sales_bestsellers_aggregated_yearly
$connection->dropForeignKey(
- $installer->getTable('sales_bestsellers_aggregated_yearly'),
+ $installer->getTable('sales_bestsellers_aggregated_yearly', self::$connectionName),
$installer->getFkName(
'sales_bestsellers_aggregated_yearly',
'product_id',
'catalog_product_entity',
- 'entity_id'
+ 'entity_id',
+ self::$connectionName
)
);
@@ -70,9 +77,9 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
*/
private function addColumnBaseGrandTotal(SchemaSetupInterface $installer)
{
- $connection = $installer->getConnection();
+ $connection = $installer->getConnection(self::$connectionName);
$connection->addColumn(
- $installer->getTable('sales_invoice_grid'),
+ $installer->getTable('sales_invoice_grid', self::$connectionName),
'base_grand_total',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
@@ -90,10 +97,10 @@ private function addColumnBaseGrandTotal(SchemaSetupInterface $installer)
*/
private function addIndexBaseGrandTotal(SchemaSetupInterface $installer)
{
- $connection = $installer->getConnection();
+ $connection = $installer->getConnection(self::$connectionName);
$connection->addIndex(
- $installer->getTable('sales_invoice_grid'),
- $installer->getIdxName('sales_invoice_grid', ['base_grand_total']),
+ $installer->getTable('sales_invoice_grid', self::$connectionName),
+ $installer->getIdxName('sales_invoice_grid', ['base_grand_total'], '', self::$connectionName),
['base_grand_total']
);
}
diff --git a/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/PdfDocumentsMassActionTest.php b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/PdfDocumentsMassActionTest.php
new file mode 100644
index 0000000000000..e93c22fb837f0
--- /dev/null
+++ b/app/code/Magento/Sales/Test/Unit/Controller/Adminhtml/PdfDocumentsMassActionTest.php
@@ -0,0 +1,114 @@
+messageManager = $this->getMock(
+ \Magento\Framework\Message\Manager::class,
+ ['addSuccess', 'addError'],
+ [],
+ '',
+ false
+ );
+
+ $this->orderCollectionMock = $this->getMock(
+ \Magento\Sales\Model\ResourceModel\Order\Collection::class,
+ [],
+ [],
+ '',
+ false
+ );
+ $this->filterMock = $this->getMock(\Magento\Ui\Component\MassAction\Filter::class, [], [], '', false);
+
+ $this->orderCollectionFactoryMock = $this->getMock(
+ \Magento\Sales\Model\ResourceModel\Order\CollectionFactory::class,
+ ['create'],
+ [],
+ '',
+ false
+ );
+
+ $this->orderCollectionFactoryMock
+ ->expects($this->once())
+ ->method('create')
+ ->willReturn($this->orderCollectionMock);
+ $this->resultRedirect = $this->getMock(\Magento\Backend\Model\View\Result\Redirect::class, [], [], '', false);
+ $resultRedirectFactory = $this->getMock(
+ \Magento\Framework\Controller\ResultFactory::class,
+ [],
+ [],
+ '',
+ false
+ );
+ $resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
+ $this->controller = $objectManagerHelper->getObject(
+ \Magento\Sales\Controller\Adminhtml\Order\Pdfinvoices::class,
+ [
+ 'filter' => $this->filterMock,
+ 'resultFactory' => $resultRedirectFactory,
+ 'messageManager' => $this->messageManager
+ ]
+ );
+ $objectManagerHelper
+ ->setBackwardCompatibleProperty(
+ $this->controller,
+ 'orderCollectionFactory',
+ $this->orderCollectionFactoryMock
+ );
+ }
+
+ public function testExecute()
+ {
+ $exception = new \Exception();
+ $this->filterMock
+ ->expects($this->once())
+ ->method('getCollection')
+ ->with($this->orderCollectionMock)
+ ->willThrowException($exception);
+ $this->messageManager->expects($this->once())->method('addError');
+
+ $this->resultRedirect->expects($this->once())->method('setPath')->willReturnSelf();
+ $this->controller->execute($exception);
+ }
+}
diff --git a/app/code/Magento/SalesSequence/Setup/InstallSchema.php b/app/code/Magento/SalesSequence/Setup/InstallSchema.php
index 023094527c59d..5da1dc1e6bf4b 100644
--- a/app/code/Magento/SalesSequence/Setup/InstallSchema.php
+++ b/app/code/Magento/SalesSequence/Setup/InstallSchema.php
@@ -14,6 +14,11 @@
*/
class InstallSchema implements InstallSchemaInterface
{
+ /**
+ * @var string
+ */
+ private static $connectionName = 'sales';
+
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -25,8 +30,8 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
/**
* Create table 'sales_sequence_profile'
*/
- $table = $installer->getConnection()->newTable(
- $installer->getTable('sales_sequence_profile')
+ $table = $installer->getConnection(self::$connectionName)->newTable(
+ $installer->getTable('sales_sequence_profile', self::$connectionName)
)->addColumn(
'profile_id',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
@@ -84,24 +89,32 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
$installer->getIdxName(
'sales_sequence_profile',
['meta_id', 'prefix', 'suffix'],
- \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE
+ \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE,
+ '',
+ self::$connectionName
),
['meta_id', 'prefix', 'suffix'],
['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE]
)->addForeignKey(
- $installer->getFkName('sales_sequence_profile', 'meta_id', 'sales_sequence_meta', 'meta_id'),
+ $installer->getFkName(
+ 'sales_sequence_profile',
+ 'meta_id',
+ 'sales_sequence_meta',
+ 'meta_id',
+ self::$connectionName
+ ),
'meta_id',
- $installer->getTable('sales_sequence_meta'),
+ $installer->getTable('sales_sequence_meta', self::$connectionName),
'meta_id',
\Magento\Framework\DB\Ddl\Table::ACTION_CASCADE
);
- $installer->getConnection()->createTable($table);
+ $installer->getConnection(self::$connectionName)->createTable($table);
/**
* Create table 'sales_sequence_meta'
*/
- $table = $installer->getConnection()->newTable(
- $installer->getTable('sales_sequence_meta')
+ $table = $installer->getConnection(self::$connectionName)->newTable(
+ $installer->getTable('sales_sequence_meta', self::$connectionName)
)->addColumn(
'meta_id',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
@@ -130,12 +143,14 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
$installer->getIdxName(
'sales_sequence_meta',
['entity_type', 'store_id'],
- \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE
+ \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE,
+ '',
+ self::$connectionName
),
['entity_type', 'store_id'],
['type' => \Magento\Framework\DB\Adapter\AdapterInterface::INDEX_TYPE_UNIQUE]
);
- $installer->getConnection()->createTable($table);
+ $installer->getConnection(self::$connectionName)->createTable($table);
$installer->endSetup();
}
}
diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable.php
index 4d2a45b1ce68b..b5f1eeb72d56a 100644
--- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable.php
+++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable.php
@@ -107,6 +107,13 @@
try {
$productToDelete = $productRepository->getById(1);
$productRepository->delete($productToDelete);
+
+ /** @var \Magento\Quote\Model\ResourceModel\Quote\Item $itemResource */
+ $itemResource = Bootstrap::getObjectManager()->get(\Magento\Quote\Model\ResourceModel\Quote\Item::class);
+ $itemResource->getConnection()->delete(
+ $itemResource->getMainTable(),
+ 'product_id = ' . $productToDelete->getId()
+ );
} catch (\Exception $e) {
// Nothing to remove
}
diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php
index 6184dd7ee4355..78342c886de96 100755
--- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php
+++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_classes.php
@@ -4225,4 +4225,5 @@
['Magento\Catalog\Test\Unit\Webapi\Product\Option\Type\File\ValidatorTest'],
['Magento\Framework\Search\Document', 'Magento\Framework\Api\Search\Document'],
['Magento\Framework\Search\DocumentField'],
+ ['Magento\Quote\Setup\Recurring'],
];
diff --git a/lib/internal/Magento/Framework/Module/Setup.php b/lib/internal/Magento/Framework/Module/Setup.php
index 0b0bbb20a33d5..7bd12bc89f1e9 100644
--- a/lib/internal/Magento/Framework/Module/Setup.php
+++ b/lib/internal/Magento/Framework/Module/Setup.php
@@ -9,6 +9,7 @@
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\SetupInterface;
+use Magento\Framework\App\ResourceConnection;
class Setup implements SetupInterface
{
@@ -57,9 +58,27 @@ public function __construct(
/**
* Get connection object
*
+ * @param string|null $connectionName
* @return \Magento\Framework\DB\Adapter\AdapterInterface
*/
- public function getConnection()
+ public function getConnection($connectionName = null)
+ {
+ if ($connectionName !== null) {
+ try {
+ return $this->resourceModel->getConnectionByName($connectionName);
+ } catch (\DomainException $exception) {
+ //Fallback to default connection
+ }
+ }
+ return $this->getDefaultConnection();
+ }
+
+ /**
+ * Returns default setup connection instance
+ *
+ * @return \Magento\Framework\DB\Adapter\AdapterInterface
+ */
+ private function getDefaultConnection()
{
if (null === $this->connection) {
$this->connection = $this->resourceModel->getConnection($this->connectionName);
@@ -95,13 +114,14 @@ public function getTablePlaceholder($tableName)
* Get table name (validated by db adapter) by table placeholder
*
* @param string|array $tableName
+ * @param string $connectionName
* @return string
*/
- public function getTable($tableName)
+ public function getTable($tableName, $connectionName = ResourceConnection::DEFAULT_CONNECTION)
{
$cacheKey = $this->_getTableCacheName($tableName);
if (!isset($this->tables[$cacheKey])) {
- $this->tables[$cacheKey] = $this->resourceModel->getTableName($tableName);
+ $this->tables[$cacheKey] = $this->resourceModel->getTableName($tableName, $connectionName);
}
return $this->tables[$cacheKey];
}
@@ -124,12 +144,13 @@ private function _getTableCacheName($tableName)
* Check is table exists
*
* @param string $table
+ * @param string $connectionName
* @return bool
*/
- public function tableExists($table)
+ public function tableExists($table, $connectionName = ResourceConnection::DEFAULT_CONNECTION)
{
- $table = $this->getTable($table);
- return $this->getConnection()->isTableExists($table);
+ $table = $this->getTable($table, $connectionName);
+ return $this->getConnection($connectionName)->isTableExists($table);
}
/**
diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/SetupTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/SetupTest.php
index 8490a735baa25..8f5c38e1ebdd1 100644
--- a/lib/internal/Magento/Framework/Module/Test/Unit/SetupTest.php
+++ b/lib/internal/Magento/Framework/Module/Test/Unit/SetupTest.php
@@ -34,7 +34,11 @@ protected function setUp()
$this->resourceModel->expects($this->any())
->method('getConnection')
->with(self::CONNECTION_NAME)
- ->will($this->returnValue($this->connection));
+ ->willReturn($this->connection);
+ $this->resourceModel->expects($this->any())
+ ->method('getConnectionByName')
+ ->with(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION)
+ ->willReturn($this->connection);
$this->object = new Setup($this->resourceModel, self::CONNECTION_NAME);
}
diff --git a/setup/src/Magento/Setup/Module/Setup.php b/setup/src/Magento/Setup/Module/Setup.php
index 4451267a0e9aa..39fa5cbda13ad 100644
--- a/setup/src/Magento/Setup/Module/Setup.php
+++ b/setup/src/Magento/Setup/Module/Setup.php
@@ -6,6 +6,7 @@
namespace Magento\Setup\Module;
use Magento\Framework\Setup\SchemaSetupInterface;
+use Magento\Framework\App\ResourceConnection;
class Setup extends \Magento\Framework\Module\Setup implements SchemaSetupInterface
{
@@ -15,11 +16,16 @@ class Setup extends \Magento\Framework\Module\Setup implements SchemaSetupInterf
* @param string $tableName
* @param array|string $fields
* @param string $indexType
+ * @param string $connectionName
* @return string
*/
- public function getIdxName($tableName, $fields, $indexType = '')
- {
- return $this->getConnection()->getIndexName($tableName, $fields, $indexType);
+ public function getIdxName(
+ $tableName,
+ $fields,
+ $indexType = '',
+ $connectionName = ResourceConnection::DEFAULT_CONNECTION
+ ) {
+ return $this->getConnection($connectionName)->getIndexName($tableName, $fields, $indexType);
}
/**
@@ -29,10 +35,21 @@ public function getIdxName($tableName, $fields, $indexType = '')
* @param string $priColumnName the target table column name
* @param string $refTableName the reference table name
* @param string $refColumnName the reference table column name
+ * @param string $connectionName
* @return string
*/
- public function getFkName($priTableName, $priColumnName, $refTableName, $refColumnName)
- {
- return $this->getConnection()->getForeignKeyName($priTableName, $priColumnName, $refTableName, $refColumnName);
+ public function getFkName(
+ $priTableName,
+ $priColumnName,
+ $refTableName,
+ $refColumnName,
+ $connectionName = ResourceConnection::DEFAULT_CONNECTION
+ ) {
+ return $this->getConnection($connectionName)->getForeignKeyName(
+ $priTableName,
+ $priColumnName,
+ $refTableName,
+ $refColumnName
+ );
}
}
diff --git a/setup/src/Magento/Setup/Test/Unit/Module/SetupTest.php b/setup/src/Magento/Setup/Test/Unit/Module/SetupTest.php
index 43c6fc0297ff0..14b571736bb28 100644
--- a/setup/src/Magento/Setup/Test/Unit/Module/SetupTest.php
+++ b/setup/src/Magento/Setup/Test/Unit/Module/SetupTest.php
@@ -30,6 +30,10 @@ protected function setUp()
->method('getConnection')
->with(self::CONNECTION_NAME)
->will($this->returnValue($this->connection));
+ $resourceModel->expects($this->any())
+ ->method('getConnectionByName')
+ ->with(\Magento\Framework\App\ResourceConnection::DEFAULT_CONNECTION)
+ ->willReturn($this->connection);
$this->setup = new Setup($resourceModel, self::CONNECTION_NAME);
}