diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Edit.php index bb02cab9badc..e240a8360017 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::SOURCE_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 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 e5609b0aaeee..006928d9d799 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->get($sourceId); + $sourceCode = $itemData[SourceInterface::SOURCE_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 1e412a642049..6593818c1af9 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Save.php @@ -69,22 +69,24 @@ public function execute(): ResultInterface { $resultRedirect = $this->resultRedirectFactory->create(); $request = $this->getRequest(); - $requestData = $request->getParams(); + $requestData = $request->getPost()->toArray(); + if (!$request->isPost() || empty($requestData['general'])) { $this->messageManager->addErrorMessage(__('Wrong request.')); $this->processRedirectAfterFailureSave($resultRedirect); - return $resultRedirect; } + $sourceCodeQueryParam = $request->getQuery(SourceInterface::SOURCE_CODE); try { - $sourceId = isset($requestData['general'][SourceInterface::SOURCE_ID]) - ? (int)$requestData['general'][SourceInterface::SOURCE_ID] - : null; - $sourceId = $this->processSave($requestData, $sourceId); + $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, $sourceId); + $this->processRedirectAfterSuccessSave($resultRedirect, $source->getSourceCode()); } catch (NoSuchEntityException $e) { $this->messageManager->addErrorMessage(__('The Source does not exist.')); $this->processRedirectAfterFailureSave($resultRedirect); @@ -92,32 +94,24 @@ public function execute(): ResultInterface foreach ($e->getErrors() as $localizedError) { $this->messageManager->addErrorMessage($localizedError->getMessage()); } - $this->processRedirectAfterFailureSave($resultRedirect, $sourceId); + $this->processRedirectAfterFailureSave($resultRedirect, $sourceCodeQueryParam ?? $sourceCodeQueryParam); } catch (CouldNotSaveException $e) { $this->messageManager->addErrorMessage($e->getMessage()); - $this->processRedirectAfterFailureSave($resultRedirect, $sourceId); + $this->processRedirectAfterFailureSave($resultRedirect, $sourceCodeQueryParam ?? $sourceCodeQueryParam); } catch (Exception $e) { $this->messageManager->addErrorMessage(__('Could not save Source.')); - $this->processRedirectAfterFailureSave($resultRedirect, $sourceId ?? null); + $this->processRedirectAfterFailureSave($resultRedirect, $sourceCodeQueryParam ?? $sourceCodeQueryParam); } - return $resultRedirect; } /** + * @param SourceInterface $source * @param array $requestData - * @param int|null $sourceId - * - * @return int + * @return void */ - private function processSave(array $requestData, int $sourceId = null): int + private function processSave(SourceInterface $source, array $requestData) { - if (null === $sourceId) { - /** @var SourceInterface $source */ - $source = $this->sourceFactory->create(); - } else { - $source = $this->sourceRepository->get($sourceId); - } $source = $this->sourceHydrator->hydrate($source, $requestData); $this->_eventManager->dispatch( @@ -128,7 +122,7 @@ private function processSave(array $requestData, int $sourceId = null): int ] ); - $sourceId = $this->sourceRepository->save($source); + $this->sourceRepository->save($source); $this->_eventManager->dispatch( 'controller_action_inventory_source_save_after', @@ -137,21 +131,18 @@ private function processSave(array $requestData, int $sourceId = null): int 'source' => $source, ] ); - - return $sourceId; } /** * @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::SOURCE_CODE => $sourceCode, '_current' => true, ]); } elseif ($this->getRequest()->getParam('redirect_to_new')) { @@ -165,17 +156,16 @@ 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::SOURCE_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 90e98aa73aa0..ece5f8ff0097 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->getSourceCode(), $sourceCodesForSave)) { + unset($sourceCodesForSave[$assignedSource->getSourceCode()]); } else { - $sourceIdsForDelete[] = $assignedSource->getSourceId(); + $sourceCodesForDelete[] = $assignedSource->getSourceCode(); } } - 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((int) $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..938e8b48e837 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::SOURCE_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,15 @@ public function execute($stockId): Select ) ->joinLeft( ['stock_source_link' => $sourceStockLinkTable], - 'source_item.' . SourceItemInterface::SOURCE_ID . ' = stock_source_link.' . StockSourceLink::SOURCE_ID, + sprintf( + 'source_item.%s = stock_source_link.%s', + SourceItemInterface::SOURCE_CODE, + 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..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/GetSkuListInStock.php b/app/code/Magento/Inventory/Indexer/SourceItem/GetSkuListInStock.php index caca132f65b5..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_ID . ' = stock_source_link.' . StockSourceLink::SOURCE_ID, + 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/Indexer/SourceItem/SourceItemIndexer.php b/app/code/Magento/Inventory/Indexer/SourceItem/SourceItemIndexer.php index 3a77edff1b5c..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; /** @@ -96,9 +95,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..5c0581cb702b 100644 --- a/app/code/Magento/Inventory/Model/ResourceModel/Source.php +++ b/app/code/Magento/Inventory/Model/ResourceModel/Source.php @@ -30,6 +30,13 @@ class Source extends AbstractDb const TABLE_NAME_SOURCE = 'inventory_source'; /**#@-*/ + /** + * Primary key auto increment flag + * + * @var bool + */ + protected $_isPkAutoIncrement = false; + /** * @var SourceCarrierLinkManagementInterface */ @@ -54,7 +61,7 @@ public function __construct( */ protected function _construct() { - $this->_init(self::TABLE_NAME_SOURCE, SourceInterface::SOURCE_ID); + $this->_init(self::TABLE_NAME_SOURCE, SourceInterface::SOURCE_CODE); } /** 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 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..22cec4f34d40 --- 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 @@ -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/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.php b/app/code/Magento/Inventory/Model/Source.php index d119ecae728f..6c66fff06d66 100644 --- a/app/code/Magento/Inventory/Model/Source.php +++ b/app/code/Magento/Inventory/Model/Source.php @@ -30,33 +30,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); - } - - /** - * @inheritdoc - */ - public function getCode() - { - return $this->getData(self::CODE); - } - - /** - * @inheritdoc - */ - public function setCode($code) - { - 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 566c63c9c7d5..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(int $sourceId): SourceInterface + public function execute(string $sourceCode): SourceInterface { /** @var SourceInterface $source */ $source = $this->sourceFactory->create(); - $this->sourceResource->load($source, $sourceId, SourceInterface::SOURCE_ID); + $this->sourceResource->load($source, $sourceCode, SourceInterface::SOURCE_CODE); - if (null === $source->getSourceId()) { - throw new NoSuchEntityException(__('Source with id "%value" does not exist.', ['value' => $sourceId])); + 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 07e2c1bd3fca..390285fde244 100644 --- a/app/code/Magento/Inventory/Model/Source/Command/GetInterface.php +++ b/app/code/Magento/Inventory/Model/Source/Command/GetInterface.php @@ -11,7 +11,7 @@ use Magento\InventoryApi\Api\Data\SourceInterface; /** - * Get Source by sourceId command (Service Provider Interface - SPI) + * Get Source by code command (Service Provider Interface - SPI) * * Separate command interface to which Repository proxies initial Get call, could be considered as SPI - Interfaces * that you should extend and implement to customize current behaviour, but NOT expected to be used (called) in the code @@ -23,11 +23,11 @@ interface GetInterface { /** - * Get Source data by given sourceId + * Get Source data by given code * - * @param int $sourceId + * @param string $sourceCode * @return SourceInterface * @throws NoSuchEntityException */ - public function execute(int $sourceId): 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 f053df7b41a8..3718e8e1443f 100644 --- a/app/code/Magento/Inventory/Model/Source/Command/Save.php +++ b/app/code/Magento/Inventory/Model/Source/Command/Save.php @@ -52,7 +52,7 @@ public function __construct( /** * @inheritdoc */ - public function execute(SourceInterface $source): int + public function execute(SourceInterface $source) { $validationResult = $this->sourceValidator->validate($source); @@ -62,7 +62,7 @@ public function execute(SourceInterface $source): int try { $this->sourceResource->save($source); - return (int)$source->getSourceId(); + $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/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/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 ce500a41c0a4..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_id = ?', $source->getSourceId()) + $connection->quoteInto('source_code = ?', $source->getSourceCode()) ); } @@ -103,7 +103,7 @@ private function saveNewCarrierLinks(SourceInterface $source) $carrierLinkData = []; foreach ($source->getCarrierLinks() as $carrierLink) { $carrierLinkData[] = [ - 'source_id' => $source->getSourceId(), + '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(SourceInterface::SOURCE_ID, $source->getSourceId()) + ->addFilter(SourceCarrierLinkInterface::SOURCE_CODE, $source->getSourceCode()) ->create(); /** @var Collection $collection */ 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 3cc0a7911bc1..9dd5b5c36212 --- a/app/code/Magento/Inventory/Model/SourceItem.php +++ b/app/code/Magento/Inventory/Model/SourceItem.php @@ -46,17 +46,17 @@ public function setSku($sku) /** * @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/SourceItem/Validator/SourceIdValidator.php b/app/code/Magento/Inventory/Model/SourceItem/Validator/SourceCodeValidator.php similarity index 64% rename from app/code/Magento/Inventory/Model/SourceItem/Validator/SourceIdValidator.php rename to app/code/Magento/Inventory/Model/SourceItem/Validator/SourceCodeValidator.php index 2e9175c9bdf9..777cd8d1f62d 100644 --- a/app/code/Magento/Inventory/Model/SourceItem/Validator/SourceIdValidator.php +++ b/app/code/Magento/Inventory/Model/SourceItem/Validator/SourceCodeValidator.php @@ -12,9 +12,9 @@ use Magento\InventoryApi\Api\Data\SourceItemInterface; /** - * Check that source id is valid + * Check that source code is valid */ -class SourceIdValidator implements SourceItemValidatorInterface +class SourceCodeValidator implements SourceItemValidatorInterface { /** * @var ValidationResultFactory @@ -34,14 +34,15 @@ public function __construct(ValidationResultFactory $validationResultFactory) */ public function validate(SourceItemInterface $source): ValidationResult { - $errors = []; - if (!is_numeric($source->getSourceId())) { - $errors[] = __( - '"%field" should be numeric.', - ['field' => SourceItemInterface::SOURCE_ID] - ); - } + $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 ccc5c84043cb..8d2c10e4921b 100644 --- a/app/code/Magento/Inventory/Model/SourceRepository.php +++ b/app/code/Magento/Inventory/Model/SourceRepository.php @@ -53,17 +53,17 @@ public function __construct( /** * @inheritdoc */ - public function save(SourceInterface $source): int + public function save(SourceInterface $source) { - return $this->commandSave->execute($source); + $this->commandSave->execute($source); } /** * @inheritdoc */ - public function get(int $sourceId): SourceInterface + public function get(string $sourceCode): SourceInterface { - return $this->commandGet->execute($sourceId); + return $this->commandGet->execute($sourceCode); } /** 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..e3787e889d62 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::SOURCE_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..6aa5201fc5fb 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, + SourceCarrierLinkInterface::SOURCE_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, + SourceCarrierLinkInterface::SOURCE_CODE, $sourceTable, - SourceInterface::SOURCE_ID + SourceInterface::SOURCE_CODE ), - SourceInterface::SOURCE_ID, + SourceCarrierLinkInterface::SOURCE_CODE, $sourceTable, - SourceInterface::SOURCE_ID, + 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 old mode 100644 new mode 100755 index a6c8b5cc225f..f0e0405cb3a1 --- 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::SOURCE_CODE ), - SourceItemInterface::SOURCE_ID, + SourceItemInterface::SOURCE_CODE, $sourceTable, - SourceInterface::SOURCE_ID, + SourceInterface::SOURCE_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/Inventory/Setup/Operation/CreateSourceTable.php b/app/code/Magento/Inventory/Setup/Operation/CreateSourceTable.php index 9c9738398c83..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( - SourceInterface::SOURCE_ID, - 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 f90c204bd01a..71c4524aa8f7 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::SOURCE_CODE ), - StockSourceLink::SOURCE_ID, + StockSourceLink::SOURCE_CODE, $sourceTable, - SourceInterface::SOURCE_ID, + SourceInterface::SOURCE_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..c40b13b31f73 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): int { $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/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/Inventory/Test/Unit/Model/Source/Validator/CodeValidatorTest.php b/app/code/Magento/Inventory/Test/Unit/Model/Source/Validator/CodeValidatorTest.php index f035068929f1..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 @@ -43,14 +43,14 @@ 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 ]); $this->source->expects($this->once()) - ->method('getCode') + ->method('getSourceCode') ->willReturn(' '); $this->codeValidator->validate($this->source); } @@ -60,13 +60,15 @@ 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 ]); $this->source->expects($this->once()) - ->method('getCode') + ->method('getSourceCode') ->willReturn(' source code '); $this->codeValidator->validate($this->source); } @@ -81,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/Inventory/Test/Unit/Model/SourceRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php index 1423f3584a97..1b0636873187 100644 --- a/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php +++ b/app/code/Magento/Inventory/Test/Unit/Model/SourceRepositoryTest.php @@ -71,15 +71,15 @@ protected function setUp() public function testSave() { - $sourceId = 42; + $sourceCode = 'source-code'; $this->commandSave ->expects($this->once()) ->method('execute') ->with($this->source) - ->willReturn($sourceId); + ->willReturn($sourceCode); - self::assertEquals($sourceId, $this->sourceRepository->save($this->source)); + $this->sourceRepository->save($this->source); } /** @@ -99,15 +99,15 @@ public function testSaveWithCouldNotSaveException() public function testGet() { - $sourceId = 42; + $sourceCode = 'source-code'; $this->commandGet ->expects($this->once()) ->method('execute') - ->with($sourceId) + ->with($sourceCode) ->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 = 'source-code'; $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/Inventory/Ui/DataProvider/SourceDataProvider.php b/app/code/Magento/Inventory/Ui/DataProvider/SourceDataProvider.php index d9604018c039..48e7cb664e21 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 = $data['items'][0][SourceInterface::SOURCE_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::SOURCE_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..85eb3d8daac9 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::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 6acb6ca0aa86..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\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..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 @@ -38,8 +38,8 @@ - source_id - source_id + source_code + source_code @@ -50,7 +50,7 @@ true general - + true 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..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 @@ - source_id + source_code Magento_InventoryApi::source - id - source_id + source_code + source_code @@ -68,7 +68,7 @@ false - source_id + source_code true inventory_source_listing.inventory_source_listing.inventory_source_listing_columns.ids @@ -85,17 +85,10 @@ - source_id + source_code - - - textRange - - asc - - - + text @@ -288,7 +281,7 @@ - source_id + 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 50e3b47b127a..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,10 +100,10 @@ data.sources.assign_sources_grid - source_id + source_code name - source_id + source_code @@ -111,7 +111,7 @@ false false record - source_id + source_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..0aac6952eeb7 100644 --- a/app/code/Magento/InventoryApi/Api/AssignSourcesToStockInterface.php +++ b/app/code/Magento/InventoryApi/Api/AssignSourcesToStockInterface.php @@ -21,11 +21,11 @@ interface AssignSourcesToStockInterface * * If one of the Sources or Stock with given id don't exist then exception will be throw * - * @param int[] $sourceIds + * @param string[] $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/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/InventoryApi/Api/Data/SourceInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php index 8a834b062c17..6a74a5186c13 100644 --- a/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceInterface.php @@ -21,8 +21,7 @@ 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 SOURCE_CODE = 'source_code'; const NAME = 'name'; const CONTACT_NAME = 'contact_name'; const EMAIL = 'email'; @@ -42,35 +41,20 @@ 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 * * @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 old mode 100644 new mode 100755 index a26f67c47b36..4ae85a76de58 --- a/app/code/Magento/InventoryApi/Api/Data/SourceItemInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/SourceItemInterface.php @@ -8,11 +8,10 @@ namespace Magento\InventoryApi\Api\Data; use Magento\Framework\Api\ExtensibleDataInterface; -use Magento\InventoryApi\Api\Data\SourceItemExtensionInterface; /** * 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 * @@ -24,7 +23,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 +51,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 string|null $sourceCode * @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/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 c6a02d2d9d1a..1f9032fd00bc 100644 --- a/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php +++ b/app/code/Magento/InventoryApi/Api/SourceRepositoryInterface.php @@ -36,21 +36,21 @@ 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 sourceId. If you want to create plugin on get method, also you need to create separate + * 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 $sourceId + * @param string $sourceCode * @return \Magento\InventoryApi\Api\Data\SourceInterface * @throws \Magento\Framework\Exception\NoSuchEntityException */ - public function get(int $sourceId): 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 e0082caf3afd..12d150265f6e 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 string $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..0fbff6d416b0 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceItemsDeleteTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceItemsDeleteTest.php @@ -32,33 +32,27 @@ 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-disabled', SourceItemInterface::SKU => 'SKU-1', SourceItemInterface::QUANTITY => 10, SourceItemInterface::STATUS => SourceItemInterface::STATUS_IN_STOCK, ], - [ - SourceItemInterface::SOURCE_ID => 50, - 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/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..ce7ca5df5ae0 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" can not be empty.', 'parameters' => [ - 'field' => SourceItemInterface::SOURCE_ID, + 'field' => SourceItemInterface::SOURCE_CODE, ], ], ], @@ -230,28 +230,73 @@ 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" 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_ID, + 'field' => SourceItemInterface::SOURCE_CODE, ], ], ], ], ], - 'not_exists_' . SourceItemInterface::SOURCE_ID => [ - SourceItemInterface::SOURCE_ID, - 100, + 'not_exists_' . SourceItemInterface::SOURCE_CODE => [ + SourceItemInterface::SOURCE_CODE, + '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,20 +355,12 @@ public function failedValidationRelatedOnlyForRestDataProvider(): array . '" processing. Invalid type for value: "test". Expected Type: "float".', ], ], - 'empty_' . SourceItemInterface::SOURCE_ID => [ - SourceItemInterface::SOURCE_ID, - '', - [ - 'message' => 'Error occurred during "' . SourceItemInterface::SOURCE_ID - . '" processing. Invalid type for value: "". Expected Type: "int".', - ], - ], - '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..33acec908455 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::SOURCE_CODE, $response); return $response; } @@ -179,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', @@ -209,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 f667c57fe3de..efa3c876453b 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CreateTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/CreateTest.php @@ -26,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', @@ -65,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() @@ -82,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' => [ @@ -99,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(SourceInterface::SOURCE_ID, $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 5d0775de25ae..9b5dcd7df2fb 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/RegionProcessingTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/RegionProcessingTest.php @@ -24,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]); @@ -42,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]); @@ -60,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', @@ -70,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]); @@ -92,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' => [ @@ -106,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' => [ @@ -130,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(SourceInterface::SOURCE_ID, $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 9931f3a952da..502015a15780 100644 --- a/app/code/Magento/InventoryApi/Test/Api/SourceRepository/UpdateTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/SourceRepository/UpdateTest.php @@ -27,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', @@ -59,7 +58,7 @@ public function testUpdate() ]; $serviceInfo = [ 'rest' => [ - 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceId, + 'resourcePath' => self::RESOURCE_PATH . '/' . $sourceCode, 'httpMethod' => Request::HTTP_METHOD_PUT, ], 'soap' => [ @@ -71,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' => [ @@ -96,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(SourceInterface::SOURCE_ID, $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 35c77802710b..68964c107acd 100644 --- a/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/AssignSourcesToStockTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/AssignSourcesToStockTest.php @@ -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, SourceInterface::SOURCE_ID)); + 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 93174e439d7b..2b305ccca970 100644 --- a/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/GetAssignedSourcesForStockTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/GetAssignedSourcesForStockTest.php @@ -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, SourceInterface::SOURCE_ID)); + 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 c711948c3c64..9954108194f8 100644 --- a/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/UnassignSourceFromStockTest.php +++ b/app/code/Magento/InventoryApi/Test/Api/StockSourceLink/UnassignSourceFromStockTest.php @@ -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, SourceInterface::SOURCE_ID)); + 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,19 +108,12 @@ 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', - 10, - [ - 'message' => 'Invalid type for value: "not_numeric". Expected Type: "int".', - ], - ], ]; } diff --git a/app/code/Magento/InventoryApi/Test/_files/products.php b/app/code/Magento/InventoryApi/Test/_files/products.php index 058f454096ac..ad4a199b7dce 100644 --- a/app/code/Magento/InventoryApi/Test/_files/products.php +++ b/app/code/Magento/InventoryApi/Test/_files/products.php @@ -70,7 +70,7 @@ // Unassign created product from default Source $searchCriteria = $searchCriteriaBuilder ->addFilter(SourceItemInterface::SKU, ['SKU-1', 'SKU-2', 'SKU-3'], 'in') - ->addFilter(SourceItemInterface::SOURCE_ID, $defaultSourceProvider->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.php b/app/code/Magento/InventoryApi/Test/_files/source.php index 38167c76fa0a..7273e7737ac1 100644 --- a/app/code/Magento/InventoryApi/Test/_files/source.php +++ b/app/code/Magento/InventoryApi/Test/_files/source.php @@ -24,8 +24,7 @@ $dataObjectHelper->populateWithArray( $source, [ - SourceInterface::SOURCE_ID => 10, - 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', diff --git a/app/code/Magento/InventoryApi/Test/_files/source_items.php b/app/code/Magento/InventoryApi/Test/_files/source_items.php index f2141062909e..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_ID => 10, // EU-source-1 + SourceItemInterface::SOURCE_CODE => 'eu-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', 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', 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-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', 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', 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 28bd271fbaa7..046b14df777c 100644 --- a/app/code/Magento/InventoryApi/Test/_files/source_rollback.php +++ b/app/code/Magento/InventoryApi/Test/_files/source_rollback.php @@ -12,5 +12,5 @@ /** @var ResourceConnection $connection */ $connection = Bootstrap::getObjectManager()->get(ResourceConnection::class); $connection->getConnection()->delete($connection->getTableName('inventory_source'), [ - SourceInterface::SOURCE_ID . ' = ?' => 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 70053b01b9f2..578e5adde4a5 100644 --- a/app/code/Magento/InventoryApi/Test/_files/sources.php +++ b/app/code/Magento/InventoryApi/Test/_files/sources.php @@ -21,8 +21,7 @@ $sourcesData = [ [ // define only required and needed for tests fields - SourceInterface::SOURCE_ID => 10, - SourceInterface::CODE => 'source-code-1', + SourceInterface::SOURCE_CODE => 'eu-1', SourceInterface::NAME => 'EU-source-1', SourceInterface::ENABLED => true, SourceInterface::PRIORITY => 100, @@ -30,8 +29,7 @@ SourceInterface::COUNTRY_ID => 'FR', ], [ - SourceInterface::SOURCE_ID => 20, - SourceInterface::CODE => 'source-code-2', + SourceInterface::SOURCE_CODE => 'eu-2', SourceInterface::NAME => 'EU-source-2', SourceInterface::ENABLED => true, SourceInterface::PRIORITY => 200, @@ -39,8 +37,7 @@ SourceInterface::COUNTRY_ID => 'FR', ], [ - SourceInterface::SOURCE_ID => 30, - SourceInterface::CODE => 'source-code-3', + SourceInterface::SOURCE_CODE => 'eu-3', SourceInterface::NAME => 'EU-source-3', SourceInterface::ENABLED => true, SourceInterface::PRIORITY => 300, @@ -48,8 +45,7 @@ SourceInterface::COUNTRY_ID => 'DE', ], [ - SourceInterface::SOURCE_ID => 40, - SourceInterface::CODE => 'source-code-4', + SourceInterface::SOURCE_CODE => 'eu-disabled', SourceInterface::NAME => 'EU-source-disabled', SourceInterface::ENABLED => false, SourceInterface::PRIORITY => 10, @@ -57,8 +53,7 @@ SourceInterface::COUNTRY_ID => 'DE', ], [ - SourceInterface::SOURCE_ID => 50, - SourceInterface::CODE => 'source-code-5', + 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 e710b72aa27f..0ffb651588f9 100644 --- a/app/code/Magento/InventoryApi/Test/_files/sources_rollback.php +++ b/app/code/Magento/InventoryApi/Test/_files/sources_rollback.php @@ -14,6 +14,6 @@ $connection->getConnection()->delete( $connection->getTableName('inventory_source'), [ - SourceInterface::SOURCE_ID . ' 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 5fd27e4a3980..8bde8fdad9f3 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-disabled) - 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-disabled) - 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-disabled'], 10); +$assignSourcesToStock->execute(['us-1'], 20); +$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 b9ae97e65561..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 @@ -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-disabled', 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-disabled', 30); +$unassignSourceFromStock->execute('us-1', 30); 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..f1a3c6927f62 100644 --- a/app/code/Magento/InventoryCatalog/Api/DefaultSourceProviderInterface.php +++ b/app/code/Magento/InventoryCatalog/Api/DefaultSourceProviderInterface.php @@ -15,9 +15,9 @@ interface DefaultSourceProviderInterface { /** - * Get Default Source id + * Get Default Source code * - * @return int + * @return string */ - public function getId(): int; + public function getCode(): string; } diff --git a/app/code/Magento/InventoryCatalog/Model/DefaultSourceProvider.php b/app/code/Magento/InventoryCatalog/Model/DefaultSourceProvider.php index 4850afd5868b..b11e17668dee 100644 --- a/app/code/Magento/InventoryCatalog/Model/DefaultSourceProvider.php +++ b/app/code/Magento/InventoryCatalog/Model/DefaultSourceProvider.php @@ -17,8 +17,8 @@ class DefaultSourceProvider implements DefaultSourceProviderInterface /** * @inheritdoc */ - public function getId(): int + public function getCode(): string { - return 1; + return 'default'; } } diff --git a/app/code/Magento/InventoryCatalog/Observer/ProcessSourceItemsObserver.php b/app/code/Magento/InventoryCatalog/Observer/ProcessSourceItemsObserver.php index 5b0c100a4b44..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 */ @@ -98,7 +101,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 +109,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 old mode 100644 new mode 100755 index be2571db68ce..4e9d99da0975 --- 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); @@ -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; @@ -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/UpdateSourceItemAtLegacyStockItemSavePlugin.php b/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/UpdateSourceItemAtLegacyStockItemSavePlugin.php old mode 100644 new mode 100755 index e95348baf476..e87bfe6f5c5b --- a/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/UpdateSourceItemAtLegacyStockItemSavePlugin.php +++ b/app/code/Magento/InventoryCatalog/Plugin/CatalogInventory/UpdateSourceItemAtLegacyStockItemSavePlugin.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)) { @@ -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/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php b/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php index cc7e565ea49e..cb7945f1c22b 100644 --- a/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php +++ b/app/code/Magento/InventoryCatalog/Plugin/InventoryApi/AssignSourcesToStock/PreventAssignSourcesToDefaultStockPlugin.php @@ -34,19 +34,22 @@ public function __construct( /** * @param AssignSourcesToStockInterface $subject - * @param array $sourceIds + * @param array $sourceCodes * @param int $stockId * @return array * @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 || !count($sourceCodes)) { + return [$sourceCodes, $stockId]; } - throw new InputException(__('You can only assign Default Source to Default Stock')); + 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/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); 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/CreateDefaultSource.php b/app/code/Magento/InventoryCatalog/Setup/Operation/CreateDefaultSource.php index 7cfdefd894ab..64bf4979d85c 100644 --- a/app/code/Magento/InventoryCatalog/Setup/Operation/CreateDefaultSource.php +++ b/app/code/Magento/InventoryCatalog/Setup/Operation/CreateDefaultSource.php @@ -64,8 +64,7 @@ public function __construct( public function execute() { $data = [ - SourceInterface::SOURCE_ID => $this->defaultSourceProvider->getId(), - 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 4a9be8da153f..8970a74b86e8 100644 --- a/app/code/Magento/InventoryCatalog/Setup/Operation/UpdateInventorySourceItem.php +++ b/app/code/Magento/InventoryCatalog/Setup/Operation/UpdateInventorySourceItem.php @@ -42,15 +42,12 @@ public function __construct( } /** - * Insert Stock Item to Inventory Source Item by raw MySQL query - * * @param ModuleDataSetupInterface $setup - * * @return void */ 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 +57,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 +69,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/Test/Api/GetDefaultSourceTest.php b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultSourceTest.php index 8d5fba7ecd89..73d9d1f6a2e0 100644 --- a/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultSourceTest.php +++ b/app/code/Magento/InventoryCatalog/Test/Api/GetDefaultSourceTest.php @@ -8,23 +8,33 @@ 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() { - $defaultSourceId = 1; + $defaultSourceCode = $this->defaultSourceProvider->getCode(); $serviceInfo = [ 'rest' => [ - 'resourcePath' => '/V1/inventory/source/' . $defaultSourceId, + 'resourcePath' => '/V1/inventory/source/' . $defaultSourceCode, 'httpMethod' => Request::HTTP_METHOD_GET, ], 'soap' => [ @@ -35,8 +45,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::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 1df184074b6e..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; - $defaultSourceId = 1; + $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([$defaultSourceId], array_column($source, SourceInterface::SOURCE_ID)); + $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/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/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, 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..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,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::SOURCE_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..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,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,11 +74,11 @@ - + 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..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 { @@ -50,14 +49,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 +78,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 +99,13 @@ private function addForeignKey( return $sourceItemConfigurationTable->addForeignKey( $setup->getFkName( $sourceItemConfigurationTable->getName(), - SourceItemConfigurationInterface::SOURCE_ID, + SourceItemConfigurationInterface::SOURCE_CODE, $sourceItemTable, - SourceInterface::SOURCE_ID + SourceItemInterface::SOURCE_CODE ), - SourceItemConfigurationInterface::SOURCE_ID, + SourceItemConfigurationInterface::SOURCE_CODE, $sourceItemTable, - SourceInterface::SOURCE_ID, + SourceItemInterface::SOURCE_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..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 @@ -65,18 +65,19 @@ private function getSourceItemsConfigurationData(array $assignedSources, Product { foreach ($assignedSources as &$source) { $sourceConfiguration = $this->getSourceItemConfiguration->execute( - (int)$source[SourceInterface::SOURCE_ID], + (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/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..ac024aa787f4 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 string $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/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/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..052c3710b138 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, ['sourceCode' => $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/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/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/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 diff --git a/app/code/Magento/InventoryImportExport/Model/Export/AttributeCollectionProvider.php b/app/code/Magento/InventoryImportExport/Model/Export/AttributeCollectionProvider.php index 822d8c674bbf..d4177ac20b91 100644 --- a/app/code/Magento/InventoryImportExport/Model/Export/AttributeCollectionProvider.php +++ b/app/code/Magento/InventoryImportExport/Model/Export/AttributeCollectionProvider.php @@ -48,13 +48,13 @@ public function __construct( 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); + /** @var \Magento\Eav\Model\Entity\Attribute $sourceCodeAttribute */ + $sourceCodeAttribute = $this->attributeFactory->create(); + $sourceCodeAttribute->setId(SourceItemInterface::SOURCE_CODE); + $sourceCodeAttribute->setDefaultFrontendLabel(SourceItemInterface::SOURCE_CODE); + $sourceCodeAttribute->setAttributeCode(SourceItemInterface::SOURCE_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..592886090dc3 100644 --- a/app/code/Magento/InventoryImportExport/Model/Export/ColumnProvider.php +++ b/app/code/Magento/InventoryImportExport/Model/Export/ColumnProvider.php @@ -8,8 +8,8 @@ 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; /** * @inheritdoc @@ -30,6 +30,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..c1e22e044bf5 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::SOURCE_CODE; + /** * @var ObjectManagerInterface */ @@ -60,7 +69,8 @@ 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); + $collection->addFieldToSelect($columns); foreach ($this->retrieveFilterData($filters) as $columnName => $value) { $attributeDefinition = $attributeCollection->getItemById($columnName); @@ -81,7 +91,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/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/SourceItemConvert.php b/app/code/Magento/InventoryImportExport/Model/Import/SourceItemConvert.php old mode 100644 new mode 100755 index b00bbd23a80b..4e918c842f3a --- 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->setSourceId($rowData[Sources::COL_SOURCE]); + $sourceItem->setSourceCode($rowData[Sources::COL_SOURCE_CODE]); $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..2b75b15f106c 100644 --- a/app/code/Magento/InventoryImportExport/Model/Import/Sources.php +++ b/app/code/Magento/InventoryImportExport/Model/Import/Sources.php @@ -27,7 +27,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 = 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 94e6f3b8c9fb..d65c97817a6b 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,25 @@ public function validate(array $rowData, int $rowNumber) /** * Returns exits already the source in sources. * - * @param int $sourceId + * @param string $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->getSourceCode(); + $this->sourceCodes[$sourceCode] = $sourceCode; } } } 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..26eb01aa8caf --- 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,9 +67,10 @@ 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->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/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(); 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..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 @@ -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-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 752c4c8699a2..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 @@ -1,4 +1,6 @@ -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-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 89cb0643b37c..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_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-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 aca33a8fff41..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 @@ -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-disabled,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 old mode 100644 new mode 100755 index 7dd7819e5d16..05aeedc5dc4b --- 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,24 +75,18 @@ 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.'); } - /** - * @expectedException \Magento\Framework\Exception\LocalizedException - */ public function testImportDataWithWrongBehavior() { $this->importer->setParameters([ 'behavior' => 'WrongBehavior' ]); - $bunch = [ - $this->buildRowDataArray(10, 'SKU-1', 6.88, 1) - ]; - $this->importData($bunch); + $this->assertEquals($this->importer->getBehavior(), \Magento\ImportExport\Model\Import::getDefaultBehavior()); } /** @@ -105,10 +106,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 +135,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,16 +161,16 @@ 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); $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); } /** @@ -183,7 +184,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([ @@ -191,30 +192,30 @@ 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); // 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); } /** - * @param int $sourceID + * @param string $sourceCode * @param string $sku * @param int $qty * @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, @@ -229,9 +230,9 @@ private function buildDataArray(array $sourceItems) { $comparableArray = []; foreach ($sourceItems as $sourceItem) { - $key = sprintf('%s-%s', $sourceItem->getSourceId(), $sourceItem->getSku()); + $key = sprintf('%s-%s', $sourceItem->getSourceCode(), $sourceItem->getSku()); $comparableArray[$key] = $this->buildRowDataArray( - $sourceItem->getSourceId(), + $sourceItem->getSourceCode(), $sourceItem->getSku(), $sourceItem->getQuantity(), $sourceItem->getStatus() @@ -248,9 +249,9 @@ 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]); + $key = sprintf('%s-%s', $bunchData[Sources::COL_SOURCE_CODE], $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] 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 562eb0b00789..12fb3d704c6c --- 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_ID => (string) $this->defaultSourceProvider->getId(), - 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); @@ -102,8 +102,8 @@ private function getSourceItemList() ); $searchCriteriaBuilder->addFilter( - SourceItemInterface::SOURCE_ID, - $this->defaultSourceProvider->getId() + SourceItemInterface::SOURCE_CODE, + $this->defaultSourceProvider->getCode() ); /** @var SearchCriteria $searchCriteria */ @@ -122,7 +122,7 @@ private function buildDataArray(array $sourceItems) $comparableArray[$sourceItem->getSku()] = [ SourceItemInterface::SKU => $sourceItem->getSku(), SourceItemInterface::QUANTITY => $sourceItem->getQuantity(), - SourceItemInterface::SOURCE_ID => $sourceItem->getSourceId(), + SourceItemInterface::SOURCE_CODE => $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(), 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', ], ], ], 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();