diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractType.php b/app/code/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractType.php index 5681b1aa6607d116b12d067a8228dfe3307a4dfd..939d6b2de67eee1bf06a7460d7a3c0e866a50877 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractType.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractType.php @@ -534,7 +534,7 @@ abstract class AbstractType public function clearEmptyData(array $rowData) { foreach ($this->_getProductAttributes($rowData) as $attrCode => $attrParams) { - if (!$attrParams['is_static'] && empty($rowData[$attrCode])) { + if (!$attrParams['is_static'] && !isset($rowData[$attrCode])) { unset($rowData[$attrCode]); } } diff --git a/app/code/Magento/CatalogInventory/Observer/AddStockItemsObserver.php b/app/code/Magento/CatalogInventory/Observer/AddStockItemsObserver.php new file mode 100644 index 0000000000000000000000000000000000000000..8fa90cf6531c434a48de22006770de0af8c01e1f --- /dev/null +++ b/app/code/Magento/CatalogInventory/Observer/AddStockItemsObserver.php @@ -0,0 +1,77 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\CatalogInventory\Observer; + +use Magento\Catalog\Model\Product; +use Magento\Catalog\Model\ResourceModel\Product\Collection; +use Magento\CatalogInventory\Api\StockConfigurationInterface; +use Magento\CatalogInventory\Api\StockItemCriteriaInterfaceFactory; +use Magento\CatalogInventory\Api\StockItemRepositoryInterface; +use Magento\Framework\Event\Observer; +use Magento\Framework\Event\ObserverInterface; + +/** + * Add Stock items to product collection. + */ +class AddStockItemsObserver implements ObserverInterface +{ + /** + * @var StockItemCriteriaInterfaceFactory + */ + private $criteriaInterfaceFactory; + + /** + * @var StockItemRepositoryInterface + */ + private $stockItemRepository; + + /** + * @var StockConfigurationInterface + */ + private $stockConfiguration; + + /** + * AddStockItemsObserver constructor. + * + * @param StockItemCriteriaInterfaceFactory $criteriaInterfaceFactory + * @param StockItemRepositoryInterface $stockItemRepository + * @param StockConfigurationInterface $stockConfiguration + */ + public function __construct( + StockItemCriteriaInterfaceFactory $criteriaInterfaceFactory, + StockItemRepositoryInterface $stockItemRepository, + StockConfigurationInterface $stockConfiguration + ) { + $this->criteriaInterfaceFactory = $criteriaInterfaceFactory; + $this->stockItemRepository = $stockItemRepository; + $this->stockConfiguration = $stockConfiguration; + } + + /** + * Add stock items to products in collection. + * + * @param Observer $observer + * @return void + */ + public function execute(Observer $observer) + { + /** @var Collection $productCollection */ + $productCollection = $observer->getData('collection'); + $productIds = array_keys($productCollection->getItems()); + $criteria = $this->criteriaInterfaceFactory->create(); + $criteria->setProductsFilter($productIds); + $criteria->setScopeFilter($this->stockConfiguration->getDefaultScopeId()); + $stockItemCollection = $this->stockItemRepository->getList($criteria); + foreach ($stockItemCollection->getItems() as $item) { + /** @var Product $product */ + $product = $productCollection->getItemById($item->getProductId()); + $productExtension = $product->getExtensionAttributes(); + $productExtension->setStockItem($item); + $product->setExtensionAttributes($productExtension); + } + } +} diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Observer/AddStockItemsObserverTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Observer/AddStockItemsObserverTest.php new file mode 100644 index 0000000000000000000000000000000000000000..8de05bd01403975d26930e29e5d18d464cfd8c41 --- /dev/null +++ b/app/code/Magento/CatalogInventory/Test/Unit/Observer/AddStockItemsObserverTest.php @@ -0,0 +1,165 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\CatalogInventory\Test\Unit\Observer; + +use Magento\Catalog\Api\Data\ProductExtensionInterface; +use Magento\Catalog\Model\Product; +use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection; +use Magento\CatalogInventory\Api\Data\StockItemCollectionInterface; +use Magento\CatalogInventory\Api\Data\StockItemInterface; +use Magento\CatalogInventory\Api\StockConfigurationInterface; +use Magento\CatalogInventory\Api\StockItemCriteriaInterface; +use Magento\CatalogInventory\Api\StockItemCriteriaInterfaceFactory; +use Magento\CatalogInventory\Api\StockItemRepositoryInterface; +use Magento\CatalogInventory\Observer\AddStockItemsObserver; +use Magento\Framework\Event\Observer; +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use PHPUnit\Framework\TestCase; + +class AddStockItemsObserverTest extends TestCase +{ + /** + * Test subject. + * + * @var AddStockItemsObserver + */ + private $subject; + /** + * @var StockItemCriteriaInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject + */ + private $criteriaInterfaceFactoryMock; + + /** + * @var StockItemRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $stockItemRepositoryMock; + + /** + * @var StockConfigurationInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $stockConfigurationMock; + + /** + * @inheritdoc + */ + protected function setUp() + { + $objectManager = new ObjectManager($this); + $this->criteriaInterfaceFactoryMock = $this->getMockBuilder(StockItemCriteriaInterfaceFactory::class) + ->setMethods(['create']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $this->stockItemRepositoryMock = $this->getMockBuilder(StockItemRepositoryInterface::class) + ->setMethods(['getList']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $this->stockConfigurationMock = $this->getMockBuilder(StockConfigurationInterface::class) + ->setMethods(['getDefaultScopeId']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $this->subject = $objectManager->getObject( + AddStockItemsObserver::class, + [ + 'criteriaInterfaceFactory' => $this->criteriaInterfaceFactoryMock, + 'stockItemRepository' => $this->stockItemRepositoryMock, + 'stockConfiguration' => $this->stockConfigurationMock + ] + ); + } + + /** + * Test AddStockItemsObserver::execute() add stock item to product as extension attribute. + */ + public function testExecute() + { + $productId = 1; + $defaultScopeId = 0; + + $criteria = $this->getMockBuilder(StockItemCriteriaInterface::class) + ->setMethods(['setProductsFilter', 'setScopeFilter']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $criteria->expects(self::once()) + ->method('setProductsFilter') + ->with(self::identicalTo([$productId])) + ->willReturn(true); + $criteria->expects(self::once()) + ->method('setScopeFilter') + ->with(self::identicalTo($defaultScopeId)) + ->willReturn(true); + + $this->criteriaInterfaceFactoryMock->expects(self::once()) + ->method('create') + ->willReturn($criteria); + $stockItemCollection = $this->getMockBuilder(StockItemCollectionInterface::class) + ->setMethods(['getItems']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $stockItem = $this->getMockBuilder(StockItemInterface::class) + ->setMethods(['getProductId']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $stockItem->expects(self::once()) + ->method('getProductId') + ->willReturn($productId); + + $stockItemCollection->expects(self::once()) + ->method('getItems') + ->willReturn([$stockItem]); + + $this->stockItemRepositoryMock->expects(self::once()) + ->method('getList') + ->with(self::identicalTo($criteria)) + ->willReturn($stockItemCollection); + + $this->stockConfigurationMock->expects(self::once()) + ->method('getDefaultScopeId') + ->willReturn($defaultScopeId); + + $productExtension = $this->getMockBuilder(ProductExtensionInterface::class) + ->setMethods(['setStockItem']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $productExtension->expects(self::once()) + ->method('setStockItem') + ->with(self::identicalTo($stockItem)); + + $product = $this->getMockBuilder(Product::class) + ->disableOriginalConstructor() + ->getMock(); + $product->expects(self::once()) + ->method('getExtensionAttributes') + ->willReturn($productExtension); + $product->expects(self::once()) + ->method('setExtensionAttributes') + ->with(self::identicalTo($productExtension)) + ->willReturnSelf(); + + /** @var ProductCollection|\PHPUnit_Framework_MockObject_MockObject $productCollection */ + $productCollection = $this->getMockBuilder(ProductCollection::class) + ->disableOriginalConstructor() + ->getMock(); + $productCollection->expects(self::once()) + ->method('getItems') + ->willReturn([$productId => $product]); + $productCollection->expects(self::once()) + ->method('getItemById') + ->with(self::identicalTo($productId)) + ->willReturn($product); + + /** @var Observer|\PHPUnit_Framework_MockObject_MockObject $observer */ + $observer = $this->getMockBuilder(Observer::class) + ->disableOriginalConstructor() + ->getMock(); + $observer->expects(self::once()) + ->method('getData') + ->with('collection') + ->willReturn($productCollection); + + $this->subject->execute($observer); + } +} diff --git a/app/code/Magento/CatalogInventory/etc/events.xml b/app/code/Magento/CatalogInventory/etc/events.xml index 3b5f2483ec57e1bc8493684af7cbf268c5a95054..0a9f3c2d40dcad6495d77ef2269f20b72d48da4e 100644 --- a/app/code/Magento/CatalogInventory/etc/events.xml +++ b/app/code/Magento/CatalogInventory/etc/events.xml @@ -42,4 +42,7 @@ <event name="admin_system_config_changed_section_cataloginventory"> <observer name="inventory" instance="Magento\CatalogInventory\Observer\UpdateItemsStockUponConfigChangeObserver"/> </event> + <event name="sales_quote_item_collection_products_after_load"> + <observer name="add_stock_items" instance="Magento\CatalogInventory\Observer\AddStockItemsObserver"/> + </event> </config> diff --git a/app/code/Magento/Payment/Helper/Data.php b/app/code/Magento/Payment/Helper/Data.php index e3122913d5dfaec734000d1e7fa0433b0998c0fb..f3565ea324290c0556b19f4af0b4bcba85f75733 100644 --- a/app/code/Magento/Payment/Helper/Data.php +++ b/app/code/Magento/Payment/Helper/Data.php @@ -293,6 +293,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper foreach ($methods as $code => $title) { if (isset($groups[$code])) { $labelValues[$code]['label'] = $title; + $labelValues[$code]['value'] = null; } elseif (isset($groupRelations[$code])) { unset($labelValues[$code]); $labelValues[$groupRelations[$code]]['value'][$code] = ['value' => $code, 'label' => $title]; diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_decimal_qty.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_decimal_qty.php new file mode 100644 index 0000000000000000000000000000000000000000..37ce93cc9c42052188ade51d7f85894eed17ddfa --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_decimal_qty.php @@ -0,0 +1,192 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +use Magento\Catalog\Api\Data\ProductTierPriceExtensionFactory; + +\Magento\TestFramework\Helper\Bootstrap::getInstance()->reinitialize(); + +/** @var \Magento\TestFramework\ObjectManager $objectManager */ +$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + +/** @var \Magento\Catalog\Api\CategoryLinkManagementInterface $categoryLinkManagement */ +$categoryLinkManagement = $objectManager->get(\Magento\Catalog\Api\CategoryLinkManagementInterface::class); + +$tierPrices = []; +/** @var \Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory $tierPriceFactory */ +$tierPriceFactory = $objectManager->get(\Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory::class); +/** @var $tpExtensionAttributes */ +$tpExtensionAttributesFactory = $objectManager->get(ProductTierPriceExtensionFactory::class); + +$adminWebsite = $objectManager->get(\Magento\Store\Api\WebsiteRepositoryInterface::class)->get('admin'); +$tierPriceExtensionAttributes1 = $tpExtensionAttributesFactory->create() + ->setWebsiteId($adminWebsite->getId()); + +$tierPrices[] = $tierPriceFactory->create( + [ + 'data' => [ + 'customer_group_id' => \Magento\Customer\Model\Group::CUST_GROUP_ALL, + 'qty' => 2, + 'value' => 8, + ], + ] +)->setExtensionAttributes($tierPriceExtensionAttributes1); + +$tierPrices[] = $tierPriceFactory->create( + [ + 'data' => [ + 'customer_group_id' => \Magento\Customer\Model\Group::CUST_GROUP_ALL, + 'qty' => 5, + 'value' => 5, + ], + ] +)->setExtensionAttributes($tierPriceExtensionAttributes1); + +$tierPrices[] = $tierPriceFactory->create( + [ + 'data' => [ + 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, + 'qty' => 3, + 'value' => 5, + ], + ] +)->setExtensionAttributes($tierPriceExtensionAttributes1); + +$tierPriceExtensionAttributes2 = $tpExtensionAttributesFactory->create() + ->setWebsiteId($adminWebsite->getId()) + ->setPercentageValue(50); + +$tierPrices[] = $tierPriceFactory->create( + [ + 'data' => [ + 'customer_group_id' => \Magento\Customer\Model\Group::NOT_LOGGED_IN_ID, + 'qty' => 10, + ], + ] +)->setExtensionAttributes($tierPriceExtensionAttributes2); + +/** @var $product \Magento\Catalog\Model\Product */ +$product = $objectManager->create(\Magento\Catalog\Model\Product::class); +$product->isObjectNew(true); +$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE) + ->setId(1) + ->setAttributeSetId(4) + ->setWebsiteIds([1]) + ->setName('Simple Product') + ->setSku('simple_with_decimal_qty') + ->setPrice(10) + ->setWeight(1) + ->setShortDescription("Short description") + ->setTaxClassId(0) + ->setTierPrices($tierPrices) + ->setDescription('Description with <b>html tag</b>') + ->setMetaTitle('meta title') + ->setMetaKeyword('meta keyword') + ->setMetaDescription('meta description') + ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH) + ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) + ->setStockData( + [ + 'use_config_manage_stock' => 1, + 'qty' => 100, + 'is_qty_decimal' => 1, + 'is_in_stock' => 1, + ] + )->setCanSaveCustomOptions(true) + ->setHasOptions(true); + +$oldOptions = [ + [ + 'previous_group' => 'text', + 'title' => 'Test Field', + 'type' => 'field', + 'is_require' => 1, + 'sort_order' => 0, + 'price' => 1, + 'price_type' => 'fixed', + 'sku' => '1-text', + 'max_characters' => 100, + ], + [ + 'previous_group' => 'date', + 'title' => 'Test Date and Time', + 'type' => 'date_time', + 'is_require' => 1, + 'sort_order' => 0, + 'price' => 2, + 'price_type' => 'fixed', + 'sku' => '2-date', + ], + [ + 'previous_group' => 'select', + 'title' => 'Test Select', + 'type' => 'drop_down', + 'is_require' => 1, + 'sort_order' => 0, + 'values' => [ + [ + 'option_type_id' => null, + 'title' => 'Option 1', + 'price' => 3, + 'price_type' => 'fixed', + 'sku' => '3-1-select', + ], + [ + 'option_type_id' => null, + 'title' => 'Option 2', + 'price' => 3, + 'price_type' => 'fixed', + 'sku' => '3-2-select', + ], + ], + ], + [ + 'previous_group' => 'select', + 'title' => 'Test Radio', + 'type' => 'radio', + 'is_require' => 1, + 'sort_order' => 0, + 'values' => [ + [ + 'option_type_id' => null, + 'title' => 'Option 1', + 'price' => 3, + 'price_type' => 'fixed', + 'sku' => '4-1-radio', + ], + [ + 'option_type_id' => null, + 'title' => 'Option 2', + 'price' => 3, + 'price_type' => 'fixed', + 'sku' => '4-2-radio', + ], + ], + ], +]; + +$options = []; + +/** @var \Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory $customOptionFactory */ +$customOptionFactory = $objectManager->create(\Magento\Catalog\Api\Data\ProductCustomOptionInterfaceFactory::class); + +foreach ($oldOptions as $option) { + /** @var \Magento\Catalog\Api\Data\ProductCustomOptionInterface $option */ + $option = $customOptionFactory->create(['data' => $option]); + $option->setProductSku($product->getSku()); + + $options[] = $option; +} + +$product->setOptions($options); + +/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepositoryFactory */ +$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); +$productRepository->save($product); + +$categoryLinkManagement->assignProductToCategories( + $product->getSku(), + [2] +); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_decimal_qty_rollback.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_decimal_qty_rollback.php new file mode 100644 index 0000000000000000000000000000000000000000..55bd53a2d5794bfbcb62d9dca711631383387093 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_decimal_qty_rollback.php @@ -0,0 +1,26 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +use Magento\Framework\Exception\NoSuchEntityException; + +\Magento\TestFramework\Helper\Bootstrap::getInstance()->getInstance()->reinitialize(); + +/** @var \Magento\Framework\Registry $registry */ +$registry = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\Registry::class); + +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', true); + +/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */ +$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() + ->get(\Magento\Catalog\Api\ProductRepositoryInterface::class); +try { + $product = $productRepository->get('simple_with_decimal_qty', false, null, true); + $productRepository->delete($product); +} catch (NoSuchEntityException $e) { +} +$registry->unregister('isSecureArea'); +$registry->register('isSecureArea', false); diff --git a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractTest.php b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractTest.php index 8860c12f0f98319da9c7000f694157a4044589b9..862ecb4cbe0280bab6c6e252124de3b0a0778f8d 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/Product/Type/AbstractTest.php @@ -12,20 +12,31 @@ class AbstractTest extends \PHPUnit\Framework\TestCase */ protected $_model; + /** + * @var \Magento\TestFramework\ObjectManager + */ + private $objectManager; + /** * On product import abstract class methods level it doesn't matter what product type is using. * That is why current tests are using simple product entity type by default */ protected function setUp() { - $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); - $params = [$objectManager->create(\Magento\CatalogImportExport\Model\Import\Product::class), 'simple']; + $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $params = [$this->objectManager->create(\Magento\CatalogImportExport\Model\Import\Product::class), 'simple']; $this->_model = $this->getMockForAbstractClass( \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType::class, [ - $objectManager->get(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory::class), - $objectManager->get(\Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory::class), - $objectManager->get(\Magento\Framework\App\ResourceConnection::class), + $this->objectManager->get( + \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\CollectionFactory::class + ), + $this->objectManager->get( + \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory::class + ), + $this->objectManager->get( + \Magento\Framework\App\ResourceConnection::class + ), $params ] ); @@ -130,6 +141,11 @@ class AbstractTest extends \PHPUnit\Framework\TestCase } /** + * Test cleaning imported attribute data from empty values (note '0' is not empty). + * + * @magentoDbIsolation enabled + * @magentoAppIsolation enabled + * @magentoDataFixture Magento/CatalogImportExport/Model/Import/_files/custom_attributes.php * @dataProvider clearEmptyDataDataProvider */ public function testClearEmptyData($rowData, $expectedAttributes) @@ -141,8 +157,14 @@ class AbstractTest extends \PHPUnit\Framework\TestCase } } + /** + * Data provider for testClearEmptyData. + * + * @return array + */ public function clearEmptyDataDataProvider() { + // We use sku attribute to test static attributes. return [ [ [ @@ -152,6 +174,7 @@ class AbstractTest extends \PHPUnit\Framework\TestCase 'product_type' => 'simple', 'name' => 'Simple 01', 'price' => 10, + 'test_attribute' => '1', ], [ 'sku' => 'simple1', @@ -159,26 +182,49 @@ class AbstractTest extends \PHPUnit\Framework\TestCase '_attribute_set' => 'Default', 'product_type' => 'simple', 'name' => 'Simple 01', - 'price' => 10 + 'price' => 10, + 'test_attribute' => '1', ], ], [ [ - 'sku' => '', - 'store_view_code' => 'German', + 'sku' => '0', + 'store_view_code' => '', '_attribute_set' => 'Default', - 'product_type' => '', - 'name' => 'Simple 01 German', - 'price' => '', + 'product_type' => 'simple', + 'name' => 'Simple 01', + 'price' => 10, + 'test_attribute' => '0', ], [ - 'sku' => '', - 'store_view_code' => 'German', + 'sku' => '0', + 'store_view_code' => '', '_attribute_set' => 'Default', - 'product_type' => '', - 'name' => 'Simple 01 German' - ] - ] + 'product_type' => 'simple', + 'name' => 'Simple 01', + 'price' => 10, + 'test_attribute' => '0', + ], + ], + [ + [ + 'sku' => null, + 'store_view_code' => '', + '_attribute_set' => 'Default', + 'product_type' => 'simple', + 'name' => 'Simple 01', + 'price' => 10, + 'test_attribute' => null, + ], + [ + 'sku' => null, + 'store_view_code' => '', + '_attribute_set' => 'Default', + 'product_type' => 'simple', + 'name' => 'Simple 01', + 'price' => 10, + ], + ], ]; } } diff --git a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/_files/custom_attributes.php b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/_files/custom_attributes.php new file mode 100644 index 0000000000000000000000000000000000000000..82c22594f30aa8ff8a7963182a4761ed17f001fe --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/_files/custom_attributes.php @@ -0,0 +1,40 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + +/** @var \Magento\Eav\Model\Entity\Type $entityType */ +$entityType = $objectManager->create(\Magento\Eav\Model\Entity\Type::class); +$entityType->loadByCode('catalog_product'); +$entityTypeId = $entityType->getId(); + +/** @var \Magento\Eav\Model\Entity\Attribute\Set $attributeSet */ +$attributeSet = $objectManager->create(\Magento\Eav\Model\Entity\Attribute\Set::class); +$attributeSet->load('default', 'attribute_set_name'); +$attributeSetId = $attributeSet->getId(); + +$attributeGroupId = $attributeSet->getDefaultGroupId($entityType->getDefaultAttributeSetId()); + +$attributeData = [ + [ + 'attribute_code' => 'test_attribute', + 'entity_type_id' => $entityTypeId, + 'backend_type' => 'varchar', + 'is_required' => 1, + 'is_user_defined' => 1, + 'is_unique' => 0, + 'attribute_set_id' => $attributeSetId, + 'attribute_group_id' => $attributeGroupId, + ], +]; + +foreach ($attributeData as $data) { + /** @var \Magento\Eav\Model\Entity\Attribute $attribute */ + $attribute = $objectManager->create(\Magento\Eav\Model\Entity\Attribute::class); + $attribute->setData($data); + $attribute->setIsStatic(true); + $attribute->save(); +} diff --git a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/_files/custom_attributes_rollback.php b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/_files/custom_attributes_rollback.php new file mode 100644 index 0000000000000000000000000000000000000000..f3afb096347ed42fe4dbf0b2971446bfcec34e33 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/_files/custom_attributes_rollback.php @@ -0,0 +1,20 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + +$attributeCodes = [ + 'test_attribute', + ]; + +foreach ($attributeCodes as $attributeCode) { + /** @var \Magento\Eav\Model\Entity\Attribute $attribute */ + $attribute = $objectManager->create(\Magento\Eav\Model\Entity\Attribute::class); + $attribute->loadByCode('catalog_product', $attributeCode); + if ($attribute->getId()) { + $attribute->delete(); + } +} diff --git a/dev/tests/integration/testsuite/Magento/CatalogInventory/Observer/AddStockItemsObserverTest.php b/dev/tests/integration/testsuite/Magento/CatalogInventory/Observer/AddStockItemsObserverTest.php new file mode 100644 index 0000000000000000000000000000000000000000..71af5d102a8d7a71b23d1746010e44c7dd8795f0 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/CatalogInventory/Observer/AddStockItemsObserverTest.php @@ -0,0 +1,41 @@ +<?php +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\CatalogInventory\Observer; + +use Magento\CatalogInventory\Api\Data\StockItemInterface; +use Magento\Quote\Model\Quote; +use Magento\Quote\Model\ResourceModel\Quote\Item\Collection; +use Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory; +use Magento\TestFramework\Helper\Bootstrap; +use PHPUnit\Framework\TestCase; + +class AddStockItemsObserverTest extends TestCase +{ + /** + * Test addStockItemsObserver add stock items to products as extension attributes in quote item collection. + * + * @magentoDataFixture Magento/Sales/_files/quote.php + */ + public function testAddStockItemsToProductCollection() + { + $quote = Bootstrap::getObjectManager()->create(Quote::class); + $quote->load('test01', 'reserved_order_id'); + /** @var CollectionFactory $collectionFactory */ + $collectionFactory = Bootstrap::getObjectManager()->create(CollectionFactory::class); + /** @var Collection $collection */ + $collection = $collectionFactory->create(); + $collection->setQuote($quote); + /** @var Quote\Item $quoteItem */ + foreach ($collection->getItems() as $quoteItem) { + self::assertNotEmpty($quoteItem->getProduct()->getExtensionAttributes()->getStockItem()); + self::assertInstanceOf( + StockItemInterface::class, + $quoteItem->getProduct()->getExtensionAttributes()->getStockItem() + ); + } + } +} diff --git a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php index 946d15b6a81d7927ba6500dad83c76ab775e237e..ee7ddc1ba1abae57bb4daf4446e7be1f35ac30b3 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php +++ b/dev/tests/integration/testsuite/Magento/Sales/Model/AdminOrder/CreateTest.php @@ -394,7 +394,7 @@ class CreateTest extends \PHPUnit\Framework\TestCase } /** - * @magentoDataFixture Magento/Catalog/_files/product_simple.php + * @magentoDataFixture Magento/Catalog/_files/product_simple_with_decimal_qty.php * @magentoDbIsolation enabled * @magentoAppIsolation enabled */ @@ -425,6 +425,10 @@ class CreateTest extends \PHPUnit\Framework\TestCase $paymentMethod ); $order = $this->_model->createOrder(); + //Check, order considering decimal qty in product. + foreach ($order->getItems() as $orderItem) { + self::assertTrue($orderItem->getIsQtyDecimal()); + } $this->_verifyCreatedOrder($order, $shippingMethod); }