Skip to content

Various fixes in Magento 2 core to support MSI #13434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

vrann
Copy link
Contributor

@vrann vrann commented Jan 31, 2018

Set of changes in the Magento core used by MSI

Description

  • add Delete Button UI Component
  • add stock item importer interface and injected to importing logic
  • added RegisterProductSaleInterface, RevertProductSaleInterface and implementation for them
  • added possibility to run integration and api-functional tests from the module directory
  • added possibility to generate and provide sample file for Import
  • added Multi-Dimensional Indexer Framework
  • fixed order of applying of data fixtures in integration/api-functional
  • added ability to change white list file path Magento/Test/Php/LiveCodeTest::getWhitelist()
  • added Magento/Test/Php/_files/blacklist/strict_type.txt for strict type test.

Manual testing scenarios

  • Covered by automated tests

Bamboo Tests:

Jenkins:

https://m2build.devops.magento.com/job/Public-Pull-Request/206/ .

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

'label' => __('Delete'),
'class' => 'delete',
'on_click' =>
"deleteConfirm('{$this->confirmationMessage}', '{$url}', {data:{{$this->idFieldName}:{$id}}})",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these variables to be escaped?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ihor-sviziev escaped confirmationMessage.

Copy link
Contributor

@maghamed maghamed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can move to Lib Predefined ID trait which we use in MSI

use Magento\Framework\EntityManager\HydratorInterface;
use Magento\InventoryApi\Api\Data\SourceItemInterface;
use Magento\InventoryApi\Api\SourceItemRepositoryInterface;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dependency on MSI in test

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maghamed removed.

class IndexNameResolver implements IndexNameResolverInterface
{
/**
* TODO: move to separate configurable interface (https://github.com/magento-engcom/msi/issues/213)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo should be removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider not removing but fixing todo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maghamed removed

}

/**
* TODO: move to separate configurable interface (https://github.com/magento-engcom/msi/issues/213)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo should be removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maghamed removed

private $replicaTableSuffix = '_replica';

/**
* TODO: move to separate configurable interface (https://github.com/magento-engcom/msi/issues/213)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo should be removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maghamed removed

@@ -21,8 +21,12 @@
</testsuite>
<testsuite name="Magento Integration Tests">
<directory suffix="Test.php">testsuite</directory>
<directory suffix="Test.php">../../../app/code/*/*/Test/Integration</directory>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove all mentions about MSI from phpunit.xml.dist (the same for WebApi)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naydav but there is no mentioning of MSI in this test configuration

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naydav removed

@@ -74,6 +103,7 @@ public function checkStockItemData($sku, array $expectedData)
$productLoadedByModel = $this->productFactory->create();
$productLoadedByModel->load($product->getId());
$this->doCheckStockItemData($product, $expectedData);
$this->checkIntegrityWithInventory($product, $expectedData);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove this check
This is related only to MSI project

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naydav

this check fully relies on Legacy CatalogInventory

