Skip to content

Provide StockImporter implementation for Magento CE #496

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

Closed
maghamed opened this issue Feb 2, 2018 · 0 comments
Closed

Provide StockImporter implementation for Magento CE #496

maghamed opened this issue Feb 2, 2018 · 0 comments
Assignees
Labels

Comments

@maghamed
Copy link
Contributor

maghamed commented Feb 2, 2018

As we are going to deliver all the changes brought in the scope of MSI into Magento CE magento/magento2#13434

to guarantee modularity of MSI and prove that Magento CE 2.3 could still work with disabled MSI
we need to adapt Product Import in CE version and provide an implementation for interface

namespace Magento\CatalogImportExport\Model;

/**
 * Interface StockItemImporterInterface
 *
 * @api
 */
interface StockItemImporterInterface
{
    /**
     * Handle Import of Stock Item Data
     *
     * @param array $stockData
     * @return void
     */
    public function import(array $stockData);
}

which currently exists just in MSI. So, CE will fatal without MSI on board.

Proposed implementation details:
The most interesting place we need to fix is:

            // Insert rows
            if (!empty($stockData)) {
                //CE Import
                $this->_connection->insertOnDuplicate($entityTable, array_values($stockData));
                //MSI Import
                $this->stockItemImporter->import($bunch);
            }

We need to import in both cases (Legacy and MSI) the same SourceItems
For legacy we need more fields (configuration), but MSI needs just Qty and Stock Status.
Business logic should look like :
$this->stockItemImporter->import($stockData);
and implementation of Importer Interface in CE

can resolve a table for insertion by its own, no need to pass it from the calling code
like this:

/** @var $stockResource \Magento\CatalogInventory\Model\ResourceModel\Stock\Item */
        $stockResource = $this->_stockResItemFac->create();
        $entityTable = $stockResource->getMainTable();

and MSI will pluginize call to

StockItemImporterInterface::import(array $stockData)

extract needed data out of $stockData because we no need configuration which is stored in $stockData

and proceed with current logic

doing so, we will make :

  1. code of the business logic would be clean and call the only API
  2. CE edition will provide own implementation knowing nothing about MSI
  3. will make MSI extend (not substitute), existing CE behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants