From 8548525caf4616c5d7feaa9914095085a1435f50 Mon Sep 17 00:00:00 2001 From: System User Date: Thu, 14 Dec 2017 15:05:01 +0300 Subject: [PATCH 01/39] MSI: issue #290 - Adapted SourceItem Import/Export to use Source Code instead of SourceId; - Fixed issue when in Stock Sources export process all fields ware excluded; - Fixed type of return value for SourceItem->getSourceId method to int(was string); - Adapted integrational test to the new Export/Import system(with source code). --- .../Model/Source/Command/GetByCode.php | 56 +++++++++++++++++++ .../Source/Command/GetByCodeInterface.php | 33 +++++++++++ .../Magento/Inventory/Model/SourceItem.php | 2 +- .../Inventory/Model/SourceRepository.php | 16 ++++++ app/code/Magento/Inventory/etc/di.xml | 1 + .../Api/SourceRepositoryInterface.php | 10 ++++ .../InventoryApi/Test/_files/source.php | 1 + .../InventoryApi/Test/_files/sources.php | 5 ++ .../Export/AttributeCollectionProvider.php | 13 +++-- .../Model/Export/ColumnProvider.php | 5 ++ .../Export/SourceItemCollectionFactory.php | 32 ++++++++++- .../Model/Import/SourceItemConvert.php | 17 +++++- .../Model/Import/Sources.php | 2 + .../Import/Validator/SourceValidator.php | 25 +++++---- .../Integration/Model/Export/SourcesTest.php | 5 +- .../Export/_files/export_filtered_by_sku.csv | 10 ++-- .../_files/export_filtered_by_source.csv | 9 +-- .../export_filtered_without_status_column.csv | 8 +-- .../Model/Export/_files/export_full.csv | 12 ++-- .../Integration/Model/Import/SourcesTest.php | 45 +++++++++------ 20 files changed, 241 insertions(+), 66 deletions(-) create mode 100644 app/code/Magento/Inventory/Model/Source/Command/GetByCode.php create mode 100644 app/code/Magento/Inventory/Model/Source/Command/GetByCodeInterface.php diff --git a/app/code/Magento/Inventory/Model/Source/Command/GetByCode.php b/app/code/Magento/Inventory/Model/Source/Command/GetByCode.php new file mode 100644 index 000000000000..11243873b0dc --- /dev/null +++ b/app/code/Magento/Inventory/Model/Source/Command/GetByCode.php @@ -0,0 +1,56 @@ +sourceResource = $sourceResource; + $this->sourceFactory = $sourceFactory; + } + + /** + * @inheritdoc + */ + public function execute(string $code): SourceInterface + { + /** @var SourceInterface $source */ + $source = $this->sourceFactory->create(); + $this->sourceResource->load($source, $code, SourceInterface::CODE); + + if (null === $source->getSourceId()) { + throw new NoSuchEntityException(__('Source with code "%value" does not exist.', ['value' => $code])); + } + return $source; + } +} diff --git a/app/code/Magento/Inventory/Model/Source/Command/GetByCodeInterface.php b/app/code/Magento/Inventory/Model/Source/Command/GetByCodeInterface.php new file mode 100644 index 000000000000..7f1da4d889b1 --- /dev/null +++ b/app/code/Magento/Inventory/Model/Source/Command/GetByCodeInterface.php @@ -0,0 +1,33 @@ +getData(self::SOURCE_ID); + return (int)$this->getData(self::SOURCE_ID); } /** diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index ccc5c84043cb..f97be88680d5 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -9,6 +9,7 @@ use Magento\Framework\Api\SearchCriteriaInterface; use Magento\Inventory\Model\Source\Command\GetInterface; +use Magento\Inventory\Model\Source\Command\GetByCodeInterface; use Magento\Inventory\Model\Source\Command\GetListInterface; use Magento\Inventory\Model\Source\Command\SaveInterface; use Magento\InventoryApi\Api\Data\SourceInterface; @@ -30,6 +31,11 @@ class SourceRepository implements SourceRepositoryInterface */ private $commandGet; + /** + * @var GetByCodeInterface + */ + private $commandGetByCode; + /** * @var GetListInterface */ @@ -43,10 +49,12 @@ class SourceRepository implements SourceRepositoryInterface public function __construct( SaveInterface $commandSave, GetInterface $commandGet, + GetByCodeInterface $commandGetByCode, GetListInterface $commandGetList ) { $this->commandSave = $commandSave; $this->commandGet = $commandGet; + $this->commandGetByCode = $commandGetByCode; $this->commandGetList = $commandGetList; } @@ -66,6 +74,14 @@ public function get(int $sourceId): SourceInterface return $this->commandGet->execute($sourceId); } + /** + * @inheritdoc + */ + public function getByCode(string $code): SourceInterface + { + return $this->commandGetByCode->execute($code); + } + /** * @inheritdoc */ diff --git a/app/code/Magento/Inventory/etc/di.xml b/app/code/Magento/Inventory/etc/di.xml index 6acb6ca0aa86..8964f77ca5f0 100644 --- a/app/code/Magento/Inventory/etc/di.xml +++ b/app/code/Magento/Inventory/etc/di.xml @@ -13,6 +13,7 @@ + diff --git a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php index c6a02d2d9d1a..47845b0807e7 100644 --- a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php +++ b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php @@ -52,6 +52,16 @@ public function save(SourceInterface $source): int; */ public function get(int $sourceId): SourceInterface; + /** + * Get Source data by given code. If you want to create plugin on get method, also you need to create separate + * plugin on getList method, because entity loading way is different for these methods + * + * @param int $code + * @return \Magento\InventoryApi\Api\Data\SourceInterface + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + public function getByCode(string $code): SourceInterface; + /** * Find Sources by SearchCriteria * SearchCriteria is not required because load all stocks is useful case diff --git a/app/code/Magento/InventoryApi/Test/_files/source.php b/app/code/Magento/InventoryApi/Test/_files/source.php index 802fe485e9e3..018604ac50df 100644 --- a/app/code/Magento/InventoryApi/Test/_files/source.php +++ b/app/code/Magento/InventoryApi/Test/_files/source.php @@ -25,6 +25,7 @@ $source, [ SourceInterface::SOURCE_ID => 10, + SourceInterface::CODE => 'source-code', SourceInterface::NAME => 'source-name-1', SourceInterface::CONTACT_NAME => 'source-contact-name', SourceInterface::EMAIL => 'source-email', diff --git a/app/code/Magento/InventoryApi/Test/_files/sources.php b/app/code/Magento/InventoryApi/Test/_files/sources.php index eda5b5867e24..453bfd8deddd 100644 --- a/app/code/Magento/InventoryApi/Test/_files/sources.php +++ b/app/code/Magento/InventoryApi/Test/_files/sources.php @@ -22,6 +22,7 @@ [ // define only required and needed for tests fields SourceInterface::SOURCE_ID => 10, + SourceInterface::CODE => 'eu-1', SourceInterface::NAME => 'EU-source-1', SourceInterface::ENABLED => true, SourceInterface::PRIORITY => 100, @@ -30,6 +31,7 @@ ], [ SourceInterface::SOURCE_ID => 20, + SourceInterface::CODE => 'eu-2', SourceInterface::NAME => 'EU-source-2', SourceInterface::ENABLED => true, SourceInterface::PRIORITY => 200, @@ -38,6 +40,7 @@ ], [ SourceInterface::SOURCE_ID => 30, + SourceInterface::CODE => 'eu-3', SourceInterface::NAME => 'EU-source-3', SourceInterface::ENABLED => true, SourceInterface::PRIORITY => 300, @@ -46,6 +49,7 @@ ], [ SourceInterface::SOURCE_ID => 40, + SourceInterface::CODE => 'eu-dis', SourceInterface::NAME => 'EU-source-disabled', SourceInterface::ENABLED => false, SourceInterface::PRIORITY => 10, @@ -54,6 +58,7 @@ ], [ SourceInterface::SOURCE_ID => 50, + SourceInterface::CODE => 'us-1', SourceInterface::NAME => 'US-source-1', SourceInterface::ENABLED => true, SourceInterface::PRIORITY => 100, diff --git a/app/code/Magento/InventoryImportExport/Model/Export/AttributeCollectionProvider.php b/app/code/Magento/InventoryImportExport/Model/Export/AttributeCollectionProvider.php index 822d8c674bbf..6c3b56bf0378 100644 --- a/app/code/Magento/InventoryImportExport/Model/Export/AttributeCollectionProvider.php +++ b/app/code/Magento/InventoryImportExport/Model/Export/AttributeCollectionProvider.php @@ -10,6 +10,7 @@ use Magento\Eav\Model\Entity\AttributeFactory; use Magento\Framework\Data\Collection; use Magento\ImportExport\Model\Export\Factory as CollectionFactory; +use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceItemInterface; use Magento\InventoryImportExport\Model\Export\Source\StockStatus; @@ -49,12 +50,12 @@ public function get(): Collection { if (count($this->collection) === 0) { /** @var \Magento\Eav\Model\Entity\Attribute $sourceIdAttribute */ - $sourceIdAttribute = $this->attributeFactory->create(); - $sourceIdAttribute->setId(SourceItemInterface::SOURCE_ID); - $sourceIdAttribute->setDefaultFrontendLabel(SourceItemInterface::SOURCE_ID); - $sourceIdAttribute->setAttributeCode(SourceItemInterface::SOURCE_ID); - $sourceIdAttribute->setBackendType('int'); - $this->collection->addItem($sourceIdAttribute); + $sourceCodeAttribute = $this->attributeFactory->create(); + $sourceCodeAttribute->setId('source_' . SourceInterface::CODE); + $sourceCodeAttribute->setDefaultFrontendLabel('source_' . SourceInterface::CODE); + $sourceCodeAttribute->setAttributeCode('source_' . SourceInterface::CODE); + $sourceCodeAttribute->setBackendType('varchar'); + $this->collection->addItem($sourceCodeAttribute); /** @var \Magento\Eav\Model\Entity\Attribute $skuAttribute */ $skuAttribute = $this->attributeFactory->create(); diff --git a/app/code/Magento/InventoryImportExport/Model/Export/ColumnProvider.php b/app/code/Magento/InventoryImportExport/Model/Export/ColumnProvider.php index 338dcde9b6b4..ed3b2b1e0bde 100644 --- a/app/code/Magento/InventoryImportExport/Model/Export/ColumnProvider.php +++ b/app/code/Magento/InventoryImportExport/Model/Export/ColumnProvider.php @@ -10,6 +10,7 @@ use Magento\Framework\Data\Collection as AttributeCollection; use Magento\InventoryImportExport\Model\Export\ColumnProviderInterface; use Magento\ImportExport\Model\Export; +use \Magento\Framework\Exception\LocalizedException; /** * @inheritdoc @@ -30,6 +31,10 @@ public function getHeaders(AttributeCollection $attributeCollection, array $filt return $columns; } + if (count($filters[Export::FILTER_ELEMENT_SKIP]) === count($columns)) { + throw new LocalizedException(__('There is no data for the export.')); + } + // remove the skipped from columns $skippedAttributes = array_flip($filters[Export::FILTER_ELEMENT_SKIP]); foreach ($columns as $key => $value) { diff --git a/app/code/Magento/InventoryImportExport/Model/Export/SourceItemCollectionFactory.php b/app/code/Magento/InventoryImportExport/Model/Export/SourceItemCollectionFactory.php index c27e830a47f5..41572c9a8b5d 100644 --- a/app/code/Magento/InventoryImportExport/Model/Export/SourceItemCollectionFactory.php +++ b/app/code/Magento/InventoryImportExport/Model/Export/SourceItemCollectionFactory.php @@ -7,10 +7,14 @@ namespace Magento\InventoryImportExport\Model\Export; +use Magento\Framework\App\ResourceConnection; use Magento\Framework\Data\Collection as AttributeCollection; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\ObjectManagerInterface; +use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\Inventory\Model\ResourceModel\SourceItem\Collection; +use Magento\InventoryApi\Api\Data\SourceInterface; +use Magento\InventoryApi\Api\Data\SourceItemInterface; use Magento\InventoryImportExport\Model\Export\ColumnProviderInterface; use Magento\InventoryImportExport\Model\Export\SourceItemCollectionFactoryInterface; use Magento\ImportExport\Model\Export; @@ -20,6 +24,11 @@ */ class SourceItemCollectionFactory implements SourceItemCollectionFactoryInterface { + /** + * Source code field name + */ + const SOURCE_CODE_FIELD = 'source_' . SourceInterface::CODE; + /** * @var ObjectManagerInterface */ @@ -35,19 +44,27 @@ class SourceItemCollectionFactory implements SourceItemCollectionFactoryInterfac */ private $columnProvider; + /** + * @var ResourceConnection + */ + private $resourceConnection; + /** * @param ObjectManagerInterface $objectManager * @param FilterProcessorAggregator $filterProcessor * @param ColumnProviderInterface $columnProvider + * @param ResourceConnection $resourceConnection */ public function __construct( ObjectManagerInterface $objectManager, FilterProcessorAggregator $filterProcessor, - ColumnProviderInterface $columnProvider + ColumnProviderInterface $columnProvider, + ResourceConnection $resourceConnection ) { $this->objectManager = $objectManager; $this->filterProcessor = $filterProcessor; $this->columnProvider = $columnProvider; + $this->resourceConnection = $resourceConnection; } /** @@ -60,7 +77,17 @@ public function create(AttributeCollection $attributeCollection, array $filters) { /** @var Collection $collection */ $collection = $this->objectManager->create(Collection::class); - $collection->addFieldToSelect($this->columnProvider->getColumns($attributeCollection, $filters)); + $columns = $this->columnProvider->getColumns($attributeCollection, $filters); + if (($key = array_search(self::SOURCE_CODE_FIELD, $columns)) !== false) { + unset($columns[$key]); + $collection->join( + ['s' => $this->resourceConnection->getTableName(SourceResourceModel::TABLE_NAME_SOURCE)], + sprintf('s.%s = main_table.%s', SourceInterface::SOURCE_ID, SourceItemInterface::SOURCE_ID), + ['source_code' => SourceInterface::CODE] + ); + $collection->addFilterToMap('source_code', sprintf('s.%s', SourceInterface::CODE)); + } + $collection->addFieldToSelect($columns); foreach ($this->retrieveFilterData($filters) as $columnName => $value) { $attributeDefinition = $attributeCollection->getItemById($columnName); @@ -81,7 +108,6 @@ public function create(AttributeCollection $attributeCollection, array $filters) $this->filterProcessor->process($type, $collection, $columnName, $value); } - return $collection; } diff --git a/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php b/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php index b00bbd23a80b..abe6425b540c 100644 --- a/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php +++ b/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php @@ -7,8 +7,10 @@ namespace Magento\InventoryImportExport\Model\Import; +use Magento\Customer\Model\Indexer\Source; use Magento\InventoryApi\Api\Data\SourceItemInterface; use Magento\InventoryApi\Api\Data\SourceItemInterfaceFactory; +use Magento\InventoryApi\Api\SourceRepositoryInterface; class SourceItemConvert { @@ -17,12 +19,20 @@ class SourceItemConvert */ private $sourceItemFactory; + /**´ + * @var SourceRepositoryInterface + */ + private $sourceRepository; + /** * @param SourceItemInterfaceFactory $sourceItemFactory */ - public function __construct(SourceItemInterfaceFactory $sourceItemFactory) - { + public function __construct( + SourceItemInterfaceFactory $sourceItemFactory, + SourceRepositoryInterface $sourceRepository + ) { $this->sourceItemFactory = $sourceItemFactory; + $this->sourceRepository = $sourceRepository; } /** @@ -34,9 +44,10 @@ public function convert(array $bunch): array { $sourceItems = []; foreach ($bunch as $rowData) { + $source = $this->sourceRepository->getByCode($rowData[Sources::COL_SOURCE_CODE]); /** @var SourceItemInterface $sourceItem */ $sourceItem = $this->sourceItemFactory->create(); - $sourceItem->setSourceId($rowData[Sources::COL_SOURCE]); + $sourceItem->setSourceId($source->getSourceId()); $sourceItem->setSku($rowData[Sources::COL_SKU]); $sourceItem->setQuantity($rowData[Sources::COL_QTY]); diff --git a/app/code/Magento/InventoryImportExport/Model/Import/Sources.php b/app/code/Magento/InventoryImportExport/Model/Import/Sources.php index 5e46a8e35d25..5559d0597097 100644 --- a/app/code/Magento/InventoryImportExport/Model/Import/Sources.php +++ b/app/code/Magento/InventoryImportExport/Model/Import/Sources.php @@ -16,6 +16,7 @@ use Magento\InventoryImportExport\Model\Import\Command\CommandInterface; use Magento\InventoryImportExport\Model\Import\Serializer\Json; use Magento\InventoryImportExport\Model\Import\Validator\ValidatorInterface; +use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceItemInterface; /** @@ -28,6 +29,7 @@ class Sources extends AbstractEntity */ const COL_SKU = SourceItemInterface::SKU; const COL_SOURCE = SourceItemInterface::SOURCE_ID; + const COL_SOURCE_CODE = 'source_' . SourceInterface::CODE; const COL_QTY = SourceItemInterface::QUANTITY; const COL_STATUS = SourceItemInterface::STATUS; diff --git a/app/code/Magento/InventoryImportExport/Model/Import/Validator/SourceValidator.php b/app/code/Magento/InventoryImportExport/Model/Import/Validator/SourceValidator.php index 94e6f3b8c9fb..ed6bd51dac4f 100644 --- a/app/code/Magento/InventoryImportExport/Model/Import/Validator/SourceValidator.php +++ b/app/code/Magento/InventoryImportExport/Model/Import/Validator/SourceValidator.php @@ -29,7 +29,7 @@ class SourceValidator implements ValidatorInterface /** * @var array */ - private $sourceIds = []; + private $sourceCodes = []; /** * @param ValidationResultFactory $validationResultFactory @@ -41,7 +41,7 @@ public function __construct( ) { $this->validationResultFactory = $validationResultFactory; $this->sourceRepository = $sourceRepository; - $this->loadSourceIds(); + $this->loadSourceCodes(); } /** @@ -51,10 +51,10 @@ public function validate(array $rowData, int $rowNumber) { $errors = []; - if (!isset($rowData[Sources::COL_SOURCE])) { - $errors[] = __('Missing required column "%column"', ['column' => Sources::COL_SOURCE]); - } elseif (!$this->isExistingSource($rowData[Sources::COL_SOURCE])) { - $errors[] = __('Source id "%id" does not exists', ['id' => $rowData[Sources::COL_SOURCE]]); + if (!isset($rowData[Sources::COL_SOURCE_CODE])) { + $errors[] = __('Missing required column "%column"', ['column' => Sources::COL_SOURCE_CODE]); + } elseif (!$this->isExistingSource($rowData[Sources::COL_SOURCE_CODE])) { + $errors[] = __('Source code "%code" does not exists', ['code' => $rowData[Sources::COL_SOURCE_CODE]]); } return $this->validationResultFactory->create(['errors' => $errors]); @@ -63,25 +63,26 @@ public function validate(array $rowData, int $rowNumber) /** * Returns exits already the source in sources. * - * @param int $sourceId + * @param int $sourceCode * @return bool */ - private function isExistingSource($sourceId): bool + private function isExistingSource($sourceCode): bool { - return isset($this->sourceIds[$sourceId]); + return isset($this->sourceCodes[$sourceCode]); } /** - * Loads all existing source ids + * Loads all existing source codes * * @return void */ - private function loadSourceIds() + private function loadSourceCodes() { $sources = $this->sourceRepository->getList(); foreach ($sources->getItems() as $source) { $sourceId = $source->getSourceId(); - $this->sourceIds[$sourceId] = $sourceId; + $sourceCode = $source->getCode(); + $this->sourceCodes[$sourceCode] = $sourceId; } } } diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/SourcesTest.php b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/SourcesTest.php index 09bd973a46e5..69ba84b87c4e 100644 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/SourcesTest.php +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/SourcesTest.php @@ -120,10 +120,7 @@ public function testExportWithSourceFilter() { $this->exporter->setParameters([ Export::FILTER_ELEMENT_GROUP => [ - 'source_id' => [ - 22, - 62 - ] + 'source_code' => 'eu' ] ]); $this->exporter->export(); diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_sku.csv b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_sku.csv index 449aeb78494e..867c3ae02281 100644 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_sku.csv +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_sku.csv @@ -1,5 +1,5 @@ -source_id,sku,status,quantity -10,SKU-1,1,5.5000 -20,SKU-1,1,3.0000 -30,SKU-1,0,10.0000 -40,SKU-1,1,10.0000 +source_code,sku,status,quantity +eu-1,SKU-1,1,5.5000 +eu-2,SKU-1,1,3.0000 +eu-3,SKU-1,0,10.0000 +eu-dis,SKU-1,1,10.0000 diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_source.csv b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_source.csv index 752c4c8699a2..867c3ae02281 100644 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_source.csv +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_source.csv @@ -1,4 +1,5 @@ -source_id,sku,status,quantity -30,SKU-1,0,10.0000 -40,SKU-1,1,10.0000 -50,SKU-2,1,5.0000 +source_code,sku,status,quantity +eu-1,SKU-1,1,5.5000 +eu-2,SKU-1,1,3.0000 +eu-3,SKU-1,0,10.0000 +eu-dis,SKU-1,1,10.0000 diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_without_status_column.csv b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_without_status_column.csv index 89cb0643b37c..49c62cb1f782 100644 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_without_status_column.csv +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_without_status_column.csv @@ -1,4 +1,4 @@ -source_id,sku,quantity -10,SKU-1,5.5000 -20,SKU-1,3.0000 -40,SKU-1,10.0000 +source_code,sku,quantity +eu-1,SKU-1,5.5000 +eu-2,SKU-1,3.0000 +eu-dis,SKU-1,10.0000 diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_full.csv b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_full.csv index aca33a8fff41..60edb310ba9e 100644 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_full.csv +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_full.csv @@ -1,6 +1,6 @@ -source_id,sku,status,quantity -10,SKU-1,1,5.5000 -20,SKU-1,1,3.0000 -30,SKU-1,0,10.0000 -40,SKU-1,1,10.0000 -50,SKU-2,1,5.0000 +source_code,sku,status,quantity +eu-1,SKU-1,1,5.5000 +eu-2,SKU-1,1,3.0000 +eu-3,SKU-1,0,10.0000 +eu-dis,SKU-1,1,10.0000 +us-1,SKU-2,1,5.0000 diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php index 7dd7819e5d16..2cffabb6e8f6 100644 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php @@ -13,6 +13,7 @@ use Magento\ImportExport\Model\ResourceModel\Import\Data as ImportData; use Magento\InventoryApi\Api\Data\SourceItemInterface; use Magento\InventoryApi\Api\SourceItemRepositoryInterface; +use Magento\InventoryApi\Api\SourceRepositoryInterface; use Magento\InventoryImportExport\Model\Import\Sources; use Magento\TestFramework\Helper\Bootstrap; use PHPUnit\Framework\TestCase; @@ -29,6 +30,11 @@ class SourcesTest extends TestCase */ private $sourceItemRepository; + /** + * @var SourceRepositoryInterface + */ + private $sourceRepository; + /** * @var SearchCriteriaBuilder */ @@ -50,6 +56,7 @@ protected function setUp() ]); $this->sourceItemRepository = Bootstrap::getObjectManager()->create(SourceItemRepositoryInterface::class); + $this->sourceRepository = Bootstrap::getObjectManager()->create(SourceRepositoryInterface::class); $this->searchCriteriaBuilder = Bootstrap::getObjectManager()->create(SearchCriteriaBuilder::class); } @@ -58,7 +65,7 @@ protected function setUp() */ public function testValidateRowExpectsInvalidRow() { - $rowData = $this->buildRowDataArray(880, 'SKU-55', 33, 1); + $rowData = $this->buildRowDataArray('us-2', 'SKU-55', 33, 1); $result = $this->importer->validateRow($rowData, 2); $this->assertNotTrue($result, 'Expect result FALSE as given source ID is not present in database.'); } @@ -68,7 +75,7 @@ public function testValidateRowExpectsInvalidRow() */ public function testValidateRowExpectsValidRow() { - $rowData = $this->buildRowDataArray(20, 'SKU-55', 33, 1); + $rowData = $this->buildRowDataArray('eu-2', 'SKU-55', 33, 1); $result = $this->importer->validateRow($rowData, 2); $this->assertTrue($result, 'Expect result TRUE as given data is valid.'); } @@ -83,7 +90,7 @@ public function testImportDataWithWrongBehavior() ]); $bunch = [ - $this->buildRowDataArray(10, 'SKU-1', 6.88, 1) + $this->buildRowDataArray('eu-1', 'SKU-1', 6.88, 1) ]; $this->importData($bunch); } @@ -105,10 +112,10 @@ public function testImportDataWithAppendBehavior() $beforeImportData = $this->getSourceItemList($searchCriteria); $bunch = [ - $this->buildRowDataArray(10, 'SKU-1', 6.8800, 1), - $this->buildRowDataArray(20, 'SKU-1', 5.0000, 1), - $this->buildRowDataArray(50, 'SKU-2', 15, 1), - $this->buildRowDataArray(10, 'SKU-2', 33, 1), + $this->buildRowDataArray('eu-1', 'SKU-1', 6.8800, 1), + $this->buildRowDataArray('eu-2', 'SKU-1', 5.0000, 1), + $this->buildRowDataArray('us-1', 'SKU-2', 15, 1), + $this->buildRowDataArray('eu-1', 'SKU-2', 33, 1), ]; $this->importData($bunch); @@ -134,8 +141,8 @@ public function testImportDataWithDelteBehavior() $searchCriteria = $this->searchCriteriaBuilder->create(); $bunch = [ - $this->buildRowDataArray(10, 'SKU-1', 6.88, 1), - $this->buildRowDataArray(20, 'SKU-1', 5, 1), + $this->buildRowDataArray('eu-1', 'SKU-1', 6.88, 1), + $this->buildRowDataArray('eu-2', 'SKU-1', 5, 1), ]; $this->importData($bunch); @@ -160,8 +167,8 @@ public function testImportDataWithReplaceBehavior() ]); $bunch = [ - $this->buildRowDataArray(20, 'SKU-1', 5, 1), - $this->buildRowDataArray(50, 'SKU-2', 15, 1), + $this->buildRowDataArray('eu-2', 'SKU-1', 5, 1), + $this->buildRowDataArray('us-1', 'SKU-2', 15, 1), ]; $this->importData($bunch); @@ -191,8 +198,8 @@ public function testImportDataWithReplaceBehaviorNoAffectOtherSources() ]); $bunch = [ - $this->buildRowDataArray(20, 'SKU-1', 20, 1), - $this->buildRowDataArray(50, 'SKU-2', 15, 1), + $this->buildRowDataArray('eu-2', 'SKU-1', 20, 1), + $this->buildRowDataArray('us-1', 'SKU-2', 15, 1), ]; $this->importData($bunch); $afterImportData = $this->getSourceItemList($searchCriteria); @@ -211,10 +218,10 @@ public function testImportDataWithReplaceBehaviorNoAffectOtherSources() * @param int $status * @return array */ - private function buildRowDataArray($sourceID, $sku, $qty, $status) + private function buildRowDataArray($sourceCode, $sku, $qty, $status) { return [ - Sources::COL_SOURCE => $sourceID, + Sources::COL_SOURCE_CODE => $sourceCode, Sources::COL_SKU => $sku, Sources::COL_QTY => $qty, Sources::COL_STATUS => $status, @@ -230,8 +237,9 @@ private function buildDataArray(array $sourceItems) $comparableArray = []; foreach ($sourceItems as $sourceItem) { $key = sprintf('%s-%s', $sourceItem->getSourceId(), $sourceItem->getSku()); + $source = $this->sourceRepository->get($sourceItem->getSourceId()); $comparableArray[$key] = $this->buildRowDataArray( - $sourceItem->getSourceId(), + $source->getCode(), $sourceItem->getSku(), $sourceItem->getQuantity(), $sourceItem->getStatus() @@ -248,9 +256,10 @@ private function buildDataArray(array $sourceItems) private function updateDataArrayByBunch(array $data, array $bunch) { foreach ($bunch as $bunchData) { - $key = sprintf('%s-%s', $bunchData[Sources::COL_SOURCE], $bunchData[Sources::COL_SKU]); + $source = $this->sourceRepository->getByCode($bunchData[Sources::COL_SOURCE_CODE]); + $key = sprintf('%s-%s', $source->getSourceId(), $bunchData[Sources::COL_SKU]); $data[$key] = $this->buildRowDataArray( - $bunchData[Sources::COL_SOURCE], + $bunchData[Sources::COL_SOURCE_CODE], $bunchData[Sources::COL_SKU], number_format($bunchData[Sources::COL_QTY], 4), $bunchData[Sources::COL_STATUS] From 32c1a3ed576bc89383b34c677f6c2fc03ef21e28 Mon Sep 17 00:00:00 2001 From: System User Date: Thu, 14 Dec 2017 19:42:02 +0300 Subject: [PATCH 02/39] MSI: issue #290 - Fixed integration test. --- .../Test/Integration/Model/StockItemImporterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/StockItemImporterTest.php b/app/code/Magento/InventoryImportExport/Test/Integration/Model/StockItemImporterTest.php index b5695c3ed000..0d0b32aaf445 100644 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/StockItemImporterTest.php +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/StockItemImporterTest.php @@ -121,7 +121,7 @@ private function buildDataArray(array $sourceItems) $comparableArray[$sourceItem->getSku()] = [ SourceItemInterface::SKU => $sourceItem->getSku(), SourceItemInterface::QUANTITY => $sourceItem->getQuantity(), - SourceItemInterface::SOURCE_ID => $sourceItem->getSourceId(), + SourceItemInterface::SOURCE_ID => (string)$sourceItem->getSourceId(), SourceItemInterface::STATUS => $sourceItem->getStatus() ]; } From ad090a084de6863bade1e3b14721c4783d86201a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=AF=D0=BA?= =?UTF-8?q?=D0=B8=D0=BC=D0=BE=D0=B2=D0=B8=D1=87?= Date: Fri, 15 Dec 2017 00:01:31 +0300 Subject: [PATCH 03/39] MSI: issue #290 - Fixed DependencyTest error. --- .../InventoryImportExport/Model/Import/SourceItemConvert.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php b/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php index abe6425b540c..c810079db9b3 100644 --- a/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php +++ b/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php @@ -7,7 +7,6 @@ namespace Magento\InventoryImportExport\Model\Import; -use Magento\Customer\Model\Indexer\Source; use Magento\InventoryApi\Api\Data\SourceItemInterface; use Magento\InventoryApi\Api\Data\SourceItemInterfaceFactory; use Magento\InventoryApi\Api\SourceRepositoryInterface; From 81fc718aa020ab99182a866faae414aa97d3c1c1 Mon Sep 17 00:00:00 2001 From: deadlexus Date: Sat, 16 Dec 2017 00:27:54 +0300 Subject: [PATCH 04/39] MSI: issue #290 - Changed SourceItem->getSourceId method. --- app/code/Magento/Inventory/Model/SourceItem.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Inventory/Model/SourceItem.php b/app/code/Magento/Inventory/Model/SourceItem.php index 6afac5962022..928d87be0ccf 100644 --- a/app/code/Magento/Inventory/Model/SourceItem.php +++ b/app/code/Magento/Inventory/Model/SourceItem.php @@ -48,7 +48,8 @@ public function setSku($sku) */ public function getSourceId() { - return (int)$this->getData(self::SOURCE_ID); + $sourceId = $this->getData(self::SOURCE_ID); + return is_null($sourceId) ? null : (int)$sourceId; } /** From 6cdfe6e7b096b5d4a6ee6507d37fb4786b5f5a95 Mon Sep 17 00:00:00 2001 From: deadlexus Date: Sun, 17 Dec 2017 13:45:33 +0300 Subject: [PATCH 05/39] MSI: issue #290 - MEQP2 fixes; --- app/code/Magento/Inventory/Model/SourceItem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Inventory/Model/SourceItem.php b/app/code/Magento/Inventory/Model/SourceItem.php index 928d87be0ccf..b0a972b6c6c3 100644 --- a/app/code/Magento/Inventory/Model/SourceItem.php +++ b/app/code/Magento/Inventory/Model/SourceItem.php @@ -49,7 +49,7 @@ public function setSku($sku) public function getSourceId() { $sourceId = $this->getData(self::SOURCE_ID); - return is_null($sourceId) ? null : (int)$sourceId; + return ($sourceId === null) ? null : (int)$sourceId; } /** From 1b85ca7ca1fd7fce07fa82033a998231a9fdb0f4 Mon Sep 17 00:00:00 2001 From: Alex Yakimovich Date: Wed, 20 Dec 2017 20:31:07 +0300 Subject: [PATCH 06/39] MSI: issue #290 - modified Source Item database structure(source_id changed to source_code); - SourceId was replaced by SourceCode in MSI Extensions; --- .../Model/ResourceModel/SourceItem.php | 2 +- .../SourceItem/DeleteMultiple.php | 8 +++---- .../ResourceModel/SourceItem/SaveMultiple.php | 2 +- .../Magento/Inventory/Model/SourceItem.php | 10 ++++----- .../Validator/SourceIdValidator.php | 6 +++--- .../Setup/Operation/CreateSourceItemTable.php | 21 +++++++++---------- .../Api/Data/SourceItemInterface.php | 14 ++++++------- .../Api/Data/SourceSearchResultsInterface.php | 0 .../Observer/SourceItemsProcessor.php | 2 +- ...teSourceItemAtLegacyStockSettingPlugin.php | 2 +- .../Model/Import/SourceItemConvert.php | 2 +- .../Model/StockItemImporter.php | 2 +- .../Integration/Model/Import/SourcesTest.php | 8 +++---- .../Model/StockItemImporterTest.php | 2 +- .../Adminhtml/Order/View/Tab/Sources.php | 2 +- 15 files changed, 40 insertions(+), 43 deletions(-) mode change 100644 => 100755 app/code/Magento/Inventory/Model/ResourceModel/SourceItem.php mode change 100644 => 100755 app/code/Magento/Inventory/Model/ResourceModel/SourceItem/DeleteMultiple.php mode change 100644 => 100755 app/code/Magento/Inventory/Model/ResourceModel/SourceItem/SaveMultiple.php mode change 100644 => 100755 app/code/Magento/Inventory/Model/SourceItem.php mode change 100644 => 100755 app/code/Magento/Inventory/Model/SourceItem/Validator/SourceIdValidator.php mode change 100644 => 100755 app/code/Magento/Inventory/Setup/Operation/CreateSourceItemTable.php mode change 100644 => 100755 app/code/Magento/InventoryApi/Api/Data/SourceItemInterface.php mode change 100644 => 100755 app/code/Magento/InventoryApi/Api/Data/SourceSearchResultsInterface.php mode change 100644 => 100755 app/code/Magento/InventoryCatalog/Observer/SourceItemsProcessor.php mode change 100644 => 100755 app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/UpdateSourceItemAtLegacyStockSettingPlugin.php mode change 100644 => 100755 app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php mode change 100644 => 100755 app/code/Magento/InventoryImportExport/Model/StockItemImporter.php mode change 100644 => 100755 app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php mode change 100644 => 100755 app/code/Magento/InventoryImportExport/Test/Integration/Model/StockItemImporterTest.php mode change 100644 => 100755 app/code/Magento/InventorySales/Block/Adminhtml/Order/View/Tab/Sources.php diff --git a/app/code/Magento/Inventory/Model/ResourceModel/SourceItem.php b/app/code/Magento/Inventory/Model/ResourceModel/SourceItem.php old mode 100644 new mode 100755 index a330d41c74c5..fb8792cb183b --- a/app/code/Magento/Inventory/Model/ResourceModel/SourceItem.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/SourceItem.php @@ -18,7 +18,7 @@ class SourceItem extends AbstractDb * Constants related to specific db layer */ const TABLE_NAME_SOURCE_ITEM = 'inventory_source_item'; - const ID_FIELD_NAME = 'source_item_id'; + const ID_FIELD_NAME = 'source_code'; /**#@-*/ /** diff --git a/app/code/Magento/Inventory/Model/ResourceModel/SourceItem/DeleteMultiple.php b/app/code/Magento/Inventory/Model/ResourceModel/SourceItem/DeleteMultiple.php old mode 100644 new mode 100755 index 56c5ec475087..79c52d2e1590 --- a/app/code/Magento/Inventory/Model/ResourceModel/SourceItem/DeleteMultiple.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/SourceItem/DeleteMultiple.php @@ -63,11 +63,11 @@ private function buildWhereSqlPart(array $sourceItems): string SourceItemInterface::SKU . ' = ?', $sourceItem->getSku() ); - $sourceIdCondition = $connection->quoteInto( - SourceItemInterface::SOURCE_ID . ' = ?', - $sourceItem->getSourceId() + $sourceCodeCondition = $connection->quoteInto( + SourceItemInterface::SOURCE_CODE . ' = ?', + $sourceItem->getSourceCode() ); - $condition[] = '(' . $skuCondition . ' AND ' . $sourceIdCondition . ')'; + $condition[] = '(' . $skuCondition . ' AND ' . $sourceCodeCondition . ')'; } return implode(' OR ', $condition); } diff --git a/app/code/Magento/Inventory/Model/ResourceModel/SourceItem/SaveMultiple.php b/app/code/Magento/Inventory/Model/ResourceModel/SourceItem/SaveMultiple.php old mode 100644 new mode 100755 index c9d1b4bcc347..3230ae2c6e9e --- a/app/code/Magento/Inventory/Model/ResourceModel/SourceItem/SaveMultiple.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/SourceItem/SaveMultiple.php @@ -100,7 +100,7 @@ private function getSqlBindData(array $sourceItems): array $bind = []; foreach ($sourceItems as $sourceItem) { $bind = array_merge($bind, [ - $sourceItem->getSourceId(), + $sourceItem->getSourceCode(), $sourceItem->getSku(), $sourceItem->getQuantity(), $sourceItem->getStatus(), diff --git a/app/code/Magento/Inventory/Model/SourceItem.php b/app/code/Magento/Inventory/Model/SourceItem.php old mode 100644 new mode 100755 index b0a972b6c6c3..d59a0cfa3670 --- a/app/code/Magento/Inventory/Model/SourceItem.php +++ b/app/code/Magento/Inventory/Model/SourceItem.php @@ -46,18 +46,18 @@ public function setSku($sku) /** * @inheritdoc */ - public function getSourceId() + public function getSourceCode() { - $sourceId = $this->getData(self::SOURCE_ID); - return ($sourceId === null) ? null : (int)$sourceId; + $sourceCode = $this->getData(self::SOURCE_CODE); + return ($sourceCode === null) ? null : (string)$sourceCode; } /** * @inheritdoc */ - public function setSourceId($sourceId) + public function setSourceCode($sourceCode) { - $this->setData(self::SOURCE_ID, $sourceId); + $this->setData(self::SOURCE_CODE, $sourceCode); } /** diff --git a/app/code/Magento/Inventory/Model/SourceItem/Validator/SourceIdValidator.php b/app/code/Magento/Inventory/Model/SourceItem/Validator/SourceIdValidator.php old mode 100644 new mode 100755 index 2e9175c9bdf9..afb859f76ca9 --- a/app/code/Magento/Inventory/Model/SourceItem/Validator/SourceIdValidator.php +++ b/app/code/Magento/Inventory/Model/SourceItem/Validator/SourceIdValidator.php @@ -35,10 +35,10 @@ public function __construct(ValidationResultFactory $validationResultFactory) public function validate(SourceItemInterface $source): ValidationResult { $errors = []; - if (!is_numeric($source->getSourceId())) { + if (!is_string($source->getSourceCode())) { $errors[] = __( - '"%field" should be numeric.', - ['field' => SourceItemInterface::SOURCE_ID] + '"%field" should be string.', + ['field' => SourceItemInterface::SOURCE_CODE] ); } diff --git a/app/code/Magento/Inventory/Setup/Operation/CreateSourceItemTable.php b/app/code/Magento/Inventory/Setup/Operation/CreateSourceItemTable.php old mode 100644 new mode 100755 index a6c8b5cc225f..38c63902a697 --- a/app/code/Magento/Inventory/Setup/Operation/CreateSourceItemTable.php +++ b/app/code/Magento/Inventory/Setup/Operation/CreateSourceItemTable.php @@ -53,14 +53,13 @@ private function createSourceItemTable(SchemaSetupInterface $setup): Table ], 'Source Item ID' )->addColumn( - SourceItemInterface::SOURCE_ID, - Table::TYPE_INTEGER, - null, + SourceItemInterface::SOURCE_CODE, + Table::TYPE_TEXT, + 255, [ - Table::OPTION_UNSIGNED => true, Table::OPTION_NULLABLE => false, ], - 'Source ID' + 'Source Code' )->addColumn( SourceItemInterface::SKU, Table::TYPE_TEXT, @@ -94,25 +93,25 @@ private function createSourceItemTable(SchemaSetupInterface $setup): Table )->addForeignKey( $setup->getFkName( $sourceItemTable, - SourceItemInterface::SOURCE_ID, + SourceItemInterface::SOURCE_CODE, $sourceTable, - SourceInterface::SOURCE_ID + SourceInterface::CODE ), - SourceItemInterface::SOURCE_ID, + SourceItemInterface::SOURCE_CODE, $sourceTable, - SourceInterface::SOURCE_ID, + SourceInterface::CODE, AdapterInterface::FK_ACTION_CASCADE )->addIndex( $setup->getIdxName( $sourceItemTable, [ - SourceItemInterface::SOURCE_ID, + SourceItemInterface::SOURCE_CODE, SourceItemInterface::SKU, ], AdapterInterface::INDEX_TYPE_UNIQUE ), [ - SourceItemInterface::SOURCE_ID, + SourceItemInterface::SOURCE_CODE, SourceItemInterface::SKU, ], ['type' => AdapterInterface::INDEX_TYPE_UNIQUE] diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceItemInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceItemInterface.php old mode 100644 new mode 100755 index a26f67c47b36..6c9498a6ed8b --- a/app/code/Magento/InventoryApi/Api/Data/SourceItemInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceItemInterface.php @@ -24,7 +24,7 @@ interface SourceItemInterface extends ExtensibleDataInterface * Constants for keys of data array. Identical to the name of the getter in snake case */ const SKU = 'sku'; - const SOURCE_ID = 'source_id'; + const SOURCE_CODE = 'source_code'; const QUANTITY = 'quantity'; const STATUS = 'status'; /**#@-*/ @@ -52,19 +52,19 @@ public function getSku(); public function setSku($sku); /** - * Get source id + * Get source code * - * @return int|null + * @return string|null */ - public function getSourceId(); + public function getSourceCode(); /** - * Set source id + * Set source code * - * @param int|null $sourceId + * @param stirng|null $sourceId * @return void */ - public function setSourceId($sourceId); + public function setSourceCode($sourceCode); /** * Get source item quantity diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceSearchResultsInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceSearchResultsInterface.php old mode 100644 new mode 100755 diff --git a/app/code/Magento/InventoryCatalog/Observer/SourceItemsProcessor.php b/app/code/Magento/InventoryCatalog/Observer/SourceItemsProcessor.php old mode 100644 new mode 100755 index be2571db68ce..f0678751a215 --- a/app/code/Magento/InventoryCatalog/Observer/SourceItemsProcessor.php +++ b/app/code/Magento/InventoryCatalog/Observer/SourceItemsProcessor.php @@ -130,7 +130,7 @@ private function getCurrentSourceItemsMap(string $sku): array $sourceItemMap = []; if ($sourceItems) { foreach ($sourceItems as $sourceItem) { - $sourceItemMap[$sourceItem->getSourceId()] = $sourceItem; + $sourceItemMap[$sourceItem->getSourceCode()] = $sourceItem; } } return $sourceItemMap; diff --git a/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/UpdateSourceItemAtLegacyStockSettingPlugin.php b/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/UpdateSourceItemAtLegacyStockSettingPlugin.php old mode 100644 new mode 100755 index 9e4fdb3d482a..579192c54e26 --- a/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/UpdateSourceItemAtLegacyStockSettingPlugin.php +++ b/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/UpdateSourceItemAtLegacyStockSettingPlugin.php @@ -132,7 +132,7 @@ private function updateSourceItemBasedOnLegacyStockItem(Item $legacyStockItem) } else { /** @var SourceItemInterface $sourceItem */ $sourceItem = $this->sourceItemFactory->create(); - $sourceItem->setSourceId($this->defaultSourceProvider->getId()); + $sourceItem->setSourceCode($this->defaultSourceProvider->getCode()); $sourceItem->setSku($productSku); } diff --git a/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php b/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php old mode 100644 new mode 100755 index c810079db9b3..7142859a56ba --- a/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php +++ b/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php @@ -46,7 +46,7 @@ public function convert(array $bunch): array $source = $this->sourceRepository->getByCode($rowData[Sources::COL_SOURCE_CODE]); /** @var SourceItemInterface $sourceItem */ $sourceItem = $this->sourceItemFactory->create(); - $sourceItem->setSourceId($source->getSourceId()); + $sourceItem->setSourceCode($source->getCode()); $sourceItem->setSku($rowData[Sources::COL_SKU]); $sourceItem->setQuantity($rowData[Sources::COL_QTY]); diff --git a/app/code/Magento/InventoryImportExport/Model/StockItemImporter.php b/app/code/Magento/InventoryImportExport/Model/StockItemImporter.php old mode 100644 new mode 100755 index 2bd49881f24a..f904b2089929 --- a/app/code/Magento/InventoryImportExport/Model/StockItemImporter.php +++ b/app/code/Magento/InventoryImportExport/Model/StockItemImporter.php @@ -68,7 +68,7 @@ public function import(array $stockData) $qty = (isset($stockDatum['qty'])) ? $stockDatum['qty'] : 0; $sourceItem = $this->sourceItemFactory->create(); $sourceItem->setSku($stockDatum[Product::COL_SKU]); - $sourceItem->setSourceId($this->defaultSource->getId()); + $sourceItem->setSourceCode($this->defaultSource->getCode()); $sourceItem->setQuantity($qty); $sourceItem->setStatus($inStock); $sourceItems[] = $sourceItem; diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php old mode 100644 new mode 100755 index 2cffabb6e8f6..d9975df6208a --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php @@ -236,10 +236,9 @@ private function buildDataArray(array $sourceItems) { $comparableArray = []; foreach ($sourceItems as $sourceItem) { - $key = sprintf('%s-%s', $sourceItem->getSourceId(), $sourceItem->getSku()); - $source = $this->sourceRepository->get($sourceItem->getSourceId()); + $key = sprintf('%s-%s', $sourceItem->getSourceCode(), $sourceItem->getSku()); $comparableArray[$key] = $this->buildRowDataArray( - $source->getCode(), + $sourceItem->getSourceCode(), $sourceItem->getSku(), $sourceItem->getQuantity(), $sourceItem->getStatus() @@ -256,8 +255,7 @@ private function buildDataArray(array $sourceItems) private function updateDataArrayByBunch(array $data, array $bunch) { foreach ($bunch as $bunchData) { - $source = $this->sourceRepository->getByCode($bunchData[Sources::COL_SOURCE_CODE]); - $key = sprintf('%s-%s', $source->getSourceId(), $bunchData[Sources::COL_SKU]); + $key = sprintf('%s-%s', $bunchData[Sources::COL_SOURCE_CODE], $bunchData[Sources::COL_SKU]); $data[$key] = $this->buildRowDataArray( $bunchData[Sources::COL_SOURCE_CODE], $bunchData[Sources::COL_SKU], diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/StockItemImporterTest.php b/app/code/Magento/InventoryImportExport/Test/Integration/Model/StockItemImporterTest.php old mode 100644 new mode 100755 index 0d0b32aaf445..403a336662bf --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/StockItemImporterTest.php +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/StockItemImporterTest.php @@ -121,7 +121,7 @@ private function buildDataArray(array $sourceItems) $comparableArray[$sourceItem->getSku()] = [ SourceItemInterface::SKU => $sourceItem->getSku(), SourceItemInterface::QUANTITY => $sourceItem->getQuantity(), - SourceItemInterface::SOURCE_ID => (string)$sourceItem->getSourceId(), + SourceItemInterface::SOURCE_CODE => (string)$sourceItem->getSourceCode(), SourceItemInterface::STATUS => $sourceItem->getStatus() ]; } diff --git a/app/code/Magento/InventorySales/Block/Adminhtml/Order/View/Tab/Sources.php b/app/code/Magento/InventorySales/Block/Adminhtml/Order/View/Tab/Sources.php old mode 100644 new mode 100755 index 2f2f922aaef0..2457eb77f2b2 --- a/app/code/Magento/InventorySales/Block/Adminhtml/Order/View/Tab/Sources.php +++ b/app/code/Magento/InventorySales/Block/Adminhtml/Order/View/Tab/Sources.php @@ -80,7 +80,7 @@ public function getSourceItemsData() $sourceItems = $this->getSourceItemsBySku($orderItem->getSku()); foreach ($sourceItems as $sourceItem) { - $sourceName = $this->sourceRepository->get((int)$sourceItem->getSourceId())->getName(); + $sourceName = $this->sourceRepository->get($sourceItem->getSourceCode())->getName(); $sourceItemsData[$sourceName][] = [ 'sku' => $sourceItem->getSku(), 'qty' => $sourceItem->getQuantity(), From fb9480df92d7e3c73f4a8dc8b0b8ff9e5304c55d Mon Sep 17 00:00:00 2001 From: deadlexus Date: Thu, 21 Dec 2017 01:04:44 +0300 Subject: [PATCH 07/39] MSI: issue #290 - source_id field usings ware replaced by source_code field - part; --- .../Controller/Adminhtml/Source/Edit.php | 6 +- .../Adminhtml/Source/InlineEdit.php | 16 +++--- .../Controller/Adminhtml/Source/Save.php | 42 +++++++------- .../Stock/StockSourceLinkProcessor.php | 22 ++++---- .../Inventory/Indexer/SelectBuilder.php | 10 ++-- .../Indexer/Source/GetAssignedStockIds.php | 6 +- .../Indexer/Source/SourceIndexer.php | 8 +-- .../Indexer/SourceItem/GetSkuListInStock.php | 2 +- .../Indexer/SourceItem/SourceItemIndexer.php | 4 +- .../Inventory/Model/ResourceModel/Source.php | 2 +- .../Model/ResourceModel/SourceItem.php | 2 +- .../ResourceModel/SourceItem/SaveMultiple.php | 2 +- .../StockSourceLink/SaveMultiple.php | 12 ++-- .../Inventory/Model/Source/Command/Get.php | 8 +-- .../Model/Source/Command/GetByCode.php | 56 ------------------- .../Source/Command/GetByCodeInterface.php | 33 ----------- .../Model/Source/Command/GetInterface.php | 8 +-- .../Inventory/Model/Source/Command/Save.php | 4 +- .../Model/Source/Command/SaveInterface.php | 4 +- .../Model/SourceCarrierLinkManagement.php | 6 +- .../Validator/SourceIdValidator.php | 2 +- .../Inventory/Model/SourceRepository.php | 22 +------- .../Inventory/Model/StockSourceLink.php | 10 ++-- .../Command/AssignSourcesToStock.php | 6 +- .../Command/GetAssignedSourcesForStock.php | 10 ++-- .../Command/UnassignSourceFromStock.php | 4 +- .../CreateSourceCarrierLinkTable.php | 17 +++--- .../Operation/CreateStockSourceLinkTable.php | 21 ++++--- .../Integration/Indexer/GetSourceItemId.php | 6 +- .../Ui/DataProvider/SourceDataProvider.php | 14 ++--- .../Ui/DataProvider/StockDataProvider.php | 2 +- app/code/Magento/Inventory/etc/di.xml | 2 +- app/code/Magento/Inventory/etc/mview.xml | 2 +- .../ui_component/inventory_source_form.xml | 4 +- .../ui_component/inventory_source_listing.xml | 12 ++-- .../ui_component/inventory_stock_form.xml | 12 ++-- .../Api/AssignSourcesToStockInterface.php | 6 +- .../Api/Data/SourceItemInterface.php | 4 +- .../Api/SourceItemRepositoryInterface.php | 2 +- .../Api/SourceRepositoryInterface.php | 16 +----- .../Api/UnassignSourceFromStockInterface.php | 6 +- .../Api/SourceItemRepository/GetListTest.php | 4 +- .../Test/Api/SourceItemsDeleteTest.php | 10 ++-- .../Test/Api/SourceItemsSave/SaveTest.php | 8 +-- .../Api/SourceItemsSave/ValidationTest.php | 40 ++++++------- .../CarrierLinkManagementTest.php | 25 ++++----- .../InventoryApi/Test/_files/products.php | 8 +-- .../InventoryApi/Test/_files/source_items.php | 12 ++-- app/code/Magento/InventoryApi/etc/webapi.xml | 6 +- .../Api/DefaultSourceProviderInterface.php | 7 +++ .../Model/DefaultSourceProvider.php | 8 +++ .../Observer/ProcessSourceItemsObserver.php | 4 +- .../Observer/SourceItemsProcessor.php | 10 ++-- ...dateSourceItemAtLegacyQtyCounterPlugin.php | 4 +- ...teSourceItemAtLegacyStockSettingPlugin.php | 2 +- .../Operation/UpdateInventorySourceItem.php | 6 +- .../Product/Form/Modifier/Sources.php | 4 +- .../adminhtml/ui_component/product_form.xml | 12 ++-- .../SourceItemConfiguration/Delete.php | 6 +- .../SourceItemConfiguration/GetData.php | 6 +- .../SourceItemConfiguration/SaveMultiple.php | 4 +- .../Model/SourceItemConfiguration.php | 8 +-- .../Command/Delete.php | 4 +- .../SourceItemConfiguration/Command/Get.php | 14 ++--- .../Command/GetDefaultValues.php | 6 +- .../SourceItemsConfigurationProcessor.php | 18 +++--- .../CreateSourceConfigurationTable.php | 19 +++---- .../Form/Modifier/SourceItemConfiguration.php | 2 +- .../adminhtml/ui_component/product_form.xml | 2 +- .../Data/SourceItemConfigurationInterface.php | 14 ++--- ...DeleteSourceItemConfigurationInterface.php | 4 +- .../GetSourceItemConfigurationInterface.php | 4 +- .../Api/GetSourceItemConfigurationTest.php | 8 +-- .../Api/SourceItemConfigurationsSaveTest.php | 16 +++--- .../Test/_files/source_item_configuration.php | 2 +- .../InventoryConfigurationApi/etc/webapi.xml | 2 +- .../Export/AttributeCollectionProvider.php | 9 ++- .../Export/SourceItemCollectionFactory.php | 9 --- .../Model/Import/Command/Replace.php | 2 +- .../Model/Import/Sources.php | 3 +- .../Import/Validator/SourceValidator.php | 3 +- .../Integration/Model/Import/SourcesTest.php | 2 +- .../Model/StockItemImporterTest.php | 6 +- 83 files changed, 330 insertions(+), 446 deletions(-) delete mode 100644 app/code/Magento/Inventory/Model/Source/Command/GetByCode.php delete mode 100644 app/code/Magento/Inventory/Model/Source/Command/GetByCodeInterface.php diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php index bb02cab9badc..8ab65da3d897 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php @@ -49,9 +49,9 @@ public function __construct( */ public function execute(): ResultInterface { - $sourceId = (int)$this->getRequest()->getParam(SourceInterface::SOURCE_ID); + $sourceCode = (string)$this->getRequest()->getParam(SourceInterface::CODE); try { - $source = $this->sourceRepository->get($sourceId); + $source = $this->sourceRepository->get($sourceCode); /** @var Page $result */ $result = $this->resultFactory->create(ResultFactory::TYPE_PAGE); @@ -64,7 +64,7 @@ public function execute(): ResultInterface /** @var Redirect $result */ $result = $this->resultRedirectFactory->create(); $this->messageManager->addErrorMessage( - __('Source with id "%value" does not exist.', ['value' => $sourceId]) + __('Source with code "%value" does not exist.', ['value' => $sourceCode]) ); $result->setPath('*/*'); } diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/InlineEdit.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/InlineEdit.php index e5609b0aaeee..633e202202ce 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/InlineEdit.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/InlineEdit.php @@ -66,27 +66,27 @@ public function execute(): ResultInterface if ($request->isXmlHttpRequest() && $request->isPost() && $requestData) { foreach ($requestData as $itemData) { try { - $sourceId = (int)$itemData[SourceInterface::SOURCE_ID]; - $source = $this->sourceRepository->get($sourceId); + $sourceCode = (string)$itemData[SourceInterface::CODE]; + $source = $this->sourceRepository->get($sourceCode); $this->dataObjectHelper->populateWithArray($source, $itemData, SourceInterface::class); $this->sourceRepository->save($source); } catch (NoSuchEntityException $e) { $errorMessages[] = __( - '[ID: %value] The Source does not exist.', - ['value' => $sourceId] + '[Code: %value] The Source does not exist.', + ['value' => $sourceCode] ); } catch (ValidationException $e) { foreach ($e->getErrors() as $localizedError) { - $errorMessages[] = __('[ID: %value] %message', [ - 'value' => $sourceId, + $errorMessages[] = __('[Code: %value] %message', [ + 'value' => $sourceCode, 'message' => $localizedError->getMessage() ]); } } catch (CouldNotSaveException $e) { $errorMessages[] = __( - '[ID: %value] %message', + '[Code: %value] %message', [ - 'value' => $sourceId, + 'value' => $sourceCode, 'message' => $e->getMessage() ] ); diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php index 1e412a642049..b6cbb7b7ac57 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php @@ -78,13 +78,13 @@ public function execute(): ResultInterface } try { - $sourceId = isset($requestData['general'][SourceInterface::SOURCE_ID]) - ? (int)$requestData['general'][SourceInterface::SOURCE_ID] + $sourceCode = isset($requestData['general'][SourceInterface::CODE]) + ? (string)$requestData['general'][SourceInterface::CODE] : null; - $sourceId = $this->processSave($requestData, $sourceId); + $sourceCode = $this->processSave($requestData, $sourceCode); $this->messageManager->addSuccessMessage(__('The Source has been saved.')); - $this->processRedirectAfterSuccessSave($resultRedirect, $sourceId); + $this->processRedirectAfterSuccessSave($resultRedirect, $sourceCode); } catch (NoSuchEntityException $e) { $this->messageManager->addErrorMessage(__('The Source does not exist.')); $this->processRedirectAfterFailureSave($resultRedirect); @@ -92,13 +92,13 @@ public function execute(): ResultInterface foreach ($e->getErrors() as $localizedError) { $this->messageManager->addErrorMessage($localizedError->getMessage()); } - $this->processRedirectAfterFailureSave($resultRedirect, $sourceId); + $this->processRedirectAfterFailureSave($resultRedirect, $sourceCode); } catch (CouldNotSaveException $e) { $this->messageManager->addErrorMessage($e->getMessage()); - $this->processRedirectAfterFailureSave($resultRedirect, $sourceId); + $this->processRedirectAfterFailureSave($resultRedirect, $sourceCode); } catch (Exception $e) { $this->messageManager->addErrorMessage(__('Could not save Source.')); - $this->processRedirectAfterFailureSave($resultRedirect, $sourceId ?? null); + $this->processRedirectAfterFailureSave($resultRedirect, $sourceCode ?? null); } return $resultRedirect; @@ -106,17 +106,17 @@ public function execute(): ResultInterface /** * @param array $requestData - * @param int|null $sourceId + * @param string|null $sourceCode * - * @return int + * @return string */ - private function processSave(array $requestData, int $sourceId = null): int + private function processSave(array $requestData, string $sourceCode = null): string { - if (null === $sourceId) { + if (null === $sourceCode) { /** @var SourceInterface $source */ $source = $this->sourceFactory->create(); } else { - $source = $this->sourceRepository->get($sourceId); + $source = $this->sourceRepository->get($sourceCode); } $source = $this->sourceHydrator->hydrate($source, $requestData); @@ -128,7 +128,7 @@ private function processSave(array $requestData, int $sourceId = null): int ] ); - $sourceId = $this->sourceRepository->save($source); + $sourceCode = $this->sourceRepository->save($source); $this->_eventManager->dispatch( 'controller_action_inventory_source_save_after', @@ -138,20 +138,20 @@ private function processSave(array $requestData, int $sourceId = null): int ] ); - return $sourceId; + return $sourceCode; } /** * @param Redirect $resultRedirect - * @param int $sourceId + * @param string $sourceCode * * @return void */ - private function processRedirectAfterSuccessSave(Redirect $resultRedirect, int $sourceId) + private function processRedirectAfterSuccessSave(Redirect $resultRedirect, string $sourceCode) { if ($this->getRequest()->getParam('back')) { $resultRedirect->setPath('*/*/edit', [ - SourceInterface::SOURCE_ID => $sourceId, + SourceInterface::CODE => $sourceCode, '_current' => true, ]); } elseif ($this->getRequest()->getParam('redirect_to_new')) { @@ -165,17 +165,17 @@ private function processRedirectAfterSuccessSave(Redirect $resultRedirect, int $ /** * @param Redirect $resultRedirect - * @param int|null $sourceId + * @param string|null $sourceCode * * @return void */ - private function processRedirectAfterFailureSave(Redirect $resultRedirect, int $sourceId = null) + private function processRedirectAfterFailureSave(Redirect $resultRedirect, string $sourceCode = null) { - if (null === $sourceId) { + if (null === $sourceCode) { $resultRedirect->setPath('*/*/new'); } else { $resultRedirect->setPath('*/*/edit', [ - SourceInterface::SOURCE_ID => $sourceId, + SourceInterface::CODE => $sourceCode, '_current' => true, ]); } diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Stock/StockSourceLinkProcessor.php b/app/code/Magento/Inventory/Controller/Adminhtml/Stock/StockSourceLinkProcessor.php index e6dde342b0a2..298f2d153274 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Stock/StockSourceLinkProcessor.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Stock/StockSourceLinkProcessor.php @@ -78,23 +78,23 @@ public function process(int $stockId, array $stockSourceLinksData) $this->validateStockSourceData($stockSourceLinksData); $assignedSources = $this->getAssignedSourcesForStock->execute($stockId); - $sourceIdsForSave = array_flip(array_column($stockSourceLinksData, StockSourceLink::SOURCE_ID)); - $sourceIdsForDelete = []; + $sourceCodesForSave = array_flip(array_column($stockSourceLinksData, StockSourceLink::SOURCE_CODE)); + $sourceCodesForDelete = []; foreach ($assignedSources as $assignedSource) { - if (array_key_exists($assignedSource->getSourceId(), $sourceIdsForSave)) { - unset($sourceIdsForSave[$assignedSource->getSourceId()]); + if (array_key_exists($assignedSource->getCode(), $sourceCodesForSave)) { + unset($sourceCodesForSave[$assignedSource->getCode()]); } else { - $sourceIdsForDelete[] = $assignedSource->getSourceId(); + $sourceCodesForDelete[] = $assignedSource->getCode(); } } - if ($sourceIdsForSave) { - $this->assignSourcesToStock->execute(array_keys($sourceIdsForSave), $stockId); + if ($sourceCodesForSave) { + $this->assignSourcesToStock->execute(array_keys($sourceCodesForSave), $stockId); } - if ($sourceIdsForDelete) { - foreach ($sourceIdsForDelete as $sourceIdForDelete) { - $this->unassignSourceFromStock->execute($sourceIdForDelete, $stockId); + if ($sourceCodesForDelete) { + foreach ($sourceCodesForDelete as $sourceCodeForDelete) { + $this->unassignSourceFromStock->execute($sourceCodeForDelete, $stockId); } } } @@ -107,7 +107,7 @@ public function process(int $stockId, array $stockSourceLinksData) private function validateStockSourceData(array $stockSourceLinksData) { foreach ($stockSourceLinksData as $stockSourceLinkData) { - if (!isset($stockSourceLinkData[StockSourceLink::SOURCE_ID])) { + if (!isset($stockSourceLinkData[StockSourceLink::SOURCE_CODE])) { throw new InputException(__('Wrong Stock to Source relation parameters given.')); } } diff --git a/app/code/Magento/Inventory/Indexer/SelectBuilder.php b/app/code/Magento/Inventory/Indexer/SelectBuilder.php index 6d5b54131822..aca443c798e1 100644 --- a/app/code/Magento/Inventory/Indexer/SelectBuilder.php +++ b/app/code/Magento/Inventory/Indexer/SelectBuilder.php @@ -51,11 +51,11 @@ public function execute($stockId): Select // find all enabled sources $select = $connection->select() - ->from($sourceTable, [SourceInterface::SOURCE_ID]) + ->from($sourceTable, [SourceInterface::CODE]) ->where(SourceInterface::ENABLED . ' = ?', 1); - $sourceIds = $connection->fetchCol($select); + $sourceCodes = $connection->fetchCol($select); - if (0 === count($sourceIds)) { + if (0 === count($sourceCodes)) { return $select; } @@ -71,11 +71,11 @@ public function execute($stockId): Select ) ->joinLeft( ['stock_source_link' => $sourceStockLinkTable], - 'source_item.' . SourceItemInterface::SOURCE_ID . ' = stock_source_link.' . StockSourceLink::SOURCE_ID, + 'source_item.' . SourceItemInterface::SOURCE_CODE . ' = stock_source_link.' . StockSourceLink::SOURCE_CODE, [] ) ->where('stock_source_link.' . StockSourceLink::STOCK_ID . ' = ?', $stockId) - ->where('stock_source_link.' . StockSourceLink::SOURCE_ID . ' IN (?)', $sourceIds) + ->where('stock_source_link.' . StockSourceLink::SOURCE_CODE . ' IN (?)', $sourceCodes) ->group([SourceItemInterface::SKU]); return $select; } diff --git a/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php b/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php index fb76d015bb3f..be873ff320a3 100644 --- a/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php +++ b/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php @@ -31,10 +31,10 @@ public function __construct( } /** - * @param int[] $sourceIds + * @param string[] $sourceCodes * @return int[] */ - public function execute(array $sourceIds): array + public function execute(array $sourceCodes): array { $connection = $this->resourceConnection->getConnection(); $sourceStockLinkTable = $this->resourceConnection->getTableName( @@ -44,7 +44,7 @@ public function execute(array $sourceIds): array $select = $connection ->select() ->from($sourceStockLinkTable, StockSourceLink::STOCK_ID) - ->where(StockSourceLink::SOURCE_ID . ' IN (?)', $sourceIds) + ->where(StockSourceLink::SOURCE_CODE . ' IN (?)', $sourceCodes) ->group(StockSourceLink::STOCK_ID); $stockIds = $connection->fetchCol($select); diff --git a/app/code/Magento/Inventory/Indexer/Source/SourceIndexer.php b/app/code/Magento/Inventory/Indexer/Source/SourceIndexer.php index cede86e7585b..42ccc84003a3 100644 --- a/app/code/Magento/Inventory/Indexer/Source/SourceIndexer.php +++ b/app/code/Magento/Inventory/Indexer/Source/SourceIndexer.php @@ -56,17 +56,17 @@ public function executeFull() /** * @inheritdoc */ - public function executeRow($sourceId) + public function executeRow($sourceCode) { - $this->executeList([$sourceId]); + $this->executeList([$sourceCode]); } /** * @inheritdoc */ - public function executeList(array $sourceIds) + public function executeList(array $sourceCode) { - $stockIds = $this->getAssignedStockIds->execute($sourceIds); + $stockIds = $this->getAssignedStockIds->execute($sourceCode); $this->stockIndexer->executeList($stockIds); } } diff --git a/app/code/Magento/Inventory/Indexer/SourceItem/GetSkuListInStock.php b/app/code/Magento/Inventory/Indexer/SourceItem/GetSkuListInStock.php index caca132f65b5..a1dd48eea313 100644 --- a/app/code/Magento/Inventory/Indexer/SourceItem/GetSkuListInStock.php +++ b/app/code/Magento/Inventory/Indexer/SourceItem/GetSkuListInStock.php @@ -76,7 +76,7 @@ public function execute(array $sourceItemIds): array ] )->joinInner( ['stock_source_link' => $sourceStockLinkTable], - 'source_item.' . SourceItemInterface::SOURCE_ID . ' = stock_source_link.' . StockSourceLink::SOURCE_ID, + 'source_item.' . SourceItemInterface::SOURCE_CODE . ' = stock_source_link.' . StockSourceLink::SOURCE_CODE, [StockSourceLink::STOCK_ID] )->where('source_item.source_item_id IN (?)', $sourceItemIds) ->group(['stock_source_link.' . StockSourceLink::STOCK_ID]); diff --git a/app/code/Magento/Inventory/Indexer/SourceItem/SourceItemIndexer.php b/app/code/Magento/Inventory/Indexer/SourceItem/SourceItemIndexer.php index 3a77edff1b5c..2ab0dbd0066c 100644 --- a/app/code/Magento/Inventory/Indexer/SourceItem/SourceItemIndexer.php +++ b/app/code/Magento/Inventory/Indexer/SourceItem/SourceItemIndexer.php @@ -96,9 +96,9 @@ public function executeFull() /** * @inheritdoc */ - public function executeRow($sourceId) + public function executeRow($sourceItemId) { - $this->executeList([$sourceId]); + $this->executeList([$sourceItemId]); } /** diff --git a/app/code/Magento/Inventory/Model/ResourceModel/Source.php b/app/code/Magento/Inventory/Model/ResourceModel/Source.php index 178ee61dae21..b2151a343e49 100644 --- a/app/code/Magento/Inventory/Model/ResourceModel/Source.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/Source.php @@ -54,7 +54,7 @@ public function __construct( */ protected function _construct() { - $this->_init(self::TABLE_NAME_SOURCE, SourceInterface::SOURCE_ID); + $this->_init(self::TABLE_NAME_SOURCE, SourceInterface::CODE); } /** diff --git a/app/code/Magento/Inventory/Model/ResourceModel/SourceItem.php b/app/code/Magento/Inventory/Model/ResourceModel/SourceItem.php index fb8792cb183b..a330d41c74c5 100755 --- a/app/code/Magento/Inventory/Model/ResourceModel/SourceItem.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/SourceItem.php @@ -18,7 +18,7 @@ class SourceItem extends AbstractDb * Constants related to specific db layer */ const TABLE_NAME_SOURCE_ITEM = 'inventory_source_item'; - const ID_FIELD_NAME = 'source_code'; + const ID_FIELD_NAME = 'source_item_id'; /**#@-*/ /** diff --git a/app/code/Magento/Inventory/Model/ResourceModel/SourceItem/SaveMultiple.php b/app/code/Magento/Inventory/Model/ResourceModel/SourceItem/SaveMultiple.php index 3230ae2c6e9e..22cec4f34d40 100755 --- a/app/code/Magento/Inventory/Model/ResourceModel/SourceItem/SaveMultiple.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/SourceItem/SaveMultiple.php @@ -46,7 +46,7 @@ public function execute(array $sourceItems) $tableName = $this->resourceConnection->getTableName(SourceItemResourceModel::TABLE_NAME_SOURCE_ITEM); $columnsSql = $this->buildColumnsSqlPart([ - SourceItemInterface::SOURCE_ID, + SourceItemInterface::SOURCE_CODE, SourceItemInterface::SKU, SourceItemInterface::QUANTITY, SourceItemInterface::STATUS diff --git a/app/code/Magento/Inventory/Model/ResourceModel/StockSourceLink/SaveMultiple.php b/app/code/Magento/Inventory/Model/ResourceModel/StockSourceLink/SaveMultiple.php index 2ab3dfe4be5e..be9f6effe76c 100644 --- a/app/code/Magento/Inventory/Model/ResourceModel/StockSourceLink/SaveMultiple.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/StockSourceLink/SaveMultiple.php @@ -32,13 +32,13 @@ public function __construct( } /** - * @param array $sourceIds + * @param array $sourceCodes * @param int $stockId * @return void */ - public function execute(array $sourceIds, int $stockId) + public function execute(array $sourceCodes, int $stockId) { - if (!count($sourceIds)) { + if (!count($sourceCodes)) { return; } $connection = $this->resourceConnection->getConnection(); @@ -47,13 +47,13 @@ public function execute(array $sourceIds, int $stockId) ); $columns = [ - StockSourceLink::SOURCE_ID, + StockSourceLink::SOURCE_CODE, StockSourceLink::STOCK_ID, ]; $data = []; - foreach ($sourceIds as $sourceId) { - $data[] = [$sourceId, $stockId]; + foreach ($sourceCodes as $sourceCode) { + $data[] = [$sourceCode, $stockId]; } if ($data) { $connection->insertArray($tableName, $columns, $data); diff --git a/app/code/Magento/Inventory/Model/Source/Command/Get.php b/app/code/Magento/Inventory/Model/Source/Command/Get.php index 566c63c9c7d5..14adfc8e47d1 100644 --- a/app/code/Magento/Inventory/Model/Source/Command/Get.php +++ b/app/code/Magento/Inventory/Model/Source/Command/Get.php @@ -42,14 +42,14 @@ public function __construct( /** * @inheritdoc */ - public function execute(int $sourceId): SourceInterface + public function execute(string $code): SourceInterface { /** @var SourceInterface $source */ $source = $this->sourceFactory->create(); - $this->sourceResource->load($source, $sourceId, SourceInterface::SOURCE_ID); + $this->sourceResource->load($source, $code, SourceInterface::CODE); - if (null === $source->getSourceId()) { - throw new NoSuchEntityException(__('Source with id "%value" does not exist.', ['value' => $sourceId])); + if (null === $source->getCode()) { + throw new NoSuchEntityException(__('Source with code "%value" does not exist.', ['value' => $code])); } return $source; } diff --git a/app/code/Magento/Inventory/Model/Source/Command/GetByCode.php b/app/code/Magento/Inventory/Model/Source/Command/GetByCode.php deleted file mode 100644 index 11243873b0dc..000000000000 --- a/app/code/Magento/Inventory/Model/Source/Command/GetByCode.php +++ /dev/null @@ -1,56 +0,0 @@ -sourceResource = $sourceResource; - $this->sourceFactory = $sourceFactory; - } - - /** - * @inheritdoc - */ - public function execute(string $code): SourceInterface - { - /** @var SourceInterface $source */ - $source = $this->sourceFactory->create(); - $this->sourceResource->load($source, $code, SourceInterface::CODE); - - if (null === $source->getSourceId()) { - throw new NoSuchEntityException(__('Source with code "%value" does not exist.', ['value' => $code])); - } - return $source; - } -} diff --git a/app/code/Magento/Inventory/Model/Source/Command/GetByCodeInterface.php b/app/code/Magento/Inventory/Model/Source/Command/GetByCodeInterface.php deleted file mode 100644 index 7f1da4d889b1..000000000000 --- a/app/code/Magento/Inventory/Model/Source/Command/GetByCodeInterface.php +++ /dev/null @@ -1,33 +0,0 @@ -sourceValidator->validate($source); @@ -62,7 +62,7 @@ public function execute(SourceInterface $source): int try { $this->sourceResource->save($source); - return (int)$source->getSourceId(); + return (string)$source->getCode(); } catch (\Exception $e) { $this->logger->error($e->getMessage()); throw new CouldNotSaveException(__('Could not save Source'), $e); diff --git a/app/code/Magento/Inventory/Model/Source/Command/SaveInterface.php b/app/code/Magento/Inventory/Model/Source/Command/SaveInterface.php index e68908f35230..0b6c390a89e3 100644 --- a/app/code/Magento/Inventory/Model/Source/Command/SaveInterface.php +++ b/app/code/Magento/Inventory/Model/Source/Command/SaveInterface.php @@ -27,9 +27,9 @@ interface SaveInterface * Save Source data * * @param SourceInterface $source - * @return int + * @return string * @throws ValidationException * @throws CouldNotSaveException */ - public function execute(SourceInterface $source): int; + public function execute(SourceInterface $source): string; } diff --git a/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php b/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php index ce500a41c0a4..041e3f2c8f53 100644 --- a/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php +++ b/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php @@ -90,7 +90,7 @@ private function deleteCurrentCarrierLinks(SourceInterface $source) $connection = $this->resourceConnection->getConnection(); $connection->delete( $this->resourceConnection->getTableName(SourceCarrierLink::TABLE_NAME_SOURCE_CARRIER_LINK), - $connection->quoteInto('source_id = ?', $source->getSourceId()) + $connection->quoteInto('source_code = ?', $source->getCode()) ); } @@ -103,7 +103,7 @@ private function saveNewCarrierLinks(SourceInterface $source) $carrierLinkData = []; foreach ($source->getCarrierLinks() as $carrierLink) { $carrierLinkData[] = [ - 'source_id' => $source->getSourceId(), + 'source_code' => $source->getCode(), SourceCarrierLinkInterface::CARRIER_CODE => $carrierLink->getCarrierCode(), SourceCarrierLinkInterface::POSITION => $carrierLink->getPosition(), ]; @@ -121,7 +121,7 @@ private function saveNewCarrierLinks(SourceInterface $source) public function loadCarrierLinksBySource(SourceInterface $source) { $searchCriteria = $this->searchCriteriaBuilder - ->addFilter(SourceInterface::SOURCE_ID, $source->getSourceId()) + ->addFilter(SourceInterface::CODE, $source->getCode()) ->create(); /** @var Collection $collection */ diff --git a/app/code/Magento/Inventory/Model/SourceItem/Validator/SourceIdValidator.php b/app/code/Magento/Inventory/Model/SourceItem/Validator/SourceIdValidator.php index afb859f76ca9..caf63dd93e21 100755 --- a/app/code/Magento/Inventory/Model/SourceItem/Validator/SourceIdValidator.php +++ b/app/code/Magento/Inventory/Model/SourceItem/Validator/SourceIdValidator.php @@ -14,7 +14,7 @@ /** * Check that source id is valid */ -class SourceIdValidator implements SourceItemValidatorInterface +class SourceCodeValidator implements SourceItemValidatorInterface { /** * @var ValidationResultFactory diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index f97be88680d5..145f365656f1 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -9,7 +9,6 @@ use Magento\Framework\Api\SearchCriteriaInterface; use Magento\Inventory\Model\Source\Command\GetInterface; -use Magento\Inventory\Model\Source\Command\GetByCodeInterface; use Magento\Inventory\Model\Source\Command\GetListInterface; use Magento\Inventory\Model\Source\Command\SaveInterface; use Magento\InventoryApi\Api\Data\SourceInterface; @@ -31,11 +30,6 @@ class SourceRepository implements SourceRepositoryInterface */ private $commandGet; - /** - * @var GetByCodeInterface - */ - private $commandGetByCode; - /** * @var GetListInterface */ @@ -49,19 +43,17 @@ class SourceRepository implements SourceRepositoryInterface public function __construct( SaveInterface $commandSave, GetInterface $commandGet, - GetByCodeInterface $commandGetByCode, GetListInterface $commandGetList ) { $this->commandSave = $commandSave; $this->commandGet = $commandGet; - $this->commandGetByCode = $commandGetByCode; $this->commandGetList = $commandGetList; } /** * @inheritdoc */ - public function save(SourceInterface $source): int + public function save(SourceInterface $source): string { return $this->commandSave->execute($source); } @@ -69,17 +61,9 @@ public function save(SourceInterface $source): int /** * @inheritdoc */ - public function get(int $sourceId): SourceInterface - { - return $this->commandGet->execute($sourceId); - } - - /** - * @inheritdoc - */ - public function getByCode(string $code): SourceInterface + public function get(string $code): SourceInterface { - return $this->commandGetByCode->execute($code); + return $this->commandGet->execute($code); } /** diff --git a/app/code/Magento/Inventory/Model/StockSourceLink.php b/app/code/Magento/Inventory/Model/StockSourceLink.php index 3c409e2001d8..b3fd5caa963b 100644 --- a/app/code/Magento/Inventory/Model/StockSourceLink.php +++ b/app/code/Magento/Inventory/Model/StockSourceLink.php @@ -20,7 +20,7 @@ class StockSourceLink extends AbstractModel /**#@+ * Constants for keys of data array. Identical to the name of the getter in snake case */ - const SOURCE_ID = 'source_id'; + const SOURCE_CODE = 'source_code'; const STOCK_ID = 'stock_id'; /**#@-*/ @@ -35,17 +35,17 @@ protected function _construct() /** * @inheritdoc */ - public function getSourceId() + public function getSourceCode() { - return $this->getData(self::SOURCE_ID); + return $this->getData(self::SOURCE_CODE); } /** * @inheritdoc */ - public function setSourceId($sourceId) + public function setSourceCode($sourceCode) { - $this->setData(self::SOURCE_ID, $sourceId); + $this->setData(self::SOURCE_CODE, $sourceCode); } /** diff --git a/app/code/Magento/Inventory/Model/StockSourceLink/Command/AssignSourcesToStock.php b/app/code/Magento/Inventory/Model/StockSourceLink/Command/AssignSourcesToStock.php index 0357e72342a3..a1ad33258eec 100644 --- a/app/code/Magento/Inventory/Model/StockSourceLink/Command/AssignSourcesToStock.php +++ b/app/code/Magento/Inventory/Model/StockSourceLink/Command/AssignSourcesToStock.php @@ -43,13 +43,13 @@ public function __construct( /** * @inheritdoc */ - public function execute(array $sourceIds, int $stockId) + public function execute(array $sourceCodes, int $stockId) { - if (empty($sourceIds)) { + if (empty($sourceCodes)) { throw new InputException(__('Input data is invalid')); } try { - $this->saveMultiple->execute($sourceIds, $stockId); + $this->saveMultiple->execute($sourceCodes, $stockId); } catch (\Exception $e) { $this->logger->error($e->getMessage()); throw new CouldNotSaveException(__('Could not assign Sources to Stock'), $e); diff --git a/app/code/Magento/Inventory/Model/StockSourceLink/Command/GetAssignedSourcesForStock.php b/app/code/Magento/Inventory/Model/StockSourceLink/Command/GetAssignedSourcesForStock.php index b189c6999ec7..8eb5ef3f4d2c 100644 --- a/app/code/Magento/Inventory/Model/StockSourceLink/Command/GetAssignedSourcesForStock.php +++ b/app/code/Magento/Inventory/Model/StockSourceLink/Command/GetAssignedSourcesForStock.php @@ -67,10 +67,10 @@ public function __construct( public function execute(int $stockId): array { try { - $sourceIds = $this->getAssignedSourceIds($stockId); + $sourceCodes = $this->getAssignedSourceCodes($stockId); $searchCriteria = $this->searchCriteriaBuilder - ->addFilter(SourceInterface::SOURCE_ID, $sourceIds, 'in') + ->addFilter(SourceInterface::CODE, $sourceCodes, 'in') ->create(); $searchResult = $this->sourceRepository->getList($searchCriteria); return $searchResult->getItems(); @@ -81,19 +81,19 @@ public function execute(int $stockId): array } /** - * Get all linked SourceIds by given stockId + * Get all linked SourceCodes by given stockId * * @param int $stockId * @return array */ - private function getAssignedSourceIds(int $stockId): array + private function getAssignedSourceCodes(int $stockId): array { $connection = $this->resourceConnection->getConnection(); $select = $connection ->select() ->from( $this->resourceConnection->getTableName(StockSourceLinkResourceModel::TABLE_NAME_STOCK_SOURCE_LINK), - [StockSourceLink::SOURCE_ID] + [StockSourceLink::SOURCE_CODE] ) ->where(StockSourceLink::STOCK_ID . ' = ?', $stockId); return $connection->fetchCol($select); diff --git a/app/code/Magento/Inventory/Model/StockSourceLink/Command/UnassignSourceFromStock.php b/app/code/Magento/Inventory/Model/StockSourceLink/Command/UnassignSourceFromStock.php index 6b13bc5dd048..19b030445825 100644 --- a/app/code/Magento/Inventory/Model/StockSourceLink/Command/UnassignSourceFromStock.php +++ b/app/code/Magento/Inventory/Model/StockSourceLink/Command/UnassignSourceFromStock.php @@ -72,11 +72,11 @@ public function __construct( /** * @inheritdoc */ - public function execute(int $sourceId, int $stockId) + public function execute(string $sourceCode, int $stockId) { $searchCriteria = $this->searchCriteriaBuilder ->addFilter(StockSourceLink::STOCK_ID, (int)$stockId) - ->addFilter(StockSourceLink::SOURCE_ID, $sourceId) + ->addFilter(StockSourceLink::SOURCE_CODE, $sourceCode) ->create(); /** @var Collection $collection */ diff --git a/app/code/Magento/Inventory/Setup/Operation/CreateSourceCarrierLinkTable.php b/app/code/Magento/Inventory/Setup/Operation/CreateSourceCarrierLinkTable.php index 703b18040a74..d6370f481f9d 100644 --- a/app/code/Magento/Inventory/Setup/Operation/CreateSourceCarrierLinkTable.php +++ b/app/code/Magento/Inventory/Setup/Operation/CreateSourceCarrierLinkTable.php @@ -53,14 +53,13 @@ private function createSourceCarrierLinkTable(SchemaSetupInterface $setup): Tabl ], 'Source Carrier Link ID' )->addColumn( - SourceInterface::SOURCE_ID, - Table::TYPE_INTEGER, - null, + SourceInterface::CODE, + Table::TYPE_TEXT, + 255, [ Table::OPTION_NULLABLE => false, - Table::OPTION_UNSIGNED => true, ], - 'Source ID' + 'Source Code' )->addColumn( SourceCarrierLinkInterface::CARRIER_CODE, Table::TYPE_TEXT, @@ -81,13 +80,13 @@ private function createSourceCarrierLinkTable(SchemaSetupInterface $setup): Tabl )->addForeignKey( $setup->getFkName( $sourceCarrierLinkTable, - SourceInterface::SOURCE_ID, + SourceInterface::CODE, $sourceTable, - SourceInterface::SOURCE_ID + SourceInterface::CODE ), - SourceInterface::SOURCE_ID, + SourceInterface::CODE, $sourceTable, - SourceInterface::SOURCE_ID, + SourceInterface::CODE, AdapterInterface::FK_ACTION_CASCADE ); } diff --git a/app/code/Magento/Inventory/Setup/Operation/CreateStockSourceLinkTable.php b/app/code/Magento/Inventory/Setup/Operation/CreateStockSourceLinkTable.php index f90c204bd01a..5096b8485aed 100644 --- a/app/code/Magento/Inventory/Setup/Operation/CreateStockSourceLinkTable.php +++ b/app/code/Magento/Inventory/Setup/Operation/CreateStockSourceLinkTable.php @@ -65,14 +65,13 @@ private function createStockSourceLinkTable(SchemaSetupInterface $setup): Table ], 'Stock ID' )->addColumn( - StockSourceLink::SOURCE_ID, - Table::TYPE_INTEGER, - null, + StockSourceLink::SOURCE_CODE, + Table::TYPE_TEXT, + 255, [ Table::OPTION_NULLABLE => false, - Table::OPTION_UNSIGNED => true, ], - 'Source ID' + 'Source Code' )->addForeignKey( $setup->getFkName( $stockSourceLinkTable, @@ -87,26 +86,26 @@ private function createStockSourceLinkTable(SchemaSetupInterface $setup): Table )->addForeignKey( $setup->getFkName( $stockSourceLinkTable, - StockSourceLink::SOURCE_ID, + StockSourceLink::SOURCE_CODE, $sourceTable, - SourceInterface::SOURCE_ID + SourceInterface::CODE ), - StockSourceLink::SOURCE_ID, + StockSourceLink::SOURCE_CODE, $sourceTable, - SourceInterface::SOURCE_ID, + SourceInterface::CODE, AdapterInterface::FK_ACTION_CASCADE )->addIndex( $setup->getIdxName( $stockSourceLinkTable, [ StockSourceLink::STOCK_ID, - StockSourceLink::SOURCE_ID, + StockSourceLink::SOURCE_CODE, ], AdapterInterface::INDEX_TYPE_UNIQUE ), [ StockSourceLink::STOCK_ID, - StockSourceLink::SOURCE_ID, + StockSourceLink::SOURCE_CODE, ], ['type' => AdapterInterface::INDEX_TYPE_UNIQUE] ); diff --git a/app/code/Magento/Inventory/Test/Integration/Indexer/GetSourceItemId.php b/app/code/Magento/Inventory/Test/Integration/Indexer/GetSourceItemId.php index d98d968250b0..a7fb09c3709d 100644 --- a/app/code/Magento/Inventory/Test/Integration/Indexer/GetSourceItemId.php +++ b/app/code/Magento/Inventory/Test/Integration/Indexer/GetSourceItemId.php @@ -28,10 +28,10 @@ public function __construct(ResourceConnection $resourceConnection) /** * @param string $sku - * @param int $sourceId + * @param string $sourceCode * @return int */ - public function execute(string $sku, int $sourceId): int + public function execute(string $sku, string $sourceCode): string { $connection = $this->resourceConnection->getConnection(); $select = $connection->select() @@ -40,7 +40,7 @@ public function execute(string $sku, int $sourceId): int [SourceItemResourceModel::ID_FIELD_NAME] ) ->where(SourceItemInterface::SKU . ' = ?', $sku) - ->where(SourceItemInterface::SOURCE_ID . ' = ?', $sourceId); + ->where(SourceItemInterface::SOURCE_CODE . ' = ?', $sourceCode); return (int)$connection->fetchOne($select); } diff --git a/app/code/Magento/Inventory/Ui/DataProvider/SourceDataProvider.php b/app/code/Magento/Inventory/Ui/DataProvider/SourceDataProvider.php index d9604018c039..385d50603686 100644 --- a/app/code/Magento/Inventory/Ui/DataProvider/SourceDataProvider.php +++ b/app/code/Magento/Inventory/Ui/DataProvider/SourceDataProvider.php @@ -83,10 +83,10 @@ public function getData() // It is need for support of several fieldsets. // For details see \Magento\Ui\Component\Form::getDataSourceData if ($data['totalRecords'] > 0) { - $sourceId = (int)$data['items'][0][SourceInterface::SOURCE_ID]; + $sourceCode = (string)$data['items'][0][SourceInterface::CODE]; $sourceGeneralData = $data['items'][0]; - $sourceGeneralData['carrier_codes'] = $this->getAssignedCarrierCodes($sourceId); - $dataForSingle[$sourceId] = [ + $sourceGeneralData['carrier_codes'] = $this->getAssignedCarrierCodes($sourceCode); + $dataForSingle[$sourceCode] = [ 'general' => $sourceGeneralData, ]; $data = $dataForSingle; @@ -109,18 +109,18 @@ public function getSearchResult() $result->getItems(), $result->getTotalCount(), $searchCriteria, - SourceInterface::SOURCE_ID + SourceInterface::CODE ); return $searchResult; } /** - * @param int $sourceId + * @param string $sourceCode * @return array */ - private function getAssignedCarrierCodes(int $sourceId): array + private function getAssignedCarrierCodes(string $sourceCode): array { - $source = $this->sourceRepository->get($sourceId); + $source = $this->sourceRepository->get($sourceCode); $carrierCodes = []; $carrierLinks = $source->getCarrierLinks(); diff --git a/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php b/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php index 38b1cd0aa32a..f4514968e269 100644 --- a/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php +++ b/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php @@ -137,7 +137,7 @@ private function getAssignedSourcesData(int $stockId): array $assignedSourcesData = []; foreach ($assignedSources as $assignedSource) { $assignedSourcesData[] = [ - SourceInterface::SOURCE_ID => $assignedSource->getSourceId(), + SourceInterface::CODE => $assignedSource->getCode(), SourceInterface::NAME => $assignedSource->getName(), ]; } diff --git a/app/code/Magento/Inventory/etc/di.xml b/app/code/Magento/Inventory/etc/di.xml index 8964f77ca5f0..82c4aefbedc8 100644 --- a/app/code/Magento/Inventory/etc/di.xml +++ b/app/code/Magento/Inventory/etc/di.xml @@ -43,7 +43,7 @@ Magento\Inventory\Model\SourceItem\Validator\SkuValidator - Magento\Inventory\Model\SourceItem\Validator\SourceIdValidator + Magento\Inventory\Model\SourceItem\Validator\SourceCodeValidator Magento\Inventory\Model\SourceItem\Validator\QuantityValidator Magento\Inventory\Model\SourceItem\Validator\StatusValidator diff --git a/app/code/Magento/Inventory/etc/mview.xml b/app/code/Magento/Inventory/etc/mview.xml index 44a586422a35..ebb3b0aa45d4 100644 --- a/app/code/Magento/Inventory/etc/mview.xml +++ b/app/code/Magento/Inventory/etc/mview.xml @@ -13,7 +13,7 @@ - +
diff --git a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml index 78aed75bcf76..d6a629b0b989 100644 --- a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml +++ b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml @@ -38,8 +38,8 @@ - source_id - source_id + code + code diff --git a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml index 7dbad88c838f..0f245f768980 100644 --- a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml +++ b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml @@ -27,15 +27,15 @@ - source_id + source_code Magento_InventoryApi::source - id - source_id + code + code @@ -68,7 +68,7 @@ false - source_id + code true inventory_source_listing.inventory_source_listing.inventory_source_listing_columns.ids @@ -85,7 +85,7 @@ - source_id + code @@ -288,7 +288,7 @@ - source_id + code diff --git a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_form.xml b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_form.xml index 50e3b47b127a..bd7424ef305c 100644 --- a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_form.xml +++ b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_form.xml @@ -100,10 +100,10 @@ data.sources.assign_sources_grid - source_id + code name - source_id + code @@ -111,7 +111,7 @@ false false record - source_id + code ${ $.provider }:${ $.dataProvider } @@ -128,12 +128,12 @@ - + ui/dynamic-rows/cells/text text - source_id - + source_code + diff --git a/app/code/Magento/InventoryApi/Api/AssignSourcesToStockInterface.php b/app/code/Magento/InventoryApi/Api/AssignSourcesToStockInterface.php index ad3f0bfb4c5f..049570cf1df9 100644 --- a/app/code/Magento/InventoryApi/Api/AssignSourcesToStockInterface.php +++ b/app/code/Magento/InventoryApi/Api/AssignSourcesToStockInterface.php @@ -19,13 +19,13 @@ interface AssignSourcesToStockInterface /** * Assign Sources to Stock * - * If one of the Sources or Stock with given id don't exist then exception will be throw + * If one of the Sources or Stock with given codes don't exist then exception will be throw * - * @param int[] $sourceIds + * @param int[] $sourceCodes * @param int $stockId * @return void * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\CouldNotSaveException */ - public function execute(array $sourceIds, int $stockId); + public function execute(array $sourceCodes, int $stockId); } diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceItemInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceItemInterface.php index 6c9498a6ed8b..4b6d61c44fbd 100755 --- a/app/code/Magento/InventoryApi/Api/Data/SourceItemInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceItemInterface.php @@ -12,7 +12,7 @@ /** * Represents amount of product on physical storage - * Entity id getter is missed because entity identifies by compound identifier (sku and source_id) + * Entity id getter is missed because entity identifies by compound identifier (sku and source_code) * * Used fully qualified namespaces in annotations for proper work of WebApi request parser * @@ -61,7 +61,7 @@ public function getSourceCode(); /** * Set source code * - * @param stirng|null $sourceId + * @param stirng|null $sourceCode * @return void */ public function setSourceCode($sourceCode); diff --git a/app/code/Magento/InventoryApi/Api/SourceItemRepositoryInterface.php b/app/code/Magento/InventoryApi/Api/SourceItemRepositoryInterface.php index d17208720c5c..c2bb4836dc9b 100644 --- a/app/code/Magento/InventoryApi/Api/SourceItemRepositoryInterface.php +++ b/app/code/Magento/InventoryApi/Api/SourceItemRepositoryInterface.php @@ -25,7 +25,7 @@ * The method save is absent, due to different semantic (save multiple) * @see SourceItemsSaveInterface * - * There is no get method because SourceItem identifies by compound identifier (sku and source_id), + * There is no get method because SourceItem identifies by compound identifier (sku and source_code), * so need to use getList() method * * Used fully qualified namespaces in annotations for proper work of WebApi request parser diff --git a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php index 47845b0807e7..a3cae6bd4475 100644 --- a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php +++ b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php @@ -36,21 +36,11 @@ interface SourceRepositoryInterface * Save Source data * * @param \Magento\InventoryApi\Api\Data\SourceInterface $source - * @return int + * @return string * @throws \Magento\Framework\Validation\ValidationException * @throws \Magento\Framework\Exception\CouldNotSaveException */ - public function save(SourceInterface $source): int; - - /** - * Get Source data by given sourceId. If you want to create plugin on get method, also you need to create separate - * plugin on getList method, because entity loading way is different for these methods - * - * @param int $sourceId - * @return \Magento\InventoryApi\Api\Data\SourceInterface - * @throws \Magento\Framework\Exception\NoSuchEntityException - */ - public function get(int $sourceId): SourceInterface; + public function save(SourceInterface $source): string; /** * Get Source data by given code. If you want to create plugin on get method, also you need to create separate @@ -60,7 +50,7 @@ public function get(int $sourceId): SourceInterface; * @return \Magento\InventoryApi\Api\Data\SourceInterface * @throws \Magento\Framework\Exception\NoSuchEntityException */ - public function getByCode(string $code): SourceInterface; + public function get(string $code): SourceInterface; /** * Find Sources by SearchCriteria diff --git a/app/code/Magento/InventoryApi/Api/UnassignSourceFromStockInterface.php b/app/code/Magento/InventoryApi/Api/UnassignSourceFromStockInterface.php index e0082caf3afd..68802ba949a2 100644 --- a/app/code/Magento/InventoryApi/Api/UnassignSourceFromStockInterface.php +++ b/app/code/Magento/InventoryApi/Api/UnassignSourceFromStockInterface.php @@ -19,13 +19,13 @@ interface UnassignSourceFromStockInterface /** * Unassign source from stock * - * If Source or Stock with given id doesn't exist then do nothing + * If Source or Stock with given code doesn't exist then do nothing * - * @param int $sourceId + * @param int $sourceCode * @param int $stockId * @return void * @throws \Magento\Framework\Exception\InputException * @throws \Magento\Framework\Exception\CouldNotDeleteException */ - public function execute(int $sourceId, int $stockId); + public function execute(string $sourceCode, int $stockId); } diff --git a/app/code/Magento/InventoryApi/Test/Api/SourceItemRepository/GetListTest.php b/app/code/Magento/InventoryApi/Test/Api/SourceItemRepository/GetListTest.php index 8c17e0c6afff..b45ac4453205 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceItemRepository/GetListTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceItemRepository/GetListTest.php @@ -56,13 +56,13 @@ public function testGetList() $expectedTotalCount = 4; $expectedItemsData = [ [ - SourceItemInterface::SOURCE_ID => 10, + SourceItemInterface::SOURCE_CODE => 'eu-1', SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 5.5, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, ], [ - SourceItemInterface::SOURCE_ID => 20, + SourceItemInterface::SOURCE_CODE => 'eu-2', SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 3, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, diff --git a/app/code/Magento/InventoryApi/Test/Api/SourceItemsDeleteTest.php b/app/code/Magento/InventoryApi/Test/Api/SourceItemsDeleteTest.php index a8e24b24a045..855deb30afa8 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceItemsDeleteTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceItemsDeleteTest.php @@ -32,29 +32,29 @@ public function testExecute() { $sourceItemsForDelete = [ [ - SourceItemInterface::SOURCE_ID => 10, + SourceItemInterface::SOURCE_CODE => 'eu-1', SourceItemInterface::SKU => 'SKU-1', ], [ - SourceItemInterface::SOURCE_ID => 20, + SourceItemInterface::SOURCE_CODE => 'eu-2', SourceItemInterface::SKU => 'SKU-1', ], ]; $expectedSourceItemsAfterDeleting = [ [ - SourceItemInterface::SOURCE_ID => 30, + SourceItemInterface::SOURCE_CODE => 'eu-3', SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 10, SourceItemInterface::STATUS => SourceItemInterface::STATUS_OUT_OF_STOCK, ], [ - SourceItemInterface::SOURCE_ID => 40, + SourceItemInterface::SOURCE_CODE => 'eu-dis', SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 10, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, ], [ - SourceItemInterface::SOURCE_ID => 50, + SourceItemInterface::SOURCE_CODE => 'us-1', SourceItemInterface::SKU => 'SKU-2', SourceItemInterface::QUANTITY => 5, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, diff --git a/app/code/Magento/InventoryApi/Test/Api/SourceItemsSave/SaveTest.php b/app/code/Magento/InventoryApi/Test/Api/SourceItemsSave/SaveTest.php index d54c22d23836..ffa4213f05af 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceItemsSave/SaveTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceItemsSave/SaveTest.php @@ -30,13 +30,13 @@ public function testExecute() { $sourceItems = [ [ - SourceItemInterface::SOURCE_ID => 10, + SourceItemInterface::SOURCE_CODE => 'eu-1', SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 5.5, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, ], [ - SourceItemInterface::SOURCE_ID => 20, + SourceItemInterface::SOURCE_CODE => 'eu-2', SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 3, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, @@ -65,11 +65,11 @@ protected function tearDown() { $sourceItems = [ [ - SourceItemInterface::SOURCE_ID => 10, + SourceItemInterface::SOURCE_CODE => 'eu-1', SourceItemInterface::SKU => 'SKU-1', ], [ - SourceItemInterface::SOURCE_ID => 20, + SourceItemInterface::SOURCE_CODE => 'eu-2', SourceItemInterface::SKU => 'SKU-1', ], ]; diff --git a/app/code/Magento/InventoryApi/Test/Api/SourceItemsSave/ValidationTest.php b/app/code/Magento/InventoryApi/Test/Api/SourceItemsSave/ValidationTest.php index bde14b6a68b7..8265212cdc50 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceItemsSave/ValidationTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceItemsSave/ValidationTest.php @@ -27,7 +27,7 @@ class ValidationTest extends WebapiAbstract private $validData = [ SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 1.5, - SourceItemInterface::SOURCE_ID => 10, + SourceItemInterface::SOURCE_CODE => 'eu-1', SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, ]; @@ -77,15 +77,15 @@ public function dataProviderRequiredFields(): array ], ], ], - 'without_' . SourceItemInterface::SOURCE_ID => [ - SourceItemInterface::SOURCE_ID, + 'without_' . SourceItemInterface::SOURCE_CODE => [ + SourceItemInterface::SOURCE_CODE, [ 'message' => 'Validation Failed', 'errors' => [ [ - 'message' => '"%field" should be numeric.', + 'message' => '"%field" should be string.', 'parameters' => [ - 'field' => SourceItemInterface::SOURCE_ID, + 'field' => SourceItemInterface::SOURCE_CODE, ], ], ], @@ -230,24 +230,24 @@ public function failedValidationDataProvider(): array ], ], ], - 'null_' . SourceItemInterface::SOURCE_ID => [ - SourceItemInterface::SOURCE_ID, + 'null_' . SourceItemInterface::SOURCE_CODE => [ + SourceItemInterface::SOURCE_CODE, null, [ 'message' => 'Validation Failed', 'errors' => [ [ - 'message' => '"%field" should be numeric.', + 'message' => '"%field" should be string.', 'parameters' => [ - 'field' => SourceItemInterface::SOURCE_ID, + 'field' => SourceItemInterface::SOURCE_CODE, ], ], ], ], ], - 'not_exists_' . SourceItemInterface::SOURCE_ID => [ - SourceItemInterface::SOURCE_ID, - 100, + 'not_exists_' . SourceItemInterface::SOURCE_CODE => [ + SourceItemInterface::SOURCE_CODE, + 'eu-12', [ 'message' => 'Could not save Source Item', ], @@ -310,20 +310,20 @@ public function failedValidationRelatedOnlyForRestDataProvider(): array . '" processing. Invalid type for value: "test". Expected Type: "float".', ], ], - 'empty_' . SourceItemInterface::SOURCE_ID => [ - SourceItemInterface::SOURCE_ID, + 'empty_' . SourceItemInterface::SOURCE_CODE => [ + SourceItemInterface::SOURCE_CODE, '', [ - 'message' => 'Error occurred during "' . SourceItemInterface::SOURCE_ID - . '" processing. Invalid type for value: "". Expected Type: "int".', + 'message' => 'Error occurred during "' . SourceItemInterface::SOURCE_CODE + . '" processing. Invalid type for value: "". Expected Type: "string".', ], ], - 'array_' . SourceItemInterface::SOURCE_ID => [ - SourceItemInterface::SOURCE_ID, + 'array_' . SourceItemInterface::SOURCE_CODE => [ + SourceItemInterface::SOURCE_CODE, [], [ - 'message' => 'Error occurred during "' . SourceItemInterface::SOURCE_ID - . '" processing. Invalid type for value: "array". Expected Type: "int".', + 'message' => 'Error occurred during "' . SourceItemInterface::SOURCE_CODE + . '" processing. Invalid type for value: "array". Expected Type: "string".', ], ], ]; diff --git a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CarrierLinkManagementTest.php b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CarrierLinkManagementTest.php index a49e54ef68db..c2d163a8cd2e 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CarrierLinkManagementTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CarrierLinkManagementTest.php @@ -28,9 +28,8 @@ class CarrierLinkManagementTest extends WebapiAbstract */ public function testCarrierLinksManagement(array $carrierLinks) { - $sourceId = 10; + $sourceCode = 'source-code-1'; $expectedData = [ - SourceInterface::CODE => 'source-code-1', SourceInterface::NAME => 'source-name-1', SourceInterface::POSTCODE => 'source-postcode', SourceInterface::COUNTRY_ID => 'US', @@ -38,8 +37,8 @@ public function testCarrierLinksManagement(array $carrierLinks) SourceInterface::CARRIER_LINKS => $carrierLinks, ]; - $this->saveSource($sourceId, $expectedData); - $sourceData = $this->getSourceDataById($sourceId); + $this->saveSource($sourceCode, $expectedData); + $sourceData = $this->getSourceDataByCode($sourceCode); self::assertArrayHasKey(SourceInterface::USE_DEFAULT_CARRIER_CONFIG, $sourceData); self::assertEquals( @@ -96,15 +95,15 @@ public function dataProviderCarrierLinks(): array } /** - * @param int $sourceId + * @param string $sourceCode * @param array $data * @return void */ - private function saveSource(int $sourceId, array $data) + private function saveSource(string $sourceCode, array $data) { $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceId, + 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceCode, 'httpMethod' => Request::HTTP_METHOD_PUT, ], 'soap' => [ @@ -116,20 +115,20 @@ private function saveSource(int $sourceId, array $data) $this->_webApiCall($serviceInfo, ['source' => $data]); } else { $requestData = $data; - $requestData['sourceId'] = $sourceId; + $requestData['sourceCode'] = $sourceCode; $this->_webApiCall($serviceInfo, ['source' => $requestData]); } } /** - * @param int $sourceId + * @param string $sourceCode * @return array */ - private function getSourceDataById(int $sourceId): array + private function getSourceDataByCode(string $sourceCode): array { $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceId, + 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceCode, 'httpMethod' => Request::HTTP_METHOD_GET, ], 'soap' => [ @@ -139,8 +138,8 @@ private function getSourceDataById(int $sourceId): array ]; $response = (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) ? $this->_webApiCall($serviceInfo) - : $this->_webApiCall($serviceInfo, ['sourceId' => $sourceId]); - self::assertArrayHasKey(SourceInterface::SOURCE_ID, $response); + : $this->_webApiCall($serviceInfo, ['sourceCode' => $sourceCode]); + self::assertArrayHasKey(SourceInterface::CODE, $response); return $response; } diff --git a/app/code/Magento/InventoryApi/Test/_files/products.php b/app/code/Magento/InventoryApi/Test/_files/products.php index e7143733c7c8..c811406689cc 100644 --- a/app/code/Magento/InventoryApi/Test/_files/products.php +++ b/app/code/Magento/InventoryApi/Test/_files/products.php @@ -14,7 +14,7 @@ use Magento\InventoryApi\Api\Data\SourceItemInterface; use Magento\InventoryApi\Api\SourceItemRepositoryInterface; use Magento\InventoryApi\Api\SourceItemsDeleteInterface; -use Magento\InventoryCatalog\Api\DefaultStockProviderInterface; +use Magento\InventoryCatalog\Api\DefaultSourceProviderInterface; use Magento\TestFramework\Helper\Bootstrap; $objectManager = Bootstrap::getObjectManager(); @@ -60,8 +60,8 @@ if ($moduleManager->isEnabled('Magento_InventoryCatalog')) { /** @var SearchCriteriaBuilder $searchCriteriaBuilder */ $searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class); - /** @var DefaultStockProviderInterface $defaultStockProvider */ - $defaultStockProvider = $objectManager->get(DefaultStockProviderInterface::class); + /** @var DefaultSourceProviderInterface $defaultSourceProvider */ + $defaultSourceProvider = $objectManager->get(DefaultSourceProviderInterface::class); /** @var SourceItemRepositoryInterface $sourceItemRepository */ $sourceItemRepository = $objectManager->get(SourceItemRepositoryInterface::class); /** @var SourceItemsDeleteInterface $sourceItemsDelete */ @@ -69,7 +69,7 @@ $searchCriteria = $searchCriteriaBuilder ->addFilter(SourceItemInterface::SKU, ['SKU-1', 'SKU-2', 'SKU-3'], 'in') - ->addFilter(SourceItemInterface::SOURCE_ID, $defaultStockProvider->getId()) + ->addFilter(SourceItemInterface::SOURCE_CODE, $defaultSourceProvider->getCode()) ->create(); $sourceItems = $sourceItemRepository->getList($searchCriteria)->getItems(); if (count($sourceItems)) { diff --git a/app/code/Magento/InventoryApi/Test/_files/source_items.php b/app/code/Magento/InventoryApi/Test/_files/source_items.php index f2141062909e..99d261e81416 100644 --- a/app/code/Magento/InventoryApi/Test/_files/source_items.php +++ b/app/code/Magento/InventoryApi/Test/_files/source_items.php @@ -30,37 +30,37 @@ */ $sourcesItemsData = [ [ - SourceItemInterface::SOURCE_ID => 10, // EU-source-1 + SourceItemInterface::SOURCE_CODE => 'eu-1', // EU-source-1 SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 5.5, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, ], [ - SourceItemInterface::SOURCE_ID => 20, // EU-source-2 + SourceItemInterface::SOURCE_CODE => 'eu-2', // EU-source-2 SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 3, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, ], [ - SourceItemInterface::SOURCE_ID => 30, // EU-source-3 + SourceItemInterface::SOURCE_CODE => 'eu-3', // EU-source-3 SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 10, SourceItemInterface::STATUS => SourceItemInterface::STATUS_OUT_OF_STOCK, ], [ - SourceItemInterface::SOURCE_ID => 40, // EU-source-disabled + SourceItemInterface::SOURCE_CODE => 'eu-dis', // EU-source-disabled SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 10, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, ], [ - SourceItemInterface::SOURCE_ID => 50, // US-source-1 + SourceItemInterface::SOURCE_CODE => 'us-1', // US-source-1 SourceItemInterface::SKU => 'SKU-2', SourceItemInterface::QUANTITY => 5, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, ], [ - SourceItemInterface::SOURCE_ID => 20, // EU-source-2 + SourceItemInterface::SOURCE_CODE => 'eu-2', // EU-source-2 SourceItemInterface::SKU => 'SKU-3', SourceItemInterface::QUANTITY => 6, SourceItemInterface::STATUS => SourceItemInterface::STATUS_OUT_OF_STOCK, diff --git a/app/code/Magento/InventoryApi/etc/webapi.xml b/app/code/Magento/InventoryApi/etc/webapi.xml index 49ebb28e67ae..0f8cd80d51b0 100644 --- a/app/code/Magento/InventoryApi/etc/webapi.xml +++ b/app/code/Magento/InventoryApi/etc/webapi.xml @@ -14,7 +14,7 @@ - + @@ -26,7 +26,7 @@ - + @@ -94,7 +94,7 @@ - + diff --git a/app/code/Magento/InventoryCatalog/Api/DefaultSourceProviderInterface.php b/app/code/Magento/InventoryCatalog/Api/DefaultSourceProviderInterface.php index ea0572844888..693d83816b0f 100644 --- a/app/code/Magento/InventoryCatalog/Api/DefaultSourceProviderInterface.php +++ b/app/code/Magento/InventoryCatalog/Api/DefaultSourceProviderInterface.php @@ -14,6 +14,13 @@ */ interface DefaultSourceProviderInterface { + /** + * Get Default Source code + * + * @return string + */ + public function getCode(): string; + /** * Get Default Source id * diff --git a/app/code/Magento/InventoryCatalog/Model/DefaultSourceProvider.php b/app/code/Magento/InventoryCatalog/Model/DefaultSourceProvider.php index 4850afd5868b..6134109efc3b 100644 --- a/app/code/Magento/InventoryCatalog/Model/DefaultSourceProvider.php +++ b/app/code/Magento/InventoryCatalog/Model/DefaultSourceProvider.php @@ -14,6 +14,14 @@ */ class DefaultSourceProvider implements DefaultSourceProviderInterface { + /** + * @inheritdoc + */ + public function getCode(): string + { + return 'default'; + } + /** * @inheritdoc */ diff --git a/app/code/Magento/InventoryCatalog/Observer/ProcessSourceItemsObserver.php b/app/code/Magento/InventoryCatalog/Observer/ProcessSourceItemsObserver.php index 5b0c100a4b44..8ca139d52cc6 100644 --- a/app/code/Magento/InventoryCatalog/Observer/ProcessSourceItemsObserver.php +++ b/app/code/Magento/InventoryCatalog/Observer/ProcessSourceItemsObserver.php @@ -98,7 +98,7 @@ private function updateDefaultSourceQty(array $productParams) $qtyAndStockStatus = $productParams['quantity_and_stock_status']; $qty = $qtyAndStockStatus['qty']; $stockStatus = $qtyAndStockStatus['is_in_stock']; - $defaultSourceId = $this->defaultSourceProvider->getId(); + $defaultSourceCode = $this->defaultSourceProvider->getCode(); /** @var $sourceItem SourceItemInterface */ $sourceItem = $this->sourceItemInterfaceFactory->create([ @@ -106,7 +106,7 @@ private function updateDefaultSourceQty(array $productParams) SourceItemInterface::SKU => $sku, SourceItemInterface::QUANTITY => $qty, SourceItemInterface::STATUS => $stockStatus, - SourceItemInterface::SOURCE_ID => $defaultSourceId + SourceItemInterface::SOURCE_CODE => $defaultSourceCode ] ]); diff --git a/app/code/Magento/InventoryCatalog/Observer/SourceItemsProcessor.php b/app/code/Magento/InventoryCatalog/Observer/SourceItemsProcessor.php index f0678751a215..4e9d99da0975 100755 --- a/app/code/Magento/InventoryCatalog/Observer/SourceItemsProcessor.php +++ b/app/code/Magento/InventoryCatalog/Observer/SourceItemsProcessor.php @@ -92,9 +92,9 @@ public function process($sku, array $sourceItemsData) foreach ($sourceItemsData as $sourceItemData) { $this->validateSourceItemData($sourceItemData); - $sourceId = $sourceItemData[SourceItemInterface::SOURCE_ID]; - if (isset($sourceItemsForDelete[$sourceId])) { - $sourceItem = $sourceItemsForDelete[$sourceId]; + $sourceCode = $sourceItemData[SourceItemInterface::SOURCE_CODE]; + if (isset($sourceItemsForDelete[$sourceCode])) { + $sourceItem = $sourceItemsForDelete[$sourceCode]; } else { /** @var SourceItemInterface $sourceItem */ $sourceItem = $this->sourceItemFactory->create(); @@ -104,7 +104,7 @@ public function process($sku, array $sourceItemsData) $this->dataObjectHelper->populateWithArray($sourceItem, $sourceItemData, SourceItemInterface::class); $sourceItemsForSave[] = $sourceItem; - unset($sourceItemsForDelete[$sourceId]); + unset($sourceItemsForDelete[$sourceCode]); } if ($sourceItemsForSave) { $this->sourceItemsSave->execute($sourceItemsForSave); @@ -143,7 +143,7 @@ private function getCurrentSourceItemsMap(string $sku): array */ private function validateSourceItemData(array $sourceItemData) { - if (!isset($sourceItemData[SourceItemInterface::SOURCE_ID])) { + if (!isset($sourceItemData[SourceItemInterface::SOURCE_CODE])) { throw new InputException(__('Wrong Product to Source relation parameters given.')); } } diff --git a/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/UpdateSourceItemAtLegacyQtyCounterPlugin.php b/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/UpdateSourceItemAtLegacyQtyCounterPlugin.php index b6ab5006436b..7ffda8a3c348 100644 --- a/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/UpdateSourceItemAtLegacyQtyCounterPlugin.php +++ b/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/UpdateSourceItemAtLegacyQtyCounterPlugin.php @@ -127,8 +127,8 @@ private function updateSourceItemAtLegacyCatalogInventoryQtyCounter( array_keys($productQuantitiesBySku), 'in' )->addFilter( - SourceItemInterface::SOURCE_ID, - $this->defaultSourceProvider->getId() + SourceItemInterface::SOURCE_CODE, + $this->defaultSourceProvider->getCode() )->create(); $sourceItems = $this->sourceItemRepository->getList($searchCriteria)->getItems(); diff --git a/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/UpdateSourceItemAtLegacyStockSettingPlugin.php b/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/UpdateSourceItemAtLegacyStockSettingPlugin.php index 579192c54e26..c465eef861aa 100755 --- a/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/UpdateSourceItemAtLegacyStockSettingPlugin.php +++ b/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/UpdateSourceItemAtLegacyStockSettingPlugin.php @@ -124,7 +124,7 @@ private function updateSourceItemBasedOnLegacyStockItem(Item $legacyStockItem) $searchCriteria = $this->searchCriteriaBuilder ->addFilter(SourceItemInterface::SKU, $productSku) - ->addFilter(SourceItemInterface::SOURCE_ID, $this->defaultSourceProvider->getId()) + ->addFilter(SourceItemInterface::SOURCE_CODE, $this->defaultSourceProvider->getCode()) ->create(); $sourceItems = $this->sourceItemRepository->getList($searchCriteria)->getItems(); if (count($sourceItems)) { diff --git a/app/code/Magento/InventoryCatalog/Setup/Operation/UpdateInventorySourceItem.php b/app/code/Magento/InventoryCatalog/Setup/Operation/UpdateInventorySourceItem.php index 4a9be8da153f..776b6faeeed6 100644 --- a/app/code/Magento/InventoryCatalog/Setup/Operation/UpdateInventorySourceItem.php +++ b/app/code/Magento/InventoryCatalog/Setup/Operation/UpdateInventorySourceItem.php @@ -50,7 +50,7 @@ public function __construct( */ public function execute(ModuleDataSetupInterface $setup) { - $defaultSourceId = $this->defaultSourceProvider->getId(); + $defaultSourceCode = $this->defaultSourceProvider->getCode(); $sourceItemTable = $setup->getTable(SourceItem::TABLE_NAME_SOURCE_ITEM); $legacyStockItemTable = $setup->getTable('cataloginventory_stock_item'); $productTable = $setup->getTable('catalog_product_entity'); @@ -60,7 +60,7 @@ public function execute(ModuleDataSetupInterface $setup) ->from( $legacyStockItemTable, [ - 'source_id' => new \Zend_Db_Expr($defaultSourceId), + 'source_code' => new \Zend_Db_Expr($defaultSourceCode), 'qty', 'is_in_stock' ] @@ -72,7 +72,7 @@ public function execute(ModuleDataSetupInterface $setup) $selectForInsert, $sourceItemTable, [ - SourceItemInterface::SOURCE_ID, + SourceItemInterface::SOURCE_CODE, SourceItemInterface::QUANTITY, SourceItemInterface::STATUS, SourceItemInterface::SKU, diff --git a/app/code/Magento/InventoryCatalog/Ui/DataProvider/Product/Form/Modifier/Sources.php b/app/code/Magento/InventoryCatalog/Ui/DataProvider/Product/Form/Modifier/Sources.php index d6d61534cf7b..840510458fbe 100644 --- a/app/code/Magento/InventoryCatalog/Ui/DataProvider/Product/Form/Modifier/Sources.php +++ b/app/code/Magento/InventoryCatalog/Ui/DataProvider/Product/Form/Modifier/Sources.php @@ -75,14 +75,14 @@ private function getSourceItemsData(): array $collection->addFilter(SourceItemInterface::SKU, $product->getSku()); $collection->join( ['s' => $this->resourceConnection->getTableName(SourceResourceModel::TABLE_NAME_SOURCE)], - sprintf('s.%s = main_table.%s', SourceInterface::SOURCE_ID, SourceItemInterface::SOURCE_ID), + sprintf('s.%s = main_table.%s', SourceInterface::CODE, SourceItemInterface::SOURCE_CODE), ['source_name' => SourceInterface::NAME] ); $sourceItemsData = []; foreach ($collection->getData() as $row) { $sourceItemsData[] = [ - SourceItemInterface::SOURCE_ID => $row[SourceItemInterface::SOURCE_ID], + SourceItemInterface::SOURCE_CODE => $row[SourceItemInterface::SOURCE_CODE], SourceItemInterface::QUANTITY => $row[SourceItemInterface::QUANTITY], SourceItemInterface::STATUS => $row[SourceItemInterface::STATUS], SourceInterface::NAME => $row['source_name'], diff --git a/app/code/Magento/InventoryCatalog/view/adminhtml/ui_component/product_form.xml b/app/code/Magento/InventoryCatalog/view/adminhtml/ui_component/product_form.xml index 30b27eb2ebfa..bfe45f109b23 100644 --- a/app/code/Magento/InventoryCatalog/view/adminhtml/ui_component/product_form.xml +++ b/app/code/Magento/InventoryCatalog/view/adminhtml/ui_component/product_form.xml @@ -45,11 +45,11 @@ data.sources.assign_sources_grid - source_id + source_code name qty - source_id + source_code @@ -57,7 +57,7 @@ false false record - source_id + source_code ${ $.provider }:${ $.dataProvider } @@ -74,12 +74,12 @@ - + ui/dynamic-rows/cells/text text - source_id - + source_code + diff --git a/app/code/Magento/InventoryConfiguration/Model/ResourceModel/SourceItemConfiguration/Delete.php b/app/code/Magento/InventoryConfiguration/Model/ResourceModel/SourceItemConfiguration/Delete.php index 85ec1d86eba7..cc5f991547d3 100644 --- a/app/code/Magento/InventoryConfiguration/Model/ResourceModel/SourceItemConfiguration/Delete.php +++ b/app/code/Magento/InventoryConfiguration/Model/ResourceModel/SourceItemConfiguration/Delete.php @@ -31,18 +31,18 @@ public function __construct( } /** - * @param int $sourceId + * @param string $sourceCode * @param string $sku * @return void */ - public function execute(int $sourceId, string $sku) + public function execute(string $sourceCode, string $sku) { $connection = $this->resourceConnection->getConnection(); $sourceItemConfigurationTable = $this->resourceConnection ->getTableName(CreateSourceConfigurationTable::TABLE_NAME_SOURCE_ITEM_CONFIGURATION); $connection->delete($sourceItemConfigurationTable, [ - SourceItemConfigurationInterface::SOURCE_ID . ' = ?' => $sourceId, + SourceItemConfigurationInterface::SOURCE_CODE . ' = ?' => $sourceCode, SourceItemConfigurationInterface::SKU . ' = ?' => $sku, ]); } diff --git a/app/code/Magento/InventoryConfiguration/Model/ResourceModel/SourceItemConfiguration/GetData.php b/app/code/Magento/InventoryConfiguration/Model/ResourceModel/SourceItemConfiguration/GetData.php index 7067ea0deebc..cc81eae31b78 100644 --- a/app/code/Magento/InventoryConfiguration/Model/ResourceModel/SourceItemConfiguration/GetData.php +++ b/app/code/Magento/InventoryConfiguration/Model/ResourceModel/SourceItemConfiguration/GetData.php @@ -30,11 +30,11 @@ public function __construct(ResourceConnection $resourceConnection) } /** - * @param int $sourceId + * @param string $sourceCode * @param string $sku * @return array|null */ - public function execute(int $sourceId, string $sku) + public function execute(string $sourceCode, string $sku) { $connection = $this->resourceConnection->getConnection(); $sourceItemConfigurationTable = $this->resourceConnection @@ -42,7 +42,7 @@ public function execute(int $sourceId, string $sku) $select = $connection->select() ->from($sourceItemConfigurationTable) - ->where(SourceItemConfigurationInterface::SOURCE_ID . ' = ?', $sourceId) + ->where(SourceItemConfigurationInterface::SOURCE_CODE . ' = ?', $sourceCode) ->where(SourceItemConfigurationInterface::SKU . ' = ?', $sku); $row = $connection->fetchRow($select); diff --git a/app/code/Magento/InventoryConfiguration/Model/ResourceModel/SourceItemConfiguration/SaveMultiple.php b/app/code/Magento/InventoryConfiguration/Model/ResourceModel/SourceItemConfiguration/SaveMultiple.php index 9852ac57e3c1..734c757a9e1f 100644 --- a/app/code/Magento/InventoryConfiguration/Model/ResourceModel/SourceItemConfiguration/SaveMultiple.php +++ b/app/code/Magento/InventoryConfiguration/Model/ResourceModel/SourceItemConfiguration/SaveMultiple.php @@ -45,7 +45,7 @@ public function execute(array $sourceItemConfigurations) ->getTableName(CreateSourceConfigurationTable::TABLE_NAME_SOURCE_ITEM_CONFIGURATION); $columnsSql = $this->buildColumnsSqlPart([ - SourceItemConfigurationInterface::SOURCE_ID, + SourceItemConfigurationInterface::SOURCE_CODE, SourceItemConfigurationInterface::SKU, SourceItemConfigurationInterface::INVENTORY_NOTIFY_QTY ]); @@ -97,7 +97,7 @@ private function getSqlBindData(array $sourceItemConfigurations): array $bind = []; foreach ($sourceItemConfigurations as $sourceItemConfiguration) { $bind = array_merge($bind, [ - $sourceItemConfiguration->getSourceId(), + $sourceItemConfiguration->getSourceCode(), $sourceItemConfiguration->getSku(), $sourceItemConfiguration->getNotifyStockQty() ]); diff --git a/app/code/Magento/InventoryConfiguration/Model/SourceItemConfiguration.php b/app/code/Magento/InventoryConfiguration/Model/SourceItemConfiguration.php index df97d1ea365a..6986d557aed9 100644 --- a/app/code/Magento/InventoryConfiguration/Model/SourceItemConfiguration.php +++ b/app/code/Magento/InventoryConfiguration/Model/SourceItemConfiguration.php @@ -19,17 +19,17 @@ class SourceItemConfiguration extends AbstractExtensibleModel implements SourceI /** * @inheritdoc */ - public function getSourceId() + public function getSourceCode() { - return $this->getData(self::SOURCE_ID); + return $this->getData(self::SOURCE_CODE); } /** * @inheritdoc */ - public function setSourceId(int $sourceId) + public function setSourceCode(string $sourceCode) { - $this->setData(self::SOURCE_ID, $sourceId); + $this->setData(self::SOURCE_CODE, $sourceCode); } /** diff --git a/app/code/Magento/InventoryConfiguration/Model/SourceItemConfiguration/Command/Delete.php b/app/code/Magento/InventoryConfiguration/Model/SourceItemConfiguration/Command/Delete.php index 93c43a880653..1dc92a8363c7 100644 --- a/app/code/Magento/InventoryConfiguration/Model/SourceItemConfiguration/Command/Delete.php +++ b/app/code/Magento/InventoryConfiguration/Model/SourceItemConfiguration/Command/Delete.php @@ -42,10 +42,10 @@ public function __construct( /** * @inheritdoc */ - public function execute(int $sourceId, string $sku) + public function execute(string $sourceCode, string $sku) { try { - $this->deleteResourceModel->execute($sourceId, $sku); + $this->deleteResourceModel->execute($sourceCode, $sku); } catch (\Exception $e) { $this->logger->error($e->getMessage()); throw new CouldNotDeleteException(__('Could not delete SourceItem Configuration.'), $e); diff --git a/app/code/Magento/InventoryConfiguration/Model/SourceItemConfiguration/Command/Get.php b/app/code/Magento/InventoryConfiguration/Model/SourceItemConfiguration/Command/Get.php index 534a59332d55..0de225311254 100644 --- a/app/code/Magento/InventoryConfiguration/Model/SourceItemConfiguration/Command/Get.php +++ b/app/code/Magento/InventoryConfiguration/Model/SourceItemConfiguration/Command/Get.php @@ -70,14 +70,14 @@ public function __construct( /** * @inheritdoc */ - public function execute(int $sourceId, string $sku): SourceItemConfigurationInterface + public function execute(string $sourceCode, string $sku): SourceItemConfigurationInterface { - if (empty($sourceId) || empty($sku)) { + if (empty($sourceCode) || empty($sku)) { throw new InputException(__('Wrong input data')); } try { - return $this->getConfiguration($sourceId, $sku); + return $this->getConfiguration($sourceCode, $sku); } catch (\Exception $e) { $this->logger->error($e->getMessage()); throw new LocalizedException(__('Could not load Source Item Configuration.'), $e); @@ -85,16 +85,16 @@ public function execute(int $sourceId, string $sku): SourceItemConfigurationInte } /** - * @param int $sourceId + * @param string $sourceCode * @param string $sku * @return SourceItemConfigurationInterface */ - private function getConfiguration(int $sourceId, string $sku): SourceItemConfigurationInterface + private function getConfiguration(string $sourceCode, string $sku): SourceItemConfigurationInterface { - $sourceItemConfigurationData = $this->getDataResourceModel->execute($sourceId, $sku); + $sourceItemConfigurationData = $this->getDataResourceModel->execute($sourceCode, $sku); if (null === $sourceItemConfigurationData) { - $sourceItemConfigurationData = $this->getDefaultValues->execute($sourceId, $sku); + $sourceItemConfigurationData = $this->getDefaultValues->execute($sourceCode, $sku); } /** @var SourceItemConfigurationInterface $sourceItem */ diff --git a/app/code/Magento/InventoryConfiguration/Model/SourceItemConfiguration/Command/GetDefaultValues.php b/app/code/Magento/InventoryConfiguration/Model/SourceItemConfiguration/Command/GetDefaultValues.php index e85ef95b7101..02d5d71c7516 100644 --- a/app/code/Magento/InventoryConfiguration/Model/SourceItemConfiguration/Command/GetDefaultValues.php +++ b/app/code/Magento/InventoryConfiguration/Model/SourceItemConfiguration/Command/GetDefaultValues.php @@ -35,16 +35,16 @@ public function __construct( } /** - * @param int $sourceId + * @param string $sourceCode * @param string $sku * @return array */ - public function execute(int $sourceId, string $sku) : array + public function execute(string $sourceCode, string $sku) : array { $inventoryNotifyQty = (float)$this->scopeConfig->getValue(self::XML_PATH_NOTIFY_STOCK_QTY); $defaultConfiguration = [ - SourceItemConfigurationInterface::SOURCE_ID => $sourceId, + SourceItemConfigurationInterface::SOURCE_CODE => $sourceCode, SourceItemConfigurationInterface::SKU => $sku, SourceItemConfigurationInterface::INVENTORY_NOTIFY_QTY => $inventoryNotifyQty, ]; diff --git a/app/code/Magento/InventoryConfiguration/Observer/SourceItemsConfigurationProcessor.php b/app/code/Magento/InventoryConfiguration/Observer/SourceItemsConfigurationProcessor.php index 648477e6e6b2..4b0e1e2b5334 100644 --- a/app/code/Magento/InventoryConfiguration/Observer/SourceItemsConfigurationProcessor.php +++ b/app/code/Magento/InventoryConfiguration/Observer/SourceItemsConfigurationProcessor.php @@ -73,9 +73,9 @@ public function process($sku, array $sourceItemsData) foreach ($sourceItemsData as $sourceItemData) { $this->validateSourceItemData($sourceItemData); - $sourceId = $sourceItemData[SourceItemInterface::SOURCE_ID]; - if (isset($sourceItemsForDelete[$sourceId])) { - $sourceItem = $sourceItemsForDelete[$sourceId]; + $sourceCode = $sourceItemData[SourceItemInterface::SOURCE_CODE]; + if (isset($sourceItemsForDelete[$sourceCode])) { + $sourceItem = $sourceItemsForDelete[$sourceCode]; } else { /** @var SourceItemInterface $sourceItem */ $sourceItem = $this->sourceItemConfigurationFactory->create(); @@ -89,7 +89,7 @@ public function process($sku, array $sourceItemsData) ); $sourceItemsForSave[] = $sourceItem; - unset($sourceItemsForDelete[$sourceId]); + unset($sourceItemsForDelete[$sourceCode]); } if ($sourceItemsForSave) { $this->sourceItemConfigurationSave->execute($sourceItemsForSave); @@ -112,8 +112,8 @@ private function getCurrentSourceItemsMap(string $sku, array $sourceItemsData): /** @var \Magento\Inventory\Model\SourceItem $sourceItem */ foreach ($sourceItemsData as $sourceItem) { - $sourceId = $sourceItem[SourceItemInterface::SOURCE_ID]; - $sourceItemConfig = $this->getSourceItemConfiguration->execute((int)$sourceId, $sku); + $sourceCode = $sourceItem[SourceItemInterface::SOURCE_CODE]; + $sourceItemConfig = $this->getSourceItemConfiguration->execute((string)$sourceCode, $sku); if (null !== $sourceItemConfig) { $sourceItems[] = $sourceItemConfig; @@ -123,7 +123,7 @@ private function getCurrentSourceItemsMap(string $sku, array $sourceItemsData): $sourceItemMap = []; if ($sourceItems) { foreach ($sourceItems as $sourceItem) { - $sourceItemMap[(int)$sourceItem[SourceItemInterface::SOURCE_ID]] = $sourceItem; + $sourceItemMap[(string)$sourceItem[SourceItemInterface::SOURCE_CODE]] = $sourceItem; } } return $sourceItemMap; @@ -136,7 +136,7 @@ private function getCurrentSourceItemsMap(string $sku, array $sourceItemsData): */ private function validateSourceItemData(array $sourceItemData) { - if (!isset($sourceItemData[SourceItemInterface::SOURCE_ID])) { + if (!isset($sourceItemData[SourceItemInterface::SOURCE_CODE])) { throw new InputException(__('Wrong Product to Source relation parameters given.')); } } @@ -150,7 +150,7 @@ private function deleteSourceItemsConfiguration(array $sourceItemsConfigurations /** @var SourceItemInterface $sourceItemConfiguration */ foreach ($sourceItemsConfigurations as $sourceItemConfiguration) { $this->sourceItemConfigurationDelete->execute( - $sourceItemConfiguration->getSourceId(), + $sourceItemConfiguration->getSourceCode(), $sourceItemConfiguration->getSku() ); } diff --git a/app/code/Magento/InventoryConfiguration/Setup/Operation/CreateSourceConfigurationTable.php b/app/code/Magento/InventoryConfiguration/Setup/Operation/CreateSourceConfigurationTable.php index e9fb15dbc3d4..9f1cfebd7947 100644 --- a/app/code/Magento/InventoryConfiguration/Setup/Operation/CreateSourceConfigurationTable.php +++ b/app/code/Magento/InventoryConfiguration/Setup/Operation/CreateSourceConfigurationTable.php @@ -50,14 +50,13 @@ public function execute(SchemaSetupInterface $setup) private function addBaseFields(Table $sourceItemConfigurationTable): Table { return $sourceItemConfigurationTable->addColumn( - SourceItemConfigurationInterface::SOURCE_ID, - Table::TYPE_INTEGER, - null, + SourceItemConfigurationInterface::SOURCE_CODE, + Table::TYPE_TEXT, + 255, [ - Table::OPTION_UNSIGNED => true, Table::OPTION_NULLABLE => false, ], - 'Source ID' + 'Source Code' )->addColumn( SourceItemInterface::SKU, Table::TYPE_TEXT, @@ -80,7 +79,7 @@ private function addBaseFields(Table $sourceItemConfigurationTable): Table 'Notify Quantity' )->addIndex( 'idx_primary', - [SourceItemConfigurationInterface::SOURCE_ID, SourceItemInterface::SKU], + [SourceItemConfigurationInterface::SOURCE_CODE, SourceItemInterface::SKU], ['type' => AdapterInterface::INDEX_TYPE_PRIMARY] ); } @@ -101,13 +100,13 @@ private function addForeignKey( return $sourceItemConfigurationTable->addForeignKey( $setup->getFkName( $sourceItemConfigurationTable->getName(), - SourceItemConfigurationInterface::SOURCE_ID, + SourceItemConfigurationInterface::SOURCE_CODE, $sourceItemTable, - SourceInterface::SOURCE_ID + SourceInterface::CODE ), - SourceItemConfigurationInterface::SOURCE_ID, + SourceItemConfigurationInterface::SOURCE_CODE, $sourceItemTable, - SourceInterface::SOURCE_ID, + SourceInterface::CODE, AdapterInterface::FK_ACTION_CASCADE ); } diff --git a/app/code/Magento/InventoryConfiguration/Ui/DataProvider/Product/Form/Modifier/SourceItemConfiguration.php b/app/code/Magento/InventoryConfiguration/Ui/DataProvider/Product/Form/Modifier/SourceItemConfiguration.php index 1bd4b78b30b0..6435051c43ba 100644 --- a/app/code/Magento/InventoryConfiguration/Ui/DataProvider/Product/Form/Modifier/SourceItemConfiguration.php +++ b/app/code/Magento/InventoryConfiguration/Ui/DataProvider/Product/Form/Modifier/SourceItemConfiguration.php @@ -65,7 +65,7 @@ private function getSourceItemsConfigurationData(array $assignedSources, Product { foreach ($assignedSources as &$source) { $sourceConfiguration = $this->getSourceItemConfiguration->execute( - (int)$source[SourceInterface::SOURCE_ID], + (string)$source[SourceInterface::CODE], $product->getSku() ); diff --git a/app/code/Magento/InventoryConfiguration/view/adminhtml/ui_component/product_form.xml b/app/code/Magento/InventoryConfiguration/view/adminhtml/ui_component/product_form.xml index 513d3c89d4cc..3bbe8298ea41 100644 --- a/app/code/Magento/InventoryConfiguration/view/adminhtml/ui_component/product_form.xml +++ b/app/code/Magento/InventoryConfiguration/view/adminhtml/ui_component/product_form.xml @@ -13,7 +13,7 @@ notify_stock_qty - source_id + source_code diff --git a/app/code/Magento/InventoryConfigurationApi/Api/Data/SourceItemConfigurationInterface.php b/app/code/Magento/InventoryConfigurationApi/Api/Data/SourceItemConfigurationInterface.php index a2983729e249..72dde5faff45 100644 --- a/app/code/Magento/InventoryConfigurationApi/Api/Data/SourceItemConfigurationInterface.php +++ b/app/code/Magento/InventoryConfigurationApi/Api/Data/SourceItemConfigurationInterface.php @@ -21,24 +21,24 @@ interface SourceItemConfigurationInterface extends ExtensibleDataInterface /** * Constant for fields in data array */ - const SOURCE_ID = 'source_id'; + const SOURCE_CODE = 'source_code'; const SKU = 'sku'; const INVENTORY_NOTIFY_QTY = 'notify_stock_qty'; /** - * Get source id + * Get source code * - * @return int|null + * @return string|null */ - public function getSourceId(); + public function getSourceCode(); /** - * Set source id + * Set source code * - * @param int $sourceId + * @param int $sourceCode * @return void */ - public function setSourceId(int $sourceId); + public function setSourceCode(string $sourceCode); /** * Get notify stock qty diff --git a/app/code/Magento/InventoryConfigurationApi/Api/DeleteSourceItemConfigurationInterface.php b/app/code/Magento/InventoryConfigurationApi/Api/DeleteSourceItemConfigurationInterface.php index 2f1fc53140ad..1edcdadc2448 100644 --- a/app/code/Magento/InventoryConfigurationApi/Api/DeleteSourceItemConfigurationInterface.php +++ b/app/code/Magento/InventoryConfigurationApi/Api/DeleteSourceItemConfigurationInterface.php @@ -15,9 +15,9 @@ interface DeleteSourceItemConfigurationInterface { /** - * @param int $sourceId + * @param string $sourceCode * @param string $sku * @return void */ - public function execute(int $sourceId, string $sku); + public function execute(string $sourceCode, string $sku); } diff --git a/app/code/Magento/InventoryConfigurationApi/Api/GetSourceItemConfigurationInterface.php b/app/code/Magento/InventoryConfigurationApi/Api/GetSourceItemConfigurationInterface.php index 44da3d8e80a1..2863ab4f3dd6 100644 --- a/app/code/Magento/InventoryConfigurationApi/Api/GetSourceItemConfigurationInterface.php +++ b/app/code/Magento/InventoryConfigurationApi/Api/GetSourceItemConfigurationInterface.php @@ -22,10 +22,10 @@ interface GetSourceItemConfigurationInterface /** * Get the source item configuration * - * @param int $sourceId + * @param string $sourceCode * @param string $sku * @return \Magento\InventoryConfigurationApi\Api\Data\SourceItemConfigurationInterface * @throws \Magento\Framework\Exception\LocalizedException */ - public function execute(int $sourceId, string $sku): SourceItemConfigurationInterface; + public function execute(string $sourceCode, string $sku): SourceItemConfigurationInterface; } diff --git a/app/code/Magento/InventoryConfigurationApi/Test/Api/GetSourceItemConfigurationTest.php b/app/code/Magento/InventoryConfigurationApi/Test/Api/GetSourceItemConfigurationTest.php index fbefcbdb4284..cf435ba9f47a 100644 --- a/app/code/Magento/InventoryConfigurationApi/Test/Api/GetSourceItemConfigurationTest.php +++ b/app/code/Magento/InventoryConfigurationApi/Test/Api/GetSourceItemConfigurationTest.php @@ -23,12 +23,12 @@ class GetSourceItemConfigurationTest extends WebapiAbstract */ public function testGetSourceItemConfiguration() { - $sourceId = 10; + $sourceCode = 'eu-1'; $sku = 'SKU-1'; $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceId . '/' . $sku, + 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceCode . '/' . $sku, 'httpMethod' => Request::HTTP_METHOD_GET, ], 'soap' => [ @@ -39,12 +39,12 @@ public function testGetSourceItemConfiguration() $sourceItemConfiguration = (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST) ? $this->_webApiCall($serviceInfo) - : $this->_webApiCall($serviceInfo, ['sourceId' => $sourceId, 'sku' => $sku]); + : $this->_webApiCall($serviceInfo, ['sourceCode' => $sourceCode, 'sku' => $sku]); self::assertInternalType('array', $sourceItemConfiguration); self::assertNotEmpty($sourceItemConfiguration); - self::assertEquals($sourceId, $sourceItemConfiguration[SourceItemConfigurationInterface::SOURCE_ID]); + self::assertEquals($sourceCode, $sourceItemConfiguration[SourceItemConfigurationInterface::SOURCE_CODE]); self::assertEquals($sku, $sourceItemConfiguration[SourceItemConfigurationInterface::SKU]); self::assertEquals(2, $sourceItemConfiguration[SourceItemConfigurationInterface::INVENTORY_NOTIFY_QTY]); } diff --git a/app/code/Magento/InventoryConfigurationApi/Test/Api/SourceItemConfigurationsSaveTest.php b/app/code/Magento/InventoryConfigurationApi/Test/Api/SourceItemConfigurationsSaveTest.php index 829b2a5dc892..4a045af33e03 100644 --- a/app/code/Magento/InventoryConfigurationApi/Test/Api/SourceItemConfigurationsSaveTest.php +++ b/app/code/Magento/InventoryConfigurationApi/Test/Api/SourceItemConfigurationsSaveTest.php @@ -25,12 +25,12 @@ public function testSaveSourceItemConfiguration() { $sourceItemConfigurations = [ [ - SourceItemConfigurationInterface::SOURCE_ID => 10, + SourceItemConfigurationInterface::SOURCE_CODE => 'eu-1', SourceItemConfigurationInterface::SKU => 'SKU-1', SourceItemConfigurationInterface::INVENTORY_NOTIFY_QTY => 2, ], [ - SourceItemConfigurationInterface::SOURCE_ID => 20, + SourceItemConfigurationInterface::SOURCE_CODE => 'eu-2', SourceItemConfigurationInterface::SKU => 'SKU-1', SourceItemConfigurationInterface::INVENTORY_NOTIFY_QTY => 1, ] @@ -49,23 +49,23 @@ public function testSaveSourceItemConfiguration() $this->_webApiCall($serviceInfo, ['sourceItemConfigurations' => $sourceItemConfigurations]); - $sourceItemConfiguration = $this->getSourceItemConfiguration(10, 'SKU-1'); + $sourceItemConfiguration = $this->getSourceItemConfiguration('eu-1', 'SKU-1'); self::assertEquals($sourceItemConfigurations[0], $sourceItemConfiguration); - $sourceItemConfiguration = $this->getSourceItemConfiguration(20, 'SKU-1'); + $sourceItemConfiguration = $this->getSourceItemConfiguration('eu-2', 'SKU-1'); self::assertEquals($sourceItemConfigurations[1], $sourceItemConfiguration); } /** - * @param int $sourceId + * @param string $sourceCode * @param string $sku * @return array */ - private function getSourceItemConfiguration(int $sourceId, string $sku) + private function getSourceItemConfiguration(string $sourceCode, string $sku) { $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceId . '/' . $sku, + 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceCode . '/' . $sku, 'httpMethod' => Request::HTTP_METHOD_GET, ], 'soap' => [ @@ -75,7 +75,7 @@ private function getSourceItemConfiguration(int $sourceId, string $sku) ]; $sourceItemConfiguration = (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST) ? $this->_webApiCall($serviceInfo) - : $this->_webApiCall($serviceInfo, ['sourceId' => $sourceId, 'sku' => $sku]); + : $this->_webApiCall($serviceInfo, ['sourceId' => $sourceCode, 'sku' => $sku]); self::assertInternalType('array', $sourceItemConfiguration); self::assertNotEmpty($sourceItemConfiguration); diff --git a/app/code/Magento/InventoryConfigurationApi/Test/_files/source_item_configuration.php b/app/code/Magento/InventoryConfigurationApi/Test/_files/source_item_configuration.php index bcba42fd859a..a8c1323ab65e 100644 --- a/app/code/Magento/InventoryConfigurationApi/Test/_files/source_item_configuration.php +++ b/app/code/Magento/InventoryConfigurationApi/Test/_files/source_item_configuration.php @@ -19,7 +19,7 @@ $sourceItemConfigurationsSave = Bootstrap::getObjectManager()->get(SourceItemConfigurationsSaveInterface::class); $inventoryConfigurationData = [ - SourceItemConfigurationInterface::SOURCE_ID => 10, + SourceItemConfigurationInterface::SOURCE_CODE => 'eu-1', SourceItemConfigurationInterface::SKU => 'SKU-1', SourceItemConfigurationInterface::INVENTORY_NOTIFY_QTY => 2.000, ]; diff --git a/app/code/Magento/InventoryConfigurationApi/etc/webapi.xml b/app/code/Magento/InventoryConfigurationApi/etc/webapi.xml index d287ef707c65..a0b0b2cf22ff 100644 --- a/app/code/Magento/InventoryConfigurationApi/etc/webapi.xml +++ b/app/code/Magento/InventoryConfigurationApi/etc/webapi.xml @@ -6,7 +6,7 @@ --> - + diff --git a/app/code/Magento/InventoryImportExport/Model/Export/AttributeCollectionProvider.php b/app/code/Magento/InventoryImportExport/Model/Export/AttributeCollectionProvider.php index 6c3b56bf0378..d4177ac20b91 100644 --- a/app/code/Magento/InventoryImportExport/Model/Export/AttributeCollectionProvider.php +++ b/app/code/Magento/InventoryImportExport/Model/Export/AttributeCollectionProvider.php @@ -10,7 +10,6 @@ use Magento\Eav\Model\Entity\AttributeFactory; use Magento\Framework\Data\Collection; use Magento\ImportExport\Model\Export\Factory as CollectionFactory; -use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceItemInterface; use Magento\InventoryImportExport\Model\Export\Source\StockStatus; @@ -49,11 +48,11 @@ public function __construct( public function get(): Collection { if (count($this->collection) === 0) { - /** @var \Magento\Eav\Model\Entity\Attribute $sourceIdAttribute */ + /** @var \Magento\Eav\Model\Entity\Attribute $sourceCodeAttribute */ $sourceCodeAttribute = $this->attributeFactory->create(); - $sourceCodeAttribute->setId('source_' . SourceInterface::CODE); - $sourceCodeAttribute->setDefaultFrontendLabel('source_' . SourceInterface::CODE); - $sourceCodeAttribute->setAttributeCode('source_' . SourceInterface::CODE); + $sourceCodeAttribute->setId(SourceItemInterface::SOURCE_CODE); + $sourceCodeAttribute->setDefaultFrontendLabel(SourceItemInterface::SOURCE_CODE); + $sourceCodeAttribute->setAttributeCode(SourceItemInterface::SOURCE_CODE); $sourceCodeAttribute->setBackendType('varchar'); $this->collection->addItem($sourceCodeAttribute); diff --git a/app/code/Magento/InventoryImportExport/Model/Export/SourceItemCollectionFactory.php b/app/code/Magento/InventoryImportExport/Model/Export/SourceItemCollectionFactory.php index 41572c9a8b5d..657e10ea0824 100644 --- a/app/code/Magento/InventoryImportExport/Model/Export/SourceItemCollectionFactory.php +++ b/app/code/Magento/InventoryImportExport/Model/Export/SourceItemCollectionFactory.php @@ -78,15 +78,6 @@ public function create(AttributeCollection $attributeCollection, array $filters) /** @var Collection $collection */ $collection = $this->objectManager->create(Collection::class); $columns = $this->columnProvider->getColumns($attributeCollection, $filters); - if (($key = array_search(self::SOURCE_CODE_FIELD, $columns)) !== false) { - unset($columns[$key]); - $collection->join( - ['s' => $this->resourceConnection->getTableName(SourceResourceModel::TABLE_NAME_SOURCE)], - sprintf('s.%s = main_table.%s', SourceInterface::SOURCE_ID, SourceItemInterface::SOURCE_ID), - ['source_code' => SourceInterface::CODE] - ); - $collection->addFilterToMap('source_code', sprintf('s.%s', SourceInterface::CODE)); - } $collection->addFieldToSelect($columns); foreach ($this->retrieveFilterData($filters) as $columnName => $value) { diff --git a/app/code/Magento/InventoryImportExport/Model/Import/Command/Replace.php b/app/code/Magento/InventoryImportExport/Model/Import/Command/Replace.php index 17131d140009..45289121a89b 100644 --- a/app/code/Magento/InventoryImportExport/Model/Import/Command/Replace.php +++ b/app/code/Magento/InventoryImportExport/Model/Import/Command/Replace.php @@ -49,7 +49,7 @@ public function __construct( /** * {@inheritdoc} * - * If an SKU and SOURCE_ID in the import data matches the SKU and SOURCE_ID of an existing entity, + * If an SKU and SOURCE_CODE in the import data matches the SKU and SOURCE_CODE of an existing entity, * all fields are deleted and new a record is created. */ public function execute(array $bunch) diff --git a/app/code/Magento/InventoryImportExport/Model/Import/Sources.php b/app/code/Magento/InventoryImportExport/Model/Import/Sources.php index 5559d0597097..56746c514d59 100644 --- a/app/code/Magento/InventoryImportExport/Model/Import/Sources.php +++ b/app/code/Magento/InventoryImportExport/Model/Import/Sources.php @@ -28,8 +28,7 @@ class Sources extends AbstractEntity * Column names for import file */ const COL_SKU = SourceItemInterface::SKU; - const COL_SOURCE = SourceItemInterface::SOURCE_ID; - const COL_SOURCE_CODE = 'source_' . SourceInterface::CODE; + const COL_SOURCE_CODE = SourceItemInterface::SOURCE_CODE; const COL_QTY = SourceItemInterface::QUANTITY; const COL_STATUS = SourceItemInterface::STATUS; diff --git a/app/code/Magento/InventoryImportExport/Model/Import/Validator/SourceValidator.php b/app/code/Magento/InventoryImportExport/Model/Import/Validator/SourceValidator.php index ed6bd51dac4f..53fd1acc06e5 100644 --- a/app/code/Magento/InventoryImportExport/Model/Import/Validator/SourceValidator.php +++ b/app/code/Magento/InventoryImportExport/Model/Import/Validator/SourceValidator.php @@ -80,9 +80,8 @@ private function loadSourceCodes() { $sources = $this->sourceRepository->getList(); foreach ($sources->getItems() as $source) { - $sourceId = $source->getSourceId(); $sourceCode = $source->getCode(); - $this->sourceCodes[$sourceCode] = $sourceId; + $this->sourceCodes[$sourceCode] = $sourceCode; } } } diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php index d9975df6208a..d6e96823da4e 100755 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php @@ -212,7 +212,7 @@ public function testImportDataWithReplaceBehaviorNoAffectOtherSources() } /** - * @param int $sourceID + * @param string $sourceCode * @param string $sku * @param int $qty * @param int $status diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/StockItemImporterTest.php b/app/code/Magento/InventoryImportExport/Test/Integration/Model/StockItemImporterTest.php index 403a336662bf..32628c255206 100755 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/StockItemImporterTest.php +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/StockItemImporterTest.php @@ -77,7 +77,7 @@ public function testSourceItemImportWithDefaultSource() $expectedData = [ SourceItemInterface::SKU => $stockData['sku'], SourceItemInterface::QUANTITY => '1.0000', - SourceItemInterface::SOURCE_ID => (string) $this->defaultSourceProvider->getId(), + SourceItemInterface::SOURCE_CODE => (string) $this->defaultSourceProvider->getCode(), SourceItemInterface::STATUS => (string) SourceItemInterface::STATUS_IN_STOCK ]; @@ -101,8 +101,8 @@ private function getSourceItemList() ); $searchCriteriaBuilder->addFilter( - SourceItemInterface::SOURCE_ID, - $this->defaultSourceProvider->getId() + SourceItemInterface::SOURCE_CODE, + $this->defaultSourceProvider->getCode() ); /** @var SearchCriteria $searchCriteria */ From c0705214cead0120614de199f8d6c7b269e42222 Mon Sep 17 00:00:00 2001 From: deadlexus Date: Thu, 21 Dec 2017 01:24:08 +0300 Subject: [PATCH 08/39] MSI: issue #290 - fixed foreign key issue with source_item_configuration setup schema; - tests fixes - part; --- .../{SourceIdValidator.php => SourceCodeValidator.php} | 0 .../Inventory/Test/Unit/Model/SourceRepositoryTest.php | 10 +++++----- .../Setup/Operation/CreateSourceConfigurationTable.php | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) rename app/code/Magento/Inventory/Model/SourceItem/Validator/{SourceIdValidator.php => SourceCodeValidator.php} (100%) mode change 100755 => 100644 diff --git a/app/code/Magento/Inventory/Model/SourceItem/Validator/SourceIdValidator.php b/app/code/Magento/Inventory/Model/SourceItem/Validator/SourceCodeValidator.php old mode 100755 new mode 100644 similarity index 100% rename from app/code/Magento/Inventory/Model/SourceItem/Validator/SourceIdValidator.php rename to app/code/Magento/Inventory/Model/SourceItem/Validator/SourceCodeValidator.php diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php index 1423f3584a97..0282fe62e087 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php @@ -99,7 +99,7 @@ public function testSaveWithCouldNotSaveException() public function testGet() { - $sourceId = 42; + $sourceCode = 'default'; $this->commandGet ->expects($this->once()) @@ -107,7 +107,7 @@ public function testGet() ->with($sourceId) ->willReturn($this->source); - self::assertEquals($this->source, $this->sourceRepository->get($sourceId)); + self::assertEquals($this->source, $this->sourceRepository->get($sourceCode)); } /** @@ -116,15 +116,15 @@ public function testGet() */ public function testGetWithNoSuchEntityException() { - $sourceId = 42; + $sourceCode = 'default'; $this->commandGet ->expects($this->once()) ->method('execute') - ->with($sourceId) + ->with($sourceCode) ->willThrowException(new NoSuchEntityException(__('Some error'))); - $this->sourceRepository->get($sourceId); + $this->sourceRepository->get($sourceCode); } public function testGetListWithoutSearchCriteria() diff --git a/app/code/Magento/InventoryConfiguration/Setup/Operation/CreateSourceConfigurationTable.php b/app/code/Magento/InventoryConfiguration/Setup/Operation/CreateSourceConfigurationTable.php index 9f1cfebd7947..57241dfd9675 100644 --- a/app/code/Magento/InventoryConfiguration/Setup/Operation/CreateSourceConfigurationTable.php +++ b/app/code/Magento/InventoryConfiguration/Setup/Operation/CreateSourceConfigurationTable.php @@ -14,7 +14,6 @@ use Magento\Inventory\Model\ResourceModel\SourceItem; use Magento\InventoryApi\Api\Data\SourceItemInterface; use Magento\InventoryConfigurationApi\Api\Data\SourceItemConfigurationInterface; -use Magento\InventoryApi\Api\Data\SourceInterface; class CreateSourceConfigurationTable { @@ -102,11 +101,11 @@ private function addForeignKey( $sourceItemConfigurationTable->getName(), SourceItemConfigurationInterface::SOURCE_CODE, $sourceItemTable, - SourceInterface::CODE + SourceItemInterface::SOURCE_CODE ), SourceItemConfigurationInterface::SOURCE_CODE, $sourceItemTable, - SourceInterface::CODE, + SourceItemInterface::SOURCE_CODE, AdapterInterface::FK_ACTION_CASCADE ); } From bb971db9c4a5ea8a52781738d48547d19cad9c5a Mon Sep 17 00:00:00 2001 From: deadlexus Date: Thu, 21 Dec 2017 01:54:10 +0300 Subject: [PATCH 09/39] MSI: issue #290 - Fixed setup schema script for creatind default source; - Tests fexes - part; --- app/code/Magento/Inventory/Indexer/SelectBuilder.php | 6 +++++- .../Inventory/Indexer/SourceItem/GetSkuListInStock.php | 6 +++++- .../Setup/Operation/CreateSourceCarrierLinkTable.php | 6 +++--- .../Inventory/Test/Unit/Model/SourceRepositoryTest.php | 2 +- .../InventoryApi/Api/Data/SourceCarrierLinkInterface.php | 1 + .../Setup/Operation/CreateDefaultSource.php | 1 - 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Inventory/Indexer/SelectBuilder.php b/app/code/Magento/Inventory/Indexer/SelectBuilder.php index aca443c798e1..26c3862260b9 100644 --- a/app/code/Magento/Inventory/Indexer/SelectBuilder.php +++ b/app/code/Magento/Inventory/Indexer/SelectBuilder.php @@ -71,7 +71,11 @@ public function execute($stockId): Select ) ->joinLeft( ['stock_source_link' => $sourceStockLinkTable], - 'source_item.' . SourceItemInterface::SOURCE_CODE . ' = stock_source_link.' . StockSourceLink::SOURCE_CODE, + sprintf( + 'source_item.%s = stock_source_link.%s', + SourceItemInterface::SOURCE_CODE, + StockSourceLink::SOURCE_CODE + ), [] ) ->where('stock_source_link.' . StockSourceLink::STOCK_ID . ' = ?', $stockId) diff --git a/app/code/Magento/Inventory/Indexer/SourceItem/GetSkuListInStock.php b/app/code/Magento/Inventory/Indexer/SourceItem/GetSkuListInStock.php index a1dd48eea313..e1f11955cd0a 100644 --- a/app/code/Magento/Inventory/Indexer/SourceItem/GetSkuListInStock.php +++ b/app/code/Magento/Inventory/Indexer/SourceItem/GetSkuListInStock.php @@ -76,7 +76,11 @@ public function execute(array $sourceItemIds): array ] )->joinInner( ['stock_source_link' => $sourceStockLinkTable], - 'source_item.' . SourceItemInterface::SOURCE_CODE . ' = stock_source_link.' . StockSourceLink::SOURCE_CODE, + sprintf( + 'source_item.%s = stock_source_link.%s', + SourceItemInterface::SOURCE_CODE, + StockSourceLink::SOURCE_CODE + ), [StockSourceLink::STOCK_ID] )->where('source_item.source_item_id IN (?)', $sourceItemIds) ->group(['stock_source_link.' . StockSourceLink::STOCK_ID]); diff --git a/app/code/Magento/Inventory/Setup/Operation/CreateSourceCarrierLinkTable.php b/app/code/Magento/Inventory/Setup/Operation/CreateSourceCarrierLinkTable.php index d6370f481f9d..8c0aead9da1a 100644 --- a/app/code/Magento/Inventory/Setup/Operation/CreateSourceCarrierLinkTable.php +++ b/app/code/Magento/Inventory/Setup/Operation/CreateSourceCarrierLinkTable.php @@ -53,7 +53,7 @@ private function createSourceCarrierLinkTable(SchemaSetupInterface $setup): Tabl ], 'Source Carrier Link ID' )->addColumn( - SourceInterface::CODE, + SourceCarrierLinkInterface::SOURCE_CODE, Table::TYPE_TEXT, 255, [ @@ -80,11 +80,11 @@ private function createSourceCarrierLinkTable(SchemaSetupInterface $setup): Tabl )->addForeignKey( $setup->getFkName( $sourceCarrierLinkTable, - SourceInterface::CODE, + SourceCarrierLinkInterface::SOURCE_CODE, $sourceTable, SourceInterface::CODE ), - SourceInterface::CODE, + SourceCarrierLinkInterface::SOURCE_CODE, $sourceTable, SourceInterface::CODE, AdapterInterface::FK_ACTION_CASCADE diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php index 0282fe62e087..65080df394b9 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php @@ -104,7 +104,7 @@ public function testGet() $this->commandGet ->expects($this->once()) ->method('execute') - ->with($sourceId) + ->with($sourceCode) ->willReturn($this->source); self::assertEquals($this->source, $this->sourceRepository->get($sourceCode)); diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php index 4b6acd8069dd..27c4b476ee41 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceCarrierLinkInterface.php @@ -23,6 +23,7 @@ interface SourceCarrierLinkInterface extends ExtensibleDataInterface */ const CARRIER_CODE = 'carrier_code'; const POSITION = 'position'; + const SOURCE_CODE = 'source_code'; /**#@-*/ /** diff --git a/app/code/Magento/InventoryCatalog/Setup/Operation/CreateDefaultSource.php b/app/code/Magento/InventoryCatalog/Setup/Operation/CreateDefaultSource.php index 7cfdefd894ab..9c0bc0b60b61 100644 --- a/app/code/Magento/InventoryCatalog/Setup/Operation/CreateDefaultSource.php +++ b/app/code/Magento/InventoryCatalog/Setup/Operation/CreateDefaultSource.php @@ -64,7 +64,6 @@ public function __construct( public function execute() { $data = [ - SourceInterface::SOURCE_ID => $this->defaultSourceProvider->getId(), SourceInterface::CODE => 'default', SourceInterface::NAME => 'Default Source', SourceInterface::ENABLED => 1, From 84610237d71278c5188d87c6316262ec4fa516b8 Mon Sep 17 00:00:00 2001 From: deadlexus Date: Thu, 21 Dec 2017 22:10:13 +0300 Subject: [PATCH 10/39] MSI: issue #290 - fixed install schema/data issues; - fixed issues on Source grid; - identity field returned to source_id on Source mode; --- .../Controller/Adminhtml/Source/Edit.php | 6 +- .../Adminhtml/Source/InlineEdit.php | 16 +++--- .../Controller/Adminhtml/Source/Save.php | 42 +++++++------- .../Inventory/Model/ResourceModel/Source.php | 2 +- .../Model/Source/Command/GetBySourceId.php | 56 +++++++++++++++++++ .../Source/Command/GetBySourceIdInterface.php | 33 +++++++++++ .../Inventory/Model/Source/Command/Save.php | 4 +- .../Model/Source/Command/SaveInterface.php | 4 +- .../Model/SourceCarrierLinkManagement.php | 2 +- .../Inventory/Model/SourceRepository.php | 19 ++++++- .../Ui/DataProvider/SourceDataProvider.php | 5 +- app/code/Magento/Inventory/etc/di.xml | 2 +- .../ui_component/inventory_source_form.xml | 4 +- .../ui_component/inventory_source_listing.xml | 18 ++---- .../Api/SourceRepositoryInterface.php | 16 +++++- .../Setup/Operation/AssignSourceToStock.php | 2 +- .../Operation/UpdateInventorySourceItem.php | 2 +- 17 files changed, 172 insertions(+), 61 deletions(-) create mode 100644 app/code/Magento/Inventory/Model/Source/Command/GetBySourceId.php create mode 100644 app/code/Magento/Inventory/Model/Source/Command/GetBySourceIdInterface.php diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php index 8ab65da3d897..b8d323976af5 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php @@ -49,9 +49,9 @@ public function __construct( */ public function execute(): ResultInterface { - $sourceCode = (string)$this->getRequest()->getParam(SourceInterface::CODE); + $sourceId = (int)$this->getRequest()->getParam(SourceInterface::SOURCE_ID); try { - $source = $this->sourceRepository->get($sourceCode); + $source = $this->sourceRepository->getBySourceId($sourceId); /** @var Page $result */ $result = $this->resultFactory->create(ResultFactory::TYPE_PAGE); @@ -64,7 +64,7 @@ public function execute(): ResultInterface /** @var Redirect $result */ $result = $this->resultRedirectFactory->create(); $this->messageManager->addErrorMessage( - __('Source with code "%value" does not exist.', ['value' => $sourceCode]) + __('Source with source id "%value" does not exist.', ['value' => $sourceId]) ); $result->setPath('*/*'); } diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/InlineEdit.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/InlineEdit.php index 633e202202ce..c15aeb7a5ee4 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/InlineEdit.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/InlineEdit.php @@ -66,27 +66,27 @@ public function execute(): ResultInterface if ($request->isXmlHttpRequest() && $request->isPost() && $requestData) { foreach ($requestData as $itemData) { try { - $sourceCode = (string)$itemData[SourceInterface::CODE]; - $source = $this->sourceRepository->get($sourceCode); + $sourceId = (int)$itemData[SourceInterface::SOURCE_ID]; + $source = $this->sourceRepository->getBySourceId($sourceId); $this->dataObjectHelper->populateWithArray($source, $itemData, SourceInterface::class); $this->sourceRepository->save($source); } catch (NoSuchEntityException $e) { $errorMessages[] = __( - '[Code: %value] The Source does not exist.', - ['value' => $sourceCode] + '[ID: %value] The Source does not exist.', + ['value' => $sourceId] ); } catch (ValidationException $e) { foreach ($e->getErrors() as $localizedError) { - $errorMessages[] = __('[Code: %value] %message', [ - 'value' => $sourceCode, + $errorMessages[] = __('[ID: %value] %message', [ + 'value' => $sourceId, 'message' => $localizedError->getMessage() ]); } } catch (CouldNotSaveException $e) { $errorMessages[] = __( - '[Code: %value] %message', + '[ID: %value] %message', [ - 'value' => $sourceCode, + 'value' => $sourceId, 'message' => $e->getMessage() ] ); diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php index b6cbb7b7ac57..957caeae8801 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php @@ -78,13 +78,13 @@ public function execute(): ResultInterface } try { - $sourceCode = isset($requestData['general'][SourceInterface::CODE]) - ? (string)$requestData['general'][SourceInterface::CODE] + $sourceId = isset($requestData['general'][SourceInterface::SOURCE_ID]) + ? (int)$requestData['general'][SourceInterface::SOURCE_ID] : null; - $sourceCode = $this->processSave($requestData, $sourceCode); + $sourceId = $this->processSave($requestData, $sourceId); $this->messageManager->addSuccessMessage(__('The Source has been saved.')); - $this->processRedirectAfterSuccessSave($resultRedirect, $sourceCode); + $this->processRedirectAfterSuccessSave($resultRedirect, $sourceId); } catch (NoSuchEntityException $e) { $this->messageManager->addErrorMessage(__('The Source does not exist.')); $this->processRedirectAfterFailureSave($resultRedirect); @@ -92,13 +92,13 @@ public function execute(): ResultInterface foreach ($e->getErrors() as $localizedError) { $this->messageManager->addErrorMessage($localizedError->getMessage()); } - $this->processRedirectAfterFailureSave($resultRedirect, $sourceCode); + $this->processRedirectAfterFailureSave($resultRedirect, $sourceId); } catch (CouldNotSaveException $e) { $this->messageManager->addErrorMessage($e->getMessage()); - $this->processRedirectAfterFailureSave($resultRedirect, $sourceCode); + $this->processRedirectAfterFailureSave($resultRedirect, $sourceId); } catch (Exception $e) { $this->messageManager->addErrorMessage(__('Could not save Source.')); - $this->processRedirectAfterFailureSave($resultRedirect, $sourceCode ?? null); + $this->processRedirectAfterFailureSave($resultRedirect, $sourceId ?? null); } return $resultRedirect; @@ -106,17 +106,17 @@ public function execute(): ResultInterface /** * @param array $requestData - * @param string|null $sourceCode + * @param int|null $sourceId * - * @return string + * @return int */ - private function processSave(array $requestData, string $sourceCode = null): string + private function processSave(array $requestData, int $sourceId = null): int { - if (null === $sourceCode) { + if (null === $sourceId) { /** @var SourceInterface $source */ $source = $this->sourceFactory->create(); } else { - $source = $this->sourceRepository->get($sourceCode); + $source = $this->sourceRepository->getBySourceId($sourceId); } $source = $this->sourceHydrator->hydrate($source, $requestData); @@ -128,7 +128,7 @@ private function processSave(array $requestData, string $sourceCode = null): str ] ); - $sourceCode = $this->sourceRepository->save($source); + $sourceId = $this->sourceRepository->save($source); $this->_eventManager->dispatch( 'controller_action_inventory_source_save_after', @@ -138,20 +138,20 @@ private function processSave(array $requestData, string $sourceCode = null): str ] ); - return $sourceCode; + return $sourceId; } /** * @param Redirect $resultRedirect - * @param string $sourceCode + * @param int $sourceId * * @return void */ - private function processRedirectAfterSuccessSave(Redirect $resultRedirect, string $sourceCode) + private function processRedirectAfterSuccessSave(Redirect $resultRedirect, int $sourceId) { if ($this->getRequest()->getParam('back')) { $resultRedirect->setPath('*/*/edit', [ - SourceInterface::CODE => $sourceCode, + SourceInterface::SOURCE_ID => $sourceId, '_current' => true, ]); } elseif ($this->getRequest()->getParam('redirect_to_new')) { @@ -165,17 +165,17 @@ private function processRedirectAfterSuccessSave(Redirect $resultRedirect, strin /** * @param Redirect $resultRedirect - * @param string|null $sourceCode + * @param int|null $sourceId * * @return void */ - private function processRedirectAfterFailureSave(Redirect $resultRedirect, string $sourceCode = null) + private function processRedirectAfterFailureSave(Redirect $resultRedirect, int $sourceId = null) { - if (null === $sourceCode) { + if (null === $sourceId) { $resultRedirect->setPath('*/*/new'); } else { $resultRedirect->setPath('*/*/edit', [ - SourceInterface::CODE => $sourceCode, + SourceInterface::SOURCE_ID => $sourceId, '_current' => true, ]); } diff --git a/app/code/Magento/Inventory/Model/ResourceModel/Source.php b/app/code/Magento/Inventory/Model/ResourceModel/Source.php index b2151a343e49..178ee61dae21 100644 --- a/app/code/Magento/Inventory/Model/ResourceModel/Source.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/Source.php @@ -54,7 +54,7 @@ public function __construct( */ protected function _construct() { - $this->_init(self::TABLE_NAME_SOURCE, SourceInterface::CODE); + $this->_init(self::TABLE_NAME_SOURCE, SourceInterface::SOURCE_ID); } /** diff --git a/app/code/Magento/Inventory/Model/Source/Command/GetBySourceId.php b/app/code/Magento/Inventory/Model/Source/Command/GetBySourceId.php new file mode 100644 index 000000000000..f61afb1fbb2a --- /dev/null +++ b/app/code/Magento/Inventory/Model/Source/Command/GetBySourceId.php @@ -0,0 +1,56 @@ +sourceResource = $sourceResource; + $this->sourceFactory = $sourceFactory; + } + + /** + * @inheritdoc + */ + public function execute(int $sourceId): SourceInterface + { + /** @var SourceInterface $source */ + $source = $this->sourceFactory->create(); + $this->sourceResource->load($source, $sourceId, SourceInterface::SOURCE_ID); + + if (null === $source->getCode()) { + throw new NoSuchEntityException(__('Source with id "%value" does not exist.', ['value' => $sourceId])); + } + return $source; + } +} diff --git a/app/code/Magento/Inventory/Model/Source/Command/GetBySourceIdInterface.php b/app/code/Magento/Inventory/Model/Source/Command/GetBySourceIdInterface.php new file mode 100644 index 000000000000..828223b42e02 --- /dev/null +++ b/app/code/Magento/Inventory/Model/Source/Command/GetBySourceIdInterface.php @@ -0,0 +1,33 @@ +sourceValidator->validate($source); @@ -62,7 +62,7 @@ public function execute(SourceInterface $source): string try { $this->sourceResource->save($source); - return (string)$source->getCode(); + return (int)$source->getSourceId(); } catch (\Exception $e) { $this->logger->error($e->getMessage()); throw new CouldNotSaveException(__('Could not save Source'), $e); diff --git a/app/code/Magento/Inventory/Model/Source/Command/SaveInterface.php b/app/code/Magento/Inventory/Model/Source/Command/SaveInterface.php index 0b6c390a89e3..e68908f35230 100644 --- a/app/code/Magento/Inventory/Model/Source/Command/SaveInterface.php +++ b/app/code/Magento/Inventory/Model/Source/Command/SaveInterface.php @@ -27,9 +27,9 @@ interface SaveInterface * Save Source data * * @param SourceInterface $source - * @return string + * @return int * @throws ValidationException * @throws CouldNotSaveException */ - public function execute(SourceInterface $source): string; + public function execute(SourceInterface $source): int; } diff --git a/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php b/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php index 041e3f2c8f53..67b9fbf1e832 100644 --- a/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php +++ b/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php @@ -121,7 +121,7 @@ private function saveNewCarrierLinks(SourceInterface $source) public function loadCarrierLinksBySource(SourceInterface $source) { $searchCriteria = $this->searchCriteriaBuilder - ->addFilter(SourceInterface::CODE, $source->getCode()) + ->addFilter(SourceCarrierLinkInterface::SOURCE_CODE, $source->getCode()) ->create(); /** @var Collection $collection */ diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 145f365656f1..571a176daf36 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -9,6 +9,7 @@ use Magento\Framework\Api\SearchCriteriaInterface; use Magento\Inventory\Model\Source\Command\GetInterface; +use Magento\Inventory\Model\Source\Command\GetBySourceIdInterface; use Magento\Inventory\Model\Source\Command\GetListInterface; use Magento\Inventory\Model\Source\Command\SaveInterface; use Magento\InventoryApi\Api\Data\SourceInterface; @@ -30,6 +31,11 @@ class SourceRepository implements SourceRepositoryInterface */ private $commandGet; + /** + * @var GetBySourceIdInterface + */ + private $commandGetBySourceId; + /** * @var GetListInterface */ @@ -38,22 +44,25 @@ class SourceRepository implements SourceRepositoryInterface /** * @param SaveInterface $commandSave * @param GetInterface $commandGet + * @param GetBySourceIdInterface $commandGetBySourceId * @param GetListInterface $commandGetList */ public function __construct( SaveInterface $commandSave, GetInterface $commandGet, + GetBySourceIdInterface $commandGetBySourceId, GetListInterface $commandGetList ) { $this->commandSave = $commandSave; $this->commandGet = $commandGet; + $this->commandGetBySourceId = $commandGetBySourceId; $this->commandGetList = $commandGetList; } /** * @inheritdoc */ - public function save(SourceInterface $source): string + public function save(SourceInterface $source): int { return $this->commandSave->execute($source); } @@ -66,6 +75,14 @@ public function get(string $code): SourceInterface return $this->commandGet->execute($code); } + /** + * @inheritdoc + */ + public function getBySourceId(int $sourceId): SourceInterface + { + return $this->commandGetBySourceId->execute($sourceId); + } + /** * @inheritdoc */ diff --git a/app/code/Magento/Inventory/Ui/DataProvider/SourceDataProvider.php b/app/code/Magento/Inventory/Ui/DataProvider/SourceDataProvider.php index 385d50603686..c8461d701760 100644 --- a/app/code/Magento/Inventory/Ui/DataProvider/SourceDataProvider.php +++ b/app/code/Magento/Inventory/Ui/DataProvider/SourceDataProvider.php @@ -83,10 +83,11 @@ public function getData() // It is need for support of several fieldsets. // For details see \Magento\Ui\Component\Form::getDataSourceData if ($data['totalRecords'] > 0) { + $sourceId = (int)$data['items'][0][SourceInterface::SOURCE_ID]; $sourceCode = (string)$data['items'][0][SourceInterface::CODE]; $sourceGeneralData = $data['items'][0]; $sourceGeneralData['carrier_codes'] = $this->getAssignedCarrierCodes($sourceCode); - $dataForSingle[$sourceCode] = [ + $dataForSingle[$sourceId] = [ 'general' => $sourceGeneralData, ]; $data = $dataForSingle; @@ -109,7 +110,7 @@ public function getSearchResult() $result->getItems(), $result->getTotalCount(), $searchCriteria, - SourceInterface::CODE + SourceInterface::SOURCE_ID ); return $searchResult; } diff --git a/app/code/Magento/Inventory/etc/di.xml b/app/code/Magento/Inventory/etc/di.xml index 82c4aefbedc8..96b4b2a30eaa 100644 --- a/app/code/Magento/Inventory/etc/di.xml +++ b/app/code/Magento/Inventory/etc/di.xml @@ -13,7 +13,7 @@ - + diff --git a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml index d6a629b0b989..78aed75bcf76 100644 --- a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml +++ b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml @@ -38,8 +38,8 @@ - code - code + source_id + source_id diff --git a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml index 0f245f768980..d3c546e4516e 100644 --- a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml +++ b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml @@ -27,15 +27,15 @@ - source_code + source_id Magento_InventoryApi::source - code - code + source_id + source_id @@ -68,7 +68,7 @@ false - code + source_id true inventory_source_listing.inventory_source_listing.inventory_source_listing_columns.ids @@ -85,7 +85,7 @@ - code + source_id @@ -99,12 +99,6 @@ text - - text - - true - - @@ -288,7 +282,7 @@ - code + source_id diff --git a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php index a3cae6bd4475..f9a58c3f0e78 100644 --- a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php +++ b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php @@ -36,22 +36,32 @@ interface SourceRepositoryInterface * Save Source data * * @param \Magento\InventoryApi\Api\Data\SourceInterface $source - * @return string + * @return int * @throws \Magento\Framework\Validation\ValidationException * @throws \Magento\Framework\Exception\CouldNotSaveException */ - public function save(SourceInterface $source): string; + public function save(SourceInterface $source): int; /** * Get Source data by given code. If you want to create plugin on get method, also you need to create separate * plugin on getList method, because entity loading way is different for these methods * - * @param int $code + * @param string $code * @return \Magento\InventoryApi\Api\Data\SourceInterface * @throws \Magento\Framework\Exception\NoSuchEntityException */ public function get(string $code): SourceInterface; + /** + * Get Source data by given source id. If you want to create plugin on get method, also you need to create separate + * plugin on getList method, because entity loading way is different for these methods + * + * @param int $sourceId + * @return \Magento\InventoryApi\Api\Data\SourceInterface + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ + public function getBySourceId(int $sourceId): SourceInterface; + /** * Find Sources by SearchCriteria * SearchCriteria is not required because load all stocks is useful case diff --git a/app/code/Magento/InventoryCatalog/Setup/Operation/AssignSourceToStock.php b/app/code/Magento/InventoryCatalog/Setup/Operation/AssignSourceToStock.php index 7cb7e99dc5c8..d9f06f70e231 100644 --- a/app/code/Magento/InventoryCatalog/Setup/Operation/AssignSourceToStock.php +++ b/app/code/Magento/InventoryCatalog/Setup/Operation/AssignSourceToStock.php @@ -54,7 +54,7 @@ public function __construct( public function execute() { $this->assignSourcesToStock->execute( - [$this->defaultSourceProvider->getId()], + [$this->defaultSourceProvider->getCode()], $this->defaultStockProvider->getId() ); } diff --git a/app/code/Magento/InventoryCatalog/Setup/Operation/UpdateInventorySourceItem.php b/app/code/Magento/InventoryCatalog/Setup/Operation/UpdateInventorySourceItem.php index 776b6faeeed6..39deb2977e01 100644 --- a/app/code/Magento/InventoryCatalog/Setup/Operation/UpdateInventorySourceItem.php +++ b/app/code/Magento/InventoryCatalog/Setup/Operation/UpdateInventorySourceItem.php @@ -60,7 +60,7 @@ public function execute(ModuleDataSetupInterface $setup) ->from( $legacyStockItemTable, [ - 'source_code' => new \Zend_Db_Expr($defaultSourceCode), + 'source_code' => new \Zend_Db_Expr('\'' .$defaultSourceCode . '\''), 'qty', 'is_in_stock' ] From 044bc6f07034298da6a3aadbbe04c0426f0c30fd Mon Sep 17 00:00:00 2001 From: deadlexus Date: Fri, 22 Dec 2017 00:43:58 +0300 Subject: [PATCH 11/39] MSI: issue #290 - Fixed issue with with incorrect query on product edit page; --- .../Product/Form/Modifier/SourceItemConfiguration.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/InventoryConfiguration/Ui/DataProvider/Product/Form/Modifier/SourceItemConfiguration.php b/app/code/Magento/InventoryConfiguration/Ui/DataProvider/Product/Form/Modifier/SourceItemConfiguration.php index 6435051c43ba..59be9a5e3e26 100644 --- a/app/code/Magento/InventoryConfiguration/Ui/DataProvider/Product/Form/Modifier/SourceItemConfiguration.php +++ b/app/code/Magento/InventoryConfiguration/Ui/DataProvider/Product/Form/Modifier/SourceItemConfiguration.php @@ -11,6 +11,7 @@ use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier; use Magento\Catalog\Model\Locator\LocatorInterface; use Magento\InventoryApi\Api\Data\SourceInterface; +use Magento\InventoryApi\Api\Data\SourceItemInterface; use Magento\InventoryConfigurationApi\Api\GetSourceItemConfigurationInterface; use Magento\InventoryConfigurationApi\Api\Data\SourceItemConfigurationInterface; @@ -65,7 +66,7 @@ private function getSourceItemsConfigurationData(array $assignedSources, Product { foreach ($assignedSources as &$source) { $sourceConfiguration = $this->getSourceItemConfiguration->execute( - (string)$source[SourceInterface::CODE], + (string)$source[SourceItemInterface::SOURCE_CODE], $product->getSku() ); From ac3175bfb20b4fa0a433e4c397ba5c2bcbddaa82 Mon Sep 17 00:00:00 2001 From: deadlexus Date: Fri, 22 Dec 2017 01:00:49 +0300 Subject: [PATCH 12/39] MSI: issue #290 - Fixed issue with source item UIcomponent on product edit page --- .../view/adminhtml/ui_component/inventory_source_listing.xml | 2 +- .../view/adminhtml/ui_component/product_form.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml index d3c546e4516e..780bf30a66f4 100644 --- a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml +++ b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml @@ -85,7 +85,7 @@ - source_id + code diff --git a/app/code/Magento/InventoryCatalog/view/adminhtml/ui_component/product_form.xml b/app/code/Magento/InventoryCatalog/view/adminhtml/ui_component/product_form.xml index bfe45f109b23..d1479bf2c763 100644 --- a/app/code/Magento/InventoryCatalog/view/adminhtml/ui_component/product_form.xml +++ b/app/code/Magento/InventoryCatalog/view/adminhtml/ui_component/product_form.xml @@ -45,7 +45,7 @@ data.sources.assign_sources_grid - source_code + code name qty From b7af8368f7ece09067ffdf779a7ba72ac7b0549b Mon Sep 17 00:00:00 2001 From: deadlexus Date: Fri, 22 Dec 2017 01:22:51 +0300 Subject: [PATCH 13/39] MSI: issue #290 - Fixed issued with UI Components on stock edit page; --- .../Magento/Inventory/Ui/DataProvider/StockDataProvider.php | 3 ++- .../view/adminhtml/ui_component/inventory_stock_form.xml | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php b/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php index f4514968e269..03a412687002 100644 --- a/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php +++ b/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php @@ -17,6 +17,7 @@ use Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider; use Magento\InventoryApi\Api\Data\StockInterface; use Magento\InventoryApi\Api\StockRepositoryInterface; +use Magento\Inventory\Model\StockSourceLink; /** * @api @@ -137,7 +138,7 @@ private function getAssignedSourcesData(int $stockId): array $assignedSourcesData = []; foreach ($assignedSources as $assignedSource) { $assignedSourcesData[] = [ - SourceInterface::CODE => $assignedSource->getCode(), + StockSourceLink::SOURCE_CODE => $assignedSource->getCode(), SourceInterface::NAME => $assignedSource->getName(), ]; } diff --git a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_form.xml b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_form.xml index bd7424ef305c..6d74b23479b6 100644 --- a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_form.xml +++ b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_form.xml @@ -100,10 +100,10 @@ data.sources.assign_sources_grid - code + code name - code + source_code @@ -111,7 +111,7 @@ false false record - code + source_code ${ $.provider }:${ $.dataProvider } From e50689189e7e7f44d29f508cfab595993644009b Mon Sep 17 00:00:00 2001 From: deadlexus Date: Fri, 22 Dec 2017 02:56:59 +0300 Subject: [PATCH 14/39] MSI: issue #290 - Integration test fixes - part; --- .../Integration/Indexer/GetSourceItemId.php | 2 +- .../Integration/Indexer/SourceIndexerTest.php | 4 +-- .../Indexer/SourceItemIndexerTest.php | 6 ++--- .../Test/_files/stock_source_link.php | 26 +++++++++---------- .../_files/stock_source_link_rollback.php | 20 +++++++------- .../_files/source_items_on_default_source.php | 6 ++--- 6 files changed, 32 insertions(+), 32 deletions(-) diff --git a/app/code/Magento/Inventory/Test/Integration/Indexer/GetSourceItemId.php b/app/code/Magento/Inventory/Test/Integration/Indexer/GetSourceItemId.php index a7fb09c3709d..c40b13b31f73 100644 --- a/app/code/Magento/Inventory/Test/Integration/Indexer/GetSourceItemId.php +++ b/app/code/Magento/Inventory/Test/Integration/Indexer/GetSourceItemId.php @@ -31,7 +31,7 @@ public function __construct(ResourceConnection $resourceConnection) * @param string $sourceCode * @return int */ - public function execute(string $sku, string $sourceCode): string + public function execute(string $sku, string $sourceCode): int { $connection = $this->resourceConnection->getConnection(); $select = $connection->select() diff --git a/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php b/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php index d3b93319ec2f..26176b0a7548 100644 --- a/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php +++ b/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php @@ -56,7 +56,7 @@ protected function tearDown() */ public function testReindexRow() { - $this->indexer->reindexRow(10); + $this->indexer->reindexRow('eu-1'); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 10)); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 30)); @@ -71,7 +71,7 @@ public function testReindexRow() */ public function testReindexList() { - $this->indexer->reindexList([10, 50]); + $this->indexer->reindexList(['eu-1', 'us-1']); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 10)); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 30)); diff --git a/app/code/Magento/Inventory/Test/Integration/Indexer/SourceItemIndexerTest.php b/app/code/Magento/Inventory/Test/Integration/Indexer/SourceItemIndexerTest.php index e6f934cad4db..d744fe19ddc6 100644 --- a/app/code/Magento/Inventory/Test/Integration/Indexer/SourceItemIndexerTest.php +++ b/app/code/Magento/Inventory/Test/Integration/Indexer/SourceItemIndexerTest.php @@ -63,7 +63,7 @@ protected function tearDown() */ public function testReindexRow() { - $this->indexer->reindexRow($this->getSourceItemId->execute('SKU-1', 10)); + $this->indexer->reindexRow($this->getSourceItemId->execute('SKU-1', 'eu-1')); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 10)); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 30)); @@ -79,8 +79,8 @@ public function testReindexRow() public function testReindexList() { $this->indexer->reindexList([ - $this->getSourceItemId->execute('SKU-1', 10), - $this->getSourceItemId->execute('SKU-2', 50), + $this->getSourceItemId->execute('SKU-1', 'eu-1'), + $this->getSourceItemId->execute('SKU-2', 'us-1'), ]); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 10)); diff --git a/app/code/Magento/InventoryApi/Test/_files/stock_source_link.php b/app/code/Magento/InventoryApi/Test/_files/stock_source_link.php index 5fd27e4a3980..5c5151f358da 100644 --- a/app/code/Magento/InventoryApi/Test/_files/stock_source_link.php +++ b/app/code/Magento/InventoryApi/Test/_files/stock_source_link.php @@ -11,19 +11,19 @@ /** @var AssignSourcesToStockInterface $assignSourcesToStock */ $assignSourcesToStock = Bootstrap::getObjectManager()->get(AssignSourcesToStockInterface::class); /** - * EU-source-1(id:10) - EU-stock(id:10) - * EU-source-2(id:20) - EU-stock(id:10) - * EU-source-3(id:30) - EU-stock(id:10) - * EU-source-disabled(id:40) - EU-stock(id:10) + * EU-source-1(code:eu-1) - EU-stock(id:10) + * EU-source-2(code:eu-2) - EU-stock(id:10) + * EU-source-3(code:eu-3) - EU-stock(id:10) + * EU-source-disabled(code:eu-dis) - EU-stock(id:10) * - * US-source-1(id:50) - US-stock(id:20) + * US-source-1(code:us-1) - US-stock(id:20) * - * EU-source-1(id:10) - Global-stock(id:30) - * EU-source-2(id:20) - Global-stock(id:30) - * EU-source-2(id:30) - Global-stock(id:30) - * EU-source-disabled(id:40) - Global-stock(id:30) - * US-source-1(id:50) - Global-stock(id:30) + * EU-source-1(code:eu-1) - Global-stock(id:30) + * EU-source-2(code:eu-2) - Global-stock(id:30) + * EU-source-2(code:eu-2) - Global-stock(id:30) + * EU-source-disabled(code:eu-dis) - Global-stock(id:30) + * US-source-1(code:us-1) - Global-stock(id:30) */ -$assignSourcesToStock->execute([10, 20, 30, 40], 10); -$assignSourcesToStock->execute([50], 20); -$assignSourcesToStock->execute([10, 20, 30, 40, 50], 30); +$assignSourcesToStock->execute(['eu-1', 'eu-2', 'eu-3', 'eu-dis'], 10); +$assignSourcesToStock->execute(['us-1'], 20); +$assignSourcesToStock->execute(['eu-1', 'eu-2', 'eu-3', 'eu-dis', 'us-1'], 30); diff --git a/app/code/Magento/InventoryApi/Test/_files/stock_source_link_rollback.php b/app/code/Magento/InventoryApi/Test/_files/stock_source_link_rollback.php index b9ae97e65561..06303fbe36f0 100644 --- a/app/code/Magento/InventoryApi/Test/_files/stock_source_link_rollback.php +++ b/app/code/Magento/InventoryApi/Test/_files/stock_source_link_rollback.php @@ -11,15 +11,15 @@ /** @var UnassignSourceFromStockInterface $unassignSourceFromStock */ $unassignSourceFromStock = Bootstrap::getObjectManager()->get(UnassignSourceFromStockInterface::class); // EU stock -$unassignSourceFromStock->execute(10, 10); -$unassignSourceFromStock->execute(20, 10); -$unassignSourceFromStock->execute(30, 10); -$unassignSourceFromStock->execute(40, 10); +$unassignSourceFromStock->execute('eu-1', 10); +$unassignSourceFromStock->execute('eu-2', 10); +$unassignSourceFromStock->execute('eu-3', 10); +$unassignSourceFromStock->execute('eu-dis', 10); // US stock -$unassignSourceFromStock->execute(50, 20); +$unassignSourceFromStock->execute('us-1', 20); // Global Stock -$unassignSourceFromStock->execute(10, 30); -$unassignSourceFromStock->execute(20, 30); -$unassignSourceFromStock->execute(30, 30); -$unassignSourceFromStock->execute(40, 30); -$unassignSourceFromStock->execute(50, 30); +$unassignSourceFromStock->execute('eu-1', 30); +$unassignSourceFromStock->execute('eu-2', 30); +$unassignSourceFromStock->execute('eu-3', 30); +$unassignSourceFromStock->execute('eu-dis', 30); +$unassignSourceFromStock->execute('us-1', 30); diff --git a/app/code/Magento/InventoryCatalog/Test/_files/source_items_on_default_source.php b/app/code/Magento/InventoryCatalog/Test/_files/source_items_on_default_source.php index e3b45e313baa..c7919c4125b8 100644 --- a/app/code/Magento/InventoryCatalog/Test/_files/source_items_on_default_source.php +++ b/app/code/Magento/InventoryCatalog/Test/_files/source_items_on_default_source.php @@ -28,19 +28,19 @@ */ $sourcesItemsData = [ [ - SourceItemInterface::SOURCE_ID => $defaultSourceProvider->getId(), + SourceItemInterface::SOURCE_CODE => $defaultSourceProvider->getCode(), SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 5.5, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, ], [ - SourceItemInterface::SOURCE_ID => $defaultSourceProvider->getId(), + SourceItemInterface::SOURCE_CODE => $defaultSourceProvider->getCode(), SourceItemInterface::SKU => 'SKU-2', SourceItemInterface::QUANTITY => 5, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, ], [ - SourceItemInterface::SOURCE_ID => $defaultSourceProvider->getId(), + SourceItemInterface::SOURCE_CODE => $defaultSourceProvider->getCode(), SourceItemInterface::SKU => 'SKU-3', SourceItemInterface::QUANTITY => 6, SourceItemInterface::STATUS => SourceItemInterface::STATUS_OUT_OF_STOCK, From 988655af881c59dbe2311a3464f956cd14e2ab6f Mon Sep 17 00:00:00 2001 From: deadlexus Date: Fri, 22 Dec 2017 03:51:40 +0300 Subject: [PATCH 15/39] MSI: issue #290 - Integration tests fixes - part; --- .../InventoryImportExport/Model/Import/SourceItemConvert.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php b/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php index 7142859a56ba..d8979821abf7 100755 --- a/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php +++ b/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php @@ -43,7 +43,7 @@ public function convert(array $bunch): array { $sourceItems = []; foreach ($bunch as $rowData) { - $source = $this->sourceRepository->getByCode($rowData[Sources::COL_SOURCE_CODE]); + $source = $this->sourceRepository->get($rowData[Sources::COL_SOURCE_CODE]); /** @var SourceItemInterface $sourceItem */ $sourceItem = $this->sourceItemFactory->create(); $sourceItem->setSourceCode($source->getCode()); From 7bbd6a50684de1ca8f1c90aedbfb04cd3acee4e9 Mon Sep 17 00:00:00 2001 From: Alex Yakimovich Date: Fri, 22 Dec 2017 13:28:07 +0300 Subject: [PATCH 16/39] MSI: issue #290 - Test fixes -part; --- .../InventoryCatalog/Test/Api/GetDefaultSourceTest.php | 8 ++++---- .../Test/Api/GetDefaultStockToSourceLinkTest.php | 4 ++-- .../SetDataToLegacyStockItemAtSourceItemsSaveTest.php | 2 +- .../SetDataToLegacyStockStatusAtSourceItemsSaveTest.php | 2 +- ...tOfStockToLegacyStockStatusAtSourceItemsDeleteTest.php | 2 +- .../SetToZeroLegacyStockItemAtSourceItemsDeleteTest.php | 2 +- .../Model/StockItemSave/StockItemDataChecker.php | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultSourceTest.php b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultSourceTest.php index 8d5fba7ecd89..009199af8f77 100644 --- a/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultSourceTest.php +++ b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultSourceTest.php @@ -21,10 +21,10 @@ class GetDefaultSourceTest extends WebapiAbstract */ public function testGetDefaultSource() { - $defaultSourceId = 1; + $defaultSourceCode = 'default'; $serviceInfo = [ 'rest' => [ - 'resourcePath' => '/V1/inventory/source/' . $defaultSourceId, + 'resourcePath' => '/V1/inventory/source/' . $defaultSourceCode, 'httpMethod' => Request::HTTP_METHOD_GET, ], 'soap' => [ @@ -35,8 +35,8 @@ public function testGetDefaultSource() if (self::ADAPTER_REST == TESTS_WEB_API_ADAPTER) { $source = $this->_webApiCall($serviceInfo); } else { - $source = $this->_webApiCall($serviceInfo, ['sourceId' => $defaultSourceId]); + $source = $this->_webApiCall($serviceInfo, ['sourceCode' => $defaultSourceCode]); } - $this->assertEquals($defaultSourceId, $source[SourceInterface::SOURCE_ID]); + $this->assertEquals($defaultSourceCode, $source[SourceInterface::CODE]); } } diff --git a/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockToSourceLinkTest.php b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockToSourceLinkTest.php index 1df184074b6e..1796cc5d0570 100644 --- a/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockToSourceLinkTest.php +++ b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockToSourceLinkTest.php @@ -22,7 +22,7 @@ class GetDefaultStockToSourceLinkTest extends WebapiAbstract public function testGetDefaultStockToSourceLink() { $defaultStockId = 1; - $defaultSourceId = 1; + $defaultSourceCode = 'default'; $serviceInfo = [ 'rest' => [ 'resourcePath' => '/V1/inventory/stock/get-assigned-sources/' . $defaultStockId, @@ -38,6 +38,6 @@ public function testGetDefaultStockToSourceLink() } else { $source = $this->_webApiCall($serviceInfo, ['stockId' => $defaultStockId]); } - $this->assertEquals([$defaultSourceId], array_column($source, SourceInterface::SOURCE_ID)); + $this->assertEquals([$defaultSourceCode], array_column($source, SourceInterface::CODE)); } } diff --git a/app/code/Magento/InventoryCatalog/Test/Integration/SetDataToLegacyStockItemAtSourceItemsSaveTest.php b/app/code/Magento/InventoryCatalog/Test/Integration/SetDataToLegacyStockItemAtSourceItemsSaveTest.php index 40db7a4aeb7d..c32e7370d1f1 100644 --- a/app/code/Magento/InventoryCatalog/Test/Integration/SetDataToLegacyStockItemAtSourceItemsSaveTest.php +++ b/app/code/Magento/InventoryCatalog/Test/Integration/SetDataToLegacyStockItemAtSourceItemsSaveTest.php @@ -96,7 +96,7 @@ public function testSetData() $searchCriteria = $this->searchCriteriaBuilder ->addFilter(SourceItemInterface::SKU, $productSku) - ->addFilter(SourceItemInterface::SOURCE_ID, $this->defaultSourceProvider->getId()) + ->addFilter(SourceItemInterface::SOURCE_CODE, $this->defaultSourceProvider->getCode()) ->create(); $sourceItems = $this->sourceItemRepository->getList($searchCriteria)->getItems(); self::assertCount(1, $sourceItems); diff --git a/app/code/Magento/InventoryCatalog/Test/Integration/SetDataToLegacyStockStatusAtSourceItemsSaveTest.php b/app/code/Magento/InventoryCatalog/Test/Integration/SetDataToLegacyStockStatusAtSourceItemsSaveTest.php index d8457df5ea81..224f2f88eb49 100644 --- a/app/code/Magento/InventoryCatalog/Test/Integration/SetDataToLegacyStockStatusAtSourceItemsSaveTest.php +++ b/app/code/Magento/InventoryCatalog/Test/Integration/SetDataToLegacyStockStatusAtSourceItemsSaveTest.php @@ -97,7 +97,7 @@ public function testSetData() $searchCriteria = $this->searchCriteriaBuilder ->addFilter(SourceItemInterface::SKU, $productSku) - ->addFilter(SourceItemInterface::SOURCE_ID, $this->defaultSourceProvider->getId()) + ->addFilter(SourceItemInterface::SOURCE_CODE, $this->defaultSourceProvider->getCode()) ->create(); $sourceItems = $this->sourceItemRepository->getList($searchCriteria)->getItems(); self::assertCount(1, $sourceItems); diff --git a/app/code/Magento/InventoryCatalog/Test/Integration/SetOutOfStockToLegacyStockStatusAtSourceItemsDeleteTest.php b/app/code/Magento/InventoryCatalog/Test/Integration/SetOutOfStockToLegacyStockStatusAtSourceItemsDeleteTest.php index 900494f0daaf..906c84bd178d 100644 --- a/app/code/Magento/InventoryCatalog/Test/Integration/SetOutOfStockToLegacyStockStatusAtSourceItemsDeleteTest.php +++ b/app/code/Magento/InventoryCatalog/Test/Integration/SetOutOfStockToLegacyStockStatusAtSourceItemsDeleteTest.php @@ -97,7 +97,7 @@ public function testSetOutOfStock() $searchCriteria = $this->searchCriteriaBuilder ->addFilter(SourceItemInterface::SKU, $productSku) - ->addFilter(SourceItemInterface::SOURCE_ID, $this->defaultSourceProvider->getId()) + ->addFilter(SourceItemInterface::SOURCE_CODE, $this->defaultSourceProvider->getCode()) ->create(); $sourceItems = $this->sourceItemRepository->getList($searchCriteria)->getItems(); self::assertCount(1, $sourceItems); diff --git a/app/code/Magento/InventoryCatalog/Test/Integration/SetToZeroLegacyStockItemAtSourceItemsDeleteTest.php b/app/code/Magento/InventoryCatalog/Test/Integration/SetToZeroLegacyStockItemAtSourceItemsDeleteTest.php index f3044e2731cd..27c97cad3e6e 100644 --- a/app/code/Magento/InventoryCatalog/Test/Integration/SetToZeroLegacyStockItemAtSourceItemsDeleteTest.php +++ b/app/code/Magento/InventoryCatalog/Test/Integration/SetToZeroLegacyStockItemAtSourceItemsDeleteTest.php @@ -96,7 +96,7 @@ public function testSetToZero() $searchCriteria = $this->searchCriteriaBuilder ->addFilter(SourceItemInterface::SKU, $productSku) - ->addFilter(SourceItemInterface::SOURCE_ID, $this->defaultSourceProvider->getId()) + ->addFilter(SourceItemInterface::SOURCE_CODE, $this->defaultSourceProvider->getCode()) ->create(); $sourceItems = $this->sourceItemRepository->getList($searchCriteria)->getItems(); self::assertCount(1, $sourceItems); diff --git a/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/StockItemSave/StockItemDataChecker.php b/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/StockItemSave/StockItemDataChecker.php index b489fbdc33b8..5c1ef6462af9 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/StockItemSave/StockItemDataChecker.php +++ b/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/StockItemSave/StockItemDataChecker.php @@ -167,7 +167,7 @@ private function assertArrayContains(array $expected, array $actual) private function checkIntegrityWithInventory(Product $product, array $expectedData) { $searchCriteria = $this->searchCriteriaBuilder - ->addFilter(SourceItemInterface::SOURCE_ID, $this->defaultSourceProvider->getId()) + ->addFilter(SourceItemInterface::SOURCE_CODE, $this->defaultSourceProvider->getCode()) ->addFilter(SourceItemInterface::SKU, $product->getSku()) ->create(); $sourceItems = $this->sourceItemRepository->getList($searchCriteria)->getItems(); From cfb2611f56c43f09248c34bc03c3e2282dcac9a7 Mon Sep 17 00:00:00 2001 From: Igor Miniailo Date: Fri, 22 Dec 2017 13:42:20 +0200 Subject: [PATCH 17/39] Adapt SourceCodes with PreventAssignSourcesToDefaultStockPlugin logic --- .../PreventAssignSourcesToDefaultStockPlugin.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php b/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php index cc7e565ea49e..6fbdbdfaf377 100644 --- a/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php +++ b/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php @@ -40,11 +40,11 @@ public function __construct( * @throws InputException * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function beforeExecute(AssignSourcesToStockInterface $subject, array $sourceIds, int $stockId) + public function beforeExecute(AssignSourcesToStockInterface $subject, array $sourceCodes, int $stockId) { - if ($this->defaultStockProvider->getId() !== $stockId - || (1 == count($sourceIds) && $this->defaultSourceProvider->getId() == $sourceIds[0])) { - return [$sourceIds, $stockId]; + if ($this->defaultStockProvider->getId() === $stockId + && (1 === count($sourceCodes) && $this->defaultSourceProvider->getCode() === $sourceCodes[0])) { + return [$sourceCodes, $stockId]; } throw new InputException(__('You can only assign Default Source to Default Stock')); From 622438b2481c4c1161c15fa6f8409e3e18144eb5 Mon Sep 17 00:00:00 2001 From: Igor Miniailo Date: Fri, 22 Dec 2017 13:47:37 +0200 Subject: [PATCH 18/39] Adapt SourceCodes with PreventAssignSourcesToDefaultStockPlugin logic --- .../PreventAssignSourcesToDefaultStockPlugin.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php b/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php index 6fbdbdfaf377..47430e2b7829 100644 --- a/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php +++ b/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php @@ -42,11 +42,11 @@ public function __construct( */ public function beforeExecute(AssignSourcesToStockInterface $subject, array $sourceCodes, int $stockId) { - if ($this->defaultStockProvider->getId() === $stockId - && (1 === count($sourceCodes) && $this->defaultSourceProvider->getCode() === $sourceCodes[0])) { - return [$sourceCodes, $stockId]; + if ($this->defaultStockProvider->getId() === $stockId) { + if((1 !== count($sourceCodes) || $this->defaultSourceProvider->getCode() !== $sourceCodes[0])) { + throw new InputException(__('You can only assign Default Source to Default Stock')); + } } - - throw new InputException(__('You can only assign Default Source to Default Stock')); + return [$sourceCodes, $stockId]; } } From f4254738b34466a6cf4ff3cbffe710459abe3cec Mon Sep 17 00:00:00 2001 From: Igor Miniailo Date: Fri, 22 Dec 2017 14:35:51 +0200 Subject: [PATCH 19/39] Fixed Sample File for Inventory Import --- .../Files/Sample/stock_sources.csv | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/InventoryImportExport/Files/Sample/stock_sources.csv b/app/code/Magento/InventoryImportExport/Files/Sample/stock_sources.csv index 7d1852724546..501a49953883 100644 --- a/app/code/Magento/InventoryImportExport/Files/Sample/stock_sources.csv +++ b/app/code/Magento/InventoryImportExport/Files/Sample/stock_sources.csv @@ -1,5 +1,5 @@ -source_id,sku,status,quantity -1,sku1,1,10 -2,sku2,1,10 -3,sku3,1,10 -4,sku4,1,15 +source_code,sku,status,quantity +default,sku1,1,10.10 +default,sku2,1,10.55 +source-1,sku3,1,10 +source-2,sku4,1,15 From f819625d823b6d6404b8834fa2f7e89c826c1573 Mon Sep 17 00:00:00 2001 From: Alex Yakimovich Date: Fri, 22 Dec 2017 15:45:47 +0300 Subject: [PATCH 20/39] MSI: issue #290 - MEQP2 fixes; - SourceImportExport integration tests fixes - part; - Stock Source Import: modified sample file; --- .../PreventAssignSourcesToDefaultStockPlugin.php | 2 +- .../Files/Sample/stock_sources.csv | 10 +++++----- .../Export/_files/export_filtered_by_source.csv | 1 + .../Test/Integration/Model/Import/SourcesTest.php | 12 ++++++------ 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php b/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php index 47430e2b7829..873408373920 100644 --- a/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php +++ b/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php @@ -43,7 +43,7 @@ public function __construct( public function beforeExecute(AssignSourcesToStockInterface $subject, array $sourceCodes, int $stockId) { if ($this->defaultStockProvider->getId() === $stockId) { - if((1 !== count($sourceCodes) || $this->defaultSourceProvider->getCode() !== $sourceCodes[0])) { + if ((1 !== count($sourceCodes) || $this->defaultSourceProvider->getCode() !== $sourceCodes[0])) { throw new InputException(__('You can only assign Default Source to Default Stock')); } } diff --git a/app/code/Magento/InventoryImportExport/Files/Sample/stock_sources.csv b/app/code/Magento/InventoryImportExport/Files/Sample/stock_sources.csv index 7d1852724546..30feda1a1d21 100644 --- a/app/code/Magento/InventoryImportExport/Files/Sample/stock_sources.csv +++ b/app/code/Magento/InventoryImportExport/Files/Sample/stock_sources.csv @@ -1,5 +1,5 @@ -source_id,sku,status,quantity -1,sku1,1,10 -2,sku2,1,10 -3,sku3,1,10 -4,sku4,1,15 +source_code,sku,status,quantity +ue-1,sku1,1,10 +eu-2,sku2,1,10 +eu-3,sku3,1,10 +eu-dis,sku4,1,15 diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_source.csv b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_source.csv index 867c3ae02281..767f04704498 100644 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_source.csv +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_source.csv @@ -3,3 +3,4 @@ eu-1,SKU-1,1,5.5000 eu-2,SKU-1,1,3.0000 eu-3,SKU-1,0,10.0000 eu-dis,SKU-1,1,10.0000 +eu-2,SKU-3,0,6.0000 diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php index d6e96823da4e..de20265f3c82 100755 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php @@ -175,8 +175,8 @@ public function testImportDataWithReplaceBehavior() $searchCriteria = $this->searchCriteriaBuilder->create(); $afterImportData = $this->getSourceItemList($searchCriteria); - $this->assertArrayHasKey('20-SKU-1', $afterImportData); - $this->assertArrayHasKey('50-SKU-2', $afterImportData); + $this->assertArrayHasKey('eu-2-SKU-1', $afterImportData); + $this->assertArrayHasKey('us-1-SKU-2', $afterImportData); } /** @@ -190,7 +190,7 @@ public function testImportDataWithReplaceBehaviorNoAffectOtherSources() { $searchCriteria = $this->searchCriteriaBuilder->create(); $beforeImportData = $this->getSourceItemList($searchCriteria); - $this->assertArrayHasKey('10-SKU-1', $beforeImportData); + $this->assertArrayHasKey('eu-1-SKU-1', $beforeImportData); /** @see \Magento\InventoryImportExport\Model\Import\Command\Replace::execute */ $this->importer->setParameters([ @@ -205,10 +205,10 @@ public function testImportDataWithReplaceBehaviorNoAffectOtherSources() $afterImportData = $this->getSourceItemList($searchCriteria); // checks whether original source item which has not been imported stays in database - $this->assertEquals($beforeImportData['10-SKU-1'], $afterImportData['10-SKU-1']); + $this->assertEquals($beforeImportData['eu-1-SKU-1'], $afterImportData['eu-1-SKU-1']); - $this->assertArrayHasKey('20-SKU-1', $afterImportData); - $this->assertArrayHasKey('50-SKU-2', $afterImportData); + $this->assertArrayHasKey('eu-2-SKU-1', $afterImportData); + $this->assertArrayHasKey('us-1-SKU-2', $afterImportData); } /** From de53a75cb9b8e47614c448ef4bba2c11d272c782 Mon Sep 17 00:00:00 2001 From: Igor Miniailo Date: Fri, 22 Dec 2017 14:55:56 +0200 Subject: [PATCH 21/39] Fix conflicts with develop --- app/code/Magento/Inventory/Model/SourceItem.php | 3 +-- .../Api/DefaultSourceProviderInterface.php | 7 ------- .../InventoryCatalog/Model/DefaultSourceProvider.php | 8 -------- .../PreventAssignSourcesToDefaultStockPlugin.php | 2 +- ...ataToLegacyCatalogInventoryAtSourceItemsSavePlugin.php | 2 +- ...eroLegacyCatalogInventoryAtSourceItemsDeletePlugin.php | 2 +- 6 files changed, 4 insertions(+), 20 deletions(-) diff --git a/app/code/Magento/Inventory/Model/SourceItem.php b/app/code/Magento/Inventory/Model/SourceItem.php index d59a0cfa3670..9dd5b5c36212 100755 --- a/app/code/Magento/Inventory/Model/SourceItem.php +++ b/app/code/Magento/Inventory/Model/SourceItem.php @@ -48,8 +48,7 @@ public function setSku($sku) */ public function getSourceCode() { - $sourceCode = $this->getData(self::SOURCE_CODE); - return ($sourceCode === null) ? null : (string)$sourceCode; + return $this->getData(self::SOURCE_CODE); } /** diff --git a/app/code/Magento/InventoryCatalog/Api/DefaultSourceProviderInterface.php b/app/code/Magento/InventoryCatalog/Api/DefaultSourceProviderInterface.php index 693d83816b0f..f1a3c6927f62 100644 --- a/app/code/Magento/InventoryCatalog/Api/DefaultSourceProviderInterface.php +++ b/app/code/Magento/InventoryCatalog/Api/DefaultSourceProviderInterface.php @@ -20,11 +20,4 @@ interface DefaultSourceProviderInterface * @return string */ public function getCode(): string; - - /** - * Get Default Source id - * - * @return int - */ - public function getId(): int; } diff --git a/app/code/Magento/InventoryCatalog/Model/DefaultSourceProvider.php b/app/code/Magento/InventoryCatalog/Model/DefaultSourceProvider.php index 6134109efc3b..b11e17668dee 100644 --- a/app/code/Magento/InventoryCatalog/Model/DefaultSourceProvider.php +++ b/app/code/Magento/InventoryCatalog/Model/DefaultSourceProvider.php @@ -21,12 +21,4 @@ public function getCode(): string { return 'default'; } - - /** - * @inheritdoc - */ - public function getId(): int - { - return 1; - } } diff --git a/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php b/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php index 873408373920..259f51ff1cc8 100644 --- a/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php +++ b/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php @@ -34,7 +34,7 @@ public function __construct( /** * @param AssignSourcesToStockInterface $subject - * @param array $sourceIds + * @param array $sourceCodes * @param int $stockId * @return array * @throws InputException diff --git a/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/SetDataToLegacyCatalogInventoryAtSourceItemsSavePlugin.php b/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/SetDataToLegacyCatalogInventoryAtSourceItemsSavePlugin.php index 7c70726c205b..fd20ca03ca6b 100644 --- a/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/SetDataToLegacyCatalogInventoryAtSourceItemsSavePlugin.php +++ b/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/SetDataToLegacyCatalogInventoryAtSourceItemsSavePlugin.php @@ -60,7 +60,7 @@ public function __construct( public function afterExecute(SourceItemsSaveInterface $subject, $result, array $sourceItems) { foreach ($sourceItems as $sourceItem) { - if ((int)$sourceItem->getSourceId() !== $this->defaultSourceProvider->getId()) { + if ($sourceItem->getSourceCode() !== $this->defaultSourceProvider->getCode()) { continue; } $this->setDataToLegacyStockItem->execute( diff --git a/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/SetToZeroLegacyCatalogInventoryAtSourceItemsDeletePlugin.php b/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/SetToZeroLegacyCatalogInventoryAtSourceItemsDeletePlugin.php index 165228dc9def..b80606572818 100644 --- a/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/SetToZeroLegacyCatalogInventoryAtSourceItemsDeletePlugin.php +++ b/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/SetToZeroLegacyCatalogInventoryAtSourceItemsDeletePlugin.php @@ -61,7 +61,7 @@ public function __construct( public function afterExecute(SourceItemsDeleteInterface $subject, $result, array $sourceItems) { foreach ($sourceItems as $sourceItem) { - if ((int)$sourceItem->getSourceId() !== $this->defaultSourceProvider->getId()) { + if ($sourceItem->getSourceCode() !== $this->defaultSourceProvider->getCode()) { continue; } $this->setDataToLegacyStockItem->execute($sourceItem->getSku(), 0, 0); From 5e7fcae65e13fe8c202bc56fd068f2bffb349c22 Mon Sep 17 00:00:00 2001 From: Igor Miniailo Date: Fri, 22 Dec 2017 17:21:07 +0200 Subject: [PATCH 22/39] Make Indexers to use SourceId instead of SourceCode --- .../Indexer/Source/GetAssignedStockIds.php | 25 ++++++++++++++++--- .../Indexer/Source/SourceIndexer.php | 8 +++--- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php b/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php index be873ff320a3..d68969e3a68c 100644 --- a/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php +++ b/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php @@ -10,6 +10,8 @@ use Magento\Framework\App\ResourceConnection; use Magento\Inventory\Model\ResourceModel\StockSourceLink as StockSourceLinkResourceModel; use Magento\Inventory\Model\StockSourceLink; +use Magento\Inventory\Model\ResourceModel\Source; +use Magento\InventoryApi\Api\Data\SourceInterface; /** * Returns assigned Stock ids by given Source ids @@ -31,20 +33,35 @@ public function __construct( } /** - * @param string[] $sourceCodes + * @param string[] $sourceIds * @return int[] */ - public function execute(array $sourceCodes): array + public function execute(array $sourceIds): array { $connection = $this->resourceConnection->getConnection(); $sourceStockLinkTable = $this->resourceConnection->getTableName( StockSourceLinkResourceModel::TABLE_NAME_STOCK_SOURCE_LINK ); + $sourceTable = $this->resourceConnection->getTableName( + Source::TABLE_NAME_SOURCE + ); $select = $connection ->select() - ->from($sourceStockLinkTable, StockSourceLink::STOCK_ID) - ->where(StockSourceLink::SOURCE_CODE . ' IN (?)', $sourceCodes) + ->from( + ['sourceStockLink' => $sourceStockLinkTable], + StockSourceLink::STOCK_ID + ) + ->joinInner( + ['source' => $sourceTable], + sprintf( + 'sourceStockLink.%s = source.%s', + SourceInterface::CODE, + StockSourceLink::SOURCE_CODE + ), + [] + ) + ->where(SourceInterface::SOURCE_ID . ' IN (?)', $sourceIds) ->group(StockSourceLink::STOCK_ID); $stockIds = $connection->fetchCol($select); diff --git a/app/code/Magento/Inventory/Indexer/Source/SourceIndexer.php b/app/code/Magento/Inventory/Indexer/Source/SourceIndexer.php index 42ccc84003a3..cede86e7585b 100644 --- a/app/code/Magento/Inventory/Indexer/Source/SourceIndexer.php +++ b/app/code/Magento/Inventory/Indexer/Source/SourceIndexer.php @@ -56,17 +56,17 @@ public function executeFull() /** * @inheritdoc */ - public function executeRow($sourceCode) + public function executeRow($sourceId) { - $this->executeList([$sourceCode]); + $this->executeList([$sourceId]); } /** * @inheritdoc */ - public function executeList(array $sourceCode) + public function executeList(array $sourceIds) { - $stockIds = $this->getAssignedStockIds->execute($sourceCode); + $stockIds = $this->getAssignedStockIds->execute($sourceIds); $this->stockIndexer->executeList($stockIds); } } From dac634d106e216a88192002860335562f3507090 Mon Sep 17 00:00:00 2001 From: Igor Miniailo Date: Fri, 22 Dec 2017 17:29:42 +0200 Subject: [PATCH 23/39] Make Indexers to use SourceId instead of SourceCode --- app/code/Magento/Inventory/etc/mview.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Inventory/etc/mview.xml b/app/code/Magento/Inventory/etc/mview.xml index ebb3b0aa45d4..44a586422a35 100644 --- a/app/code/Magento/Inventory/etc/mview.xml +++ b/app/code/Magento/Inventory/etc/mview.xml @@ -13,7 +13,7 @@ -
+
From 5364986113830691a50c0a7dd96c545f2e41c995 Mon Sep 17 00:00:00 2001 From: Igor Miniailo Date: Fri, 22 Dec 2017 18:00:00 +0200 Subject: [PATCH 24/39] Make Indexers to use SourceId instead of SourceCode --- .../Magento/Inventory/Indexer/Source/GetAssignedStockIds.php | 4 ++-- .../Inventory/Test/Integration/Indexer/SourceIndexerTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php b/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php index d68969e3a68c..f1cdca21a445 100644 --- a/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php +++ b/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php @@ -56,8 +56,8 @@ public function execute(array $sourceIds): array ['source' => $sourceTable], sprintf( 'sourceStockLink.%s = source.%s', - SourceInterface::CODE, - StockSourceLink::SOURCE_CODE + StockSourceLink::SOURCE_CODE, + SourceInterface::CODE ), [] ) diff --git a/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php b/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php index 26176b0a7548..d3b93319ec2f 100644 --- a/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php +++ b/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php @@ -56,7 +56,7 @@ protected function tearDown() */ public function testReindexRow() { - $this->indexer->reindexRow('eu-1'); + $this->indexer->reindexRow(10); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 10)); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 30)); @@ -71,7 +71,7 @@ public function testReindexRow() */ public function testReindexList() { - $this->indexer->reindexList(['eu-1', 'us-1']); + $this->indexer->reindexList([10, 50]); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 10)); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 30)); From c6e0ebfc1c0a20e505ec674557ad02eb1a34f1ae Mon Sep 17 00:00:00 2001 From: Igor Miniailo Date: Sat, 23 Dec 2017 11:41:33 +0200 Subject: [PATCH 25/39] Remove Source Id from Admin UI --- .../Controller/Adminhtml/Source/Edit.php | 6 +-- .../Adminhtml/Source/InlineEdit.php | 10 ++--- .../Controller/Adminhtml/Source/Save.php | 39 +++++++++---------- .../Inventory/Model/ResourceModel/Source.php | 2 +- .../Ui/DataProvider/SourceDataProvider.php | 7 ++-- .../ui_component/inventory_source_form.xml | 4 +- .../ui_component/inventory_source_listing.xml | 17 +++----- 7 files changed, 38 insertions(+), 47 deletions(-) diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php index b8d323976af5..80034ed50b0e 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php @@ -49,9 +49,9 @@ public function __construct( */ public function execute(): ResultInterface { - $sourceId = (int)$this->getRequest()->getParam(SourceInterface::SOURCE_ID); + $sourceCode = $this->getRequest()->getParam(SourceInterface::CODE); try { - $source = $this->sourceRepository->getBySourceId($sourceId); + $source = $this->sourceRepository->get($sourceCode); /** @var Page $result */ $result = $this->resultFactory->create(ResultFactory::TYPE_PAGE); @@ -64,7 +64,7 @@ public function execute(): ResultInterface /** @var Redirect $result */ $result = $this->resultRedirectFactory->create(); $this->messageManager->addErrorMessage( - __('Source with source id "%value" does not exist.', ['value' => $sourceId]) + __('Source with source code "%value" does not exist.', ['value' => $sourceCode]) ); $result->setPath('*/*'); } diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/InlineEdit.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/InlineEdit.php index c15aeb7a5ee4..bf54d6a59b6a 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/InlineEdit.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/InlineEdit.php @@ -66,19 +66,19 @@ public function execute(): ResultInterface if ($request->isXmlHttpRequest() && $request->isPost() && $requestData) { foreach ($requestData as $itemData) { try { - $sourceId = (int)$itemData[SourceInterface::SOURCE_ID]; - $source = $this->sourceRepository->getBySourceId($sourceId); + $sourceCode = $itemData[SourceInterface::CODE]; + $source = $this->sourceRepository->get($sourceCode); $this->dataObjectHelper->populateWithArray($source, $itemData, SourceInterface::class); $this->sourceRepository->save($source); } catch (NoSuchEntityException $e) { $errorMessages[] = __( '[ID: %value] The Source does not exist.', - ['value' => $sourceId] + ['value' => $sourceCode] ); } catch (ValidationException $e) { foreach ($e->getErrors() as $localizedError) { $errorMessages[] = __('[ID: %value] %message', [ - 'value' => $sourceId, + 'value' => $sourceCode, 'message' => $localizedError->getMessage() ]); } @@ -86,7 +86,7 @@ public function execute(): ResultInterface $errorMessages[] = __( '[ID: %value] %message', [ - 'value' => $sourceId, + 'value' => $sourceCode, 'message' => $e->getMessage() ] ); diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php index 957caeae8801..9ccca6c28ab7 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php @@ -78,13 +78,11 @@ public function execute(): ResultInterface } try { - $sourceId = isset($requestData['general'][SourceInterface::SOURCE_ID]) - ? (int)$requestData['general'][SourceInterface::SOURCE_ID] - : null; - $sourceId = $this->processSave($requestData, $sourceId); + $sourceCode = $requestData['general'][SourceInterface::CODE]; + $sourceId = $this->processSave($requestData, $sourceCode); $this->messageManager->addSuccessMessage(__('The Source has been saved.')); - $this->processRedirectAfterSuccessSave($resultRedirect, $sourceId); + $this->processRedirectAfterSuccessSave($resultRedirect, $sourceCode); } catch (NoSuchEntityException $e) { $this->messageManager->addErrorMessage(__('The Source does not exist.')); $this->processRedirectAfterFailureSave($resultRedirect); @@ -92,13 +90,13 @@ public function execute(): ResultInterface foreach ($e->getErrors() as $localizedError) { $this->messageManager->addErrorMessage($localizedError->getMessage()); } - $this->processRedirectAfterFailureSave($resultRedirect, $sourceId); + $this->processRedirectAfterFailureSave($resultRedirect, $sourceCode); } catch (CouldNotSaveException $e) { $this->messageManager->addErrorMessage($e->getMessage()); - $this->processRedirectAfterFailureSave($resultRedirect, $sourceId); + $this->processRedirectAfterFailureSave($resultRedirect, $sourceCode); } catch (Exception $e) { $this->messageManager->addErrorMessage(__('Could not save Source.')); - $this->processRedirectAfterFailureSave($resultRedirect, $sourceId ?? null); + $this->processRedirectAfterFailureSave($resultRedirect, $sourceCode); } return $resultRedirect; @@ -106,18 +104,19 @@ public function execute(): ResultInterface /** * @param array $requestData - * @param int|null $sourceId + * @param string $sourceCode * * @return int */ - private function processSave(array $requestData, int $sourceId = null): int + private function processSave(array $requestData, string $sourceCode): int { - if (null === $sourceId) { + try { + $source = $this->sourceRepository->get($sourceCode); + } catch (NoSuchEntityException $e) { /** @var SourceInterface $source */ $source = $this->sourceFactory->create(); - } else { - $source = $this->sourceRepository->getBySourceId($sourceId); } + $source = $this->sourceHydrator->hydrate($source, $requestData); $this->_eventManager->dispatch( @@ -143,15 +142,15 @@ private function processSave(array $requestData, int $sourceId = null): int /** * @param Redirect $resultRedirect - * @param int $sourceId + * @param string $sourceCode * * @return void */ - private function processRedirectAfterSuccessSave(Redirect $resultRedirect, int $sourceId) + private function processRedirectAfterSuccessSave(Redirect $resultRedirect, string $sourceCode) { if ($this->getRequest()->getParam('back')) { $resultRedirect->setPath('*/*/edit', [ - SourceInterface::SOURCE_ID => $sourceId, + SourceInterface::CODE => $sourceCode, '_current' => true, ]); } elseif ($this->getRequest()->getParam('redirect_to_new')) { @@ -165,17 +164,17 @@ private function processRedirectAfterSuccessSave(Redirect $resultRedirect, int $ /** * @param Redirect $resultRedirect - * @param int|null $sourceId + * @param string $sourceCode * * @return void */ - private function processRedirectAfterFailureSave(Redirect $resultRedirect, int $sourceId = null) + private function processRedirectAfterFailureSave(Redirect $resultRedirect, string $sourceCode) { - if (null === $sourceId) { + if (null === $sourceCode) { $resultRedirect->setPath('*/*/new'); } else { $resultRedirect->setPath('*/*/edit', [ - SourceInterface::SOURCE_ID => $sourceId, + SourceInterface::CODE => $sourceCode, '_current' => true, ]); } diff --git a/app/code/Magento/Inventory/Model/ResourceModel/Source.php b/app/code/Magento/Inventory/Model/ResourceModel/Source.php index 178ee61dae21..b2151a343e49 100644 --- a/app/code/Magento/Inventory/Model/ResourceModel/Source.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/Source.php @@ -54,7 +54,7 @@ public function __construct( */ protected function _construct() { - $this->_init(self::TABLE_NAME_SOURCE, SourceInterface::SOURCE_ID); + $this->_init(self::TABLE_NAME_SOURCE, SourceInterface::CODE); } /** diff --git a/app/code/Magento/Inventory/Ui/DataProvider/SourceDataProvider.php b/app/code/Magento/Inventory/Ui/DataProvider/SourceDataProvider.php index c8461d701760..7a85c4c10466 100644 --- a/app/code/Magento/Inventory/Ui/DataProvider/SourceDataProvider.php +++ b/app/code/Magento/Inventory/Ui/DataProvider/SourceDataProvider.php @@ -83,11 +83,10 @@ public function getData() // It is need for support of several fieldsets. // For details see \Magento\Ui\Component\Form::getDataSourceData if ($data['totalRecords'] > 0) { - $sourceId = (int)$data['items'][0][SourceInterface::SOURCE_ID]; - $sourceCode = (string)$data['items'][0][SourceInterface::CODE]; + $sourceCode = $data['items'][0][SourceInterface::CODE]; $sourceGeneralData = $data['items'][0]; $sourceGeneralData['carrier_codes'] = $this->getAssignedCarrierCodes($sourceCode); - $dataForSingle[$sourceId] = [ + $dataForSingle[$sourceCode] = [ 'general' => $sourceGeneralData, ]; $data = $dataForSingle; @@ -110,7 +109,7 @@ public function getSearchResult() $result->getItems(), $result->getTotalCount(), $searchCriteria, - SourceInterface::SOURCE_ID + SourceInterface::CODE ); return $searchResult; } diff --git a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml index 78aed75bcf76..d6a629b0b989 100644 --- a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml +++ b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml @@ -38,8 +38,8 @@ - source_id - source_id + code + code diff --git a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml index 780bf30a66f4..9df198fbb7a6 100644 --- a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml +++ b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml @@ -27,15 +27,15 @@ - source_id + code Magento_InventoryApi::source - source_id - source_id + code + code @@ -68,7 +68,7 @@ false - source_id + code true inventory_source_listing.inventory_source_listing.inventory_source_listing_columns.ids @@ -88,13 +88,6 @@ code - - - textRange - - asc - - text @@ -282,7 +275,7 @@ - source_id + code From abacf956c8f296cebd502695fd89bb6bd7e86941 Mon Sep 17 00:00:00 2001 From: Igor Miniailo Date: Sat, 23 Dec 2017 11:56:59 +0200 Subject: [PATCH 26/39] remove Source ID from API Interfaces --- .../Controller/Adminhtml/Source/Save.php | 8 +-- app/code/Magento/Inventory/Model/Source.php | 16 ------ .../Model/Source/Command/GetBySourceId.php | 56 ------------------- .../Source/Command/GetBySourceIdInterface.php | 33 ----------- .../Inventory/Model/Source/Command/Save.php | 5 +- .../Model/Source/Command/SaveInterface.php | 4 +- .../Inventory/Model/SourceRepository.php | 19 +------ .../Test/Unit/Model/SourceRepositoryTest.php | 7 +-- app/code/Magento/Inventory/etc/di.xml | 1 - .../InventoryApi/Api/Data/SourceInterface.php | 15 ----- .../Api/SourceRepositoryInterface.php | 14 +---- 11 files changed, 12 insertions(+), 166 deletions(-) delete mode 100644 app/code/Magento/Inventory/Model/Source/Command/GetBySourceId.php delete mode 100644 app/code/Magento/Inventory/Model/Source/Command/GetBySourceIdInterface.php diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php index 9ccca6c28ab7..f5f46bd0be3e 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php @@ -79,7 +79,7 @@ public function execute(): ResultInterface try { $sourceCode = $requestData['general'][SourceInterface::CODE]; - $sourceId = $this->processSave($requestData, $sourceCode); + $this->processSave($requestData, $sourceCode); $this->messageManager->addSuccessMessage(__('The Source has been saved.')); $this->processRedirectAfterSuccessSave($resultRedirect, $sourceCode); @@ -106,7 +106,7 @@ public function execute(): ResultInterface * @param array $requestData * @param string $sourceCode * - * @return int + * @return void */ private function processSave(array $requestData, string $sourceCode): int { @@ -127,7 +127,7 @@ private function processSave(array $requestData, string $sourceCode): int ] ); - $sourceId = $this->sourceRepository->save($source); + $this->sourceRepository->save($source); $this->_eventManager->dispatch( 'controller_action_inventory_source_save_after', @@ -136,8 +136,6 @@ private function processSave(array $requestData, string $sourceCode): int 'source' => $source, ] ); - - return $sourceId; } /** diff --git a/app/code/Magento/Inventory/Model/Source.php b/app/code/Magento/Inventory/Model/Source.php index d119ecae728f..a7be04539b81 100644 --- a/app/code/Magento/Inventory/Model/Source.php +++ b/app/code/Magento/Inventory/Model/Source.php @@ -27,22 +27,6 @@ protected function _construct() $this->_init(SourceResourceModel::class); } - /** - * @inheritdoc - */ - public function getSourceId() - { - return $this->getData(self::SOURCE_ID); - } - - /** - * @inheritdoc - */ - public function setSourceId($sourceId) - { - $this->setData(self::SOURCE_ID, $sourceId); - } - /** * @inheritdoc */ diff --git a/app/code/Magento/Inventory/Model/Source/Command/GetBySourceId.php b/app/code/Magento/Inventory/Model/Source/Command/GetBySourceId.php deleted file mode 100644 index f61afb1fbb2a..000000000000 --- a/app/code/Magento/Inventory/Model/Source/Command/GetBySourceId.php +++ /dev/null @@ -1,56 +0,0 @@ -sourceResource = $sourceResource; - $this->sourceFactory = $sourceFactory; - } - - /** - * @inheritdoc - */ - public function execute(int $sourceId): SourceInterface - { - /** @var SourceInterface $source */ - $source = $this->sourceFactory->create(); - $this->sourceResource->load($source, $sourceId, SourceInterface::SOURCE_ID); - - if (null === $source->getCode()) { - throw new NoSuchEntityException(__('Source with id "%value" does not exist.', ['value' => $sourceId])); - } - return $source; - } -} diff --git a/app/code/Magento/Inventory/Model/Source/Command/GetBySourceIdInterface.php b/app/code/Magento/Inventory/Model/Source/Command/GetBySourceIdInterface.php deleted file mode 100644 index 828223b42e02..000000000000 --- a/app/code/Magento/Inventory/Model/Source/Command/GetBySourceIdInterface.php +++ /dev/null @@ -1,33 +0,0 @@ -sourceValidator->validate($source); @@ -61,8 +61,7 @@ public function execute(SourceInterface $source): int } try { - $this->sourceResource->save($source); - return (int)$source->getSourceId(); + return $this->sourceResource->save($source); } catch (\Exception $e) { $this->logger->error($e->getMessage()); throw new CouldNotSaveException(__('Could not save Source'), $e); diff --git a/app/code/Magento/Inventory/Model/Source/Command/SaveInterface.php b/app/code/Magento/Inventory/Model/Source/Command/SaveInterface.php index e68908f35230..24e5805b069b 100644 --- a/app/code/Magento/Inventory/Model/Source/Command/SaveInterface.php +++ b/app/code/Magento/Inventory/Model/Source/Command/SaveInterface.php @@ -27,9 +27,9 @@ interface SaveInterface * Save Source data * * @param SourceInterface $source - * @return int + * @return void * @throws ValidationException * @throws CouldNotSaveException */ - public function execute(SourceInterface $source): int; + public function execute(SourceInterface $source); } diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index 571a176daf36..dbc0a9e300e6 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -9,7 +9,6 @@ use Magento\Framework\Api\SearchCriteriaInterface; use Magento\Inventory\Model\Source\Command\GetInterface; -use Magento\Inventory\Model\Source\Command\GetBySourceIdInterface; use Magento\Inventory\Model\Source\Command\GetListInterface; use Magento\Inventory\Model\Source\Command\SaveInterface; use Magento\InventoryApi\Api\Data\SourceInterface; @@ -31,11 +30,6 @@ class SourceRepository implements SourceRepositoryInterface */ private $commandGet; - /** - * @var GetBySourceIdInterface - */ - private $commandGetBySourceId; - /** * @var GetListInterface */ @@ -44,25 +38,22 @@ class SourceRepository implements SourceRepositoryInterface /** * @param SaveInterface $commandSave * @param GetInterface $commandGet - * @param GetBySourceIdInterface $commandGetBySourceId * @param GetListInterface $commandGetList */ public function __construct( SaveInterface $commandSave, GetInterface $commandGet, - GetBySourceIdInterface $commandGetBySourceId, GetListInterface $commandGetList ) { $this->commandSave = $commandSave; $this->commandGet = $commandGet; - $this->commandGetBySourceId = $commandGetBySourceId; $this->commandGetList = $commandGetList; } /** * @inheritdoc */ - public function save(SourceInterface $source): int + public function save(SourceInterface $source) { return $this->commandSave->execute($source); } @@ -75,14 +66,6 @@ public function get(string $code): SourceInterface return $this->commandGet->execute($code); } - /** - * @inheritdoc - */ - public function getBySourceId(int $sourceId): SourceInterface - { - return $this->commandGetBySourceId->execute($sourceId); - } - /** * @inheritdoc */ diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php index 65080df394b9..4e51b6b30a71 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php @@ -71,15 +71,12 @@ protected function setUp() public function testSave() { - $sourceId = 42; - $this->commandSave ->expects($this->once()) ->method('execute') - ->with($this->source) - ->willReturn($sourceId); + ->with($this->source); - self::assertEquals($sourceId, $this->sourceRepository->save($this->source)); + $this->sourceRepository->save($this->source); } /** diff --git a/app/code/Magento/Inventory/etc/di.xml b/app/code/Magento/Inventory/etc/di.xml index 96b4b2a30eaa..c5877a634cb3 100644 --- a/app/code/Magento/Inventory/etc/di.xml +++ b/app/code/Magento/Inventory/etc/di.xml @@ -13,7 +13,6 @@ - diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php index 8a834b062c17..d47b8740aa1f 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php @@ -42,21 +42,6 @@ interface SourceInterface extends ExtensibleDataInterface const USE_DEFAULT_CARRIER_CONFIG = 'use_default_carrier_config'; const CARRIER_LINKS = 'carrier_links'; - /** - * Get source id - * - * @return int|null - */ - public function getSourceId(); - - /** - * Set source id - * - * @param int|null $sourceId - * @return void - */ - public function setSourceId($sourceId); - /** * Get source code * diff --git a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php index f9a58c3f0e78..5d9bb4e06967 100644 --- a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php +++ b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php @@ -36,11 +36,11 @@ interface SourceRepositoryInterface * Save Source data * * @param \Magento\InventoryApi\Api\Data\SourceInterface $source - * @return int + * @return void * @throws \Magento\Framework\Validation\ValidationException * @throws \Magento\Framework\Exception\CouldNotSaveException */ - public function save(SourceInterface $source): int; + public function save(SourceInterface $source); /** * Get Source data by given code. If you want to create plugin on get method, also you need to create separate @@ -52,16 +52,6 @@ public function save(SourceInterface $source): int; */ public function get(string $code): SourceInterface; - /** - * Get Source data by given source id. If you want to create plugin on get method, also you need to create separate - * plugin on getList method, because entity loading way is different for these methods - * - * @param int $sourceId - * @return \Magento\InventoryApi\Api\Data\SourceInterface - * @throws \Magento\Framework\Exception\NoSuchEntityException - */ - public function getBySourceId(int $sourceId): SourceInterface; - /** * Find Sources by SearchCriteria * SearchCriteria is not required because load all stocks is useful case From 1ce881b08d3ca721480bc3eae1e01bf85f8c2c95 Mon Sep 17 00:00:00 2001 From: Igor Miniailo Date: Sat, 23 Dec 2017 12:04:07 +0200 Subject: [PATCH 27/39] remove Source ID from API Interfaces --- app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php index f5f46bd0be3e..d723e880bd3e 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php @@ -108,7 +108,7 @@ public function execute(): ResultInterface * * @return void */ - private function processSave(array $requestData, string $sourceCode): int + private function processSave(array $requestData, string $sourceCode) { try { $source = $this->sourceRepository->get($sourceCode); From 54f6e59ea8f533363605bff93cf807bb26c83ec2 Mon Sep 17 00:00:00 2001 From: deadlexus Date: Sat, 23 Dec 2017 15:39:02 +0300 Subject: [PATCH 28/39] Added setSourceId method to the Source model --- app/code/Magento/Inventory/Model/Source.php | 8 ++++++++ .../Magento/InventoryApi/Api/Data/SourceInterface.php | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/app/code/Magento/Inventory/Model/Source.php b/app/code/Magento/Inventory/Model/Source.php index a7be04539b81..c0396f83a7a4 100644 --- a/app/code/Magento/Inventory/Model/Source.php +++ b/app/code/Magento/Inventory/Model/Source.php @@ -27,6 +27,14 @@ protected function _construct() $this->_init(SourceResourceModel::class); } + /** + * @inheritdoc + */ + public function setSourceId($sourceId) + { + return $this->setData(self::SOURCE_ID, $sourceId); + } + /** * @inheritdoc */ diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php index d47b8740aa1f..ddc70ab758be 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php @@ -42,6 +42,14 @@ interface SourceInterface extends ExtensibleDataInterface const USE_DEFAULT_CARRIER_CONFIG = 'use_default_carrier_config'; const CARRIER_LINKS = 'carrier_links'; + /** + * Set source id + * + * @param int|null $sourceId + * @return void + */ + public function setSourceId($sourceId); + /** * Get source code * From 948d4f6245bb6a3727eabaa2629bb8595ac69083 Mon Sep 17 00:00:00 2001 From: deadlexus Date: Sat, 23 Dec 2017 15:57:40 +0300 Subject: [PATCH 29/39] source_id field constant moved from 'Source' model to resource model --- .../Inventory/Indexer/Source/GetAssignedStockIds.php | 3 ++- .../Magento/Inventory/Model/ResourceModel/Source.php | 1 + app/code/Magento/Inventory/Model/Source.php | 2 +- .../Inventory/Setup/Operation/CreateSourceTable.php | 2 +- .../Magento/InventoryApi/Api/Data/SourceInterface.php | 1 - .../Test/Api/SourceRepository/CreateTest.php | 3 ++- .../Api/SourceRepository/RegionProcessingTest.php | 3 ++- .../Test/Api/SourceRepository/UpdateTest.php | 3 ++- .../Api/StockSourceLink/AssignSourcesToStockTest.php | 4 ++-- .../GetAssignedSourcesForStockTest.php | 4 ++-- .../StockSourceLink/UnassignSourceFromStockTest.php | 4 ++-- app/code/Magento/InventoryApi/Test/_files/source.php | 3 ++- .../InventoryApi/Test/_files/source_rollback.php | 4 ++-- app/code/Magento/InventoryApi/Test/_files/sources.php | 11 ++++++----- .../InventoryApi/Test/_files/sources_rollback.php | 4 ++-- 15 files changed, 29 insertions(+), 23 deletions(-) diff --git a/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php b/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php index f1cdca21a445..46bba19d5500 100644 --- a/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php +++ b/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php @@ -8,6 +8,7 @@ namespace Magento\Inventory\Indexer\Source; use Magento\Framework\App\ResourceConnection; +use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\Inventory\Model\ResourceModel\StockSourceLink as StockSourceLinkResourceModel; use Magento\Inventory\Model\StockSourceLink; use Magento\Inventory\Model\ResourceModel\Source; @@ -61,7 +62,7 @@ public function execute(array $sourceIds): array ), [] ) - ->where(SourceInterface::SOURCE_ID . ' IN (?)', $sourceIds) + ->where(SourceResourceModel::SOURCE_ID_FIELD . ' IN (?)', $sourceIds) ->group(StockSourceLink::STOCK_ID); $stockIds = $connection->fetchCol($select); diff --git a/app/code/Magento/Inventory/Model/ResourceModel/Source.php b/app/code/Magento/Inventory/Model/ResourceModel/Source.php index b2151a343e49..6e0d2b8bd9c6 100644 --- a/app/code/Magento/Inventory/Model/ResourceModel/Source.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/Source.php @@ -29,6 +29,7 @@ class Source extends AbstractDb */ const TABLE_NAME_SOURCE = 'inventory_source'; /**#@-*/ + const SOURCE_ID_FIELD = 'source_id'; /** * @var SourceCarrierLinkManagementInterface diff --git a/app/code/Magento/Inventory/Model/Source.php b/app/code/Magento/Inventory/Model/Source.php index c0396f83a7a4..2f5e2f75aeca 100644 --- a/app/code/Magento/Inventory/Model/Source.php +++ b/app/code/Magento/Inventory/Model/Source.php @@ -32,7 +32,7 @@ protected function _construct() */ public function setSourceId($sourceId) { - return $this->setData(self::SOURCE_ID, $sourceId); + return $this->setData(SourceResourceModel::SOURCE_ID_FIELD, $sourceId); } /** diff --git a/app/code/Magento/Inventory/Setup/Operation/CreateSourceTable.php b/app/code/Magento/Inventory/Setup/Operation/CreateSourceTable.php index 9c9738398c83..c2250988109a 100644 --- a/app/code/Magento/Inventory/Setup/Operation/CreateSourceTable.php +++ b/app/code/Magento/Inventory/Setup/Operation/CreateSourceTable.php @@ -50,7 +50,7 @@ public function execute(SchemaSetupInterface $setup) private function addBaseFields(Table $sourceTable): Table { return $sourceTable->addColumn( - SourceInterface::SOURCE_ID, + SourceResourceModel::SOURCE_ID_FIELD, Table::TYPE_INTEGER, null, [ diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php index ddc70ab758be..811c3b388495 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php @@ -21,7 +21,6 @@ interface SourceInterface extends ExtensibleDataInterface /** * Constants for keys of data array. Identical to the name of the getter in snake case */ - const SOURCE_ID = 'source_id'; const CODE = 'code'; const NAME = 'name'; const CONTACT_NAME = 'contact_name'; diff --git a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CreateTest.php b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CreateTest.php index f667c57fe3de..c7e75d6a9ace 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CreateTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CreateTest.php @@ -9,6 +9,7 @@ use Magento\Framework\App\ResourceConnection; use Magento\Framework\Webapi\Rest\Request; +use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\TestFramework\Assert\AssertArrayContains; @@ -100,7 +101,7 @@ private function getSourceDataById(int $sourceId): array $response = (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) ? $this->_webApiCall($serviceInfo) : $this->_webApiCall($serviceInfo, ['sourceId' => $sourceId]); - self::assertArrayHasKey(SourceInterface::SOURCE_ID, $response); + self::assertArrayHasKey(SourceResourceModel::SOURCE_ID_FIELD, $response); return $response; } } diff --git a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/RegionProcessingTest.php b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/RegionProcessingTest.php index 5d0775de25ae..ca61cae57d16 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/RegionProcessingTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/RegionProcessingTest.php @@ -9,6 +9,7 @@ use Magento\Framework\App\ResourceConnection; use Magento\Framework\Webapi\Rest\Request; +use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\WebapiAbstract; @@ -131,7 +132,7 @@ private function getSourceDataById(int $sourceId): array $response = (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) ? $this->_webApiCall($serviceInfo) : $this->_webApiCall($serviceInfo, ['sourceId' => $sourceId]); - self::assertArrayHasKey(SourceInterface::SOURCE_ID, $response); + self::assertArrayHasKey(SourceResourceModel::SOURCE_ID_FIELD, $response); return $response; } } diff --git a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/UpdateTest.php b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/UpdateTest.php index 9931f3a952da..3e9f7afaecbe 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/UpdateTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/UpdateTest.php @@ -8,6 +8,7 @@ namespace Magento\InventoryApi\Test\Api\SourceRepository; use Magento\Framework\Webapi\Rest\Request; +use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\TestFramework\Assert\AssertArrayContains; @@ -97,7 +98,7 @@ private function getSourceDataById(int $sourceId): array $response = (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) ? $this->_webApiCall($serviceInfo) : $this->_webApiCall($serviceInfo, ['sourceId' => $sourceId]); - self::assertArrayHasKey(SourceInterface::SOURCE_ID, $response); + self::assertArrayHasKey(SourceResourceModel::SOURCE_ID_FIELD, $response); return $response; } } diff --git a/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/AssignSourcesToStockTest.php b/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/AssignSourcesToStockTest.php index 35c77802710b..32d24baf9a59 100644 --- a/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/AssignSourcesToStockTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/AssignSourcesToStockTest.php @@ -9,7 +9,7 @@ use Magento\Framework\Webapi\Exception; use Magento\Framework\Webapi\Rest\Request; -use Magento\InventoryApi\Api\Data\SourceInterface; +use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\TestFramework\TestCase\WebapiAbstract; class AssignSourcesToStockTest extends WebapiAbstract @@ -46,7 +46,7 @@ public function testAssignSourcesToStock() : $this->_webApiCall($serviceInfo, ['sourceIds' => $sourceIds, 'stockId' => $stockId]); $assignedSourcesForStock = $this->getAssignedSourcesForStock($stockId); - self::assertEquals($sourceIds, array_column($assignedSourcesForStock, SourceInterface::SOURCE_ID)); + self::assertEquals($sourceIds, array_column($assignedSourcesForStock, SourceResourceModel::SOURCE_ID_FIELD)); } /** diff --git a/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/GetAssignedSourcesForStockTest.php b/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/GetAssignedSourcesForStockTest.php index 93174e439d7b..cddeca853cbf 100644 --- a/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/GetAssignedSourcesForStockTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/GetAssignedSourcesForStockTest.php @@ -9,7 +9,7 @@ use Magento\Framework\Webapi\Exception; use Magento\Framework\Webapi\Rest\Request; -use Magento\InventoryApi\Api\Data\SourceInterface; +use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\TestFramework\TestCase\WebapiAbstract; class GetAssignedSourcesForStockTest extends WebapiAbstract @@ -42,7 +42,7 @@ public function testGetAssignedSourcesForStock() $response = (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) ? $this->_webApiCall($serviceInfo) : $this->_webApiCall($serviceInfo, ['stockId' => $stockId]); - self::assertEquals([10, 20, 30, 40], array_column($response, SourceInterface::SOURCE_ID)); + self::assertEquals([10, 20, 30, 40], array_column($response, SourceResourceModel::SOURCE_ID_FIELD)); } /** diff --git a/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/UnassignSourceFromStockTest.php b/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/UnassignSourceFromStockTest.php index c711948c3c64..b0a0af483286 100644 --- a/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/UnassignSourceFromStockTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/UnassignSourceFromStockTest.php @@ -9,7 +9,7 @@ use Magento\Framework\Webapi\Exception; use Magento\Framework\Webapi\Rest\Request; -use Magento\InventoryApi\Api\Data\SourceInterface; +use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\TestFramework\TestCase\WebapiAbstract; class UnassignSourceFromStockTest extends WebapiAbstract @@ -62,7 +62,7 @@ public function testUnassignSourceFromStock() : $this->_webApiCall($serviceInfo, ['sourceId' => $sourceId, 'stockId' => $stockId]); $assignedSourcesForStock = $this->getAssignedSourcesForStock($stockId); - self::assertEquals([20, 30, 40], array_column($assignedSourcesForStock, SourceInterface::SOURCE_ID)); + self::assertEquals([20, 30, 40], array_column($assignedSourcesForStock, SourceResourceModel::SOURCE_ID_FIELD)); } /** diff --git a/app/code/Magento/InventoryApi/Test/_files/source.php b/app/code/Magento/InventoryApi/Test/_files/source.php index 018604ac50df..3ef31db23706 100644 --- a/app/code/Magento/InventoryApi/Test/_files/source.php +++ b/app/code/Magento/InventoryApi/Test/_files/source.php @@ -6,6 +6,7 @@ declare(strict_types=1); use Magento\Framework\Api\DataObjectHelper; +use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; @@ -24,7 +25,7 @@ $dataObjectHelper->populateWithArray( $source, [ - SourceInterface::SOURCE_ID => 10, + SourceResourceModel::SOURCE_ID_FIELD => 10, SourceInterface::CODE => 'source-code', SourceInterface::NAME => 'source-name-1', SourceInterface::CONTACT_NAME => 'source-contact-name', diff --git a/app/code/Magento/InventoryApi/Test/_files/source_rollback.php b/app/code/Magento/InventoryApi/Test/_files/source_rollback.php index 28bd271fbaa7..40653a75fa43 100644 --- a/app/code/Magento/InventoryApi/Test/_files/source_rollback.php +++ b/app/code/Magento/InventoryApi/Test/_files/source_rollback.php @@ -6,11 +6,11 @@ declare(strict_types=1); use Magento\Framework\App\ResourceConnection; -use Magento\InventoryApi\Api\Data\SourceInterface; +use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\TestFramework\Helper\Bootstrap; /** @var ResourceConnection $connection */ $connection = Bootstrap::getObjectManager()->get(ResourceConnection::class); $connection->getConnection()->delete($connection->getTableName('inventory_source'), [ - SourceInterface::SOURCE_ID . ' = ?' => 10, + SourceResourceModel::SOURCE_ID_FIELD . ' = ?' => 10, ]); diff --git a/app/code/Magento/InventoryApi/Test/_files/sources.php b/app/code/Magento/InventoryApi/Test/_files/sources.php index 453bfd8deddd..edfb0b2a3e00 100644 --- a/app/code/Magento/InventoryApi/Test/_files/sources.php +++ b/app/code/Magento/InventoryApi/Test/_files/sources.php @@ -6,6 +6,7 @@ declare(strict_types=1); use Magento\Framework\Api\DataObjectHelper; +use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; use Magento\InventoryApi\Api\SourceRepositoryInterface; @@ -21,7 +22,7 @@ $sourcesData = [ [ // define only required and needed for tests fields - SourceInterface::SOURCE_ID => 10, + SourceResourceModel::SOURCE_ID_FIELD => 10, SourceInterface::CODE => 'eu-1', SourceInterface::NAME => 'EU-source-1', SourceInterface::ENABLED => true, @@ -30,7 +31,7 @@ SourceInterface::COUNTRY_ID => 'FR', ], [ - SourceInterface::SOURCE_ID => 20, + SourceResourceModel::SOURCE_ID_FIELD => 20, SourceInterface::CODE => 'eu-2', SourceInterface::NAME => 'EU-source-2', SourceInterface::ENABLED => true, @@ -39,7 +40,7 @@ SourceInterface::COUNTRY_ID => 'FR', ], [ - SourceInterface::SOURCE_ID => 30, + SourceResourceModel::SOURCE_ID_FIELD => 30, SourceInterface::CODE => 'eu-3', SourceInterface::NAME => 'EU-source-3', SourceInterface::ENABLED => true, @@ -48,7 +49,7 @@ SourceInterface::COUNTRY_ID => 'DE', ], [ - SourceInterface::SOURCE_ID => 40, + SourceResourceModel::SOURCE_ID_FIELD => 40, SourceInterface::CODE => 'eu-dis', SourceInterface::NAME => 'EU-source-disabled', SourceInterface::ENABLED => false, @@ -57,7 +58,7 @@ SourceInterface::COUNTRY_ID => 'DE', ], [ - SourceInterface::SOURCE_ID => 50, + SourceResourceModel::SOURCE_ID_FIELD => 50, SourceInterface::CODE => 'us-1', SourceInterface::NAME => 'US-source-1', SourceInterface::ENABLED => true, diff --git a/app/code/Magento/InventoryApi/Test/_files/sources_rollback.php b/app/code/Magento/InventoryApi/Test/_files/sources_rollback.php index e710b72aa27f..8ecab970ada8 100644 --- a/app/code/Magento/InventoryApi/Test/_files/sources_rollback.php +++ b/app/code/Magento/InventoryApi/Test/_files/sources_rollback.php @@ -6,7 +6,7 @@ declare(strict_types=1); use Magento\Framework\App\ResourceConnection; -use Magento\InventoryApi\Api\Data\SourceInterface; +use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\TestFramework\Helper\Bootstrap; /** @var ResourceConnection $connection */ @@ -14,6 +14,6 @@ $connection->getConnection()->delete( $connection->getTableName('inventory_source'), [ - SourceInterface::SOURCE_ID . ' IN (?)' => [10, 20, 30, 40, 50], + SourceResourceModel::SOURCE_ID_FIELD . ' IN (?)' => [10, 20, 30, 40, 50], ] ); From e8f84d4e07ae6abe0d1342c0a7a6b44bb504d764 Mon Sep 17 00:00:00 2001 From: Alex Yakimovich Date: Tue, 26 Dec 2017 13:37:43 +0300 Subject: [PATCH 30/39] Removed setSourceId method from source model; fixed integration test; --- app/code/Magento/Inventory/Model/Source.php | 8 ----- .../Integration/Indexer/SourceIndexerTest.php | 33 +++++++++++++++++-- .../InventoryApi/Api/Data/SourceInterface.php | 8 ----- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/app/code/Magento/Inventory/Model/Source.php b/app/code/Magento/Inventory/Model/Source.php index 2f5e2f75aeca..a7be04539b81 100644 --- a/app/code/Magento/Inventory/Model/Source.php +++ b/app/code/Magento/Inventory/Model/Source.php @@ -27,14 +27,6 @@ protected function _construct() $this->_init(SourceResourceModel::class); } - /** - * @inheritdoc - */ - public function setSourceId($sourceId) - { - return $this->setData(SourceResourceModel::SOURCE_ID_FIELD, $sourceId); - } - /** * @inheritdoc */ diff --git a/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php b/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php index d3b93319ec2f..3c03c91e2add 100644 --- a/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php +++ b/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php @@ -7,9 +7,13 @@ namespace Magento\Inventory\Test\Integration\Indexer; +use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\Indexer\IndexerInterface; use Magento\Inventory\Indexer\Source\SourceIndexer; +use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; +use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\GetProductQuantityInStockInterface; +use Magento\InventoryApi\Api\SourceRepositoryInterface; use Magento\TestFramework\Helper\Bootstrap; use PHPUnit\Framework\TestCase; @@ -30,6 +34,16 @@ class SourceIndexerTest extends TestCase */ private $removeIndexData; + /** + * @var SearchCriteriaBuilder + */ + private $searchCriteriaBuilder; + + /** + * @var SourceRepositoryInterface + */ + private $sourceRepository; + protected function setUp() { $this->indexer = Bootstrap::getObjectManager()->get(IndexerInterface::class); @@ -40,6 +54,11 @@ protected function setUp() $this->removeIndexData = Bootstrap::getObjectManager()->get(RemoveIndexData::class); $this->removeIndexData->execute([10, 20, 30]); + + + $this->sourceRepository = Bootstrap::getObjectManager()->get(SourceRepositoryInterface::class); + + $this->searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class); } protected function tearDown() @@ -56,7 +75,8 @@ protected function tearDown() */ public function testReindexRow() { - $this->indexer->reindexRow(10); + $source = $this->sourceRepository->get('eu-1'); + $this->indexer->reindexRow($source->getData(SourceResourceModel::SOURCE_ID_FIELD)); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 10)); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 30)); @@ -71,7 +91,16 @@ public function testReindexRow() */ public function testReindexList() { - $this->indexer->reindexList([10, 50]); + $sourceIds = []; + $searchCriteria = $this->searchCriteriaBuilder + ->addFilter(SourceInterface::CODE, ['eu-1', 'us-1'], 'in') + ->create(); + $sourceList = $this->sourceRepository->getList($searchCriteria); + foreach ($sourceList->getItems() as $source) { + $sourceIds[] = $source->getData(SourceResourceModel::SOURCE_ID_FIELD); + } + + $this->indexer->reindexList($sourceIds); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 10)); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 30)); diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php index 811c3b388495..62d19eb8f5a3 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php @@ -41,14 +41,6 @@ interface SourceInterface extends ExtensibleDataInterface const USE_DEFAULT_CARRIER_CONFIG = 'use_default_carrier_config'; const CARRIER_LINKS = 'carrier_links'; - /** - * Set source id - * - * @param int|null $sourceId - * @return void - */ - public function setSourceId($sourceId); - /** * Get source code * From b9de5f5b7ea4ab5c900bf798fcd87c7c3c0edaf3 Mon Sep 17 00:00:00 2001 From: Alex Yakimovich Date: Tue, 26 Dec 2017 15:33:28 +0300 Subject: [PATCH 31/39] Fixed integration test --- .../Test/Integration/Model/Import/SourcesTest.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php index de20265f3c82..05aeedc5dc4b 100755 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Import/SourcesTest.php @@ -80,19 +80,13 @@ public function testValidateRowExpectsValidRow() $this->assertTrue($result, 'Expect result TRUE as given data is valid.'); } - /** - * @expectedException \Magento\Framework\Exception\LocalizedException - */ public function testImportDataWithWrongBehavior() { $this->importer->setParameters([ 'behavior' => 'WrongBehavior' ]); - $bunch = [ - $this->buildRowDataArray('eu-1', 'SKU-1', 6.88, 1) - ]; - $this->importData($bunch); + $this->assertEquals($this->importer->getBehavior(), \Magento\ImportExport\Model\Import::getDefaultBehavior()); } /** From 5e93ef584b937a8f9cbc0d50a22012e258215c00 Mon Sep 17 00:00:00 2001 From: Alex Yakimovich Date: Tue, 26 Dec 2017 15:34:51 +0300 Subject: [PATCH 32/39] Fixed static test --- .../Inventory/Test/Integration/Indexer/SourceIndexerTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php b/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php index 3c03c91e2add..991b65c5beca 100644 --- a/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php +++ b/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php @@ -54,8 +54,7 @@ protected function setUp() $this->removeIndexData = Bootstrap::getObjectManager()->get(RemoveIndexData::class); $this->removeIndexData->execute([10, 20, 30]); - - + $this->sourceRepository = Bootstrap::getObjectManager()->get(SourceRepositoryInterface::class); $this->searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class); From 580e823491ce264545c7557c7e8bf42fe83d9b04 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Tue, 26 Dec 2017 19:13:36 +0200 Subject: [PATCH 33/39] MSI: Task 290 import export source code --- .../Controller/Adminhtml/Source/Edit.php | 2 +- .../Adminhtml/Source/InlineEdit.php | 2 +- .../Stock/StockSourceLinkProcessor.php | 6 +- .../Inventory/Indexer/SelectBuilder.php | 2 +- .../Indexer/Source/GetAssignedStockIds.php | 26 +- .../Indexer/Source/SourceIndexer.php | 8 +- .../Indexer/SourceItem/SourceItemIndexer.php | 1 - .../Inventory/Model/ResourceModel/Source.php | 10 +- app/code/Magento/Inventory/Model/Source.php | 8 +- .../Inventory/Model/Source/Command/Get.php | 8 +- .../Model/Source/Command/GetInterface.php | 4 +- .../Inventory/Model/Source/Command/Save.php | 3 +- .../Model/Source/Validator/CodeValidator.php | 7 +- .../Source/Validator/CountryValidator.php | 2 +- .../Model/SourceCarrierLinkManagement.php | 6 +- .../Validator/SourceCodeValidator.php | 17 +- .../Inventory/Model/SourceRepository.php | 6 +- .../Command/GetAssignedSourcesForStock.php | 2 +- .../CreateSourceCarrierLinkTable.php | 4 +- .../Setup/Operation/CreateSourceItemTable.php | 4 +- .../Setup/Operation/CreateSourceTable.php | 38 +- .../Operation/CreateStockSourceLinkTable.php | 4 +- .../Integration/Indexer/SourceIndexerTest.php | 32 +- .../Source/Validator/CodeValidatorTest.php | 6 +- .../Test/Unit/Model/SourceRepositoryTest.php | 11 +- .../Ui/DataProvider/SourceDataProvider.php | 4 +- .../Ui/DataProvider/StockDataProvider.php | 3 +- app/code/Magento/Inventory/etc/di.xml | 2 +- app/code/Magento/Inventory/etc/mview.xml | 2 +- .../ui_component/inventory_source_form.xml | 4 +- .../ui_component/inventory_source_listing.xml | 20 +- .../ui_component/inventory_stock_form.xml | 2 +- .../Api/AssignSourcesToStockInterface.php | 4 +- .../InventoryApi/Api/Data/SourceInterface.php | 8 +- .../Api/Data/SourceItemInterface.php | 3 +- .../Api/SourceRepositoryInterface.php | 4 +- .../Api/UnassignSourceFromStockInterface.php | 2 +- .../Test/Api/SourceItemsDeleteTest.php | 24 +- .../Api/SourceItemsSave/ValidationTest.php | 59 ++- .../CarrierLinkManagementTest.php | 4 +- .../Test/Api/SourceRepository/CreateTest.php | 19 +- .../Test/Api/SourceRepository/GetTest.php | 14 +- .../SourceRepository/RegionProcessingTest.php | 38 +- .../Test/Api/SourceRepository/UpdateTest.php | 20 +- .../Api/SourceRepository/ValidationTest.php | 370 +++++++++--------- .../AssignSourcesToStockTest.php | 34 +- .../GetAssignedSourcesForStockTest.php | 7 +- .../UnassignSourceFromStockTest.php | 31 +- .../InventoryApi/Test/_files/source.php | 4 +- .../InventoryApi/Test/_files/source_items.php | 12 +- .../Test/_files/source_rollback.php | 4 +- .../InventoryApi/Test/_files/sources.php | 16 +- .../Test/_files/sources_rollback.php | 4 +- .../Test/_files/stock_source_link.php | 8 +- .../_files/stock_source_link_rollback.php | 4 +- .../Observer/ProcessSourceItemsObserver.php | 5 +- ...eventAssignSourcesToDefaultStockPlugin.php | 11 +- .../Setup/Operation/CreateDefaultSource.php | 2 +- .../Operation/UpdateInventorySourceItem.php | 3 - .../Test/Api/GetDefaultSourceTest.php | 20 +- .../Test/Api/GetDefaultStockTest.php | 18 +- .../Api/GetDefaultStockToSourceLinkTest.php | 29 +- .../PreventDefaultStockDeletingTest.php | 3 - ...reventAssignSourcesToDefaultStockTest.php} | 24 +- .../Product/Form/Modifier/Sources.php | 2 +- .../adminhtml/ui_component/product_form.xml | 4 +- .../Form/Modifier/SourceItemConfiguration.php | 6 +- .../Data/SourceItemConfigurationInterface.php | 2 +- .../Api/DeleteSourceItemConfigurationTest.php | 16 +- .../Api/SourceItemConfigurationsSaveTest.php | 2 +- .../source_item_configuration_rollback.php | 2 +- .../Model/Export/ColumnProvider.php | 3 +- .../Export/SourceItemCollectionFactory.php | 12 +- .../Model/Import/SourceItemConvert.php | 16 +- .../Model/Import/Sources.php | 1 - .../Import/Validator/SourceValidator.php | 4 +- .../Model/StockItemImporter.php | 2 + .../Export/_files/export_filtered_by_sku.csv | 2 +- .../_files/export_filtered_by_source.csv | 2 +- .../export_filtered_without_status_column.csv | 2 +- .../Model/Export/_files/export_full.csv | 2 +- .../Model/StockItemImporterTest.php | 6 +- .../SalesChannelManagementTest.php | 4 +- 83 files changed, 582 insertions(+), 572 deletions(-) rename app/code/Magento/InventoryCatalog/Test/Api/StockSourceLink/{AssignSourcesToStockTest.php => PreventAssignSourcesToDefaultStockTest.php} (77%) diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php index 80034ed50b0e..e240a8360017 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php @@ -49,7 +49,7 @@ public function __construct( */ public function execute(): ResultInterface { - $sourceCode = $this->getRequest()->getParam(SourceInterface::CODE); + $sourceCode = $this->getRequest()->getParam(SourceInterface::SOURCE_CODE); try { $source = $this->sourceRepository->get($sourceCode); diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/InlineEdit.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/InlineEdit.php index bf54d6a59b6a..006928d9d799 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/InlineEdit.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/InlineEdit.php @@ -66,7 +66,7 @@ public function execute(): ResultInterface if ($request->isXmlHttpRequest() && $request->isPost() && $requestData) { foreach ($requestData as $itemData) { try { - $sourceCode = $itemData[SourceInterface::CODE]; + $sourceCode = $itemData[SourceInterface::SOURCE_CODE]; $source = $this->sourceRepository->get($sourceCode); $this->dataObjectHelper->populateWithArray($source, $itemData, SourceInterface::class); $this->sourceRepository->save($source); diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Stock/StockSourceLinkProcessor.php b/app/code/Magento/Inventory/Controller/Adminhtml/Stock/StockSourceLinkProcessor.php index 298f2d153274..ece5f8ff0097 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Stock/StockSourceLinkProcessor.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Stock/StockSourceLinkProcessor.php @@ -82,10 +82,10 @@ public function process(int $stockId, array $stockSourceLinksData) $sourceCodesForDelete = []; foreach ($assignedSources as $assignedSource) { - if (array_key_exists($assignedSource->getCode(), $sourceCodesForSave)) { - unset($sourceCodesForSave[$assignedSource->getCode()]); + if (array_key_exists($assignedSource->getSourceCode(), $sourceCodesForSave)) { + unset($sourceCodesForSave[$assignedSource->getSourceCode()]); } else { - $sourceCodesForDelete[] = $assignedSource->getCode(); + $sourceCodesForDelete[] = $assignedSource->getSourceCode(); } } diff --git a/app/code/Magento/Inventory/Indexer/SelectBuilder.php b/app/code/Magento/Inventory/Indexer/SelectBuilder.php index 26c3862260b9..938e8b48e837 100644 --- a/app/code/Magento/Inventory/Indexer/SelectBuilder.php +++ b/app/code/Magento/Inventory/Indexer/SelectBuilder.php @@ -51,7 +51,7 @@ public function execute($stockId): Select // find all enabled sources $select = $connection->select() - ->from($sourceTable, [SourceInterface::CODE]) + ->from($sourceTable, [SourceInterface::SOURCE_CODE]) ->where(SourceInterface::ENABLED . ' = ?', 1); $sourceCodes = $connection->fetchCol($select); diff --git a/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php b/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php index 46bba19d5500..be873ff320a3 100644 --- a/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php +++ b/app/code/Magento/Inventory/Indexer/Source/GetAssignedStockIds.php @@ -8,11 +8,8 @@ namespace Magento\Inventory\Indexer\Source; use Magento\Framework\App\ResourceConnection; -use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\Inventory\Model\ResourceModel\StockSourceLink as StockSourceLinkResourceModel; use Magento\Inventory\Model\StockSourceLink; -use Magento\Inventory\Model\ResourceModel\Source; -use Magento\InventoryApi\Api\Data\SourceInterface; /** * Returns assigned Stock ids by given Source ids @@ -34,35 +31,20 @@ public function __construct( } /** - * @param string[] $sourceIds + * @param string[] $sourceCodes * @return int[] */ - public function execute(array $sourceIds): array + public function execute(array $sourceCodes): array { $connection = $this->resourceConnection->getConnection(); $sourceStockLinkTable = $this->resourceConnection->getTableName( StockSourceLinkResourceModel::TABLE_NAME_STOCK_SOURCE_LINK ); - $sourceTable = $this->resourceConnection->getTableName( - Source::TABLE_NAME_SOURCE - ); $select = $connection ->select() - ->from( - ['sourceStockLink' => $sourceStockLinkTable], - StockSourceLink::STOCK_ID - ) - ->joinInner( - ['source' => $sourceTable], - sprintf( - 'sourceStockLink.%s = source.%s', - StockSourceLink::SOURCE_CODE, - SourceInterface::CODE - ), - [] - ) - ->where(SourceResourceModel::SOURCE_ID_FIELD . ' IN (?)', $sourceIds) + ->from($sourceStockLinkTable, StockSourceLink::STOCK_ID) + ->where(StockSourceLink::SOURCE_CODE . ' IN (?)', $sourceCodes) ->group(StockSourceLink::STOCK_ID); $stockIds = $connection->fetchCol($select); diff --git a/app/code/Magento/Inventory/Indexer/Source/SourceIndexer.php b/app/code/Magento/Inventory/Indexer/Source/SourceIndexer.php index cede86e7585b..34fbe9b21a12 100644 --- a/app/code/Magento/Inventory/Indexer/Source/SourceIndexer.php +++ b/app/code/Magento/Inventory/Indexer/Source/SourceIndexer.php @@ -56,17 +56,17 @@ public function executeFull() /** * @inheritdoc */ - public function executeRow($sourceId) + public function executeRow($sourceCode) { - $this->executeList([$sourceId]); + $this->executeList([$sourceCode]); } /** * @inheritdoc */ - public function executeList(array $sourceIds) + public function executeList(array $sourceCodes) { - $stockIds = $this->getAssignedStockIds->execute($sourceIds); + $stockIds = $this->getAssignedStockIds->execute($sourceCodes); $this->stockIndexer->executeList($stockIds); } } diff --git a/app/code/Magento/Inventory/Indexer/SourceItem/SourceItemIndexer.php b/app/code/Magento/Inventory/Indexer/SourceItem/SourceItemIndexer.php index 2ab0dbd0066c..db90532bf8a8 100644 --- a/app/code/Magento/Inventory/Indexer/SourceItem/SourceItemIndexer.php +++ b/app/code/Magento/Inventory/Indexer/SourceItem/SourceItemIndexer.php @@ -13,7 +13,6 @@ use Magento\Framework\MultiDimensionalIndex\IndexHandlerInterface; use Magento\Framework\MultiDimensionalIndex\IndexNameBuilder; use Magento\Framework\MultiDimensionalIndex\IndexStructureInterface; -use Magento\Inventory\Indexer\IndexDataProvider; use Magento\Inventory\Indexer\Stock\StockIndexer; /** diff --git a/app/code/Magento/Inventory/Model/ResourceModel/Source.php b/app/code/Magento/Inventory/Model/ResourceModel/Source.php index 6e0d2b8bd9c6..5c0581cb702b 100644 --- a/app/code/Magento/Inventory/Model/ResourceModel/Source.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/Source.php @@ -29,7 +29,13 @@ class Source extends AbstractDb */ const TABLE_NAME_SOURCE = 'inventory_source'; /**#@-*/ - const SOURCE_ID_FIELD = 'source_id'; + + /** + * Primary key auto increment flag + * + * @var bool + */ + protected $_isPkAutoIncrement = false; /** * @var SourceCarrierLinkManagementInterface @@ -55,7 +61,7 @@ public function __construct( */ protected function _construct() { - $this->_init(self::TABLE_NAME_SOURCE, SourceInterface::CODE); + $this->_init(self::TABLE_NAME_SOURCE, SourceInterface::SOURCE_CODE); } /** diff --git a/app/code/Magento/Inventory/Model/Source.php b/app/code/Magento/Inventory/Model/Source.php index a7be04539b81..6c66fff06d66 100644 --- a/app/code/Magento/Inventory/Model/Source.php +++ b/app/code/Magento/Inventory/Model/Source.php @@ -30,17 +30,17 @@ protected function _construct() /** * @inheritdoc */ - public function getCode() + public function getSourceCode() { - return $this->getData(self::CODE); + return $this->getData(self::SOURCE_CODE); } /** * @inheritdoc */ - public function setCode($code) + public function setSourceCode($sourceCode) { - return $this->setData(self::CODE, $code); + $this->setData(self::SOURCE_CODE, $sourceCode); } /** diff --git a/app/code/Magento/Inventory/Model/Source/Command/Get.php b/app/code/Magento/Inventory/Model/Source/Command/Get.php index 14adfc8e47d1..1b92625be539 100644 --- a/app/code/Magento/Inventory/Model/Source/Command/Get.php +++ b/app/code/Magento/Inventory/Model/Source/Command/Get.php @@ -42,14 +42,14 @@ public function __construct( /** * @inheritdoc */ - public function execute(string $code): SourceInterface + public function execute(string $sourceCode): SourceInterface { /** @var SourceInterface $source */ $source = $this->sourceFactory->create(); - $this->sourceResource->load($source, $code, SourceInterface::CODE); + $this->sourceResource->load($source, $sourceCode, SourceInterface::SOURCE_CODE); - if (null === $source->getCode()) { - throw new NoSuchEntityException(__('Source with code "%value" does not exist.', ['value' => $code])); + if (null === $source->getSourceCode()) { + throw new NoSuchEntityException(__('Source with code "%value" does not exist.', ['value' => $sourceCode])); } return $source; } diff --git a/app/code/Magento/Inventory/Model/Source/Command/GetInterface.php b/app/code/Magento/Inventory/Model/Source/Command/GetInterface.php index 279ceb88390c..390285fde244 100644 --- a/app/code/Magento/Inventory/Model/Source/Command/GetInterface.php +++ b/app/code/Magento/Inventory/Model/Source/Command/GetInterface.php @@ -25,9 +25,9 @@ interface GetInterface /** * Get Source data by given code * - * @param string $code + * @param string $sourceCode * @return SourceInterface * @throws NoSuchEntityException */ - public function execute(string $code): SourceInterface; + public function execute(string $sourceCode): SourceInterface; } diff --git a/app/code/Magento/Inventory/Model/Source/Command/Save.php b/app/code/Magento/Inventory/Model/Source/Command/Save.php index 1da58d5f2d05..3718e8e1443f 100644 --- a/app/code/Magento/Inventory/Model/Source/Command/Save.php +++ b/app/code/Magento/Inventory/Model/Source/Command/Save.php @@ -61,7 +61,8 @@ public function execute(SourceInterface $source) } try { - return $this->sourceResource->save($source); + $this->sourceResource->save($source); + $source->getSourceCode(); } catch (\Exception $e) { $this->logger->error($e->getMessage()); throw new CouldNotSaveException(__('Could not save Source'), $e); diff --git a/app/code/Magento/Inventory/Model/Source/Validator/CodeValidator.php b/app/code/Magento/Inventory/Model/Source/Validator/CodeValidator.php index dc7b2d1e3b5c..1151e1565023 100644 --- a/app/code/Magento/Inventory/Model/Source/Validator/CodeValidator.php +++ b/app/code/Magento/Inventory/Model/Source/Validator/CodeValidator.php @@ -34,16 +34,15 @@ public function __construct(ValidationResultFactory $validationResultFactory) */ public function validate(SourceInterface $source): ValidationResult { - $value = (string)$source->getCode(); + $value = (string)$source->getSourceCode(); if ('' === trim($value)) { - $errors[] = __('"%field" can not be empty.', ['field' => SourceInterface::CODE]); + $errors[] = __('"%field" can not be empty.', ['field' => SourceInterface::SOURCE_CODE]); } elseif (preg_match('/\s/', $value)) { - $errors[] = __('"%field" can not contain whitespaces.', ['field' => SourceInterface::CODE]); + $errors[] = __('"%field" can not contain whitespaces.', ['field' => SourceInterface::SOURCE_CODE]); } else { $errors = []; } - return $this->validationResultFactory->create(['errors' => $errors]); } } diff --git a/app/code/Magento/Inventory/Model/Source/Validator/CountryValidator.php b/app/code/Magento/Inventory/Model/Source/Validator/CountryValidator.php index 69754db85f5f..4483119e0cab 100644 --- a/app/code/Magento/Inventory/Model/Source/Validator/CountryValidator.php +++ b/app/code/Magento/Inventory/Model/Source/Validator/CountryValidator.php @@ -34,7 +34,7 @@ public function __construct(ValidationResultFactory $validationResultFactory) */ public function validate(SourceInterface $source): ValidationResult { - $value = $source->getCountryId(); + $value = (string)$source->getCountryId(); if ('' === trim($value)) { $errors[] = __('"%field" can not be empty.', ['field' => SourceInterface::COUNTRY_ID]); diff --git a/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php b/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php index 67b9fbf1e832..82179cd6368f 100644 --- a/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php +++ b/app/code/Magento/Inventory/Model/SourceCarrierLinkManagement.php @@ -90,7 +90,7 @@ private function deleteCurrentCarrierLinks(SourceInterface $source) $connection = $this->resourceConnection->getConnection(); $connection->delete( $this->resourceConnection->getTableName(SourceCarrierLink::TABLE_NAME_SOURCE_CARRIER_LINK), - $connection->quoteInto('source_code = ?', $source->getCode()) + $connection->quoteInto('source_code = ?', $source->getSourceCode()) ); } @@ -103,7 +103,7 @@ private function saveNewCarrierLinks(SourceInterface $source) $carrierLinkData = []; foreach ($source->getCarrierLinks() as $carrierLink) { $carrierLinkData[] = [ - 'source_code' => $source->getCode(), + 'source_code' => $source->getSourceCode(), SourceCarrierLinkInterface::CARRIER_CODE => $carrierLink->getCarrierCode(), SourceCarrierLinkInterface::POSITION => $carrierLink->getPosition(), ]; @@ -121,7 +121,7 @@ private function saveNewCarrierLinks(SourceInterface $source) public function loadCarrierLinksBySource(SourceInterface $source) { $searchCriteria = $this->searchCriteriaBuilder - ->addFilter(SourceCarrierLinkInterface::SOURCE_CODE, $source->getCode()) + ->addFilter(SourceCarrierLinkInterface::SOURCE_CODE, $source->getSourceCode()) ->create(); /** @var Collection $collection */ diff --git a/app/code/Magento/Inventory/Model/SourceItem/Validator/SourceCodeValidator.php b/app/code/Magento/Inventory/Model/SourceItem/Validator/SourceCodeValidator.php index caf63dd93e21..777cd8d1f62d 100644 --- a/app/code/Magento/Inventory/Model/SourceItem/Validator/SourceCodeValidator.php +++ b/app/code/Magento/Inventory/Model/SourceItem/Validator/SourceCodeValidator.php @@ -12,7 +12,7 @@ use Magento\InventoryApi\Api\Data\SourceItemInterface; /** - * Check that source id is valid + * Check that source code is valid */ class SourceCodeValidator implements SourceItemValidatorInterface { @@ -34,14 +34,15 @@ public function __construct(ValidationResultFactory $validationResultFactory) */ public function validate(SourceItemInterface $source): ValidationResult { - $errors = []; - if (!is_string($source->getSourceCode())) { - $errors[] = __( - '"%field" should be string.', - ['field' => SourceItemInterface::SOURCE_CODE] - ); - } + $value = (string)$source->getSourceCode(); + if ('' === trim($value)) { + $errors[] = __('"%field" can not be empty.', ['field' => SourceItemInterface::SOURCE_CODE]); + } elseif (preg_match('/\s/', $value)) { + $errors[] = __('"%field" can not contain whitespaces.', ['field' => SourceItemInterface::SOURCE_CODE]); + } else { + $errors = []; + } return $this->validationResultFactory->create(['errors' => $errors]); } } diff --git a/app/code/Magento/Inventory/Model/SourceRepository.php b/app/code/Magento/Inventory/Model/SourceRepository.php index dbc0a9e300e6..8d2c10e4921b 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -55,15 +55,15 @@ public function __construct( */ public function save(SourceInterface $source) { - return $this->commandSave->execute($source); + $this->commandSave->execute($source); } /** * @inheritdoc */ - public function get(string $code): SourceInterface + public function get(string $sourceCode): SourceInterface { - return $this->commandGet->execute($code); + return $this->commandGet->execute($sourceCode); } /** diff --git a/app/code/Magento/Inventory/Model/StockSourceLink/Command/GetAssignedSourcesForStock.php b/app/code/Magento/Inventory/Model/StockSourceLink/Command/GetAssignedSourcesForStock.php index 8eb5ef3f4d2c..e3787e889d62 100644 --- a/app/code/Magento/Inventory/Model/StockSourceLink/Command/GetAssignedSourcesForStock.php +++ b/app/code/Magento/Inventory/Model/StockSourceLink/Command/GetAssignedSourcesForStock.php @@ -70,7 +70,7 @@ public function execute(int $stockId): array $sourceCodes = $this->getAssignedSourceCodes($stockId); $searchCriteria = $this->searchCriteriaBuilder - ->addFilter(SourceInterface::CODE, $sourceCodes, 'in') + ->addFilter(SourceInterface::SOURCE_CODE, $sourceCodes, 'in') ->create(); $searchResult = $this->sourceRepository->getList($searchCriteria); return $searchResult->getItems(); diff --git a/app/code/Magento/Inventory/Setup/Operation/CreateSourceCarrierLinkTable.php b/app/code/Magento/Inventory/Setup/Operation/CreateSourceCarrierLinkTable.php index 8c0aead9da1a..6aa5201fc5fb 100644 --- a/app/code/Magento/Inventory/Setup/Operation/CreateSourceCarrierLinkTable.php +++ b/app/code/Magento/Inventory/Setup/Operation/CreateSourceCarrierLinkTable.php @@ -82,11 +82,11 @@ private function createSourceCarrierLinkTable(SchemaSetupInterface $setup): Tabl $sourceCarrierLinkTable, SourceCarrierLinkInterface::SOURCE_CODE, $sourceTable, - SourceInterface::CODE + SourceInterface::SOURCE_CODE ), SourceCarrierLinkInterface::SOURCE_CODE, $sourceTable, - SourceInterface::CODE, + SourceInterface::SOURCE_CODE, AdapterInterface::FK_ACTION_CASCADE ); } diff --git a/app/code/Magento/Inventory/Setup/Operation/CreateSourceItemTable.php b/app/code/Magento/Inventory/Setup/Operation/CreateSourceItemTable.php index 38c63902a697..f0e0405cb3a1 100755 --- a/app/code/Magento/Inventory/Setup/Operation/CreateSourceItemTable.php +++ b/app/code/Magento/Inventory/Setup/Operation/CreateSourceItemTable.php @@ -95,11 +95,11 @@ private function createSourceItemTable(SchemaSetupInterface $setup): Table $sourceItemTable, SourceItemInterface::SOURCE_CODE, $sourceTable, - SourceInterface::CODE + SourceInterface::SOURCE_CODE ), SourceItemInterface::SOURCE_CODE, $sourceTable, - SourceInterface::CODE, + SourceInterface::SOURCE_CODE, AdapterInterface::FK_ACTION_CASCADE )->addIndex( $setup->getIdxName( diff --git a/app/code/Magento/Inventory/Setup/Operation/CreateSourceTable.php b/app/code/Magento/Inventory/Setup/Operation/CreateSourceTable.php index c2250988109a..219e20c2c86b 100644 --- a/app/code/Magento/Inventory/Setup/Operation/CreateSourceTable.php +++ b/app/code/Magento/Inventory/Setup/Operation/CreateSourceTable.php @@ -38,7 +38,6 @@ public function execute(SchemaSetupInterface $setup) $sourceTable = $this->addAddressFields($sourceTable); $sourceTable = $this->addContactInfoFields($sourceTable); $sourceTable = $this->addSourceCarrierFields($sourceTable); - $sourceTable = $this->addIndex($sourceTable, $setup); $setup->getConnection()->createTable($sourceTable); } @@ -50,22 +49,12 @@ public function execute(SchemaSetupInterface $setup) private function addBaseFields(Table $sourceTable): Table { return $sourceTable->addColumn( - SourceResourceModel::SOURCE_ID_FIELD, - Table::TYPE_INTEGER, - null, - [ - Table::OPTION_IDENTITY => true, - Table::OPTION_UNSIGNED => true, - Table::OPTION_NULLABLE => false, - Table::OPTION_PRIMARY => true, - ], - 'Source ID' - )->addColumn( - SourceInterface::CODE, + SourceInterface::SOURCE_CODE, Table::TYPE_TEXT, 255, [ Table::OPTION_NULLABLE => false, + Table::OPTION_PRIMARY => true, ], 'Source Code' )->addColumn( @@ -132,7 +121,7 @@ private function addBaseFields(Table $sourceTable): Table * @param Table $sourceTable * @return Table */ - private function addAddressFields(Table $sourceTable) + private function addAddressFields(Table $sourceTable): Table { $sourceTable->addColumn( SourceInterface::COUNTRY_ID, @@ -191,7 +180,7 @@ private function addAddressFields(Table $sourceTable) * @param Table $sourceTable * @return Table */ - private function addContactInfoFields(Table $sourceTable) + private function addContactInfoFields(Table $sourceTable): Table { $sourceTable->addColumn( SourceInterface::CONTACT_NAME, @@ -233,7 +222,7 @@ private function addContactInfoFields(Table $sourceTable) * @param Table $sourceTable * @return Table */ - private function addSourceCarrierFields(Table $sourceTable) + private function addSourceCarrierFields(Table $sourceTable): Table { $sourceTable->addColumn( 'use_default_carrier_config', @@ -248,21 +237,4 @@ private function addSourceCarrierFields(Table $sourceTable) ); return $sourceTable; } - - private function addIndex(Table $sourceTable, SchemaSetupInterface $setup) - { - return $sourceTable->addIndex( - $setup->getIdxName( - $setup->getTable(SourceResourceModel::TABLE_NAME_SOURCE), - [ - SourceInterface::CODE - ], - AdapterInterface::INDEX_TYPE_UNIQUE - ), - [ - SourceInterface::CODE - ], - ['type' => AdapterInterface::INDEX_TYPE_UNIQUE] - ); - } } diff --git a/app/code/Magento/Inventory/Setup/Operation/CreateStockSourceLinkTable.php b/app/code/Magento/Inventory/Setup/Operation/CreateStockSourceLinkTable.php index 5096b8485aed..71c4524aa8f7 100644 --- a/app/code/Magento/Inventory/Setup/Operation/CreateStockSourceLinkTable.php +++ b/app/code/Magento/Inventory/Setup/Operation/CreateStockSourceLinkTable.php @@ -88,11 +88,11 @@ private function createStockSourceLinkTable(SchemaSetupInterface $setup): Table $stockSourceLinkTable, StockSourceLink::SOURCE_CODE, $sourceTable, - SourceInterface::CODE + SourceInterface::SOURCE_CODE ), StockSourceLink::SOURCE_CODE, $sourceTable, - SourceInterface::CODE, + SourceInterface::SOURCE_CODE, AdapterInterface::FK_ACTION_CASCADE )->addIndex( $setup->getIdxName( diff --git a/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php b/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php index 991b65c5beca..26176b0a7548 100644 --- a/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php +++ b/app/code/Magento/Inventory/Test/Integration/Indexer/SourceIndexerTest.php @@ -7,13 +7,9 @@ namespace Magento\Inventory\Test\Integration\Indexer; -use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\Framework\Indexer\IndexerInterface; use Magento\Inventory\Indexer\Source\SourceIndexer; -use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; -use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\GetProductQuantityInStockInterface; -use Magento\InventoryApi\Api\SourceRepositoryInterface; use Magento\TestFramework\Helper\Bootstrap; use PHPUnit\Framework\TestCase; @@ -34,16 +30,6 @@ class SourceIndexerTest extends TestCase */ private $removeIndexData; - /** - * @var SearchCriteriaBuilder - */ - private $searchCriteriaBuilder; - - /** - * @var SourceRepositoryInterface - */ - private $sourceRepository; - protected function setUp() { $this->indexer = Bootstrap::getObjectManager()->get(IndexerInterface::class); @@ -54,10 +40,6 @@ protected function setUp() $this->removeIndexData = Bootstrap::getObjectManager()->get(RemoveIndexData::class); $this->removeIndexData->execute([10, 20, 30]); - - $this->sourceRepository = Bootstrap::getObjectManager()->get(SourceRepositoryInterface::class); - - $this->searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class); } protected function tearDown() @@ -74,8 +56,7 @@ protected function tearDown() */ public function testReindexRow() { - $source = $this->sourceRepository->get('eu-1'); - $this->indexer->reindexRow($source->getData(SourceResourceModel::SOURCE_ID_FIELD)); + $this->indexer->reindexRow('eu-1'); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 10)); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 30)); @@ -90,16 +71,7 @@ public function testReindexRow() */ public function testReindexList() { - $sourceIds = []; - $searchCriteria = $this->searchCriteriaBuilder - ->addFilter(SourceInterface::CODE, ['eu-1', 'us-1'], 'in') - ->create(); - $sourceList = $this->sourceRepository->getList($searchCriteria); - foreach ($sourceList->getItems() as $source) { - $sourceIds[] = $source->getData(SourceResourceModel::SOURCE_ID_FIELD); - } - - $this->indexer->reindexList($sourceIds); + $this->indexer->reindexList(['eu-1', 'us-1']); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 10)); self::assertEquals(8.5, $this->getProductQuantityInStock->execute('SKU-1', 30)); diff --git a/app/code/Magento/Inventory/Test/Unit/Model/Source/Validator/CodeValidatorTest.php b/app/code/Magento/Inventory/Test/Unit/Model/Source/Validator/CodeValidatorTest.php index f035068929f1..79d68e627151 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/Source/Validator/CodeValidatorTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/Source/Validator/CodeValidatorTest.php @@ -43,7 +43,7 @@ public function testValidateCodeNotEmpty() $emptyValidatorResult = $this->createMock(\Magento\Framework\Validation\ValidationResult::class); $this->validationResultFactory->expects($this->once()) ->method('create') - ->with(['errors' => [__('"%field" can not be empty.', ['field' => SourceInterface::CODE])]]) + ->with(['errors' => [__('"%field" can not be empty.', ['field' => SourceInterface::SOURCE_CODE])]]) ->willReturn($emptyValidatorResult); $this->codeValidator = (new ObjectManager($this))->getObject(CodeValidator::class, [ 'validationResultFactory' => $this->validationResultFactory @@ -60,7 +60,9 @@ public function testValidateCodeNotWithWhiteSpaces() $emptyValidatorResult = $this->createMock(\Magento\Framework\Validation\ValidationResult::class); $this->validationResultFactory->expects($this->once()) ->method('create') - ->with(['errors' => [__('"%field" can not contain whitespaces.', ['field' => SourceInterface::CODE])]]) + ->with([ + 'errors' => [__('"%field" can not contain whitespaces.', ['field' => SourceInterface::SOURCE_CODE])] + ]) ->willReturn($emptyValidatorResult); $this->codeValidator = (new ObjectManager($this))->getObject(CodeValidator::class, [ 'validationResultFactory' => $this->validationResultFactory diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php index 4e51b6b30a71..af7aeda71136 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php @@ -71,12 +71,15 @@ protected function setUp() public function testSave() { + $sourceCode = 'source-code'; + $this->commandSave ->expects($this->once()) ->method('execute') - ->with($this->source); + ->with($this->source) + ->willReturn($sourceCode); - $this->sourceRepository->save($this->source); + self::assertEquals($sourceCode, $this->sourceRepository->save($this->source)); } /** @@ -96,7 +99,7 @@ public function testSaveWithCouldNotSaveException() public function testGet() { - $sourceCode = 'default'; + $sourceCode = 'source-code'; $this->commandGet ->expects($this->once()) @@ -113,7 +116,7 @@ public function testGet() */ public function testGetWithNoSuchEntityException() { - $sourceCode = 'default'; + $sourceCode = 'source-code'; $this->commandGet ->expects($this->once()) diff --git a/app/code/Magento/Inventory/Ui/DataProvider/SourceDataProvider.php b/app/code/Magento/Inventory/Ui/DataProvider/SourceDataProvider.php index 7a85c4c10466..48e7cb664e21 100644 --- a/app/code/Magento/Inventory/Ui/DataProvider/SourceDataProvider.php +++ b/app/code/Magento/Inventory/Ui/DataProvider/SourceDataProvider.php @@ -83,7 +83,7 @@ public function getData() // It is need for support of several fieldsets. // For details see \Magento\Ui\Component\Form::getDataSourceData if ($data['totalRecords'] > 0) { - $sourceCode = $data['items'][0][SourceInterface::CODE]; + $sourceCode = $data['items'][0][SourceInterface::SOURCE_CODE]; $sourceGeneralData = $data['items'][0]; $sourceGeneralData['carrier_codes'] = $this->getAssignedCarrierCodes($sourceCode); $dataForSingle[$sourceCode] = [ @@ -109,7 +109,7 @@ public function getSearchResult() $result->getItems(), $result->getTotalCount(), $searchCriteria, - SourceInterface::CODE + SourceInterface::SOURCE_CODE ); return $searchResult; } diff --git a/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php b/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php index 03a412687002..85eb3d8daac9 100644 --- a/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php +++ b/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php @@ -17,7 +17,6 @@ use Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider; use Magento\InventoryApi\Api\Data\StockInterface; use Magento\InventoryApi\Api\StockRepositoryInterface; -use Magento\Inventory\Model\StockSourceLink; /** * @api @@ -138,7 +137,7 @@ private function getAssignedSourcesData(int $stockId): array $assignedSourcesData = []; foreach ($assignedSources as $assignedSource) { $assignedSourcesData[] = [ - StockSourceLink::SOURCE_CODE => $assignedSource->getCode(), + SourceInterface::SOURCE_CODE => $assignedSource->getSourceCode(), SourceInterface::NAME => $assignedSource->getName(), ]; } diff --git a/app/code/Magento/Inventory/etc/di.xml b/app/code/Magento/Inventory/etc/di.xml index c5877a634cb3..7707f30d0d8e 100644 --- a/app/code/Magento/Inventory/etc/di.xml +++ b/app/code/Magento/Inventory/etc/di.xml @@ -42,7 +42,7 @@ Magento\Inventory\Model\SourceItem\Validator\SkuValidator - Magento\Inventory\Model\SourceItem\Validator\SourceCodeValidator + Magento\Inventory\Model\SourceItem\Validator\SourceCodeValidator Magento\Inventory\Model\SourceItem\Validator\QuantityValidator Magento\Inventory\Model\SourceItem\Validator\StatusValidator diff --git a/app/code/Magento/Inventory/etc/mview.xml b/app/code/Magento/Inventory/etc/mview.xml index 44a586422a35..ebb3b0aa45d4 100644 --- a/app/code/Magento/Inventory/etc/mview.xml +++ b/app/code/Magento/Inventory/etc/mview.xml @@ -13,7 +13,7 @@ -
+
diff --git a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml index d6a629b0b989..bcee1fa7c1c9 100644 --- a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml +++ b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml @@ -38,8 +38,8 @@ - code - code + source_code + source_code diff --git a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml index 9df198fbb7a6..4b58b782d07e 100644 --- a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml +++ b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_listing.xml @@ -27,15 +27,15 @@ - code + source_code Magento_InventoryApi::source - code - code + source_code + source_code @@ -68,7 +68,7 @@ false - code + source_code true inventory_source_listing.inventory_source_listing.inventory_source_listing_columns.ids @@ -85,13 +85,19 @@ - code + source_code - + text + + text + + true + + @@ -275,7 +281,7 @@ - code + source_code diff --git a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_form.xml b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_form.xml index 6d74b23479b6..45cb7af02888 100644 --- a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_form.xml +++ b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_form.xml @@ -100,7 +100,7 @@ data.sources.assign_sources_grid - code + source_code name source_code diff --git a/app/code/Magento/InventoryApi/Api/AssignSourcesToStockInterface.php b/app/code/Magento/InventoryApi/Api/AssignSourcesToStockInterface.php index 049570cf1df9..0aac6952eeb7 100644 --- a/app/code/Magento/InventoryApi/Api/AssignSourcesToStockInterface.php +++ b/app/code/Magento/InventoryApi/Api/AssignSourcesToStockInterface.php @@ -19,9 +19,9 @@ interface AssignSourcesToStockInterface /** * Assign Sources to Stock * - * If one of the Sources or Stock with given codes don't exist then exception will be throw + * If one of the Sources or Stock with given id don't exist then exception will be throw * - * @param int[] $sourceCodes + * @param string[] $sourceCodes * @param int $stockId * @return void * @throws \Magento\Framework\Exception\InputException diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php index 62d19eb8f5a3..6a74a5186c13 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php @@ -21,7 +21,7 @@ interface SourceInterface extends ExtensibleDataInterface /** * Constants for keys of data array. Identical to the name of the getter in snake case */ - const CODE = 'code'; + const SOURCE_CODE = 'source_code'; const NAME = 'name'; const CONTACT_NAME = 'contact_name'; const EMAIL = 'email'; @@ -46,15 +46,15 @@ interface SourceInterface extends ExtensibleDataInterface * * @return string|null */ - public function getCode(); + public function getSourceCode(); /** * Set source code * - * @param string|null $code + * @param string|null $sourceCode * @return void */ - public function setCode($code); + public function setSourceCode($sourceCode); /** * Get source name diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceItemInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceItemInterface.php index 4b6d61c44fbd..4ae85a76de58 100755 --- a/app/code/Magento/InventoryApi/Api/Data/SourceItemInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceItemInterface.php @@ -8,7 +8,6 @@ namespace Magento\InventoryApi\Api\Data; use Magento\Framework\Api\ExtensibleDataInterface; -use Magento\InventoryApi\Api\Data\SourceItemExtensionInterface; /** * Represents amount of product on physical storage @@ -61,7 +60,7 @@ public function getSourceCode(); /** * Set source code * - * @param stirng|null $sourceCode + * @param string|null $sourceCode * @return void */ public function setSourceCode($sourceCode); diff --git a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php index 5d9bb4e06967..1f9032fd00bc 100644 --- a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php +++ b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php @@ -46,11 +46,11 @@ public function save(SourceInterface $source); * Get Source data by given code. If you want to create plugin on get method, also you need to create separate * plugin on getList method, because entity loading way is different for these methods * - * @param string $code + * @param string $sourceCode * @return \Magento\InventoryApi\Api\Data\SourceInterface * @throws \Magento\Framework\Exception\NoSuchEntityException */ - public function get(string $code): SourceInterface; + public function get(string $sourceCode): SourceInterface; /** * Find Sources by SearchCriteria diff --git a/app/code/Magento/InventoryApi/Api/UnassignSourceFromStockInterface.php b/app/code/Magento/InventoryApi/Api/UnassignSourceFromStockInterface.php index 68802ba949a2..12d150265f6e 100644 --- a/app/code/Magento/InventoryApi/Api/UnassignSourceFromStockInterface.php +++ b/app/code/Magento/InventoryApi/Api/UnassignSourceFromStockInterface.php @@ -21,7 +21,7 @@ interface UnassignSourceFromStockInterface * * If Source or Stock with given code doesn't exist then do nothing * - * @param int $sourceCode + * @param string $sourceCode * @param int $stockId * @return void * @throws \Magento\Framework\Exception\InputException diff --git a/app/code/Magento/InventoryApi/Test/Api/SourceItemsDeleteTest.php b/app/code/Magento/InventoryApi/Test/Api/SourceItemsDeleteTest.php index 855deb30afa8..0fbff6d416b0 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceItemsDeleteTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceItemsDeleteTest.php @@ -48,17 +48,11 @@ public function testExecute() SourceItemInterface::STATUS => SourceItemInterface::STATUS_OUT_OF_STOCK, ], [ - SourceItemInterface::SOURCE_CODE => 'eu-dis', + SourceItemInterface::SOURCE_CODE => 'eu-disabled', SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 10, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, ], - [ - SourceItemInterface::SOURCE_CODE => 'us-1', - SourceItemInterface::SKU => 'SKU-2', - SourceItemInterface::QUANTITY => 5, - SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, - ], ]; $serviceInfo = [ @@ -78,7 +72,7 @@ public function testExecute() $actualData = $this->getSourceItems(); - self::assertEquals(3, $actualData['total_count']); + self::assertEquals(2, $actualData['total_count']); AssertArrayContains::assert($expectedSourceItemsAfterDeleting, $actualData['items']); } @@ -88,7 +82,19 @@ public function testExecute() private function getSourceItems(): array { $requestData = [ - 'searchCriteria' => [SearchCriteria::PAGE_SIZE => 10], + 'searchCriteria' => [ + SearchCriteria::FILTER_GROUPS => [ + [ + 'filters' => [ + [ + 'field' => SourceItemInterface::SKU, + 'value' => 'SKU-1', + 'condition_type' => 'eq', + ], + ], + ], + ], + ], ]; $serviceInfo = [ 'rest' => [ diff --git a/app/code/Magento/InventoryApi/Test/Api/SourceItemsSave/ValidationTest.php b/app/code/Magento/InventoryApi/Test/Api/SourceItemsSave/ValidationTest.php index 8265212cdc50..ce7ca5df5ae0 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceItemsSave/ValidationTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceItemsSave/ValidationTest.php @@ -83,7 +83,7 @@ public function dataProviderRequiredFields(): array 'message' => 'Validation Failed', 'errors' => [ [ - 'message' => '"%field" should be string.', + 'message' => '"%field" can not be empty.', 'parameters' => [ 'field' => SourceItemInterface::SOURCE_CODE, ], @@ -237,7 +237,37 @@ public function failedValidationDataProvider(): array 'message' => 'Validation Failed', 'errors' => [ [ - 'message' => '"%field" should be string.', + 'message' => '"%field" can not be empty.', + 'parameters' => [ + 'field' => SourceItemInterface::SOURCE_CODE, + ], + ], + ], + ], + ], + 'empty_' . SourceItemInterface::SOURCE_CODE => [ + SourceItemInterface::SOURCE_CODE, + '', + [ + 'message' => 'Validation Failed', + 'errors' => [ + [ + 'message' => '"%field" can not be empty.', + 'parameters' => [ + 'field' => SourceItemInterface::SOURCE_CODE, + ], + ], + ], + ], + ], + 'whitespaces_' . SourceItemInterface::SOURCE_CODE => [ + SourceItemInterface::SOURCE_CODE, + ' ', + [ + 'message' => 'Validation Failed', + 'errors' => [ + [ + 'message' => '"%field" can not be empty.', 'parameters' => [ 'field' => SourceItemInterface::SOURCE_CODE, ], @@ -247,11 +277,26 @@ public function failedValidationDataProvider(): array ], 'not_exists_' . SourceItemInterface::SOURCE_CODE => [ SourceItemInterface::SOURCE_CODE, - 'eu-12', + 'not-existed-source-code', [ 'message' => 'Could not save Source Item', ], ], + 'with_whitespaces_' . SourceItemInterface::SOURCE_CODE => [ + SourceItemInterface::SOURCE_CODE, + 'source code', + [ + 'message' => 'Validation Failed', + 'errors' => [ + [ + 'message' => '"%field" can not contain whitespaces.', + 'parameters' => [ + 'field' => SourceItemInterface::SOURCE_CODE, + ], + ], + ], + ], + ], ]; } @@ -310,14 +355,6 @@ public function failedValidationRelatedOnlyForRestDataProvider(): array . '" processing. Invalid type for value: "test". Expected Type: "float".', ], ], - 'empty_' . SourceItemInterface::SOURCE_CODE => [ - SourceItemInterface::SOURCE_CODE, - '', - [ - 'message' => 'Error occurred during "' . SourceItemInterface::SOURCE_CODE - . '" processing. Invalid type for value: "". Expected Type: "string".', - ], - ], 'array_' . SourceItemInterface::SOURCE_CODE => [ SourceItemInterface::SOURCE_CODE, [], diff --git a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CarrierLinkManagementTest.php b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CarrierLinkManagementTest.php index c2d163a8cd2e..33acec908455 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CarrierLinkManagementTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CarrierLinkManagementTest.php @@ -139,7 +139,7 @@ private function getSourceDataByCode(string $sourceCode): array $response = (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) ? $this->_webApiCall($serviceInfo) : $this->_webApiCall($serviceInfo, ['sourceCode' => $sourceCode]); - self::assertArrayHasKey(SourceInterface::CODE, $response); + self::assertArrayHasKey(SourceInterface::SOURCE_CODE, $response); return $response; } @@ -178,6 +178,7 @@ public function failedValidationDataProvider(): array return [ 'use_global_configuration_chosen' => [ [ + SourceInterface::SOURCE_CODE => 'source-code-1', SourceInterface::NAME => 'source-name-1', SourceInterface::POSTCODE => 'source-postcode', SourceInterface::COUNTRY_ID => 'US', @@ -208,6 +209,7 @@ public function failedValidationDataProvider(): array ], 'carrier_codes_not_exits' => [ [ + SourceInterface::SOURCE_CODE => 'source-code-1', SourceInterface::NAME => 'source-name-1', SourceInterface::POSTCODE => 'source-postcode', SourceInterface::COUNTRY_ID => 'US', diff --git a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CreateTest.php b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CreateTest.php index c7e75d6a9ace..efa3c876453b 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CreateTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CreateTest.php @@ -9,7 +9,6 @@ use Magento\Framework\App\ResourceConnection; use Magento\Framework\Webapi\Rest\Request; -use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\TestFramework\Assert\AssertArrayContains; @@ -27,8 +26,9 @@ class CreateTest extends WebapiAbstract public function testCreate() { + $sourceCode = 'source-code-1'; $expectedData = [ - SourceInterface::CODE => 'source-code-1', + SourceInterface::SOURCE_CODE => 'source-code-1', SourceInterface::NAME => 'source-name-1', SourceInterface::CONTACT_NAME => 'source-contact-name', SourceInterface::EMAIL => 'source-email', @@ -66,10 +66,9 @@ public function testCreate() 'operation' => self::SERVICE_NAME . 'Save', ], ]; - $sourceId = $this->_webApiCall($serviceInfo, ['source' => $expectedData]); + $this->_webApiCall($serviceInfo, ['source' => $expectedData]); - self::assertNotEmpty($sourceId); - AssertArrayContains::assert($expectedData, $this->getSourceDataById($sourceId)); + AssertArrayContains::assert($expectedData, $this->getSourceDataByCode($sourceCode)); } protected function tearDown() @@ -83,14 +82,14 @@ protected function tearDown() } /** - * @param int $sourceId + * @param string $sourceCode * @return array */ - private function getSourceDataById(int $sourceId): array + private function getSourceDataByCode(string $sourceCode): array { $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceId, + 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceCode, 'httpMethod' => Request::HTTP_METHOD_GET, ], 'soap' => [ @@ -100,8 +99,8 @@ private function getSourceDataById(int $sourceId): array ]; $response = (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) ? $this->_webApiCall($serviceInfo) - : $this->_webApiCall($serviceInfo, ['sourceId' => $sourceId]); - self::assertArrayHasKey(SourceResourceModel::SOURCE_ID_FIELD, $response); + : $this->_webApiCall($serviceInfo, ['sourceCode' => $sourceCode]); + self::assertArrayHasKey(SourceInterface::SOURCE_CODE, $response); return $response; } } diff --git a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/GetTest.php b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/GetTest.php index b788eaa9ecf5..0c35bfebdf91 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/GetTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/GetTest.php @@ -13,7 +13,7 @@ /** * Method Get is covered in CreateTest test - * @see \Magento\InventoryApi\Test\Api\SourceRepository\CreateTest::getSourceDataById + * @see \Magento\InventoryApi\Test\Api\SourceRepository\CreateTest::getSourceDataByCode */ class GetTest extends WebapiAbstract { @@ -26,10 +26,10 @@ class GetTest extends WebapiAbstract public function testGetNoSuchEntityException() { - $notExistingId = -1; + $notExistedCode = -1; $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . '/' . $notExistingId, + 'resourcePath' => self::RESOURCE_PATH . '/' . $notExistedCode, 'httpMethod' => Request::HTTP_METHOD_GET, ], 'soap' => [ @@ -38,21 +38,21 @@ public function testGetNoSuchEntityException() ], ]; - $expectedMessage = 'Source with id "%value" does not exist.'; + $expectedMessage = 'Source with code "%value" does not exist.'; try { (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) ? $this->_webApiCall($serviceInfo) - : $this->_webApiCall($serviceInfo, ['sourceId' => $notExistingId]); + : $this->_webApiCall($serviceInfo, ['sourceCode' => $notExistedCode]); $this->fail('Expected throwing exception'); } catch (\Exception $e) { if (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) { $errorData = $this->processRestExceptionResult($e); self::assertEquals($expectedMessage, $errorData['message']); - self::assertEquals($notExistingId, $errorData['parameters']['value']); + self::assertEquals($notExistedCode, $errorData['parameters']['value']); self::assertEquals(Exception::HTTP_NOT_FOUND, $e->getCode()); } elseif (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) { $this->assertInstanceOf('SoapFault', $e); - $this->checkSoapFault($e, $expectedMessage, 'env:Sender', ['value' => $notExistingId]); + $this->checkSoapFault($e, $expectedMessage, 'env:Sender', ['value' => $notExistedCode]); } else { throw $e; } diff --git a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/RegionProcessingTest.php b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/RegionProcessingTest.php index ca61cae57d16..9b5dcd7df2fb 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/RegionProcessingTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/RegionProcessingTest.php @@ -9,7 +9,6 @@ use Magento\Framework\App\ResourceConnection; use Magento\Framework\Webapi\Rest\Request; -use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\WebapiAbstract; @@ -25,16 +24,18 @@ class RegionProcessingTest extends WebapiAbstract public function testCreateWithPredefinedRegion() { + $sourceCode = 'source-code-1'; $regionId = 10; $data = [ + SourceInterface::SOURCE_CODE => $sourceCode, SourceInterface::NAME => 'source-name-1', SourceInterface::POSTCODE => 'source-postcode', SourceInterface::COUNTRY_ID => 'US', SourceInterface::REGION_ID => $regionId, ]; - $sourceId = $this->saveSource($data); - $sourceData = $this->getSourceDataById($sourceId); + $this->saveSource($data); + $sourceData = $this->getSourceDataByCode($sourceCode); self::assertArrayHasKey(SourceInterface::REGION_ID, $sourceData); self::assertEquals($regionId, $sourceData[SourceInterface::REGION_ID]); @@ -43,16 +44,18 @@ public function testCreateWithPredefinedRegion() public function testCreateWithCustomRegion() { + $sourceCode = 'source-code-1'; $regionName = 'custom-region-name'; $data = [ + SourceInterface::SOURCE_CODE => $sourceCode, SourceInterface::NAME => 'source-name-1', SourceInterface::POSTCODE => 'source-postcode', SourceInterface::COUNTRY_ID => 'US', SourceInterface::REGION => $regionName, ]; - $sourceId = $this->saveSource($data); - $sourceData = $this->getSourceDataById($sourceId); + $this->saveSource($data); + $sourceData = $this->getSourceDataByCode($sourceCode); self::assertArrayHasKey(SourceInterface::REGION, $sourceData); self::assertEquals($regionName, $sourceData[SourceInterface::REGION]); @@ -61,9 +64,11 @@ public function testCreateWithCustomRegion() public function testCreateWithBothFilledFields() { + $sourceCode = 'source-code-1'; $regionId = 10; $regionName = 'custom-region-name'; $data = [ + SourceInterface::SOURCE_CODE => $sourceCode, SourceInterface::NAME => 'source-name-1', SourceInterface::REGION_ID => $regionId, SourceInterface::POSTCODE => 'source-postcode', @@ -71,8 +76,8 @@ public function testCreateWithBothFilledFields() SourceInterface::REGION => $regionName, ]; - $sourceId = $this->saveSource($data); - $sourceData = $this->getSourceDataById($sourceId); + $this->saveSource($data); + $sourceData = $this->getSourceDataByCode($sourceCode); self::assertArrayHasKey(SourceInterface::REGION_ID, $sourceData); self::assertEquals($regionId, $sourceData[SourceInterface::REGION_ID]); @@ -93,9 +98,9 @@ protected function tearDown() /** * @param array $data - * @return int + * @return void */ - private function saveSource(array $data): int + private function saveSource(array $data) { $serviceInfo = [ 'rest' => [ @@ -107,21 +112,18 @@ private function saveSource(array $data): int 'operation' => self::SERVICE_NAME . 'Save', ], ]; - $sourceId = $this->_webApiCall($serviceInfo, ['source' => $data]); - self::assertTrue(is_numeric($sourceId)); - self::assertNotEmpty($sourceId); - return $sourceId; + $this->_webApiCall($serviceInfo, ['source' => $data]); } /** - * @param int $sourceId + * @param string $sourceCode * @return array */ - private function getSourceDataById(int $sourceId): array + private function getSourceDataByCode(string $sourceCode): array { $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceId, + 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceCode, 'httpMethod' => Request::HTTP_METHOD_GET, ], 'soap' => [ @@ -131,8 +133,8 @@ private function getSourceDataById(int $sourceId): array ]; $response = (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) ? $this->_webApiCall($serviceInfo) - : $this->_webApiCall($serviceInfo, ['sourceId' => $sourceId]); - self::assertArrayHasKey(SourceResourceModel::SOURCE_ID_FIELD, $response); + : $this->_webApiCall($serviceInfo, ['sourceCode' => $sourceCode]); + self::assertArrayHasKey(SourceInterface::SOURCE_CODE, $response); return $response; } } diff --git a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/UpdateTest.php b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/UpdateTest.php index 3e9f7afaecbe..502015a15780 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/UpdateTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/UpdateTest.php @@ -8,7 +8,6 @@ namespace Magento\InventoryApi\Test\Api\SourceRepository; use Magento\Framework\Webapi\Rest\Request; -use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\TestFramework\Assert\AssertArrayContains; @@ -28,9 +27,8 @@ class UpdateTest extends WebapiAbstract */ public function testUpdate() { - $sourceId = 10; + $sourceCode = 'source-code-1'; $expectedData = [ - SourceInterface::CODE => 'source-code-1-updated', SourceInterface::NAME => 'source-name-1-updated', SourceInterface::CONTACT_NAME => 'source-contact-name-updated', SourceInterface::EMAIL => 'source-email-updated', @@ -60,7 +58,7 @@ public function testUpdate() ]; $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceId, + 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceCode, 'httpMethod' => Request::HTTP_METHOD_PUT, ], 'soap' => [ @@ -72,22 +70,22 @@ public function testUpdate() $this->_webApiCall($serviceInfo, ['source' => $expectedData]); } else { $requestData = $expectedData; - $requestData['sourceId'] = $sourceId; + $requestData['sourceCode'] = $sourceCode; $this->_webApiCall($serviceInfo, ['source' => $requestData]); } - AssertArrayContains::assert($expectedData, $this->getSourceDataById($sourceId)); + AssertArrayContains::assert($expectedData, $this->getSourceDataByCode($sourceCode)); } /** - * @param int $sourceId + * @param string $sourceCode * @return array */ - private function getSourceDataById(int $sourceId): array + private function getSourceDataByCode(string $sourceCode): array { $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceId, + 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceCode, 'httpMethod' => Request::HTTP_METHOD_GET, ], 'soap' => [ @@ -97,8 +95,8 @@ private function getSourceDataById(int $sourceId): array ]; $response = (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) ? $this->_webApiCall($serviceInfo) - : $this->_webApiCall($serviceInfo, ['sourceId' => $sourceId]); - self::assertArrayHasKey(SourceResourceModel::SOURCE_ID_FIELD, $response); + : $this->_webApiCall($serviceInfo, ['sourceCode' => $sourceCode]); + self::assertArrayHasKey(SourceInterface::SOURCE_CODE, $response); return $response; } } diff --git a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/ValidationTest.php b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/ValidationTest.php index b47c578a4210..280aa166d9b1 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/ValidationTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/ValidationTest.php @@ -25,6 +25,7 @@ class ValidationTest extends WebapiAbstract * @var array */ private $validData = [ + SourceInterface::SOURCE_CODE => 'source-code-1', SourceInterface::NAME => 'source-name-1', SourceInterface::POSTCODE => 'source-postcode', SourceInterface::COUNTRY_ID => 'US', @@ -88,15 +89,15 @@ public function dataProviderRequiredFields(): array ], ], ], - 'without_' . SourceInterface::CODE => [ - SourceInterface::CODE, + 'without_' . SourceInterface::SOURCE_CODE => [ + SourceInterface::SOURCE_CODE, [ 'message' => 'Validation Failed', 'errors' => [ [ 'message' => '"%field" can not be empty.', 'parameters' => [ - 'field' => SourceInterface::CODE, + 'field' => SourceInterface::SOURCE_CODE, ], ], ], @@ -141,10 +142,10 @@ public function testFailedValidationOnUpdate(string $field, $value, array $expec $data = $this->validData; $data[$field] = $value; - $sourceId = 10; + $sourceCode = 'source-code-1'; $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceId, + 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceCode, 'httpMethod' => Request::HTTP_METHOD_PUT, ], 'soap' => [ @@ -164,185 +165,186 @@ public function testFailedValidationOnUpdate(string $field, $value, array $expec public function failedValidationDataProvider(): array { return [ - 'null_' . SourceInterface::CODE => [ - SourceInterface::CODE, - null, - [ - 'message' => 'Validation Failed', - 'errors' => [ - [ - 'message' => '"%field" can not be empty.', - 'parameters' => [ - 'field' => SourceInterface::CODE, - ], - ], - ], - ], - ], 'empty_' . SourceInterface::CODE => [ - SourceInterface::CODE, - '', - [ - 'message' => 'Validation Failed', - 'errors' => [ - [ - 'message' => '"%field" can not be empty.', - 'parameters' => [ - 'field' => SourceInterface::CODE, - ], - ], - ], - ], - ], - 'whitespaces_' . SourceInterface::CODE => [ - SourceInterface::CODE, - ' ', - [ - 'message' => 'Validation Failed', - 'errors' => [ - [ - 'message' => '"%field" can not be empty.', - 'parameters' => [ - 'field' => SourceInterface::CODE, - ], - ], - ], - ], - ], - 'whitespaces_in_code_' . SourceInterface::CODE => [ - SourceInterface::CODE, - 'source code', - [ - 'message' => 'Validation Failed', - 'errors' => [ - [ - 'message' => '"%field" can not contain whitespaces.', - 'parameters' => [ - 'field' => SourceInterface::CODE, - ], - ], - ], - ], - ], - 'null_' . SourceInterface::NAME => [ - SourceInterface::NAME, - null, - [ - 'message' => 'Validation Failed', - 'errors' => [ - [ - 'message' => '"%field" can not be empty.', - 'parameters' => [ - 'field' => SourceInterface::NAME, - ], - ], - ], - ], - ], - 'empty_' . SourceInterface::NAME => [ - SourceInterface::NAME, - '', - [ - 'message' => 'Validation Failed', - 'errors' => [ - [ - 'message' => '"%field" can not be empty.', - 'parameters' => [ - 'field' => SourceInterface::NAME, - ], - ], - ], - ], - ], - 'whitespaces_' . SourceInterface::NAME => [ - SourceInterface::NAME, - ' ', - [ - 'message' => 'Validation Failed', - 'errors' => [ - [ - 'message' => '"%field" can not be empty.', - 'parameters' => [ - 'field' => SourceInterface::NAME, - ], - ], - ], - ], - ], - 'empty_' . SourceInterface::POSTCODE => [ - SourceInterface::POSTCODE, - '', - [ - 'message' => 'Validation Failed', - 'errors' => [ - [ - 'message' => '"%field" can not be empty.', - 'parameters' => [ - 'field' => SourceInterface::POSTCODE, - ], - ], - ], - ], - ], - 'whitespaces_' . SourceInterface::POSTCODE => [ - SourceInterface::POSTCODE, - ' ', - [ - 'message' => 'Validation Failed', - 'errors' => [ - [ - 'message' => '"%field" can not be empty.', - 'parameters' => [ - 'field' => SourceInterface::POSTCODE, - ], - ], - ], - ], - ], - 'null_' . SourceInterface::POSTCODE => [ - SourceInterface::POSTCODE, - null, - [ - 'message' => 'Validation Failed', - 'errors' => [ - [ - 'message' => '"%field" can not be empty.', - 'parameters' => [ - 'field' => SourceInterface::POSTCODE, - ], - ], - ], - ], - ], - 'empty_' . SourceInterface::COUNTRY_ID => [ - SourceInterface::COUNTRY_ID, - '', - [ - 'message' => 'Validation Failed', - 'errors' => [ - [ - 'message' => '"%field" can not be empty.', - 'parameters' => [ - 'field' => SourceInterface::COUNTRY_ID, - ], - ], - ], - ], - ], - 'whitespaces_' . SourceInterface::COUNTRY_ID => [ - SourceInterface::COUNTRY_ID, - ' ', - [ - 'message' => 'Validation Failed', - 'errors' => [ - [ - 'message' => '"%field" can not be empty.', - 'parameters' => [ - 'field' => SourceInterface::COUNTRY_ID, - ], - ], - ], - ], - ], +// 'null_' . SourceInterface::SOURCE_CODE => [ +// SourceInterface::SOURCE_CODE, +// null, +// [ +// 'message' => 'Validation Failed', +// 'errors' => [ +// [ +// 'message' => '"%field" can not be empty.', +// 'parameters' => [ +// 'field' => SourceInterface::SOURCE_CODE, +// ], +// ], +// ], +// ], +// ], +// 'empty_' . SourceInterface::SOURCE_CODE => [ +// SourceInterface::SOURCE_CODE, +// '', +// [ +// 'message' => 'Validation Failed', +// 'errors' => [ +// [ +// 'message' => '"%field" can not be empty.', +// 'parameters' => [ +// 'field' => SourceInterface::SOURCE_CODE, +// ], +// ], +// ], +// ], +// ], +// 'whitespaces_' . SourceInterface::SOURCE_CODE => [ +// SourceInterface::SOURCE_CODE, +// ' ', +// [ +// 'message' => 'Validation Failed', +// 'errors' => [ +// [ +// 'message' => '"%field" can not be empty.', +// 'parameters' => [ +// 'field' => SourceInterface::SOURCE_CODE, +// ], +// ], +// ], +// ], +// ], +// 'with_whitespaces_' . SourceInterface::SOURCE_CODE => [ +// SourceInterface::SOURCE_CODE, +// 'source code', +// [ +// 'message' => 'Validation Failed', +// 'errors' => [ +// [ +// 'message' => '"%field" can not contain whitespaces.', +// 'parameters' => [ +// 'field' => SourceInterface::SOURCE_CODE, +// ], +// ], +// ], +// ], +// ], +// 'null_' . SourceInterface::NAME => [ +// SourceInterface::NAME, +// null, +// [ +// 'message' => 'Validation Failed', +// 'errors' => [ +// [ +// 'message' => '"%field" can not be empty.', +// 'parameters' => [ +// 'field' => SourceInterface::NAME, +// ], +// ], +// ], +// ], +// ], +// 'empty_' . SourceInterface::NAME => [ +// SourceInterface::NAME, +// '', +// [ +// 'message' => 'Validation Failed', +// 'errors' => [ +// [ +// 'message' => '"%field" can not be empty.', +// 'parameters' => [ +// 'field' => SourceInterface::NAME, +// ], +// ], +// ], +// ], +// ], +// 'whitespaces_' . SourceInterface::NAME => [ +// SourceInterface::NAME, +// ' ', +// [ +// 'message' => 'Validation Failed', +// 'errors' => [ +// [ +// 'message' => '"%field" can not be empty.', +// 'parameters' => [ +// 'field' => SourceInterface::NAME, +// ], +// ], +// ], +// ], +// ], +// 'empty_' . SourceInterface::POSTCODE => [ +// SourceInterface::POSTCODE, +// '', +// [ +// 'message' => 'Validation Failed', +// 'errors' => [ +// [ +// 'message' => '"%field" can not be empty.', +// 'parameters' => [ +// 'field' => SourceInterface::POSTCODE, +// ], +// ], +// ], +// ], +// ], +// 'whitespaces_' . SourceInterface::POSTCODE => [ +// SourceInterface::POSTCODE, +// ' ', +// [ +// 'message' => 'Validation Failed', +// 'errors' => [ +// [ +// 'message' => '"%field" can not be empty.', +// 'parameters' => [ +// 'field' => SourceInterface::POSTCODE, +// ], +// ], +// ], +// ], +// ], +// 'null_' . SourceInterface::POSTCODE => [ +// SourceInterface::POSTCODE, +// null, +// [ +// 'message' => 'Validation Failed', +// 'errors' => [ +// [ +// 'message' => '"%field" can not be empty.', +// 'parameters' => [ +// 'field' => SourceInterface::POSTCODE, +// ], +// ], +// ], +// ], +// ], +// 'empty_' . SourceInterface::COUNTRY_ID => [ +// SourceInterface::COUNTRY_ID, +// '', +// [ +// 'message' => 'Validation Failed', +// 'errors' => [ +// [ +// 'message' => '"%field" can not be empty.', +// 'parameters' => [ +// 'field' => SourceInterface::COUNTRY_ID, +// ], +// ], +// ], +// ], +// ], +// 'whitespaces_' . SourceInterface::COUNTRY_ID => [ +// SourceInterface::COUNTRY_ID, +// ' ', +// [ +// 'message' => 'Validation Failed', +// 'errors' => [ +// [ +// 'message' => '"%field" can not be empty.', +// 'parameters' => [ +// 'field' => SourceInterface::COUNTRY_ID, +// ], +// ], +// ], +// ], +// ], 'null_' . SourceInterface::COUNTRY_ID => [ SourceInterface::COUNTRY_ID, null, diff --git a/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/AssignSourcesToStockTest.php b/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/AssignSourcesToStockTest.php index 32d24baf9a59..68964c107acd 100644 --- a/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/AssignSourcesToStockTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/AssignSourcesToStockTest.php @@ -9,7 +9,7 @@ use Magento\Framework\Webapi\Exception; use Magento\Framework\Webapi\Rest\Request; -use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; +use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\TestFramework\TestCase\WebapiAbstract; class AssignSourcesToStockTest extends WebapiAbstract @@ -29,7 +29,7 @@ class AssignSourcesToStockTest extends WebapiAbstract */ public function testAssignSourcesToStock() { - $sourceIds = [10, 20]; + $sourceCodes = ['eu-1', 'eu-2']; $stockId = 10; $serviceInfo = [ 'rest' => [ @@ -42,23 +42,23 @@ public function testAssignSourcesToStock() ], ]; (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) - ? $this->_webApiCall($serviceInfo, ['sourceIds' => $sourceIds]) - : $this->_webApiCall($serviceInfo, ['sourceIds' => $sourceIds, 'stockId' => $stockId]); + ? $this->_webApiCall($serviceInfo, ['sourceCodes' => $sourceCodes]) + : $this->_webApiCall($serviceInfo, ['sourceCodes' => $sourceCodes, 'stockId' => $stockId]); $assignedSourcesForStock = $this->getAssignedSourcesForStock($stockId); - self::assertEquals($sourceIds, array_column($assignedSourcesForStock, SourceResourceModel::SOURCE_ID_FIELD)); + self::assertEquals($sourceCodes, array_column($assignedSourcesForStock, SourceInterface::SOURCE_CODE)); } /** * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock.php - * @param string|array $sourceIds + * @param string|array $sourceCodes * @param string|int $stockId * @param array $expectedErrorData * @throws \Exception * @dataProvider dataProviderWrongParameters */ - public function testAssignSourcesToStockWithWrongParameters($sourceIds, $stockId, array $expectedErrorData) + public function testAssignSourcesToStockWithWrongParameters($sourceCodes, $stockId, array $expectedErrorData) { $serviceInfo = [ 'rest' => [ @@ -72,8 +72,8 @@ public function testAssignSourcesToStockWithWrongParameters($sourceIds, $stockId ]; try { (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) - ? $this->_webApiCall($serviceInfo, ['sourceIds' => $sourceIds]) - : $this->_webApiCall($serviceInfo, ['sourceIds' => $sourceIds, 'stockId' => $stockId]); + ? $this->_webApiCall($serviceInfo, ['sourceCodes' => $sourceCodes]) + : $this->_webApiCall($serviceInfo, ['sourceCodes' => $sourceCodes, 'stockId' => $stockId]); $this->fail('Expected throwing exception'); } catch (\Exception $e) { if (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) { @@ -100,7 +100,7 @@ public function dataProviderWrongParameters(): array { return [ 'not_numeric_stock_id' => [ - [10, 20], + ['eu-1', 'eu-2'], 'not_numeric', [ 'rest_message' => 'Invalid type for value: "not_numeric". Expected Type: "int".', @@ -109,23 +109,23 @@ public function dataProviderWrongParameters(): array ], ], 'nonexistent_stock_id' => [ - [10, 20], + ['eu-1', 'eu-2'], -1, [ 'rest_message' => 'Could not assign Sources to Stock', 'soap_message' => 'Could not assign Sources to Stock', ], ], - 'not_array_source_ids' => [ + 'not_array_source_codes' => [ 'not_array', 10, [ - 'rest_message' => 'Invalid type for value: "string". Expected Type: "int[]".', - // During SOAP source_ids parameter will be converted to empty array so error is different + 'rest_message' => 'Invalid type for value: "string". Expected Type: "string[]".', + // During SOAP source_codes parameter will be converted to empty array so error is different 'soap_message' => 'Input data is invalid', ], ], - 'empty_source_ids' => [ + 'empty_source_codes' => [ [], 10, [ @@ -133,8 +133,8 @@ public function dataProviderWrongParameters(): array 'soap_message' => 'Input data is invalid', ], ], - 'nonexistent_source_id' => [ - [-1, 20], + 'nonexistent_source_code' => [ + ['not-existed-source-code', 'eu-1'], 10, [ 'rest_message' => 'Could not assign Sources to Stock', diff --git a/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/GetAssignedSourcesForStockTest.php b/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/GetAssignedSourcesForStockTest.php index cddeca853cbf..2b305ccca970 100644 --- a/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/GetAssignedSourcesForStockTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/GetAssignedSourcesForStockTest.php @@ -9,7 +9,7 @@ use Magento\Framework\Webapi\Exception; use Magento\Framework\Webapi\Rest\Request; -use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; +use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\TestFramework\TestCase\WebapiAbstract; class GetAssignedSourcesForStockTest extends WebapiAbstract @@ -42,7 +42,10 @@ public function testGetAssignedSourcesForStock() $response = (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) ? $this->_webApiCall($serviceInfo) : $this->_webApiCall($serviceInfo, ['stockId' => $stockId]); - self::assertEquals([10, 20, 30, 40], array_column($response, SourceResourceModel::SOURCE_ID_FIELD)); + self::assertEquals( + ['eu-1', 'eu-2', 'eu-3', 'eu-disabled'], + array_column($response, SourceInterface::SOURCE_CODE) + ); } /** diff --git a/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/UnassignSourceFromStockTest.php b/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/UnassignSourceFromStockTest.php index b0a0af483286..885cec4d4981 100644 --- a/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/UnassignSourceFromStockTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/UnassignSourceFromStockTest.php @@ -9,7 +9,7 @@ use Magento\Framework\Webapi\Exception; use Magento\Framework\Webapi\Rest\Request; -use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; +use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\TestFramework\TestCase\WebapiAbstract; class UnassignSourceFromStockTest extends WebapiAbstract @@ -45,11 +45,11 @@ class UnassignSourceFromStockTest extends WebapiAbstract */ public function testUnassignSourceFromStock() { - $sourceId = 10; + $sourceCode = 'eu-1'; $stockId = 10; $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH_UNASSIGN_SOURCES_FROM_STOCK . '/' . $stockId . '/' . $sourceId, + 'resourcePath' => self::RESOURCE_PATH_UNASSIGN_SOURCES_FROM_STOCK . '/' . $stockId . '/' . $sourceCode, 'httpMethod' => Request::HTTP_METHOD_DELETE, ], 'soap' => [ @@ -59,33 +59,36 @@ public function testUnassignSourceFromStock() ]; (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) ? $this->_webApiCall($serviceInfo) - : $this->_webApiCall($serviceInfo, ['sourceId' => $sourceId, 'stockId' => $stockId]); + : $this->_webApiCall($serviceInfo, ['sourceCode' => $sourceCode, 'stockId' => $stockId]); $assignedSourcesForStock = $this->getAssignedSourcesForStock($stockId); - self::assertEquals([20, 30, 40], array_column($assignedSourcesForStock, SourceResourceModel::SOURCE_ID_FIELD)); + self::assertEquals( + ['eu-2', 'eu-3', 'eu-disabled'], + array_column($assignedSourcesForStock, SourceInterface::SOURCE_CODE) + ); } /** * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock.php - * @param string|int $sourceId + * @param string|string $sourceCode * @param string|int $stockId * @param array $expectedErrorData * @throws \Exception * @dataProvider dataProviderWrongParameters */ - public function testUnassignSourceFromStockWithWrongParameters($sourceId, $stockId, array $expectedErrorData) + public function testUnassignSourceFromStockWithWrongParameters($sourceCode, $stockId, array $expectedErrorData) { if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) { $this->markTestSkipped( - 'Test works only for REST adapter because in SOAP one source_id/stock_id would be converted' + 'Test works only for REST adapter because in SOAP one source_code/stock_id would be converted' . ' into zero (zero is allowed input for service ner mind it\'s illigible value as' - . ' there are no Sources(Stocks) in the system with source_id/stock_id given)' + . ' there are no Sources(Stocks) in the system with source_code/stock_id given)' ); } $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH_UNASSIGN_SOURCES_FROM_STOCK . '/' . $stockId . '/' . $sourceId, + 'resourcePath' => self::RESOURCE_PATH_UNASSIGN_SOURCES_FROM_STOCK . '/' . $stockId . '/' . $sourceCode, 'httpMethod' => Request::HTTP_METHOD_DELETE, ], ]; @@ -105,17 +108,17 @@ public function dataProviderWrongParameters(): array { return [ 'not_numeric_stock_id' => [ - 10, + 'eu-1', 'not_numeric', [ 'message' => 'Invalid type for value: "not_numeric". Expected Type: "int".', ], ], - 'not_numeric_source_id' => [ - 'not_numeric', + 'not_string_source_code' => [ 10, + [], [ - 'message' => 'Invalid type for value: "not_numeric". Expected Type: "int".', + 'message' => 'Invalid type for value: "10". Expected Type: "string".', ], ], ]; diff --git a/app/code/Magento/InventoryApi/Test/_files/source.php b/app/code/Magento/InventoryApi/Test/_files/source.php index 3ef31db23706..7273e7737ac1 100644 --- a/app/code/Magento/InventoryApi/Test/_files/source.php +++ b/app/code/Magento/InventoryApi/Test/_files/source.php @@ -6,7 +6,6 @@ declare(strict_types=1); use Magento\Framework\Api\DataObjectHelper; -use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; @@ -25,8 +24,7 @@ $dataObjectHelper->populateWithArray( $source, [ - SourceResourceModel::SOURCE_ID_FIELD => 10, - SourceInterface::CODE => 'source-code', + SourceInterface::SOURCE_CODE => 'source-code-1', SourceInterface::NAME => 'source-name-1', SourceInterface::CONTACT_NAME => 'source-contact-name', SourceInterface::EMAIL => 'source-email', diff --git a/app/code/Magento/InventoryApi/Test/_files/source_items.php b/app/code/Magento/InventoryApi/Test/_files/source_items.php index 99d261e81416..afe11ee94b3f 100644 --- a/app/code/Magento/InventoryApi/Test/_files/source_items.php +++ b/app/code/Magento/InventoryApi/Test/_files/source_items.php @@ -30,37 +30,37 @@ */ $sourcesItemsData = [ [ - SourceItemInterface::SOURCE_CODE => 'eu-1', // EU-source-1 + SourceItemInterface::SOURCE_CODE => 'eu-1', SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 5.5, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, ], [ - SourceItemInterface::SOURCE_CODE => 'eu-2', // EU-source-2 + SourceItemInterface::SOURCE_CODE => 'eu-2', SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 3, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, ], [ - SourceItemInterface::SOURCE_CODE => 'eu-3', // EU-source-3 + SourceItemInterface::SOURCE_CODE => 'eu-3', SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 10, SourceItemInterface::STATUS => SourceItemInterface::STATUS_OUT_OF_STOCK, ], [ - SourceItemInterface::SOURCE_CODE => 'eu-dis', // EU-source-disabled + SourceItemInterface::SOURCE_CODE => 'eu-disabled', SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 10, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, ], [ - SourceItemInterface::SOURCE_CODE => 'us-1', // US-source-1 + SourceItemInterface::SOURCE_CODE => 'us-1', SourceItemInterface::SKU => 'SKU-2', SourceItemInterface::QUANTITY => 5, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, ], [ - SourceItemInterface::SOURCE_CODE => 'eu-2', // EU-source-2 + SourceItemInterface::SOURCE_CODE => 'eu-2', SourceItemInterface::SKU => 'SKU-3', SourceItemInterface::QUANTITY => 6, SourceItemInterface::STATUS => SourceItemInterface::STATUS_OUT_OF_STOCK, diff --git a/app/code/Magento/InventoryApi/Test/_files/source_rollback.php b/app/code/Magento/InventoryApi/Test/_files/source_rollback.php index 40653a75fa43..046b14df777c 100644 --- a/app/code/Magento/InventoryApi/Test/_files/source_rollback.php +++ b/app/code/Magento/InventoryApi/Test/_files/source_rollback.php @@ -6,11 +6,11 @@ declare(strict_types=1); use Magento\Framework\App\ResourceConnection; -use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; +use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\TestFramework\Helper\Bootstrap; /** @var ResourceConnection $connection */ $connection = Bootstrap::getObjectManager()->get(ResourceConnection::class); $connection->getConnection()->delete($connection->getTableName('inventory_source'), [ - SourceResourceModel::SOURCE_ID_FIELD . ' = ?' => 10, + SourceInterface::SOURCE_CODE . ' IN (?)' => ['source-code-1', 'source-code-1-updated'] ]); diff --git a/app/code/Magento/InventoryApi/Test/_files/sources.php b/app/code/Magento/InventoryApi/Test/_files/sources.php index edfb0b2a3e00..578e5adde4a5 100644 --- a/app/code/Magento/InventoryApi/Test/_files/sources.php +++ b/app/code/Magento/InventoryApi/Test/_files/sources.php @@ -6,7 +6,6 @@ declare(strict_types=1); use Magento\Framework\Api\DataObjectHelper; -use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; use Magento\InventoryApi\Api\SourceRepositoryInterface; @@ -22,8 +21,7 @@ $sourcesData = [ [ // define only required and needed for tests fields - SourceResourceModel::SOURCE_ID_FIELD => 10, - SourceInterface::CODE => 'eu-1', + SourceInterface::SOURCE_CODE => 'eu-1', SourceInterface::NAME => 'EU-source-1', SourceInterface::ENABLED => true, SourceInterface::PRIORITY => 100, @@ -31,8 +29,7 @@ SourceInterface::COUNTRY_ID => 'FR', ], [ - SourceResourceModel::SOURCE_ID_FIELD => 20, - SourceInterface::CODE => 'eu-2', + SourceInterface::SOURCE_CODE => 'eu-2', SourceInterface::NAME => 'EU-source-2', SourceInterface::ENABLED => true, SourceInterface::PRIORITY => 200, @@ -40,8 +37,7 @@ SourceInterface::COUNTRY_ID => 'FR', ], [ - SourceResourceModel::SOURCE_ID_FIELD => 30, - SourceInterface::CODE => 'eu-3', + SourceInterface::SOURCE_CODE => 'eu-3', SourceInterface::NAME => 'EU-source-3', SourceInterface::ENABLED => true, SourceInterface::PRIORITY => 300, @@ -49,8 +45,7 @@ SourceInterface::COUNTRY_ID => 'DE', ], [ - SourceResourceModel::SOURCE_ID_FIELD => 40, - SourceInterface::CODE => 'eu-dis', + SourceInterface::SOURCE_CODE => 'eu-disabled', SourceInterface::NAME => 'EU-source-disabled', SourceInterface::ENABLED => false, SourceInterface::PRIORITY => 10, @@ -58,8 +53,7 @@ SourceInterface::COUNTRY_ID => 'DE', ], [ - SourceResourceModel::SOURCE_ID_FIELD => 50, - SourceInterface::CODE => 'us-1', + SourceInterface::SOURCE_CODE => 'us-1', SourceInterface::NAME => 'US-source-1', SourceInterface::ENABLED => true, SourceInterface::PRIORITY => 100, diff --git a/app/code/Magento/InventoryApi/Test/_files/sources_rollback.php b/app/code/Magento/InventoryApi/Test/_files/sources_rollback.php index 8ecab970ada8..0ffb651588f9 100644 --- a/app/code/Magento/InventoryApi/Test/_files/sources_rollback.php +++ b/app/code/Magento/InventoryApi/Test/_files/sources_rollback.php @@ -6,7 +6,7 @@ declare(strict_types=1); use Magento\Framework\App\ResourceConnection; -use Magento\Inventory\Model\ResourceModel\Source as SourceResourceModel; +use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\TestFramework\Helper\Bootstrap; /** @var ResourceConnection $connection */ @@ -14,6 +14,6 @@ $connection->getConnection()->delete( $connection->getTableName('inventory_source'), [ - SourceResourceModel::SOURCE_ID_FIELD . ' IN (?)' => [10, 20, 30, 40, 50], + SourceInterface::SOURCE_CODE . ' IN (?)' => ['eu-1', 'eu-2', 'eu-3', 'eu-disabled', 'us-1'], ] ); diff --git a/app/code/Magento/InventoryApi/Test/_files/stock_source_link.php b/app/code/Magento/InventoryApi/Test/_files/stock_source_link.php index 5c5151f358da..8bde8fdad9f3 100644 --- a/app/code/Magento/InventoryApi/Test/_files/stock_source_link.php +++ b/app/code/Magento/InventoryApi/Test/_files/stock_source_link.php @@ -14,16 +14,16 @@ * EU-source-1(code:eu-1) - EU-stock(id:10) * EU-source-2(code:eu-2) - EU-stock(id:10) * EU-source-3(code:eu-3) - EU-stock(id:10) - * EU-source-disabled(code:eu-dis) - EU-stock(id:10) + * EU-source-disabled(code:eu-disabled) - EU-stock(id:10) * * US-source-1(code:us-1) - US-stock(id:20) * * EU-source-1(code:eu-1) - Global-stock(id:30) * EU-source-2(code:eu-2) - Global-stock(id:30) * EU-source-2(code:eu-2) - Global-stock(id:30) - * EU-source-disabled(code:eu-dis) - Global-stock(id:30) + * EU-source-disabled(code:eu-disabled) - Global-stock(id:30) * US-source-1(code:us-1) - Global-stock(id:30) */ -$assignSourcesToStock->execute(['eu-1', 'eu-2', 'eu-3', 'eu-dis'], 10); +$assignSourcesToStock->execute(['eu-1', 'eu-2', 'eu-3', 'eu-disabled'], 10); $assignSourcesToStock->execute(['us-1'], 20); -$assignSourcesToStock->execute(['eu-1', 'eu-2', 'eu-3', 'eu-dis', 'us-1'], 30); +$assignSourcesToStock->execute(['eu-1', 'eu-2', 'eu-3', 'eu-disabled', 'us-1'], 30); diff --git a/app/code/Magento/InventoryApi/Test/_files/stock_source_link_rollback.php b/app/code/Magento/InventoryApi/Test/_files/stock_source_link_rollback.php index 06303fbe36f0..67d15b6f6688 100644 --- a/app/code/Magento/InventoryApi/Test/_files/stock_source_link_rollback.php +++ b/app/code/Magento/InventoryApi/Test/_files/stock_source_link_rollback.php @@ -14,12 +14,12 @@ $unassignSourceFromStock->execute('eu-1', 10); $unassignSourceFromStock->execute('eu-2', 10); $unassignSourceFromStock->execute('eu-3', 10); -$unassignSourceFromStock->execute('eu-dis', 10); +$unassignSourceFromStock->execute('eu-disabled', 10); // US stock $unassignSourceFromStock->execute('us-1', 20); // Global Stock $unassignSourceFromStock->execute('eu-1', 30); $unassignSourceFromStock->execute('eu-2', 30); $unassignSourceFromStock->execute('eu-3', 30); -$unassignSourceFromStock->execute('eu-dis', 30); +$unassignSourceFromStock->execute('eu-disabled', 30); $unassignSourceFromStock->execute('us-1', 30); diff --git a/app/code/Magento/InventoryCatalog/Observer/ProcessSourceItemsObserver.php b/app/code/Magento/InventoryCatalog/Observer/ProcessSourceItemsObserver.php index 8ca139d52cc6..2e44da5fe51e 100644 --- a/app/code/Magento/InventoryCatalog/Observer/ProcessSourceItemsObserver.php +++ b/app/code/Magento/InventoryCatalog/Observer/ProcessSourceItemsObserver.php @@ -28,14 +28,17 @@ class ProcessSourceItemsObserver implements ObserverInterface * @var SourceItemsProcessor */ private $sourceItemsProcessor; + /** * @var DefaultSourceProviderInterface */ private $defaultSourceProvider; + /** * @var SourceItemInterfaceFactory */ private $sourceItemInterfaceFactory; + /** * @var SourceItemsSaveInterface */ @@ -106,7 +109,7 @@ private function updateDefaultSourceQty(array $productParams) SourceItemInterface::SKU => $sku, SourceItemInterface::QUANTITY => $qty, SourceItemInterface::STATUS => $stockStatus, - SourceItemInterface::SOURCE_CODE => $defaultSourceCode + SourceItemInterface::SOURCE_CODE => $defaultSourceCode, ] ]); diff --git a/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php b/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php index 259f51ff1cc8..cb7945f1c22b 100644 --- a/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php +++ b/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php @@ -42,11 +42,14 @@ public function __construct( */ public function beforeExecute(AssignSourcesToStockInterface $subject, array $sourceCodes, int $stockId) { - if ($this->defaultStockProvider->getId() === $stockId) { - if ((1 !== count($sourceCodes) || $this->defaultSourceProvider->getCode() !== $sourceCodes[0])) { - throw new InputException(__('You can only assign Default Source to Default Stock')); - } + if ($this->defaultStockProvider->getId() !== $stockId || !count($sourceCodes)) { + return [$sourceCodes, $stockId]; } + + if (count($sourceCodes) > 1 || $this->defaultSourceProvider->getCode() !== (string)$sourceCodes[0]) { + throw new InputException(__('You can only assign Default Source to Default Stock')); + } + return [$sourceCodes, $stockId]; } } diff --git a/app/code/Magento/InventoryCatalog/Setup/Operation/CreateDefaultSource.php b/app/code/Magento/InventoryCatalog/Setup/Operation/CreateDefaultSource.php index 9c0bc0b60b61..64bf4979d85c 100644 --- a/app/code/Magento/InventoryCatalog/Setup/Operation/CreateDefaultSource.php +++ b/app/code/Magento/InventoryCatalog/Setup/Operation/CreateDefaultSource.php @@ -64,7 +64,7 @@ public function __construct( public function execute() { $data = [ - SourceInterface::CODE => 'default', + SourceInterface::SOURCE_CODE => $this->defaultSourceProvider->getCode(), SourceInterface::NAME => 'Default Source', SourceInterface::ENABLED => 1, SourceInterface::DESCRIPTION => 'Default Source', diff --git a/app/code/Magento/InventoryCatalog/Setup/Operation/UpdateInventorySourceItem.php b/app/code/Magento/InventoryCatalog/Setup/Operation/UpdateInventorySourceItem.php index 39deb2977e01..8970a74b86e8 100644 --- a/app/code/Magento/InventoryCatalog/Setup/Operation/UpdateInventorySourceItem.php +++ b/app/code/Magento/InventoryCatalog/Setup/Operation/UpdateInventorySourceItem.php @@ -42,10 +42,7 @@ public function __construct( } /** - * Insert Stock Item to Inventory Source Item by raw MySQL query - * * @param ModuleDataSetupInterface $setup - * * @return void */ public function execute(ModuleDataSetupInterface $setup) diff --git a/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultSourceTest.php b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultSourceTest.php index 009199af8f77..73d9d1f6a2e0 100644 --- a/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultSourceTest.php +++ b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultSourceTest.php @@ -8,20 +8,30 @@ namespace Magento\InventoryCatalog\Test\Api; use Magento\InventoryApi\Api\Data\SourceInterface; +use Magento\InventoryCatalog\Api\DefaultSourceProviderInterface; +use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\WebapiAbstract; use Magento\Framework\Webapi\Rest\Request; -/** - * Class GetDefaultSourceTest - */ class GetDefaultSourceTest extends WebapiAbstract { + /** + * @var DefaultSourceProviderInterface + */ + private $defaultSourceProvider; + + protected function setUp() + { + parent::setUp(); + $this->defaultSourceProvider = Bootstrap::getObjectManager()->get(DefaultSourceProviderInterface::class); + } + /** * Test that default Source is present after installation */ public function testGetDefaultSource() { - $defaultSourceCode = 'default'; + $defaultSourceCode = $this->defaultSourceProvider->getCode(); $serviceInfo = [ 'rest' => [ 'resourcePath' => '/V1/inventory/source/' . $defaultSourceCode, @@ -37,6 +47,6 @@ public function testGetDefaultSource() } else { $source = $this->_webApiCall($serviceInfo, ['sourceCode' => $defaultSourceCode]); } - $this->assertEquals($defaultSourceCode, $source[SourceInterface::CODE]); + $this->assertEquals($defaultSourceCode, $source[SourceInterface::SOURCE_CODE]); } } diff --git a/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockTest.php b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockTest.php index 92cf705f132a..e2c80fedf1a1 100644 --- a/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockTest.php +++ b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockTest.php @@ -8,20 +8,30 @@ namespace Magento\InventoryCatalog\Test\Api; use Magento\InventoryApi\Api\Data\StockInterface; +use Magento\InventoryCatalog\Api\DefaultStockProviderInterface; +use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\WebapiAbstract; use Magento\Framework\Webapi\Rest\Request; -/** - * Class GetDefaultStockTest - */ class GetDefaultStockTest extends WebapiAbstract { + /** + * @var DefaultStockProviderInterface + */ + private $defaultStockProvider; + + protected function setUp() + { + parent::setUp(); + $this->defaultStockProvider = Bootstrap::getObjectManager()->get(DefaultStockProviderInterface::class); + } + /** * Test that default Stock is present after installation */ public function testGetDefaultSource() { - $defaultStockId = 1; + $defaultStockId = $this->defaultStockProvider->getId(); $serviceInfo = [ 'rest' => [ 'resourcePath' => '/V1/inventory/stock/' . $defaultStockId, diff --git a/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockToSourceLinkTest.php b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockToSourceLinkTest.php index 1796cc5d0570..3a5ae2671a8b 100644 --- a/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockToSourceLinkTest.php +++ b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultStockToSourceLinkTest.php @@ -8,21 +8,38 @@ namespace Magento\InventoryCatalog\Test\Api; use Magento\InventoryApi\Api\Data\SourceInterface; +use Magento\InventoryCatalog\Api\DefaultSourceProviderInterface; +use Magento\InventoryCatalog\Api\DefaultStockProviderInterface; +use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\WebapiAbstract; use Magento\Framework\Webapi\Rest\Request; -/** - * Class GetDefaultStockToSourceLinkTest - */ class GetDefaultStockToSourceLinkTest extends WebapiAbstract { + /** + * @var DefaultSourceProviderInterface + */ + private $defaultSourceProvider; + + /** + * @var DefaultStockProviderInterface + */ + private $defaultStockProvider; + + protected function setUp() + { + parent::setUp(); + $this->defaultSourceProvider = Bootstrap::getObjectManager()->get(DefaultSourceProviderInterface::class); + $this->defaultStockProvider = Bootstrap::getObjectManager()->get(DefaultStockProviderInterface::class); + } + /** * Test that default Stock is present after installation */ public function testGetDefaultStockToSourceLink() { - $defaultStockId = 1; - $defaultSourceCode = 'default'; + $defaultStockId = $this->defaultStockProvider->getId(); + $defaultSourceCode = $this->defaultSourceProvider->getCode(); $serviceInfo = [ 'rest' => [ 'resourcePath' => '/V1/inventory/stock/get-assigned-sources/' . $defaultStockId, @@ -38,6 +55,6 @@ public function testGetDefaultStockToSourceLink() } else { $source = $this->_webApiCall($serviceInfo, ['stockId' => $defaultStockId]); } - $this->assertEquals([$defaultSourceCode], array_column($source, SourceInterface::CODE)); + $this->assertEquals([$defaultSourceCode], array_column($source, SourceInterface::SOURCE_CODE)); } } diff --git a/app/code/Magento/InventoryCatalog/Test/Api/StockRepository/PreventDefaultStockDeletingTest.php b/app/code/Magento/InventoryCatalog/Test/Api/StockRepository/PreventDefaultStockDeletingTest.php index d17b73a05bc2..e3dc317ded89 100644 --- a/app/code/Magento/InventoryCatalog/Test/Api/StockRepository/PreventDefaultStockDeletingTest.php +++ b/app/code/Magento/InventoryCatalog/Test/Api/StockRepository/PreventDefaultStockDeletingTest.php @@ -20,9 +20,6 @@ class PreventDefaultStockDeletingTest extends WebapiAbstract */ private $defaultStockProvider; - /** - * {@inheritdoc} - */ protected function setUp() { parent::setUp(); diff --git a/app/code/Magento/InventoryCatalog/Test/Api/StockSourceLink/AssignSourcesToStockTest.php b/app/code/Magento/InventoryCatalog/Test/Api/StockSourceLink/PreventAssignSourcesToDefaultStockTest.php similarity index 77% rename from app/code/Magento/InventoryCatalog/Test/Api/StockSourceLink/AssignSourcesToStockTest.php rename to app/code/Magento/InventoryCatalog/Test/Api/StockSourceLink/PreventAssignSourcesToDefaultStockTest.php index c3bb0ef8897a..0d818ddde169 100644 --- a/app/code/Magento/InventoryCatalog/Test/Api/StockSourceLink/AssignSourcesToStockTest.php +++ b/app/code/Magento/InventoryCatalog/Test/Api/StockSourceLink/PreventAssignSourcesToDefaultStockTest.php @@ -9,9 +9,12 @@ use Magento\Framework\Webapi\Exception; use Magento\Framework\Webapi\Rest\Request; +use Magento\InventoryCatalog\Api\DefaultSourceProviderInterface; +use Magento\InventoryCatalog\Api\DefaultStockProviderInterface; +use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\TestCase\WebapiAbstract; -class AssignSourcesToStockTest extends WebapiAbstract +class PreventAssignSourcesToDefaultStockTest extends WebapiAbstract { /**#@+ * Service constants @@ -23,14 +26,14 @@ class AssignSourcesToStockTest extends WebapiAbstract /** * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php * @magentoApiDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock.php - * @param array $sourceIds + * @param array $sourceCodes * @param int $stockId * @param array $expectedErrorData * @throws \Exception * @dataProvider dataProviderWrongParameters */ public function testAssignSourcesToStockWithWrongParameters( - array $sourceIds, + array $sourceCodes, int $stockId, array $expectedErrorData ) { @@ -46,8 +49,8 @@ public function testAssignSourcesToStockWithWrongParameters( ]; try { (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) - ? $this->_webApiCall($serviceInfo, ['sourceIds' => $sourceIds]) - : $this->_webApiCall($serviceInfo, ['sourceIds' => $sourceIds, 'stockId' => $stockId]); + ? $this->_webApiCall($serviceInfo, ['sourceCodes' => $sourceCodes]) + : $this->_webApiCall($serviceInfo, ['sourceCodes' => $sourceCodes, 'stockId' => $stockId]); $this->fail('Expected throwing exception'); } catch (\Exception $e) { if (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) { @@ -72,18 +75,21 @@ public function testAssignSourcesToStockWithWrongParameters( */ public function dataProviderWrongParameters(): array { + $defaultSourceProvider = Bootstrap::getObjectManager()->get(DefaultSourceProviderInterface::class); + $defaultStockProvider = Bootstrap::getObjectManager()->get(DefaultStockProviderInterface::class); + return [ 'multiple_sources_assigned_to_default_stock' => [ - [1, 20], - 1, + [$defaultSourceProvider->getCode(), 'eu-2'], + $defaultStockProvider->getId(), [ 'rest_message' => 'You can only assign Default Source to Default Stock', 'soap_message' => 'You can only assign Default Source to Default Stock', ], ], 'not_default_source_assigned_to_default_stock' => [ - [10], - 1, + ['eu-1'], + $defaultStockProvider->getId(), [ 'rest_message' => 'You can only assign Default Source to Default Stock', 'soap_message' => 'You can only assign Default Source to Default Stock', diff --git a/app/code/Magento/InventoryCatalog/Ui/DataProvider/Product/Form/Modifier/Sources.php b/app/code/Magento/InventoryCatalog/Ui/DataProvider/Product/Form/Modifier/Sources.php index 840510458fbe..d8b2ed60f37e 100644 --- a/app/code/Magento/InventoryCatalog/Ui/DataProvider/Product/Form/Modifier/Sources.php +++ b/app/code/Magento/InventoryCatalog/Ui/DataProvider/Product/Form/Modifier/Sources.php @@ -75,7 +75,7 @@ private function getSourceItemsData(): array $collection->addFilter(SourceItemInterface::SKU, $product->getSku()); $collection->join( ['s' => $this->resourceConnection->getTableName(SourceResourceModel::TABLE_NAME_SOURCE)], - sprintf('s.%s = main_table.%s', SourceInterface::CODE, SourceItemInterface::SOURCE_CODE), + sprintf('s.%s = main_table.%s', SourceInterface::SOURCE_CODE, SourceItemInterface::SOURCE_CODE), ['source_name' => SourceInterface::NAME] ); diff --git a/app/code/Magento/InventoryCatalog/view/adminhtml/ui_component/product_form.xml b/app/code/Magento/InventoryCatalog/view/adminhtml/ui_component/product_form.xml index d1479bf2c763..5d47d1a64faf 100644 --- a/app/code/Magento/InventoryCatalog/view/adminhtml/ui_component/product_form.xml +++ b/app/code/Magento/InventoryCatalog/view/adminhtml/ui_component/product_form.xml @@ -45,7 +45,7 @@ data.sources.assign_sources_grid - code + source_code name qty @@ -79,7 +79,7 @@ ui/dynamic-rows/cells/text text source_code - + diff --git a/app/code/Magento/InventoryConfiguration/Ui/DataProvider/Product/Form/Modifier/SourceItemConfiguration.php b/app/code/Magento/InventoryConfiguration/Ui/DataProvider/Product/Form/Modifier/SourceItemConfiguration.php index 59be9a5e3e26..bf9de2b99f8e 100644 --- a/app/code/Magento/InventoryConfiguration/Ui/DataProvider/Product/Form/Modifier/SourceItemConfiguration.php +++ b/app/code/Magento/InventoryConfiguration/Ui/DataProvider/Product/Form/Modifier/SourceItemConfiguration.php @@ -11,7 +11,6 @@ use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier; use Magento\Catalog\Model\Locator\LocatorInterface; use Magento\InventoryApi\Api\Data\SourceInterface; -use Magento\InventoryApi\Api\Data\SourceItemInterface; use Magento\InventoryConfigurationApi\Api\GetSourceItemConfigurationInterface; use Magento\InventoryConfigurationApi\Api\Data\SourceItemConfigurationInterface; @@ -66,18 +65,19 @@ private function getSourceItemsConfigurationData(array $assignedSources, Product { foreach ($assignedSources as &$source) { $sourceConfiguration = $this->getSourceItemConfiguration->execute( - (string)$source[SourceItemInterface::SOURCE_CODE], + (string)$source[SourceInterface::SOURCE_CODE], $product->getSku() ); $source[SourceItemConfigurationInterface::INVENTORY_NOTIFY_QTY] = $sourceConfiguration[SourceItemConfigurationInterface::INVENTORY_NOTIFY_QTY]; } + unset($source); return $assignedSources; } /** - * {@inheritdoc} + * @inheritdoc */ public function modifyMeta(array $meta) { diff --git a/app/code/Magento/InventoryConfigurationApi/Api/Data/SourceItemConfigurationInterface.php b/app/code/Magento/InventoryConfigurationApi/Api/Data/SourceItemConfigurationInterface.php index 72dde5faff45..ac024aa787f4 100644 --- a/app/code/Magento/InventoryConfigurationApi/Api/Data/SourceItemConfigurationInterface.php +++ b/app/code/Magento/InventoryConfigurationApi/Api/Data/SourceItemConfigurationInterface.php @@ -35,7 +35,7 @@ public function getSourceCode(); /** * Set source code * - * @param int $sourceCode + * @param string $sourceCode * @return void */ public function setSourceCode(string $sourceCode); diff --git a/app/code/Magento/InventoryConfigurationApi/Test/Api/DeleteSourceItemConfigurationTest.php b/app/code/Magento/InventoryConfigurationApi/Test/Api/DeleteSourceItemConfigurationTest.php index 9ad27bac8815..7d3f28085160 100644 --- a/app/code/Magento/InventoryConfigurationApi/Test/Api/DeleteSourceItemConfigurationTest.php +++ b/app/code/Magento/InventoryConfigurationApi/Test/Api/DeleteSourceItemConfigurationTest.php @@ -24,13 +24,13 @@ class DeleteSourceItemConfigurationTest extends WebapiAbstract */ public function testDeleteSourceItemConfiguration() { - $sourceId = 10; + $sourceCode = 'eu-1'; $sku = 'SKU-1'; $serviceInfo = [ 'rest' => [ 'resourcePath' => self::RESOURCE_PATH . '?' - . http_build_query(['sourceId' => $sourceId, 'sku' => $sku]), + . http_build_query(['sourceCode' => $sourceCode, 'sku' => $sku]), 'httpMethod' => Request::HTTP_METHOD_DELETE, ], 'soap' => [ @@ -41,9 +41,9 @@ public function testDeleteSourceItemConfiguration() (TESTS_WEB_API_ADAPTER == self::ADAPTER_REST) ? $this->_webApiCall($serviceInfo) - : $this->_webApiCall($serviceInfo, ['sourceId' => $sourceId, 'sku' => $sku]); + : $this->_webApiCall($serviceInfo, ['sourceCode' => $sourceCode, 'sku' => $sku]); - $sourceItemConfiguration = $this->getSourceItemConfiguration($sourceId, $sku); + $sourceItemConfiguration = $this->getSourceItemConfiguration($sourceCode, $sku); $defaultNotifyQtyValue = 1; self::assertEquals( $defaultNotifyQtyValue, @@ -52,15 +52,15 @@ public function testDeleteSourceItemConfiguration() } /** - * @param int $sourceId + * @param string $sourceCode * @param string $sku * @return array */ - private function getSourceItemConfiguration(int $sourceId, string $sku) + private function getSourceItemConfiguration(string $sourceCode, string $sku) { $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceId . '/' . $sku, + 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceCode . '/' . $sku, 'httpMethod' => Request::HTTP_METHOD_GET, ], 'soap' => [ @@ -70,7 +70,7 @@ private function getSourceItemConfiguration(int $sourceId, string $sku) ]; $sourceItemConfiguration = (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST) ? $this->_webApiCall($serviceInfo) - : $this->_webApiCall($serviceInfo, ['sourceId' => $sourceId, 'sku' => $sku]); + : $this->_webApiCall($serviceInfo, ['sourceCode' => $sourceCode, 'sku' => $sku]); self::assertInternalType('array', $sourceItemConfiguration); self::assertNotEmpty($sourceItemConfiguration); diff --git a/app/code/Magento/InventoryConfigurationApi/Test/Api/SourceItemConfigurationsSaveTest.php b/app/code/Magento/InventoryConfigurationApi/Test/Api/SourceItemConfigurationsSaveTest.php index 4a045af33e03..052c3710b138 100644 --- a/app/code/Magento/InventoryConfigurationApi/Test/Api/SourceItemConfigurationsSaveTest.php +++ b/app/code/Magento/InventoryConfigurationApi/Test/Api/SourceItemConfigurationsSaveTest.php @@ -75,7 +75,7 @@ private function getSourceItemConfiguration(string $sourceCode, string $sku) ]; $sourceItemConfiguration = (TESTS_WEB_API_ADAPTER === self::ADAPTER_REST) ? $this->_webApiCall($serviceInfo) - : $this->_webApiCall($serviceInfo, ['sourceId' => $sourceCode, 'sku' => $sku]); + : $this->_webApiCall($serviceInfo, ['sourceCode' => $sourceCode, 'sku' => $sku]); self::assertInternalType('array', $sourceItemConfiguration); self::assertNotEmpty($sourceItemConfiguration); diff --git a/app/code/Magento/InventoryConfigurationApi/Test/_files/source_item_configuration_rollback.php b/app/code/Magento/InventoryConfigurationApi/Test/_files/source_item_configuration_rollback.php index 3aa00b1ee1a7..9f82525eefe4 100644 --- a/app/code/Magento/InventoryConfigurationApi/Test/_files/source_item_configuration_rollback.php +++ b/app/code/Magento/InventoryConfigurationApi/Test/_files/source_item_configuration_rollback.php @@ -10,4 +10,4 @@ /** @var DeleteSourceItemConfigurationInterface $deleteSourceItemConfiguration */ $deleteSourceItemConfiguration = Bootstrap::getObjectManager()->get(DeleteSourceItemConfigurationInterface::class); -$deleteSourceItemConfiguration->execute(10, 'SKU-1'); +$deleteSourceItemConfiguration->execute('eu-1', 'SKU-1'); diff --git a/app/code/Magento/InventoryImportExport/Model/Export/ColumnProvider.php b/app/code/Magento/InventoryImportExport/Model/Export/ColumnProvider.php index ed3b2b1e0bde..592886090dc3 100644 --- a/app/code/Magento/InventoryImportExport/Model/Export/ColumnProvider.php +++ b/app/code/Magento/InventoryImportExport/Model/Export/ColumnProvider.php @@ -8,7 +8,6 @@ namespace Magento\InventoryImportExport\Model\Export; use Magento\Framework\Data\Collection as AttributeCollection; -use Magento\InventoryImportExport\Model\Export\ColumnProviderInterface; use Magento\ImportExport\Model\Export; use \Magento\Framework\Exception\LocalizedException; @@ -31,7 +30,7 @@ public function getHeaders(AttributeCollection $attributeCollection, array $filt return $columns; } - if (count($filters[Export::FILTER_ELEMENT_SKIP]) === count($columns)) { + if (count($filters[Export::FILTER_ELEMENT_SKIP]) === count($columns)) { throw new LocalizedException(__('There is no data for the export.')); } diff --git a/app/code/Magento/InventoryImportExport/Model/Export/SourceItemCollectionFactory.php b/app/code/Magento/InventoryImportExport/Model/Export/SourceItemCollectionFactory.php index 657e10ea0824..c1e22e044bf5 100644 --- a/app/code/Magento/InventoryImportExport/Model/Export/SourceItemCollectionFactory.php +++ b/app/code/Magento/InventoryImportExport/Model/Export/SourceItemCollectionFactory.php @@ -27,7 +27,7 @@ class SourceItemCollectionFactory implements SourceItemCollectionFactoryInterfac /** * Source code field name */ - const SOURCE_CODE_FIELD = 'source_' . SourceInterface::CODE; + const SOURCE_CODE_FIELD = 'source_' . SourceInterface::SOURCE_CODE; /** * @var ObjectManagerInterface @@ -44,27 +44,19 @@ class SourceItemCollectionFactory implements SourceItemCollectionFactoryInterfac */ private $columnProvider; - /** - * @var ResourceConnection - */ - private $resourceConnection; - /** * @param ObjectManagerInterface $objectManager * @param FilterProcessorAggregator $filterProcessor * @param ColumnProviderInterface $columnProvider - * @param ResourceConnection $resourceConnection */ public function __construct( ObjectManagerInterface $objectManager, FilterProcessorAggregator $filterProcessor, - ColumnProviderInterface $columnProvider, - ResourceConnection $resourceConnection + ColumnProviderInterface $columnProvider ) { $this->objectManager = $objectManager; $this->filterProcessor = $filterProcessor; $this->columnProvider = $columnProvider; - $this->resourceConnection = $resourceConnection; } /** diff --git a/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php b/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php index d8979821abf7..8cd133d3cf91 100755 --- a/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php +++ b/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php @@ -9,7 +9,6 @@ use Magento\InventoryApi\Api\Data\SourceItemInterface; use Magento\InventoryApi\Api\Data\SourceItemInterfaceFactory; -use Magento\InventoryApi\Api\SourceRepositoryInterface; class SourceItemConvert { @@ -18,20 +17,12 @@ class SourceItemConvert */ private $sourceItemFactory; - /**´ - * @var SourceRepositoryInterface - */ - private $sourceRepository; - /** * @param SourceItemInterfaceFactory $sourceItemFactory */ - public function __construct( - SourceItemInterfaceFactory $sourceItemFactory, - SourceRepositoryInterface $sourceRepository - ) { + public function __construct(SourceItemInterfaceFactory $sourceItemFactory) + { $this->sourceItemFactory = $sourceItemFactory; - $this->sourceRepository = $sourceRepository; } /** @@ -43,10 +34,9 @@ public function convert(array $bunch): array { $sourceItems = []; foreach ($bunch as $rowData) { - $source = $this->sourceRepository->get($rowData[Sources::COL_SOURCE_CODE]); /** @var SourceItemInterface $sourceItem */ $sourceItem = $this->sourceItemFactory->create(); - $sourceItem->setSourceCode($source->getCode()); + $sourceItem->setSourceCode($rowData[Sources::COL_SOURCE]); $sourceItem->setSku($rowData[Sources::COL_SKU]); $sourceItem->setQuantity($rowData[Sources::COL_QTY]); diff --git a/app/code/Magento/InventoryImportExport/Model/Import/Sources.php b/app/code/Magento/InventoryImportExport/Model/Import/Sources.php index 56746c514d59..2b75b15f106c 100644 --- a/app/code/Magento/InventoryImportExport/Model/Import/Sources.php +++ b/app/code/Magento/InventoryImportExport/Model/Import/Sources.php @@ -16,7 +16,6 @@ use Magento\InventoryImportExport\Model\Import\Command\CommandInterface; use Magento\InventoryImportExport\Model\Import\Serializer\Json; use Magento\InventoryImportExport\Model\Import\Validator\ValidatorInterface; -use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceItemInterface; /** diff --git a/app/code/Magento/InventoryImportExport/Model/Import/Validator/SourceValidator.php b/app/code/Magento/InventoryImportExport/Model/Import/Validator/SourceValidator.php index 53fd1acc06e5..d65c97817a6b 100644 --- a/app/code/Magento/InventoryImportExport/Model/Import/Validator/SourceValidator.php +++ b/app/code/Magento/InventoryImportExport/Model/Import/Validator/SourceValidator.php @@ -63,7 +63,7 @@ public function validate(array $rowData, int $rowNumber) /** * Returns exits already the source in sources. * - * @param int $sourceCode + * @param string $sourceCode * @return bool */ private function isExistingSource($sourceCode): bool @@ -80,7 +80,7 @@ private function loadSourceCodes() { $sources = $this->sourceRepository->getList(); foreach ($sources->getItems() as $source) { - $sourceCode = $source->getCode(); + $sourceCode = $source->getSourceCode(); $this->sourceCodes[$sourceCode] = $sourceCode; } } diff --git a/app/code/Magento/InventoryImportExport/Model/StockItemImporter.php b/app/code/Magento/InventoryImportExport/Model/StockItemImporter.php index f904b2089929..26eb01aa8caf 100755 --- a/app/code/Magento/InventoryImportExport/Model/StockItemImporter.php +++ b/app/code/Magento/InventoryImportExport/Model/StockItemImporter.php @@ -10,6 +10,7 @@ use Magento\CatalogImportExport\Model\StockItemImporterInterface; use Magento\CatalogImportExport\Model\Import\Product; use Magento\Inventory\Model\SourceItemFactory; +use Magento\InventoryApi\Api\Data\SourceItemInterface; use Magento\InventoryApi\Api\SourceItemsSaveInterface; use Magento\InventoryCatalog\Api\DefaultSourceProviderInterface; @@ -66,6 +67,7 @@ public function import(array $stockData) if (isset($stockDatum[Product::COL_SKU])) { $inStock = (isset($stockDatum['is_in_stock'])) ? $stockDatum['is_in_stock'] : 0; $qty = (isset($stockDatum['qty'])) ? $stockDatum['qty'] : 0; + /** @var SourceItemInterface $sourceItem */ $sourceItem = $this->sourceItemFactory->create(); $sourceItem->setSku($stockDatum[Product::COL_SKU]); $sourceItem->setSourceCode($this->defaultSource->getCode()); diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_sku.csv b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_sku.csv index 867c3ae02281..040759777007 100644 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_sku.csv +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_sku.csv @@ -2,4 +2,4 @@ source_code,sku,status,quantity eu-1,SKU-1,1,5.5000 eu-2,SKU-1,1,3.0000 eu-3,SKU-1,0,10.0000 -eu-dis,SKU-1,1,10.0000 +eu-disabled,SKU-1,1,10.0000 diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_source.csv b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_source.csv index 767f04704498..5d30c3f9e7a6 100644 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_source.csv +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_by_source.csv @@ -2,5 +2,5 @@ source_code,sku,status,quantity eu-1,SKU-1,1,5.5000 eu-2,SKU-1,1,3.0000 eu-3,SKU-1,0,10.0000 -eu-dis,SKU-1,1,10.0000 +eu-disabled,SKU-1,1,10.0000 eu-2,SKU-3,0,6.0000 diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_without_status_column.csv b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_without_status_column.csv index 49c62cb1f782..7a9ec068d744 100644 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_without_status_column.csv +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_filtered_without_status_column.csv @@ -1,4 +1,4 @@ source_code,sku,quantity eu-1,SKU-1,5.5000 eu-2,SKU-1,3.0000 -eu-dis,SKU-1,10.0000 +eu-disabled,SKU-1,10.0000 diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_full.csv b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_full.csv index 60edb310ba9e..0e6d1ed2b358 100644 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_full.csv +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/_files/export_full.csv @@ -2,5 +2,5 @@ source_code,sku,status,quantity eu-1,SKU-1,1,5.5000 eu-2,SKU-1,1,3.0000 eu-3,SKU-1,0,10.0000 -eu-dis,SKU-1,1,10.0000 +eu-disabled,SKU-1,1,10.0000 us-1,SKU-2,1,5.0000 diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/StockItemImporterTest.php b/app/code/Magento/InventoryImportExport/Test/Integration/Model/StockItemImporterTest.php index b98b29c8dda1..12fb3d704c6c 100755 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/StockItemImporterTest.php +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/StockItemImporterTest.php @@ -78,8 +78,8 @@ public function testSourceItemImportWithDefaultSource() $expectedData = [ SourceItemInterface::SKU => $stockData['sku'], SourceItemInterface::QUANTITY => '1.0000', - SourceItemInterface::SOURCE_CODE => (string) $this->defaultSourceProvider->getCode(), - SourceItemInterface::STATUS => (string) SourceItemInterface::STATUS_IN_STOCK + SourceItemInterface::SOURCE_CODE => (string)$this->defaultSourceProvider->getCode(), + SourceItemInterface::STATUS => (string)SourceItemInterface::STATUS_IN_STOCK ]; $this->assertArrayHasKey('SKU-1', $compareData); @@ -122,7 +122,7 @@ private function buildDataArray(array $sourceItems) $comparableArray[$sourceItem->getSku()] = [ SourceItemInterface::SKU => $sourceItem->getSku(), SourceItemInterface::QUANTITY => $sourceItem->getQuantity(), - SourceItemInterface::SOURCE_CODE => (string)$sourceItem->getSourceCode(), + SourceItemInterface::SOURCE_CODE => $sourceItem->getSourceCode(), SourceItemInterface::STATUS => $sourceItem->getStatus() ]; } diff --git a/app/code/Magento/InventorySalesApi/Test/Api/StockRepository/SalesChannelManagementTest.php b/app/code/Magento/InventorySalesApi/Test/Api/StockRepository/SalesChannelManagementTest.php index 7fc70b76406c..793aa56c8337 100644 --- a/app/code/Magento/InventorySalesApi/Test/Api/StockRepository/SalesChannelManagementTest.php +++ b/app/code/Magento/InventorySalesApi/Test/Api/StockRepository/SalesChannelManagementTest.php @@ -90,11 +90,11 @@ public function updateStockWithSalesChannelsReplacingDataProvider(): array [ [ SalesChannelInterface::TYPE => SalesChannelInterface::TYPE_WEBSITE, - SalesChannelInterface::CODE => 'us_website', + SalesChannelInterface::CODE => 'global_website', ], [ SalesChannelInterface::TYPE => SalesChannelInterface::TYPE_WEBSITE, - SalesChannelInterface::CODE => 'global_website', + SalesChannelInterface::CODE => 'us_website', ], ], ], From 79972cef4858d23fb06b37aa89ae93b84993ca09 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Wed, 27 Dec 2017 12:09:17 +0200 Subject: [PATCH 34/39] MSI: Task 290 import export source code --- .../Test/Unit/Model/Source/Validator/CodeValidatorTest.php | 6 +++--- .../Api/StockSourceLink/UnassignSourceFromStockTest.php | 7 ------- .../Model/Import/SourceItemConvert.php | 2 +- 3 files changed, 4 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/Inventory/Test/Unit/Model/Source/Validator/CodeValidatorTest.php b/app/code/Magento/Inventory/Test/Unit/Model/Source/Validator/CodeValidatorTest.php index 79d68e627151..0c4584203237 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/Source/Validator/CodeValidatorTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/Source/Validator/CodeValidatorTest.php @@ -50,7 +50,7 @@ public function testValidateCodeNotEmpty() ]); $this->source->expects($this->once()) - ->method('getCode') + ->method('getSourceCode') ->willReturn(' '); $this->codeValidator->validate($this->source); } @@ -68,7 +68,7 @@ public function testValidateCodeNotWithWhiteSpaces() 'validationResultFactory' => $this->validationResultFactory ]); $this->source->expects($this->once()) - ->method('getCode') + ->method('getSourceCode') ->willReturn(' source code '); $this->codeValidator->validate($this->source); } @@ -83,7 +83,7 @@ public function testValidateCodeSuccessfully() 'validationResultFactory' => $this->validationResultFactory ]); $this->source->expects($this->once()) - ->method('getCode') + ->method('getSourceCode') ->willReturn(' source_code '); $result = $this->codeValidator->validate($this->source); diff --git a/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/UnassignSourceFromStockTest.php b/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/UnassignSourceFromStockTest.php index 885cec4d4981..9954108194f8 100644 --- a/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/UnassignSourceFromStockTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/UnassignSourceFromStockTest.php @@ -114,13 +114,6 @@ public function dataProviderWrongParameters(): array 'message' => 'Invalid type for value: "not_numeric". Expected Type: "int".', ], ], - 'not_string_source_code' => [ - 10, - [], - [ - 'message' => 'Invalid type for value: "10". Expected Type: "string".', - ], - ], ]; } diff --git a/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php b/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php index 8cd133d3cf91..4e918c842f3a 100755 --- a/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php +++ b/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php @@ -36,7 +36,7 @@ public function convert(array $bunch): array foreach ($bunch as $rowData) { /** @var SourceItemInterface $sourceItem */ $sourceItem = $this->sourceItemFactory->create(); - $sourceItem->setSourceCode($rowData[Sources::COL_SOURCE]); + $sourceItem->setSourceCode($rowData[Sources::COL_SOURCE_CODE]); $sourceItem->setSku($rowData[Sources::COL_SKU]); $sourceItem->setQuantity($rowData[Sources::COL_QTY]); From 9f210cdd9117e67f5e3fd20b0230f863fc97fa74 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Wed, 27 Dec 2017 13:55:41 +0200 Subject: [PATCH 35/39] MSI: Task 290 import export source code --- .../Controller/Adminhtml/Source/Save.php | 21 +++++++++---------- .../Integration/Model/Export/SourcesTest.php | 5 ++++- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php index d723e880bd3e..d473c04a4ce3 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php @@ -70,7 +70,10 @@ public function execute(): ResultInterface $resultRedirect = $this->resultRedirectFactory->create(); $request = $this->getRequest(); $requestData = $request->getParams(); - if (!$request->isPost() || empty($requestData['general'])) { + if (!$request->isPost() + || empty($requestData['general']) + || empty($requestData['general'][SourceInterface::SOURCE_CODE]) + ) { $this->messageManager->addErrorMessage(__('Wrong request.')); $this->processRedirectAfterFailureSave($resultRedirect); @@ -78,14 +81,14 @@ public function execute(): ResultInterface } try { - $sourceCode = $requestData['general'][SourceInterface::CODE]; + $sourceCode = $requestData['general'][SourceInterface::SOURCE_CODE]; $this->processSave($requestData, $sourceCode); $this->messageManager->addSuccessMessage(__('The Source has been saved.')); $this->processRedirectAfterSuccessSave($resultRedirect, $sourceCode); } catch (NoSuchEntityException $e) { $this->messageManager->addErrorMessage(__('The Source does not exist.')); - $this->processRedirectAfterFailureSave($resultRedirect); + $this->processRedirectAfterFailureSave($resultRedirect, $sourceCode); } catch (ValidationException $e) { foreach ($e->getErrors() as $localizedError) { $this->messageManager->addErrorMessage($localizedError->getMessage()); @@ -105,7 +108,6 @@ public function execute(): ResultInterface /** * @param array $requestData * @param string $sourceCode - * * @return void */ private function processSave(array $requestData, string $sourceCode) @@ -116,7 +118,6 @@ private function processSave(array $requestData, string $sourceCode) /** @var SourceInterface $source */ $source = $this->sourceFactory->create(); } - $source = $this->sourceHydrator->hydrate($source, $requestData); $this->_eventManager->dispatch( @@ -141,14 +142,13 @@ private function processSave(array $requestData, string $sourceCode) /** * @param Redirect $resultRedirect * @param string $sourceCode - * * @return void */ private function processRedirectAfterSuccessSave(Redirect $resultRedirect, string $sourceCode) { if ($this->getRequest()->getParam('back')) { $resultRedirect->setPath('*/*/edit', [ - SourceInterface::CODE => $sourceCode, + SourceInterface::SOURCE_CODE => $sourceCode, '_current' => true, ]); } elseif ($this->getRequest()->getParam('redirect_to_new')) { @@ -162,17 +162,16 @@ private function processRedirectAfterSuccessSave(Redirect $resultRedirect, strin /** * @param Redirect $resultRedirect - * @param string $sourceCode - * + * @param string|null $sourceCode * @return void */ - private function processRedirectAfterFailureSave(Redirect $resultRedirect, string $sourceCode) + private function processRedirectAfterFailureSave(Redirect $resultRedirect, string $sourceCode = null) { if (null === $sourceCode) { $resultRedirect->setPath('*/*/new'); } else { $resultRedirect->setPath('*/*/edit', [ - SourceInterface::CODE => $sourceCode, + SourceInterface::SOURCE_CODE => $sourceCode, '_current' => true, ]); } diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/SourcesTest.php b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/SourcesTest.php index 77693884cddc..485705f22b89 100644 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/SourcesTest.php +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/SourcesTest.php @@ -121,7 +121,10 @@ public function testExportWithSourceFilter() { $this->exporter->setParameters([ Export::FILTER_ELEMENT_GROUP => [ - 'source_code' => 'eu' + 'source_id' => [ + 22, + 62 + ] ] ]); $this->exporter->export(); From 902ca8778c44b3215a702b47c23fef081500ec9f Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Wed, 27 Dec 2017 13:56:24 +0200 Subject: [PATCH 36/39] MSI: Task 290 import export source code --- .../Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php index af7aeda71136..1b0636873187 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php @@ -79,7 +79,7 @@ public function testSave() ->with($this->source) ->willReturn($sourceCode); - self::assertEquals($sourceCode, $this->sourceRepository->save($this->source)); + $this->sourceRepository->save($this->source); } /** From 6d7782bc6265b15d224a5274ad2e76dfae2e795b Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Wed, 27 Dec 2017 14:14:34 +0200 Subject: [PATCH 37/39] MSI: Task 290 import export source code --- .../Controller/Adminhtml/Source/Save.php | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php index d473c04a4ce3..bb6d9b2e094c 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php @@ -69,55 +69,49 @@ public function execute(): ResultInterface { $resultRedirect = $this->resultRedirectFactory->create(); $request = $this->getRequest(); - $requestData = $request->getParams(); - if (!$request->isPost() - || empty($requestData['general']) - || empty($requestData['general'][SourceInterface::SOURCE_CODE]) - ) { + $requestData = $request->getPost(); + + if (!$request->isPost() || empty($requestData['general'])) { $this->messageManager->addErrorMessage(__('Wrong request.')); $this->processRedirectAfterFailureSave($resultRedirect); - return $resultRedirect; } + $sourceCodeQueryParam = $request->getQuery(SourceInterface::SOURCE_CODE); try { - $sourceCode = $requestData['general'][SourceInterface::SOURCE_CODE]; - $this->processSave($requestData, $sourceCode); + $source = (null !== $sourceCodeQueryParam) + ? $this->sourceRepository->get($sourceCodeQueryParam) + : $this->sourceFactory->create(); + + $this->processSave($source, $requestData); $this->messageManager->addSuccessMessage(__('The Source has been saved.')); - $this->processRedirectAfterSuccessSave($resultRedirect, $sourceCode); + $this->processRedirectAfterSuccessSave($resultRedirect, $source->getSourceCode()); } catch (NoSuchEntityException $e) { $this->messageManager->addErrorMessage(__('The Source does not exist.')); - $this->processRedirectAfterFailureSave($resultRedirect, $sourceCode); + $this->processRedirectAfterFailureSave($resultRedirect); } catch (ValidationException $e) { foreach ($e->getErrors() as $localizedError) { $this->messageManager->addErrorMessage($localizedError->getMessage()); } - $this->processRedirectAfterFailureSave($resultRedirect, $sourceCode); + $this->processRedirectAfterFailureSave($resultRedirect, $sourceCodeQueryParam ?? $sourceCodeQueryParam); } catch (CouldNotSaveException $e) { $this->messageManager->addErrorMessage($e->getMessage()); - $this->processRedirectAfterFailureSave($resultRedirect, $sourceCode); + $this->processRedirectAfterFailureSave($resultRedirect, $sourceCodeQueryParam ?? $sourceCodeQueryParam); } catch (Exception $e) { $this->messageManager->addErrorMessage(__('Could not save Source.')); - $this->processRedirectAfterFailureSave($resultRedirect, $sourceCode); + $this->processRedirectAfterFailureSave($resultRedirect, $sourceCodeQueryParam ?? $sourceCodeQueryParam); } - return $resultRedirect; } /** + * @param SourceInterface $source * @param array $requestData - * @param string $sourceCode * @return void */ - private function processSave(array $requestData, string $sourceCode) + private function processSave(SourceInterface $source, array $requestData) { - try { - $source = $this->sourceRepository->get($sourceCode); - } catch (NoSuchEntityException $e) { - /** @var SourceInterface $source */ - $source = $this->sourceFactory->create(); - } $source = $this->sourceHydrator->hydrate($source, $requestData); $this->_eventManager->dispatch( From 8b8ee98d3a38dce7e42ce96faaa08ba4e3773f4b Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Wed, 27 Dec 2017 14:31:37 +0200 Subject: [PATCH 38/39] MSI: Task 290 import export source code --- app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php | 2 +- .../view/adminhtml/ui_component/inventory_source_form.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php index bb6d9b2e094c..6593818c1af9 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php @@ -69,7 +69,7 @@ public function execute(): ResultInterface { $resultRedirect = $this->resultRedirectFactory->create(); $request = $this->getRequest(); - $requestData = $request->getPost(); + $requestData = $request->getPost()->toArray(); if (!$request->isPost() || empty($requestData['general'])) { $this->messageManager->addErrorMessage(__('Wrong request.')); diff --git a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml index bcee1fa7c1c9..90fae339e52b 100644 --- a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml +++ b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_source_form.xml @@ -50,7 +50,7 @@ true general - + true From 16948bd765e3259e5b380dd4c08569becbf428bd Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Wed, 27 Dec 2017 15:24:11 +0200 Subject: [PATCH 39/39] MSI: Task 290 import export source code --- .../Test/Integration/Model/Export/SourcesTest.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/SourcesTest.php b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/SourcesTest.php index 485705f22b89..77693884cddc 100644 --- a/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/SourcesTest.php +++ b/app/code/Magento/InventoryImportExport/Test/Integration/Model/Export/SourcesTest.php @@ -121,10 +121,7 @@ public function testExportWithSourceFilter() { $this->exporter->setParameters([ Export::FILTER_ELEMENT_GROUP => [ - 'source_id' => [ - 22, - 62 - ] + 'source_code' => 'eu' ] ]); $this->exporter->export();