    /**
     * @param Product $product
     * @param array $expectedData
     * @return void
     */
    private function checkIntegrityWithInventory(Product $product, array $expectedData)
    {
        $searchCriteria = $this->searchCriteriaBuilder
            ->addFilter(SourceItemInterface::SOURCE_CODE, $this->defaultSourceProvider->getCode())
            ->addFilter(SourceItemInterface::SKU, $product->getSku())
            ->create();
        $sourceItems = $this->sourceItemRepository->getList($searchCriteria)->getItems();
        Assert::assertCount(1, $sourceItems);

        $sourceItem = reset($sourceItems);
        Assert::assertEquals(
            $expectedData[StockItemInterface::QTY],
            $sourceItem->getQuantity()
        );
        Assert::assertEquals(
            $expectedData[StockItemInterface::IS_IN_STOCK],
            (int)$sourceItem->getStatus()
        );
    }

there are no problems to have it in CE

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maghamed $this->sourceItemRepository is instance of Magento\InventoryApi\Api\SourceItemRepositoryInterface.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naydav removed

@@ -203,7 +203,8 @@ protected function _applyFixtures(array $fixtures)
*/
protected function _revertFixtures()
{
foreach ($this->_appliedFixtures as $fixture) {
$appliedFixtures = array_reverse($this->_appliedFixtures);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to do same for WebApi framework

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@naydav done

@@ -0,0 +1 @@
MultiDimensionalIndexer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to provide more descriptive read me

*
* @api
*/
interface StockItemImporterInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no default implementation of this interface in CE, just in MSI

that will lead to Fatal Error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@ishakhsuvarov
Copy link
Contributor

@vrann @maghamed @naydav I strongly suggest to try and keep information on original history from the MSI repository, possible cherry-picking related commits, or, at least, giving credits to the original authors in the commit message to this change set.

Additionally, provided description is not clear on what was changed in the scope of this PR, making it hard to identify and test components affected by this commit.

Copy link
Contributor

@ishakhsuvarov ishakhsuvarov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update Pull Request description to describe the affected components and possible impact.

/**
* Constructor
*
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
* @param \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory
* @param \Magento\ImportExport\Model\Import\SampleFileProvider $sampleFileProvider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect order of params in docBlock

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In constructor signature SampleFileProvider is after ComponentRegistrar

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -11,6 +11,7 @@
use Magento\Framework\Setup\InstallSchemaInterface;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InstallSchema is obsolete. Please update with latest mainline and use declarative schema

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -19,6 +19,10 @@
<testsuite name="Magento REST web API functional tests">
<directory suffix="Test.php">testsuite</directory>
<exclude>testsuite/Magento/GraphQl</exclude>
<directory suffix="Test.php">../../../app/code/*/*/Test/Api</directory>
</testsuite>
<testsuite name="msi">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this was only needed to execute tests on MSI fork

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ishakhsuvarov removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is it removed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

* @return array
*/
public static function getWhitelist($fileTypes = ['php'], $changedFilesBaseDir = '', $baseFilesFolder = '')
{
public static function getWhitelist(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updates to this test are not reflected in PR description.
Please update with relevant information

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

/**
* Tests whitelisted files for strict type declarations.
*/
public function testStrictTypes()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be implemented consistently with other static tests using PHPCS

@@ -0,0 +1 @@
# Format: <componentType=module|library|theme|language|*> <componentName> <globPattern> or simply <globPattern>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reflect these changes in PR description

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -0,0 +1 @@
# Format: <componentType=module|library|theme|language|*> <componentName> <globPattern> or simply <globPattern>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it required to have blacklist and whitelist at the same time?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ishakhsuvarov blacklist removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ishakhsuvarov, blacklist returned. Yes it is required.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no value in delivering test which has empty whitelist. I assume it would not test anything.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blacklist deleted.

@@ -71,7 +71,7 @@ case $TEST_SUITE in
--output-file="$changed_files_ce" \
--base-path="$TRAVIS_BUILD_DIR" \
--repo='https://github.com/magento/magento2.git' \
--branch="$TRAVIS_BRANCH"
--branch='$TRAVIS_BRANCH'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change only seems to bring more inconsistency to this script

* @param string $connectionName
* @return bool
*/
public function isExist(IndexName $indexName, string $connectionName): bool;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any obstacle in making create and delete idempotent eliminating this method?

p-bystritsky and others added 8 commits March 13, 2018 15:09
…nges-no-history

# Conflicts:
#	app/code/Magento/CatalogImportExport/Model/Import/Product.php
#	app/code/Magento/Store/Setup/InstallSchema.php
#	app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js
#	app/etc/di.xml
#	composer.lock
…nges-no-history

# Conflicts:
#	app/code/Magento/Store/Setup/Patch/Schema/InitializeStoresAndWebsites.php
#	app/etc/di.xml
@ishakhsuvarov
Copy link
Contributor

@p-bystritsky Please avoid commit messages like Some fixes

@p-bystritsky p-bystritsky removed their assignment Mar 14, 2018
/**
* {@inheritdoc}
*/
public function getButtonData()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class seems to be unused in the current implementation.
I would suggest delivering it with the code which actually uses it and provides functional test coverage or with unit/integration test which would ensure that it is not broken in the future.

private function getModuleName(string $entityName): string
{
if (!isset($this->samples[$entityName])) {
throw new NoSuchEntityException();
Copy link
Contributor

@naydav naydav Mar 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use NoSuchEntityException for missed array key?
Maybe do we need to use something like \Magento\Framework\Exception\InputException?

*/
private function getPath(string $entityName): string
{
$directoryRead = $this->getDirectoryRead($entityName);
Copy link
Contributor

@naydav naydav Mar 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Underhood of this method, we create the directory, but in getModuleName(next call) we can throw the exception
So maybe do we need to finish all of the checks before performing some actions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* @param string $connectionName
* @return void
*/
public function saveIndex(IndexName $indexName, \Traversable $documents, string $connectionName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What the purpose of using connectionName as an argument for index handler?
Why this is not a responsibility of index class?

* @param string $connectionName
* @return void
*/
public function cleanIndex(IndexName $indexName, \Traversable $documents, string $connectionName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, that you use indexName with pre-build information about current dimension - it forse us to build it in client code. But we can pass DImensionInterface (specific for concrete index) which will have all required information for build index table name + the same approach can be use for resolve table name on front

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Mar 17, 2018

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
4 out of 5 committers have signed the CLA.

✅ vrann
✅ p-bystritsky
✅ RomaKis
✅ vkublytskyi
❌ maghamed

@vkublytskyi vkublytskyi force-pushed the msi-core-changes-no-history branch from c114abd to e949bdb Compare March 27, 2018 09:15
@magento-engcom-team magento-engcom-team merged commit d62db82 into magento:2.3-develop Mar 28, 2018
@vkublytskyi vkublytskyi deleted the msi-core-changes-no-history branch April 26, 2018 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants