diff --git a/app/code/Magento/Catalog/Plugin/Model/ResourceModel/ReadSnapshotPlugin.php b/app/code/Magento/Catalog/Plugin/Model/ResourceModel/ReadSnapshotPlugin.php index 1fbba1279928e..4dae4ec68efa8 100644 --- a/app/code/Magento/Catalog/Plugin/Model/ResourceModel/ReadSnapshotPlugin.php +++ b/app/code/Magento/Catalog/Plugin/Model/ResourceModel/ReadSnapshotPlugin.php @@ -7,7 +7,7 @@ use Magento\Catalog\Api\Data\CategoryInterface; use Magento\Catalog\Api\Data\ProductInterface; -use Magento\Eav\Model\Config; +use Magento\Eav\Model\Config as EavConfig; use Magento\Eav\Model\ResourceModel\ReadSnapshot; use Magento\Framework\EntityManager\MetadataPool; @@ -24,17 +24,17 @@ class ReadSnapshotPlugin private $metadataPool; /** - * @var Config + * @var EavConfig */ private $config; /** * @param MetadataPool $metadataPool - * @param Config $config + * @param EavConfig $config */ public function __construct( MetadataPool $metadataPool, - Config $config + EavConfig $config ) { $this->metadataPool = $metadataPool; $this->config = $config; diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/ProductCollection.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/ProductCollection.php new file mode 100644 index 0000000000000..f4334bc25efd8 --- /dev/null +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/ProductCollection.php @@ -0,0 +1,28 @@ +_productLimitationFilters->setUsePriceIndex(false); + return $this->_productLimitationPrice(true); + } +} diff --git a/app/code/Magento/Catalog/etc/adminhtml/di.xml b/app/code/Magento/Catalog/etc/adminhtml/di.xml index 34d089580906f..9739ee28a6dae 100644 --- a/app/code/Magento/Catalog/etc/adminhtml/di.xml +++ b/app/code/Magento/Catalog/etc/adminhtml/di.xml @@ -78,6 +78,11 @@ + + + \Magento\Catalog\Ui\DataProvider\Product\ProductCollection + + @@ -86,6 +91,7 @@ Magento\Catalog\Ui\DataProvider\Product\AddStoreFieldToCollection + \Magento\Catalog\Ui\DataProvider\Product\ProductCollectionFactory diff --git a/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php b/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php index bfd197758dc8b..19877a51c4869 100644 --- a/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php +++ b/app/code/Magento/Eav/Model/Entity/Attribute/AbstractAttribute.php @@ -133,6 +133,8 @@ abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtens * @var array */ private $emptyStringTypes = [ + 'int', + 'decimal', 'datetime', 'varchar', 'text', diff --git a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Collection.php b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Collection.php index 872a9b79c9ba6..c1f693b92d2a1 100644 --- a/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Collection.php +++ b/app/code/Magento/Eav/Model/ResourceModel/Entity/Attribute/Collection.php @@ -210,17 +210,19 @@ public function setAttributeSetsFilter(array $setIds) */ public function setInAllAttributeSetsFilter(array $setIds) { - foreach ($setIds as $setId) { - $setId = (int)$setId; - if (!$setId) { - continue; - } - $alias = sprintf('entity_attribute_%d', $setId); - $joinCondition = $this->getConnection()->quoteInto( - "{$alias}.attribute_id = main_table.attribute_id AND {$alias}.attribute_set_id =?", - $setId - ); - $this->join([$alias => 'eav_entity_attribute'], $joinCondition, 'attribute_id'); + if (!empty($setIds)) { + $this->getSelect() + ->join( + ['entity_attribute' => $this->getTable('eav_entity_attribute')], + 'entity_attribute.attribute_id = main_table.attribute_id', + ['count' => new \Zend_Db_Expr('COUNT(*)')] + ) + ->where( + 'entity_attribute.attribute_set_id IN (?)', + $setIds + ) + ->group('entity_attribute.attribute_id') + ->having('count = ' . count($setIds)); } //$this->getSelect()->distinct(true); diff --git a/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/AbstractAttributeTest.php b/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/AbstractAttributeTest.php index 68fcb7e979e38..5f5398c77488c 100644 --- a/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/AbstractAttributeTest.php +++ b/app/code/Magento/Eav/Test/Unit/Model/Entity/Attribute/AbstractAttributeTest.php @@ -228,8 +228,8 @@ public function testIsValueEmpty($isEmpty, $value, $attributeType) public function attributeValueDataProvider() { return [ - [false, '', 'int'], - [false, '', 'decimal'], + [true, '', 'int'], + [true, '', 'decimal'], [true, '', 'datetime'], [true, '', 'varchar'], [true, '', 'text'], diff --git a/app/code/Magento/Eav/Test/Unit/Model/ResourceModel/Entity/Attribute/CollectionTest.php b/app/code/Magento/Eav/Test/Unit/Model/ResourceModel/Entity/Attribute/CollectionTest.php new file mode 100644 index 0000000000000..138e1363bb6dd --- /dev/null +++ b/app/code/Magento/Eav/Test/Unit/Model/ResourceModel/Entity/Attribute/CollectionTest.php @@ -0,0 +1,158 @@ +entityFactoryMock = $this->getMockBuilder(\Magento\Framework\Data\Collection\EntityFactory::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->fetchStrategyMock = $this->getMockBuilder(FetchStrategyInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->eventManagerMock = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->eavConfigMock = $this->getMockBuilder(\Magento\Eav\Model\Config::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\Pdo\Mysql::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->resourceMock = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\Db\AbstractDb::class) + ->setMethods(['__wakeup', 'getConnection', 'getMainTable', 'getTable']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + + $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->connectionMock); + $this->resourceMock->expects($this->any())->method('getMainTable')->willReturn('eav_entity_attribute'); + + $this->selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->connectionMock->expects($this->any())->method('select')->willReturn($this->selectMock); + + $objectManager = new ObjectManager($this); + $this->model = $objectManager->getObject( + \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection::class, + [ + 'entityFactory' => $this->entityFactoryMock, + 'logger' => $this->loggerMock, + 'fetchStrategy' => $this->fetchStrategyMock, + 'eventManager' => $this->eventManagerMock, + 'eavConfig' => $this->eavConfigMock, + 'connection' => $this->connectionMock, + 'resource' => $this->resourceMock, + ] + ); + } + + /** + * Test method \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection::setInAllAttributeSetsFilter + * + * @return void + */ + public function testSetInAllAttributeSetsFilter() + { + $setIds = [1, 2, 3]; + + $this->selectMock->expects($this->atLeastOnce()) + ->method('where') + ->with('entity_attribute.attribute_set_id IN (?)', $setIds) + ->willReturnSelf(); + $this->selectMock->expects($this->atLeastOnce())->method('join')->with( + ['entity_attribute' => $this->model->getTable('eav_entity_attribute')], + 'entity_attribute.attribute_id = main_table.attribute_id', + ['count' => new \Zend_Db_Expr('COUNT(*)')] + )->willReturnSelf(); + + $this->selectMock->expects($this->atLeastOnce())->method('group')->with('entity_attribute.attribute_id') + ->willReturnSelf(); + + $this->selectMock->expects($this->atLeastOnce())->method('having')->with('count = ' . count($setIds)) + ->willReturnSelf(); + + $this->model->setInAllAttributeSetsFilter($setIds); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Setup/Console/Command/GenerateFixturesCommandTest.php b/dev/tests/integration/testsuite/Magento/Setup/Console/Command/GenerateFixturesCommandTest.php new file mode 100644 index 0000000000000..eaa8b2f6fdbbf --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Setup/Console/Command/GenerateFixturesCommandTest.php @@ -0,0 +1,151 @@ +objectManager = Bootstrap::getObjectManager(); + + $this->objectManager->get(\Magento\TestFramework\App\Config::class)->clean(); + + $this->fixtureModelMock = $this->getMockBuilder(FixtureModel::class) + ->setMethods(['getObjectManager']) + ->setConstructorArgs([$this->objectManager->get(IndexerReindexCommand::class)]) + ->getMock(); + $this->fixtureModelMock + ->method('getObjectManager') + ->willReturn($this->objectManager); + + $this->command = $this->objectManager->create( + GenerateFixturesCommand::class, + [ + 'fixtureModel' => $this->fixtureModelMock + ] + ); + + $objectFactoryMock = $this->getMockBuilder(ObjectManagerFactory::class) + ->setMethods(['create']) + ->disableOriginalConstructor() + ->getMock(); + $objectFactoryMock + ->method('create') + ->willReturn($this->objectManager); + + $this->indexerCommand = new CommandTester($this->objectManager->create( + IndexerReindexCommand::class, + ['objectManagerFactory' => $objectFactoryMock] + )); + + $this->commandTester = new CommandTester($this->command); + + $this->setIncrement(3); + + parent::setUp(); + } + + /** + * @return string + */ + private function getEdition() + { + return trim(file_get_contents(__DIR__ . '/_files/edition')); + } + + /** + * teardown + */ + public function tearDown() + { + $this->setIncrement(1); + + parent::tearDown(); + } + + public static function setUpBeforeClass() + { + $db = Bootstrap::getInstance()->getBootstrap() + ->getApplication() + ->getDbInstance(); + if (!$db->isDbDumpExists()) { + throw new \LogicException('DB dump does not exist.'); + } + $db->restoreFromDbDump(); + + parent::setUpBeforeClass(); + } + + /** + * @magentoAppArea adminhtml + * @magentoAppIsolation enabled + */ + public function testExecute() + { + $profile = BP . "/setup/performance-toolkit/profiles/{$this->getEdition()}/small.xml"; + $this->commandTester->execute( + [ + GenerateFixturesCommand::PROFILE_ARGUMENT => $profile, + '--' . GenerateFixturesCommand::SKIP_REINDEX_OPTION => true + ] + ); + $this->indexerCommand->execute([]); + + static::assertEquals( + Cli::RETURN_SUCCESS, + $this->indexerCommand->getStatusCode(), + $this->indexerCommand->getDisplay(true) + ); + + static::assertEquals( + Cli::RETURN_SUCCESS, + $this->commandTester->getStatusCode(), + $this->commandTester->getDisplay(true) + ); + } + + /** + * @param $value + */ + private function setIncrement($value) + { + /** @var \Magento\Framework\DB\Adapter\AdapterInterface $db */ + $db = Bootstrap::getObjectManager()->get(ResourceConnection::class)->getConnection(); + $db->query("SET @@session.auto_increment_increment=$value"); + $db->query("SET @@session.auto_increment_offset=$value"); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/edition b/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/edition new file mode 100644 index 0000000000000..a2a77c324b740 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Setup/Console/Command/_files/edition @@ -0,0 +1 @@ +ce diff --git a/setup/src/Magento/Setup/Fixtures/OrdersFixture.php b/setup/src/Magento/Setup/Fixtures/OrdersFixture.php index 74ff84189f557..1acad6dbc1787 100644 --- a/setup/src/Magento/Setup/Fixtures/OrdersFixture.php +++ b/setup/src/Magento/Setup/Fixtures/OrdersFixture.php @@ -232,6 +232,12 @@ public function execute() return; } + $ruleId = $this->getMaxEntityId( + 'salesrule', + \Magento\SalesRule\Model\ResourceModel\Rule::class, + 'rule_id' + ); + $maxItemId = $this->getMaxEntityId( 'sales_order_item', \Magento\Sales\Model\ResourceModel\Order\Item::class, @@ -330,6 +336,7 @@ public function execute() '%productStoreId%' => $productStoreId($entityId), '%productStoreName%' => $productStoreName($entityId), '%entityId%' => $entityId, + '%ruleId%' => $ruleId, ]; $shippingAddress = ['%orderAddressId%' => $entityId * 2 - 1, '%addressType%' => 'shipping']; $billingAddress = ['%orderAddressId%' => $entityId * 2, '%addressType%' => 'billing']; diff --git a/setup/src/Magento/Setup/Fixtures/_files/orders_fixture_data.json b/setup/src/Magento/Setup/Fixtures/_files/orders_fixture_data.json index 864ad45533afe..d323246cf6d34 100644 --- a/setup/src/Magento/Setup/Fixtures/_files/orders_fixture_data.json +++ b/setup/src/Magento/Setup/Fixtures/_files/orders_fixture_data.json @@ -102,7 +102,7 @@ "weight": 2.0000, "customer_dob": "NULL", "increment_id": "'%orderNumber%'", - "applied_rule_ids": 1, + "applied_rule_ids": "%ruleId%", "base_currency_code": "'USD'", "customer_email": "'%email%'", "customer_firstname": "NULL", @@ -208,7 +208,7 @@ "sku": "'%sku%'", "name": "'%name%'", "description": "NULL", - "applied_rule_ids": "'1'", + "applied_rule_ids": "'%ruleId%'", "additional_data": "NULL", "is_qty_decimal": "'0'", "no_discount": "'0'", @@ -374,7 +374,7 @@ "customer_note_notify": 1, "customer_is_guest": 1, "remote_ip": "'127.0.0.1'", - "applied_rule_ids": "'1'", + "applied_rule_ids": "'%ruleId%'", "reserved_order_id": "NULL", "password_hash": "NULL", "coupon_code": "NULL", @@ -512,7 +512,7 @@ "sku": "'%sku%'", "name": "'%name%'", "description": "NULL", - "applied_rule_ids": "'1'", + "applied_rule_ids": "'%ruleId%'", "additional_data": "NULL", "is_qty_decimal": "0", "no_discount": "0",