From be1d21ea7c226fc095d257c5df1d244539e53ef3 Mon Sep 17 00:00:00 2001 From: Eugene Tulika Date: Mon, 26 Jun 2017 13:01:16 +0100 Subject: [PATCH 01/16] magento-engcom/magento#34: Source to Stock Mapping UI and API - created Resource models, models and APIs --- .../Inventory/Model/ResourceModel/Stock.php | 35 ++++++++ .../Model/ResourceModel/Stock/Collection.php | 54 ++++++++++++ app/code/Magento/Inventory/Model/Stock.php | 83 +++++++++++++++++++ .../InventoryApi/Api/Data/StockInterface.php | 51 ++++++++++++ .../Api/Data/StockSearchResultsInterface.php | 29 +++++++ .../Api/StockRepositoryInterface.php | 41 +++++++++ 6 files changed, 293 insertions(+) create mode 100644 app/code/Magento/Inventory/Model/ResourceModel/Stock.php create mode 100644 app/code/Magento/Inventory/Model/ResourceModel/Stock/Collection.php create mode 100644 app/code/Magento/Inventory/Model/Stock.php create mode 100644 app/code/Magento/InventoryApi/Api/Data/StockInterface.php create mode 100644 app/code/Magento/InventoryApi/Api/Data/StockSearchResultsInterface.php create mode 100644 app/code/Magento/InventoryApi/Api/StockRepositoryInterface.php diff --git a/app/code/Magento/Inventory/Model/ResourceModel/Stock.php b/app/code/Magento/Inventory/Model/ResourceModel/Stock.php new file mode 100644 index 000000000000..0493faaf547a --- /dev/null +++ b/app/code/Magento/Inventory/Model/ResourceModel/Stock.php @@ -0,0 +1,35 @@ +_init(InstallSchema::TABLE_NAME_STOCK, StockInterface::STOCK_ID); + } +} diff --git a/app/code/Magento/Inventory/Model/ResourceModel/Stock/Collection.php b/app/code/Magento/Inventory/Model/ResourceModel/Stock/Collection.php new file mode 100644 index 000000000000..5f4f2532295c --- /dev/null +++ b/app/code/Magento/Inventory/Model/ResourceModel/Stock/Collection.php @@ -0,0 +1,54 @@ +_init(StockModel::class, ResourceStock::class); + } +} diff --git a/app/code/Magento/Inventory/Model/Stock.php b/app/code/Magento/Inventory/Model/Stock.php new file mode 100644 index 000000000000..9724fa9eb604 --- /dev/null +++ b/app/code/Magento/Inventory/Model/Stock.php @@ -0,0 +1,83 @@ +_init(\Magento\Inventory\Model\ResourceModel\Stock::class); + } + + /** + * @inheritdoc + */ + public function getStockId() + { + return $this->getData(StockInterface::STOCK_ID); + } + + /** + * @inheritdoc + */ + public function setStockId($stockId) + { + $this->setData(StockInterface::STOCK_ID, $stockId); + } + + /** + * @inheritdoc + */ + public function getName() + { + return $this->getData(StockInterface::NAME); + } + + /** + * @inheritdoc + */ + public function setName($name) + { + $this->setData(StockInterface::NAME, $name); + } + + /** + * @inheritdoc + */ + public function getExtensionAttributes() + { + $extensionAttributes = $this->_getExtensionAttributes(); + if (null === $extensionAttributes) { + $extensionAttributes = $this->extensionAttributesFactory->create(StockInterface::class); + $this->setExtensionAttributes($extensionAttributes); + } + return $extensionAttributes; + } + + /** + * @inheritdoc + */ + public function setExtensionAttributes( + \Magento\InventoryApi\Api\Data\StockExtensionInterface $extensionAttributes + ) { + return $this->_setExtensionAttributes($extensionAttributes); + } +} diff --git a/app/code/Magento/InventoryApi/Api/Data/StockInterface.php b/app/code/Magento/InventoryApi/Api/Data/StockInterface.php new file mode 100644 index 000000000000..b754c0daa183 --- /dev/null +++ b/app/code/Magento/InventoryApi/Api/Data/StockInterface.php @@ -0,0 +1,51 @@ + Date: Mon, 26 Jun 2017 14:04:19 +0100 Subject: [PATCH 02/16] agento-engcom/magento#34: Source to Stock Mapping UI and API --- .../Ui/DataProvider/StockDataProvider.php | 130 ++++++++ .../layout/inventory_stock_index.xml | 15 + .../ui_component/inventory_stock_listing.xml | 282 ++++++++++++++++++ 3 files changed, 427 insertions(+) create mode 100644 app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php create mode 100644 app/code/Magento/Inventory/view/adminhtml/layout/inventory_stock_index.xml create mode 100644 app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_listing.xml diff --git a/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php b/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php new file mode 100644 index 000000000000..ff6fb225bb0f --- /dev/null +++ b/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php @@ -0,0 +1,130 @@ +sourceRepository = $sourceRepository; + $this->searchResultFactory = $searchResultFactory; + } + + /** + * {@inheritdoc} + */ + public function getData() + { + $data = parent::getData(); + if ('inventory_source_form_data_source' === $this->name) { + // It is need for support of several fieldsets. + // For details see \Magento\Ui\Component\Form::getDataSourceData + if ($data['totalRecords'] > 0) { + $sourceId = $data['items'][0][SourceInterface::SOURCE_ID]; + $sourceGeneralData = $data['items'][0]; + $sourceGeneralData['carrier_codes'] = $this->getAssignedCarrierCodes($sourceId); + $dataForSingle[$sourceId] = [ + 'general' => $sourceGeneralData, + ]; + $data = $dataForSingle; + } else { + $data = []; + } + } + return $data; + } + + /** + * {@inheritdoc} + */ + public function getSearchResult() + { + $searchCriteria = $this->getSearchCriteria(); + $result = $this->sourceRepository->getList($searchCriteria); + + $searchResult = $this->searchResultFactory->create( + $result->getItems(), + $result->getTotalCount(), + $searchCriteria, + SourceInterface::SOURCE_ID + ); + return $searchResult; + } + + /** + * @param int $sourceId + * @return array + */ + private function getAssignedCarrierCodes($sourceId) + { + $source = $this->sourceRepository->get($sourceId); + + $carrierCodes = []; + foreach ($source->getCarrierLinks() as $carrierLink) { + $carrierCodes[] = $carrierLink->getCarrierCode(); + } + return $carrierCodes; + } +} diff --git a/app/code/Magento/Inventory/view/adminhtml/layout/inventory_stock_index.xml b/app/code/Magento/Inventory/view/adminhtml/layout/inventory_stock_index.xml new file mode 100644 index 000000000000..890d2ae5a5bc --- /dev/null +++ b/app/code/Magento/Inventory/view/adminhtml/layout/inventory_stock_index.xml @@ -0,0 +1,15 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_listing.xml b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_listing.xml new file mode 100644 index 000000000000..1f7bc1a4bd29 --- /dev/null +++ b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_listing.xml @@ -0,0 +1,282 @@ + + ++ + + inventory_stock_listing.inventory_stock_listing_data_stock + + + + + + + inventory_stock_listing_columns + + inventory_stock_listing.inventory_stock_listing_data_stock + + + + + + stock_id + + + + + + id + stock_id + + + + + + true + + + + + + + + + + + + + + + + + + + + + + false + + stock_id + true + inventory_stock_listing.inventory_stock_listing.inventory_stock_listing_columns.ids + + + + inventory_stock_listing.inventory_stock_listing.inventory_stock_listing_columns_editor + startEdit + + ${ $.$data.rowIndex } + true + + + + + + + stock_id + + + + + textRange + + asc + + + + + text + + + text + + true + + + + + + + text + + text + + + false + + + + + text + + text + + true + + + + false + + + + + + select + select + + + + + + + + + text + + text + + true + + + + false + + + + + text + + text + + true + + + + false + + + + + + false + select + select + + + + + + + false + select + select + + + + + + text + + false + + + + + text + + text + + + false + + + + + text + + text + + + false + + + + + text + + text + + true + + + + false + + + + + text + + text + + true + + + + false + + + + + text + + text + + true + + + + false + + + + + text + + text + + true + + + + + + + + + inventory/stock/edit + + + + stock_id + + + + From 67775b712822f30846dffd2f38d7dc706294623c Mon Sep 17 00:00:00 2001 From: Eugene Tulika Date: Mon, 26 Jun 2017 14:04:23 +0100 Subject: [PATCH 03/16] magento-engcom/magento#34: Source to Stock Mapping UI and API - created StockRepositoryInterface and StockRepository --- .../Inventory/Model/StockRepository.php | 134 ++++++++++++++++++ .../Api/StockRepositoryInterface.php | 18 +-- 2 files changed, 143 insertions(+), 9 deletions(-) create mode 100644 app/code/Magento/Inventory/Model/StockRepository.php diff --git a/app/code/Magento/Inventory/Model/StockRepository.php b/app/code/Magento/Inventory/Model/StockRepository.php new file mode 100644 index 000000000000..ad2957ef8f85 --- /dev/null +++ b/app/code/Magento/Inventory/Model/StockRepository.php @@ -0,0 +1,134 @@ +resourceStock = $resourceStock; + $this->stockFactory = $stockFactory; + $this->collectionProcessor = $collectionProcessor; + $this->stockCollectionFactory = $stockCollectionFactory; + $this->stockSearchResultsFactory = $stockSearchResultsFactory; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->logger = $logger; + } + + /** + * @inheritdoc + */ + public function save(StockInterface $stock) + { + try { + $this->resourceStock->save($stock); + return $stock->getStockId(); + } catch (\Exception $e) { + $this->logger->error($e->getMessage()); + throw new CouldNotSaveException(__('Could not save stock'), $e); + } + } + + /** + * @inheritdoc + */ + public function get($stockId) + { + $stock = $this->stockFactory->create(); + $this->resourceStock->load($stock, $stockId, StockInterface::STOCK_ID); + + if (!$stock->getStockId()) { + throw NoSuchEntityException::singleField(StockInterface::STOCK_ID, $stockId); + } + return $stock; + } + + /** + * @inheritdoc + */ + public function getList(SearchCriteriaInterface $searchCriteria = null) + { + $collection = $this->stockCollectionFactory->create(); + + if (null === $searchCriteria) { + $searchCriteria = $this->searchCriteriaBuilder->create(); + } else { + $this->collectionProcessor->process($searchCriteria, $collection); + } + + $searchResult = $this->stockCollectionFactory->create(); + $searchResult->setItems($collection->getItems()); + $searchResult->setTotalCount($collection->getSize()); + $searchResult->setSearchCriteria($searchCriteria); + return $searchResult; + } +} diff --git a/app/code/Magento/InventoryApi/Api/StockRepositoryInterface.php b/app/code/Magento/InventoryApi/Api/StockRepositoryInterface.php index 8eb6dbb39fee..935ec750547a 100644 --- a/app/code/Magento/InventoryApi/Api/StockRepositoryInterface.php +++ b/app/code/Magento/InventoryApi/Api/StockRepositoryInterface.php @@ -8,29 +8,29 @@ /** * @api */ -interface SourceRepositoryInterface +interface StockRepositoryInterface { /** - * Save Source data. If you want to create plugin on get method, also you need to create separate plugin + * Save Stock data. 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 \Magento\InventoryApi\Api\Data\SourceInterface $source + * @param \Magento\InventoryApi\Api\Data\StockInterface $stock * @return int * @throws \Magento\Framework\Exception\CouldNotSaveException */ - public function save(\Magento\InventoryApi\Api\Data\SourceInterface $source); + public function save(\Magento\InventoryApi\Api\Data\StockInterface $stock); /** - * Get Source data by given sourceId. + * Get Stock data by given stockId. * - * @param int $sourceId - * @return \Magento\InventoryApi\Api\Data\SourceInterface + * @param int $stockId + * @return \Magento\InventoryApi\Api\Data\StockInterface * @throws \Magento\Framework\Exception\NoSuchEntityException */ - public function get($sourceId); + public function get($stockId); /** - * Load Source data collection by given search criteria. + * Load Stock data collection by given search criteria. * * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria * @return \Magento\InventoryApi\Api\Data\StockSearchResultsInterface From 17556002067a77675cc6cefdc46006ebf3492a60 Mon Sep 17 00:00:00 2001 From: astyczen Date: Mon, 26 Jun 2017 14:11:04 +0100 Subject: [PATCH 04/16] magento-engcom/magento#34 Inventory Stock table created --- .../Magento/Inventory/Setup/UpgradeSchema.php | 123 ++++++++++++++++++ app/code/Magento/Inventory/etc/module.xml | 2 +- 2 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 app/code/Magento/Inventory/Setup/UpgradeSchema.php diff --git a/app/code/Magento/Inventory/Setup/UpgradeSchema.php b/app/code/Magento/Inventory/Setup/UpgradeSchema.php new file mode 100644 index 000000000000..04eb35d5b778 --- /dev/null +++ b/app/code/Magento/Inventory/Setup/UpgradeSchema.php @@ -0,0 +1,123 @@ +startSetup(); + + if (version_compare($context->getVersion(), '2.0.0', '>')) { + $stockTable = $this->createStockTable($setup); + $setup->getConnection()->createTable($stockTable); +// $this->createSourceStockLinkTable($setup); + } + + $setup->endSetup(); + } + + private function createStockTable($setup) { + /** + * Create table 'inventory_stock' + */ + $sourceTable = $setup->getTable(UpgradeSchema::TABLE_NAME_STOCK); + + return $setup->getConnection()->newTable( + $sourceTable + )->setComment( + 'Inventory Stock Table' + )->addColumn( + StockInterface::STOCK_ID, + Table::TYPE_INTEGER, + null, + [ + UpgradeSchema::OPTION_IDENTITY => true, + UpgradeSchema::OPTION_UNSIGNED => true, + UpgradeSchema::OPTION_NULLABLE => false, + UpgradeSchema::OPTION_PRIMARY => true, + ], + 'Stock ID' + )->addColumn( + StockInterface::NAME, + Table::TYPE_TEXT, + 255, + [ + UpgradeSchema::OPTION_NULLABLE => false, + ], + 'Stock Name' + ); + } + +// private function createSourceStockLinkTable($setup) { +// /** +// * Create table 'inventory_source_stock_link' +// */ +// $sourceTable = $setup->getTable(UpgradeSchema::TABLE_NAME_SOURCE_STOCK_LINK); +// +// return $setup->getConnection()->newTable( +// $sourceTable +// )->setComment( +// 'Inventory Source Stock Link Table' +// )->addColumn( +// SourceStockLinkInterface::LINK_ID, +// Table::TYPE_INTEGER, +// null, +// [ +// UpgradeSchema::OPTION_IDENTITY => true, +// UpgradeSchema::OPTION_UNSIGNED => true, +// UpgradeSchema::OPTION_NULLABLE => false, +// UpgradeSchema::OPTION_PRIMARY => true, +// ], +// 'Link ID' +// )->addColumn( +// SourceStockLinkInterface::STOCK_ID, +// Table::TYPE_INTEGER, +// null, +// [ +// UpgradeSchema::OPTION_NULLABLE => false, +// ], +// 'Stock Id' +// )->addColumn( +// SourceStockLinkInterface::SOURCE_ID, +// Table::TYPE_INTEGER, +// null, +// [ +// UpgradeSchema::OPTION_NULLABLE => false, +// ], +// 'Source Id' +// ); +// } +} diff --git a/app/code/Magento/Inventory/etc/module.xml b/app/code/Magento/Inventory/etc/module.xml index 2ef165277a57..9047111bbd7e 100644 --- a/app/code/Magento/Inventory/etc/module.xml +++ b/app/code/Magento/Inventory/etc/module.xml @@ -6,7 +6,7 @@ */ --> - + From 35a65fb8558307bab695f215bfdee923252471e6 Mon Sep 17 00:00:00 2001 From: astyczen Date: Mon, 26 Jun 2017 14:37:53 +0100 Subject: [PATCH 05/16] magento-engcom/magento#34 Source stock link table created --- .../Magento/Inventory/Setup/UpgradeSchema.php | 82 ++++++++++--------- app/code/Magento/Inventory/etc/module.xml | 2 +- .../Api/Data/SourceStockLinkInterface.php | 68 +++++++++++++++ 3 files changed, 111 insertions(+), 41 deletions(-) create mode 100644 app/code/Magento/InventoryApi/Api/Data/SourceStockLinkInterface.php diff --git a/app/code/Magento/Inventory/Setup/UpgradeSchema.php b/app/code/Magento/Inventory/Setup/UpgradeSchema.php index 04eb35d5b778..18c9672ebda3 100644 --- a/app/code/Magento/Inventory/Setup/UpgradeSchema.php +++ b/app/code/Magento/Inventory/Setup/UpgradeSchema.php @@ -10,6 +10,7 @@ use Magento\Framework\Setup\UpgradeSchemaInterface; use Magento\Framework\DB\Ddl\Table; use Magento\InventoryApi\Api\Data\StockInterface; +use Magento\InventoryApi\Api\Data\SourceStockLinkInterface; /** * Class for integration tables schema upgrades @@ -43,7 +44,8 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con if (version_compare($context->getVersion(), '2.0.0', '>')) { $stockTable = $this->createStockTable($setup); $setup->getConnection()->createTable($stockTable); -// $this->createSourceStockLinkTable($setup); + $stockLinkTable = $this->createSourceStockLinkTable($setup); + $setup->getConnection()->createTable($stockLinkTable); } $setup->endSetup(); @@ -81,43 +83,43 @@ private function createStockTable($setup) { ); } -// private function createSourceStockLinkTable($setup) { -// /** -// * Create table 'inventory_source_stock_link' -// */ -// $sourceTable = $setup->getTable(UpgradeSchema::TABLE_NAME_SOURCE_STOCK_LINK); -// -// return $setup->getConnection()->newTable( -// $sourceTable -// )->setComment( -// 'Inventory Source Stock Link Table' -// )->addColumn( -// SourceStockLinkInterface::LINK_ID, -// Table::TYPE_INTEGER, -// null, -// [ -// UpgradeSchema::OPTION_IDENTITY => true, -// UpgradeSchema::OPTION_UNSIGNED => true, -// UpgradeSchema::OPTION_NULLABLE => false, -// UpgradeSchema::OPTION_PRIMARY => true, -// ], -// 'Link ID' -// )->addColumn( -// SourceStockLinkInterface::STOCK_ID, -// Table::TYPE_INTEGER, -// null, -// [ -// UpgradeSchema::OPTION_NULLABLE => false, -// ], -// 'Stock Id' -// )->addColumn( -// SourceStockLinkInterface::SOURCE_ID, -// Table::TYPE_INTEGER, -// null, -// [ -// UpgradeSchema::OPTION_NULLABLE => false, -// ], -// 'Source Id' -// ); -// } + private function createSourceStockLinkTable($setup) { + /** + * Create table 'inventory_source_stock_link' + */ + $sourceTable = $setup->getTable(UpgradeSchema::TABLE_NAME_SOURCE_STOCK_LINK); + + return $setup->getConnection()->newTable( + $sourceTable + )->setComment( + 'Inventory Source Stock Link Table' + )->addColumn( + SourceStockLinkInterface::LINK_ID, + Table::TYPE_INTEGER, + null, + [ + UpgradeSchema::OPTION_IDENTITY => true, + UpgradeSchema::OPTION_UNSIGNED => true, + UpgradeSchema::OPTION_NULLABLE => false, + UpgradeSchema::OPTION_PRIMARY => true, + ], + 'Link ID' + )->addColumn( + SourceStockLinkInterface::STOCK_ID, + Table::TYPE_INTEGER, + null, + [ + UpgradeSchema::OPTION_NULLABLE => false, + ], + 'Stock Id' + )->addColumn( + SourceStockLinkInterface::SOURCE_ID, + Table::TYPE_INTEGER, + null, + [ + UpgradeSchema::OPTION_NULLABLE => false, + ], + 'Source Id' + ); + } } diff --git a/app/code/Magento/Inventory/etc/module.xml b/app/code/Magento/Inventory/etc/module.xml index 9047111bbd7e..d66860d18442 100644 --- a/app/code/Magento/Inventory/etc/module.xml +++ b/app/code/Magento/Inventory/etc/module.xml @@ -6,7 +6,7 @@ */ --> - + diff --git a/app/code/Magento/InventoryApi/Api/Data/SourceStockLinkInterface.php b/app/code/Magento/InventoryApi/Api/Data/SourceStockLinkInterface.php new file mode 100644 index 000000000000..719150576f9a --- /dev/null +++ b/app/code/Magento/InventoryApi/Api/Data/SourceStockLinkInterface.php @@ -0,0 +1,68 @@ + Date: Mon, 26 Jun 2017 14:50:47 +0100 Subject: [PATCH 06/16] magento-engcom/magento#34 upgrade moved to the install script --- .../Magento/Inventory/Setup/InstallSchema.php | 88 ++++++++++++ .../Magento/Inventory/Setup/UpgradeSchema.php | 125 ------------------ app/code/Magento/Inventory/etc/module.xml | 2 +- 3 files changed, 89 insertions(+), 126 deletions(-) delete mode 100644 app/code/Magento/Inventory/Setup/UpgradeSchema.php diff --git a/app/code/Magento/Inventory/Setup/InstallSchema.php b/app/code/Magento/Inventory/Setup/InstallSchema.php index d9fbffe8b477..8080fff86201 100644 --- a/app/code/Magento/Inventory/Setup/InstallSchema.php +++ b/app/code/Magento/Inventory/Setup/InstallSchema.php @@ -12,6 +12,8 @@ use Magento\Framework\Setup\SchemaSetupInterface; use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\InventoryApi\Api\Data\SourceCarrierLinkInterface; +use Magento\InventoryApi\Api\Data\StockInterface; +use Magento\InventoryApi\Api\Data\SourceStockLinkInterface; /** * @codeCoverageIgnore @@ -28,6 +30,16 @@ class InstallSchema implements InstallSchemaInterface */ const TABLE_NAME_SOURCE_CARRIER_LINK = 'inventory_source_carrier_link'; + /** + * Constant for table names of the model \Magento\Inventory\Model\Stock + */ + const TABLE_NAME_STOCK = 'inventory_stock'; + + /** + * Constant for table name of \Magento\Inventory\Model\SourceStockLink + */ + const TABLE_NAME_SOURCE_STOCK_LINK = 'inventory_source_stock_link'; + /** * Constant for decimal precision for latitude and longitude */ @@ -62,6 +74,10 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con $setup->getConnection()->createTable($sourceTable); $setup->getConnection()->createTable($this->createSourceCarrierLinkTable($setup)); + + $setup->getConnection()->createTable($this->createStockTable($setup)); + $setup->getConnection()->createTable($this->createSourceStockLinkTable($setup)); + $setup->endSetup(); } @@ -332,4 +348,76 @@ private function createSourceCarrierLinkTable(SchemaSetupInterface $setup) AdapterInterface::FK_ACTION_CASCADE ); } + + private function createStockTable($setup) { + /** + * Create table 'inventory_stock' + */ + $sourceTable = $setup->getTable(InstallSchema::TABLE_NAME_STOCK); + + return $setup->getConnection()->newTable( + $sourceTable + )->setComment( + 'Inventory Stock Table' + )->addColumn( + StockInterface::STOCK_ID, + Table::TYPE_INTEGER, + null, + [ + InstallSchema::OPTION_IDENTITY => true, + InstallSchema::OPTION_UNSIGNED => true, + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_PRIMARY => true, + ], + 'Stock ID' + )->addColumn( + StockInterface::NAME, + Table::TYPE_TEXT, + 255, + [ + InstallSchema::OPTION_NULLABLE => false, + ], + 'Stock Name' + ); + } + + private function createSourceStockLinkTable($setup) { + /** + * Create table 'inventory_source_stock_link' + */ + $sourceTable = $setup->getTable(InstallSchema::TABLE_NAME_SOURCE_STOCK_LINK); + + return $setup->getConnection()->newTable( + $sourceTable + )->setComment( + 'Inventory Source Stock Link Table' + )->addColumn( + SourceStockLinkInterface::LINK_ID, + Table::TYPE_INTEGER, + null, + [ + InstallSchema::OPTION_IDENTITY => true, + InstallSchema::OPTION_UNSIGNED => true, + InstallSchema::OPTION_NULLABLE => false, + InstallSchema::OPTION_PRIMARY => true, + ], + 'Link ID' + )->addColumn( + SourceStockLinkInterface::STOCK_ID, + Table::TYPE_INTEGER, + null, + [ + InstallSchema::OPTION_NULLABLE => false, + ], + 'Stock Id' + )->addColumn( + SourceStockLinkInterface::SOURCE_ID, + Table::TYPE_INTEGER, + null, + [ + InstallSchema::OPTION_NULLABLE => false, + ], + 'Source Id' + ); + } } diff --git a/app/code/Magento/Inventory/Setup/UpgradeSchema.php b/app/code/Magento/Inventory/Setup/UpgradeSchema.php deleted file mode 100644 index 18c9672ebda3..000000000000 --- a/app/code/Magento/Inventory/Setup/UpgradeSchema.php +++ /dev/null @@ -1,125 +0,0 @@ -startSetup(); - - if (version_compare($context->getVersion(), '2.0.0', '>')) { - $stockTable = $this->createStockTable($setup); - $setup->getConnection()->createTable($stockTable); - $stockLinkTable = $this->createSourceStockLinkTable($setup); - $setup->getConnection()->createTable($stockLinkTable); - } - - $setup->endSetup(); - } - - private function createStockTable($setup) { - /** - * Create table 'inventory_stock' - */ - $sourceTable = $setup->getTable(UpgradeSchema::TABLE_NAME_STOCK); - - return $setup->getConnection()->newTable( - $sourceTable - )->setComment( - 'Inventory Stock Table' - )->addColumn( - StockInterface::STOCK_ID, - Table::TYPE_INTEGER, - null, - [ - UpgradeSchema::OPTION_IDENTITY => true, - UpgradeSchema::OPTION_UNSIGNED => true, - UpgradeSchema::OPTION_NULLABLE => false, - UpgradeSchema::OPTION_PRIMARY => true, - ], - 'Stock ID' - )->addColumn( - StockInterface::NAME, - Table::TYPE_TEXT, - 255, - [ - UpgradeSchema::OPTION_NULLABLE => false, - ], - 'Stock Name' - ); - } - - private function createSourceStockLinkTable($setup) { - /** - * Create table 'inventory_source_stock_link' - */ - $sourceTable = $setup->getTable(UpgradeSchema::TABLE_NAME_SOURCE_STOCK_LINK); - - return $setup->getConnection()->newTable( - $sourceTable - )->setComment( - 'Inventory Source Stock Link Table' - )->addColumn( - SourceStockLinkInterface::LINK_ID, - Table::TYPE_INTEGER, - null, - [ - UpgradeSchema::OPTION_IDENTITY => true, - UpgradeSchema::OPTION_UNSIGNED => true, - UpgradeSchema::OPTION_NULLABLE => false, - UpgradeSchema::OPTION_PRIMARY => true, - ], - 'Link ID' - )->addColumn( - SourceStockLinkInterface::STOCK_ID, - Table::TYPE_INTEGER, - null, - [ - UpgradeSchema::OPTION_NULLABLE => false, - ], - 'Stock Id' - )->addColumn( - SourceStockLinkInterface::SOURCE_ID, - Table::TYPE_INTEGER, - null, - [ - UpgradeSchema::OPTION_NULLABLE => false, - ], - 'Source Id' - ); - } -} diff --git a/app/code/Magento/Inventory/etc/module.xml b/app/code/Magento/Inventory/etc/module.xml index d66860d18442..2ef165277a57 100644 --- a/app/code/Magento/Inventory/etc/module.xml +++ b/app/code/Magento/Inventory/etc/module.xml @@ -6,7 +6,7 @@ */ --> - + From 9cb180272943a1820f00a9535cf3bd15460f037d Mon Sep 17 00:00:00 2001 From: Eugene Tulika Date: Mon, 26 Jun 2017 14:58:57 +0100 Subject: [PATCH 07/16] magento-engcom/magento#34: Source to Stock Mapping UI and API - created test for StockRepository --- app/code/Magento/Inventory/Model/Stock.php | 4 - .../Test/Unit/Model/StockRepositoryTest.php | 309 ++++++++++++++++++ app/code/Magento/Inventory/etc/di.xml | 3 + 3 files changed, 312 insertions(+), 4 deletions(-) create mode 100644 app/code/Magento/Inventory/Test/Unit/Model/StockRepositoryTest.php diff --git a/app/code/Magento/Inventory/Model/Stock.php b/app/code/Magento/Inventory/Model/Stock.php index 9724fa9eb604..62e171c6c4ed 100644 --- a/app/code/Magento/Inventory/Model/Stock.php +++ b/app/code/Magento/Inventory/Model/Stock.php @@ -15,10 +15,6 @@ */ class Stock extends AbstractExtensibleModel implements StockInterface { - const STOCK_ID = 'stock_id'; - const NAME = 'name'; - - /** * @inheritdoc */ diff --git a/app/code/Magento/Inventory/Test/Unit/Model/StockRepositoryTest.php b/app/code/Magento/Inventory/Test/Unit/Model/StockRepositoryTest.php new file mode 100644 index 000000000000..7f8fe39c7f6d --- /dev/null +++ b/app/code/Magento/Inventory/Test/Unit/Model/StockRepositoryTest.php @@ -0,0 +1,309 @@ +resourceStock = $this->getMockBuilder(SourceResource::class)->disableOriginalConstructor()->getMock(); + $this->searchCriteriaBuilder = $this->getMockBuilder(SearchCriteriaBuilder::class) + ->disableOriginalConstructor() + ->getMock(); + $this->stockFactory = $this->getMockBuilder(SourceInterfaceFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->collectionProcessor = $this->getMockBuilder(CollectionProcessorInterface::class) + ->disableOriginalConstructor() + ->setMethods(['process']) + ->getMock(); + $this->stockCollectionFactory = $this->getMockBuilder(SourceCollectionFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->stockSearchResultsFactory = $this->getMockBuilder(SourceSearchResultsInterfaceFactory::class) + ->disableOriginalConstructor() + ->setMethods(['create']) + ->getMock(); + $this->loggerMock = $this->getMockBuilder(\Psr\Log\LoggerInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->stock = $this->getMockBuilder(Stock::class) + ->disableOriginalConstructor() + ->getMock(); + + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->model = $objectManager->getObject( + \Magento\Inventory\Model\StockRepository::class, + [ + 'resourceSource' => $this->resourceStock, + 'sourceFactory' => $this->stockFactory, + 'collectionProcessor' => $this->collectionProcessor, + 'sourceCollectionFactory' => $this->stockCollectionFactory, + 'sourceSearchResultsFactory' => $this->stockSearchResultsFactory, + 'searchCriteriaBuilder' => $this->searchCriteriaBuilder, + 'logger' => $this->loggerMock, + ] + ); + } + + public function testSave() + { + $stockId = 42; + + $this->stock + ->expects($this->once()) + ->method('getSourceId') + ->willReturn($stockId); + $this->resourceStock + ->expects($this->once()) + ->method('save') + ->with($this->stock); + + self::assertEquals($stockId, $this->model->save($this->stock)); + } + + /** + * @expectedException \Magento\Framework\Exception\CouldNotSaveException + */ + public function testSaveErrorExpectsException() + { + $message = 'some message'; + + $this->resourceStock + ->expects($this->once()) + ->method('save') + ->willThrowException(new \Exception($message)); + + $this->loggerMock + ->expects($this->once()) + ->method('error') + ->with($message); + + $this->model->save($this->stock); + } + + public function testGet() + { + $stockId = 345; + + $this->stock + ->expects($this->once()) + ->method('getSourceId') + ->willReturn($stockId); + $this->stockFactory + ->expects($this->once()) + ->method('create') + ->willReturn($this->stock); + $this->resourceStock + ->expects($this->once()) + ->method('load') + ->with($this->stock, $stockId, StockInterface::STOCK_ID); + + self::assertSame($this->stock, $this->model->get($stockId)); + } + + /** + * @expectedException \Magento\Framework\Exception\NoSuchEntityException + */ + public function testGetErrorExpectsException() + { + $stockId = 345; + + $this->stock + ->expects($this->once()) + ->method('getSourceId') + ->willReturn(null); + $this->stockFactory + ->expects($this->once()) + ->method('create') + ->willReturn($this->stock); + $this->resourceStock->expects($this->once()) + ->method('load') + ->with( + $this->stock, + $stockId, + StockInterface::STOCK_ID + ); + + $this->model->get($stockId); + } + + public function testGetListWithSearchCriteria() + { + $items = [ + $this->getMockBuilder(Stock::class)->disableOriginalConstructor()->getMock(), + $this->getMockBuilder(Stock::class)->disableOriginalConstructor()->getMock() + ]; + $totalCount = 2; + $searchCriteria = $this->getMockBuilder(SearchCriteriaInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $stockCollection = $this->getMockBuilder(StockCollection::class) + ->disableOriginalConstructor() + ->getMock(); + $stockCollection + ->expects($this->once()) + ->method('getItems') + ->willReturn($items); + $stockCollection + ->expects($this->once()) + ->method('getSize') + ->willReturn($totalCount); + $this->stockCollectionFactory + ->expects($this->once()) + ->method('create') + ->willReturn($stockCollection); + + $searchResults = $this->getMockBuilder(StockSearchResultsInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $searchResults + ->expects($this->once()) + ->method('setItems') + ->with($items); + $searchResults + ->expects($this->once()) + ->method('setTotalCount') + ->with($totalCount); + $searchResults + ->expects($this->once()) + ->method('setSearchCriteria') + ->with($searchCriteria); + $this->sourceSearchResultsFactory + ->expects($this->once()) + ->method('create') + ->willReturn($searchResults); + + $this->collectionProcessor + ->expects($this->once()) + ->method('process') + ->with($searchCriteria, $stockCollection); + + self::assertSame($searchResults, $this->model->getList($searchCriteria)); + } + + public function testGetListWithoutSearchCriteria() + { + $items = [ + $this->getMockBuilder(Stock::class)->disableOriginalConstructor()->getMock(), + $this->getMockBuilder(Stock::class)->disableOriginalConstructor()->getMock() + ]; + $totalCount = 2; + + $searchCriteria = $this->getMockBuilder(SearchCriteriaInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $this->searchCriteriaBuilder + ->expects($this->once()) + ->method('create') + ->willReturn($searchCriteria); + + $stockCollection = $this->getMockBuilder(StockCollection::class) + ->disableOriginalConstructor() + ->getMock(); + $stockCollection + ->expects($this->once()) + ->method('getItems') + ->willReturn($items); + $stockCollection + ->expects($this->once()) + ->method('getSize') + ->willReturn($totalCount); + $this->stockCollectionFactory + ->expects($this->once()) + ->method('create') + ->willReturn($stockCollection); + + $searchResults = $this->getMockBuilder(StockSearchResultsInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $searchResults + ->expects($this->once()) + ->method('setItems') + ->with($items); + $searchResults + ->expects($this->once()) + ->method('setTotalCount') + ->with($totalCount); + $searchResults + ->expects($this->once()) + ->method('setSearchCriteria') + ->with($searchCriteria); + $this->stockSearchResultsFactory + ->expects($this->once()) + ->method('create') + ->willReturn($searchResults); + + $this->collectionProcessor + ->expects($this->never()) + ->method('process'); + + self::assertSame($searchResults, $this->model->getList()); + } +} diff --git a/app/code/Magento/Inventory/etc/di.xml b/app/code/Magento/Inventory/etc/di.xml index 3c6091ff5561..53323691a46d 100644 --- a/app/code/Magento/Inventory/etc/di.xml +++ b/app/code/Magento/Inventory/etc/di.xml @@ -11,4 +11,7 @@ + + + From e712957fee0d23cc935663b0db8ca2e5742b8653 Mon Sep 17 00:00:00 2001 From: jonfres Date: Mon, 26 Jun 2017 14:59:54 +0100 Subject: [PATCH 08/16] magento-engcom/magento#34: Source to Stock Mapping UI and API - controller Stock and menu option for Manage Stock added --- .../Controller/Adminhtml/Source/Stock.php | 34 +++++++++++++++++++ .../Magento/Inventory/etc/adminhtml/menu.xml | 8 +++++ 2 files changed, 42 insertions(+) create mode 100644 app/code/Magento/Inventory/Controller/Adminhtml/Source/Stock.php diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Stock.php b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Stock.php new file mode 100644 index 000000000000..4b56980bfff4 --- /dev/null +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Source/Stock.php @@ -0,0 +1,34 @@ +resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->setActiveMenu('Magento_Inventory::stock') + ->addBreadcrumb(__('Sources'), __('List')); + $resultPage->getConfig()->getTitle()->prepend(__('Manage Stock')); + return $resultPage; + } +} diff --git a/app/code/Magento/Inventory/etc/adminhtml/menu.xml b/app/code/Magento/Inventory/etc/adminhtml/menu.xml index bd4c7e9e1e3f..cd96628949b5 100644 --- a/app/code/Magento/Inventory/etc/adminhtml/menu.xml +++ b/app/code/Magento/Inventory/etc/adminhtml/menu.xml @@ -15,5 +15,13 @@ parent="Magento_Backend::stores_settings" action="inventory/source/index" resource="Magento_Inventory::source"/> + From b6595795233d5d181e78f76509db4e1b063d3538 Mon Sep 17 00:00:00 2001 From: astyczen Date: Mon, 26 Jun 2017 15:12:25 +0100 Subject: [PATCH 09/16] magento-engcom/magento#34 stock interface stock id constant change --- app/code/Magento/InventoryApi/Api/Data/StockInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/InventoryApi/Api/Data/StockInterface.php b/app/code/Magento/InventoryApi/Api/Data/StockInterface.php index b754c0daa183..3d7998b8ef6b 100644 --- a/app/code/Magento/InventoryApi/Api/Data/StockInterface.php +++ b/app/code/Magento/InventoryApi/Api/Data/StockInterface.php @@ -15,7 +15,7 @@ interface StockInterface extends ExtensibleDataInterface /** * Constants for keys of data array. Identical to the name of the getter in snake case */ - const STOCK_ID = 'source_id'; + const STOCK_ID = 'stock_id'; const NAME = 'name'; /**#@-*/ From 97884404f30a466751fcab7191a5ef3c81abe564 Mon Sep 17 00:00:00 2001 From: jonfres Date: Mon, 26 Jun 2017 15:33:59 +0100 Subject: [PATCH 10/16] magento-engcom/magento#34: Source to Stock Mapping UI and API - controller Stock and menu option for Manage Stock added2 --- .../Adminhtml/{Source/Stock.php => Stock/Index.php} | 4 ++-- app/code/Magento/Inventory/etc/adminhtml/menu.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename app/code/Magento/Inventory/Controller/Adminhtml/{Source/Stock.php => Stock/Index.php} (90%) diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Stock.php b/app/code/Magento/Inventory/Controller/Adminhtml/Stock/Index.php similarity index 90% rename from app/code/Magento/Inventory/Controller/Adminhtml/Source/Stock.php rename to app/code/Magento/Inventory/Controller/Adminhtml/Stock/Index.php index 4b56980bfff4..47d87240b9c5 100644 --- a/app/code/Magento/Inventory/Controller/Adminhtml/Source/Stock.php +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Stock/Index.php @@ -3,7 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\Inventory\Controller\Adminhtml\Source; +namespace Magento\Inventory\Controller\Adminhtml\Stock; use Magento\Backend\App\Action; use Magento\Backend\Model\View\Result\Page; @@ -12,7 +12,7 @@ /** * Class Index */ -class Stock extends Action +class Index extends Action { /** * @see _isAllowed() diff --git a/app/code/Magento/Inventory/etc/adminhtml/menu.xml b/app/code/Magento/Inventory/etc/adminhtml/menu.xml index cd96628949b5..02a39856399b 100644 --- a/app/code/Magento/Inventory/etc/adminhtml/menu.xml +++ b/app/code/Magento/Inventory/etc/adminhtml/menu.xml @@ -16,7 +16,7 @@ action="inventory/source/index" resource="Magento_Inventory::source"/> - + \ No newline at end of file From 2530ee2dd998a8bdf1cde0c4edfef96a35635f96 Mon Sep 17 00:00:00 2001 From: Eugene Tulika Date: Mon, 26 Jun 2017 16:07:57 +0100 Subject: [PATCH 11/16] magento-engcom/magento#34: Source to Stock Mapping UI and API - changed implementation of StockRepository --- .../Inventory/Model/StockRepository.php | 2 +- .../Ui/DataProvider/StockDataProvider.php | 57 +++---------------- 2 files changed, 10 insertions(+), 49 deletions(-) diff --git a/app/code/Magento/Inventory/Model/StockRepository.php b/app/code/Magento/Inventory/Model/StockRepository.php index ad2957ef8f85..960d4c742db8 100644 --- a/app/code/Magento/Inventory/Model/StockRepository.php +++ b/app/code/Magento/Inventory/Model/StockRepository.php @@ -125,7 +125,7 @@ public function getList(SearchCriteriaInterface $searchCriteria = null) $this->collectionProcessor->process($searchCriteria, $collection); } - $searchResult = $this->stockCollectionFactory->create(); + $searchResult = $this->stockSearchResultsFactory->create(); $searchResult->setItems($collection->getItems()); $searchResult->setTotalCount($collection->getSize()); $searchResult->setSearchCriteria($searchCriteria); diff --git a/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php b/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php index ff6fb225bb0f..9e6c5bf4fe81 100644 --- a/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php +++ b/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php @@ -5,14 +5,14 @@ */ namespace Magento\Inventory\Ui\DataProvider; -use Magento\InventoryApi\Api\Data\SourceInterface; +use Magento\InventoryApi\Api\Data\StockInterface; use Magento\Ui\DataProvider\SearchResultFactory; use Magento\Framework\Api\FilterBuilder; use Magento\Framework\Api\Search\ReportingInterface; use Magento\Framework\Api\Search\SearchCriteriaBuilder; use Magento\Framework\App\RequestInterface; use Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider; -use Magento\InventoryApi\Api\SourceRepositoryInterface; +use Magento\InventoryApi\Api\StockRepositoryInterface; /** * Class SourceDataProvider @@ -21,9 +21,9 @@ class StockDataProvider extends DataProvider { /** - * @var SourceRepositoryInterface + * @var StockRepositoryInterface */ - private $sourceRepository; + private $stockRepository; /** * @var SearchResultFactory @@ -38,7 +38,7 @@ class StockDataProvider extends DataProvider * @param SearchCriteriaBuilder $searchCriteriaBuilder * @param RequestInterface $request * @param FilterBuilder $filterBuilder - * @param SourceRepositoryInterface $sourceRepository + * @param StockRepositoryInterface $stockRepository * @param SearchResultFactory $searchResultFactory * @param array $meta * @param array $data @@ -52,7 +52,7 @@ public function __construct( SearchCriteriaBuilder $searchCriteriaBuilder, RequestInterface $request, FilterBuilder $filterBuilder, - StockRepositoryInterface $sourceRepository, + StockRepositoryInterface $stockRepository, SearchResultFactory $searchResultFactory, array $meta = [], array $data = [] @@ -68,63 +68,24 @@ public function __construct( $meta, $data ); - $this->sourceRepository = $sourceRepository; + $this->stockRepository = $stockRepository; $this->searchResultFactory = $searchResultFactory; } - /** - * {@inheritdoc} - */ - public function getData() - { - $data = parent::getData(); - if ('inventory_source_form_data_source' === $this->name) { - // It is need for support of several fieldsets. - // For details see \Magento\Ui\Component\Form::getDataSourceData - if ($data['totalRecords'] > 0) { - $sourceId = $data['items'][0][SourceInterface::SOURCE_ID]; - $sourceGeneralData = $data['items'][0]; - $sourceGeneralData['carrier_codes'] = $this->getAssignedCarrierCodes($sourceId); - $dataForSingle[$sourceId] = [ - 'general' => $sourceGeneralData, - ]; - $data = $dataForSingle; - } else { - $data = []; - } - } - return $data; - } - /** * {@inheritdoc} */ public function getSearchResult() { $searchCriteria = $this->getSearchCriteria(); - $result = $this->sourceRepository->getList($searchCriteria); + $result = $this->stockRepository->getList($searchCriteria); $searchResult = $this->searchResultFactory->create( $result->getItems(), $result->getTotalCount(), $searchCriteria, - SourceInterface::SOURCE_ID + StockInterface::STOCK_ID ); return $searchResult; } - - /** - * @param int $sourceId - * @return array - */ - private function getAssignedCarrierCodes($sourceId) - { - $source = $this->sourceRepository->get($sourceId); - - $carrierCodes = []; - foreach ($source->getCarrierLinks() as $carrierLink) { - $carrierCodes[] = $carrierLink->getCarrierCode(); - } - return $carrierCodes; - } } From 9fab8e25eed379b236a6e53514ab6c05feabc458 Mon Sep 17 00:00:00 2001 From: astyczen Date: Mon, 26 Jun 2017 16:11:36 +0100 Subject: [PATCH 12/16] magento-engcom/magento#34 admin add/edit Stock form and action added --- .../Controller/Adminhtml/Stock/Edit.php | 70 +++++++++++++++++++ .../Controller/Adminhtml/Stock/NewAction.php | 34 +++++++++ .../Inventory/Model/StockRepository.php | 2 +- .../Ui/DataProvider/StockDataProvider.php | 48 +++++-------- .../Magento/Inventory/etc/adminhtml/di.xml | 5 ++ .../adminhtml/layout/inventory_stock_edit.xml | 15 ++++ .../adminhtml/layout/inventory_stock_new.xml | 11 +++ 7 files changed, 152 insertions(+), 33 deletions(-) create mode 100644 app/code/Magento/Inventory/Controller/Adminhtml/Stock/Edit.php create mode 100644 app/code/Magento/Inventory/Controller/Adminhtml/Stock/NewAction.php create mode 100644 app/code/Magento/Inventory/view/adminhtml/layout/inventory_stock_edit.xml create mode 100644 app/code/Magento/Inventory/view/adminhtml/layout/inventory_stock_new.xml diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Stock/Edit.php b/app/code/Magento/Inventory/Controller/Adminhtml/Stock/Edit.php new file mode 100644 index 000000000000..039e9dfb21d0 --- /dev/null +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Stock/Edit.php @@ -0,0 +1,70 @@ +stockRepository = $stockRepository; + } + + /** + * {@inheritdoc} + */ + public function execute() + { + $stockId = $this->getRequest()->getParam(StockInterface::STOCK_ID); + try { + $stock = $this->stockRepository->get($stockId); + + /** @var Page $result */ + $result = $this->resultFactory->create(ResultFactory::TYPE_PAGE); + $result->setActiveMenu('Magento_Inventory::stock') + ->addBreadcrumb(__('Edit Stock'), __('Edit Stock')); + $result->getConfig() + ->getTitle() + ->prepend(__('Edit Stock: %1', $stock->getName())); + } catch (NoSuchEntityException $e) { + /** @var Redirect $result */ + $result = $this->resultRedirectFactory->create(); + $this->messageManager->addErrorMessage( + __('Stock with id "%1" does not exist.', $stockId) + ); + $result->setPath('*/*'); + } + return $result; + } +} diff --git a/app/code/Magento/Inventory/Controller/Adminhtml/Stock/NewAction.php b/app/code/Magento/Inventory/Controller/Adminhtml/Stock/NewAction.php new file mode 100644 index 000000000000..af9d8f10cf6a --- /dev/null +++ b/app/code/Magento/Inventory/Controller/Adminhtml/Stock/NewAction.php @@ -0,0 +1,34 @@ +resultFactory->create(ResultFactory::TYPE_PAGE); + $resultPage->setActiveMenu('Magento_Inventory::stock'); + $resultPage->getConfig()->getTitle()->prepend(__('New Stock')); + return $resultPage; + } +} diff --git a/app/code/Magento/Inventory/Model/StockRepository.php b/app/code/Magento/Inventory/Model/StockRepository.php index ad2957ef8f85..960d4c742db8 100644 --- a/app/code/Magento/Inventory/Model/StockRepository.php +++ b/app/code/Magento/Inventory/Model/StockRepository.php @@ -125,7 +125,7 @@ public function getList(SearchCriteriaInterface $searchCriteria = null) $this->collectionProcessor->process($searchCriteria, $collection); } - $searchResult = $this->stockCollectionFactory->create(); + $searchResult = $this->stockSearchResultsFactory->create(); $searchResult->setItems($collection->getItems()); $searchResult->setTotalCount($collection->getSize()); $searchResult->setSearchCriteria($searchCriteria); diff --git a/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php b/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php index ff6fb225bb0f..21569c5eb7ac 100644 --- a/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php +++ b/app/code/Magento/Inventory/Ui/DataProvider/StockDataProvider.php @@ -5,25 +5,25 @@ */ namespace Magento\Inventory\Ui\DataProvider; -use Magento\InventoryApi\Api\Data\SourceInterface; use Magento\Ui\DataProvider\SearchResultFactory; use Magento\Framework\Api\FilterBuilder; use Magento\Framework\Api\Search\ReportingInterface; use Magento\Framework\Api\Search\SearchCriteriaBuilder; use Magento\Framework\App\RequestInterface; use Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider; -use Magento\InventoryApi\Api\SourceRepositoryInterface; +use Magento\InventoryApi\Api\Data\StockInterface; +use Magento\InventoryApi\Api\StockRepositoryInterface; /** - * Class SourceDataProvider + * Class stockDataProvider * @api */ class StockDataProvider extends DataProvider { /** - * @var SourceRepositoryInterface + * @var StockRepositoryInterface */ - private $sourceRepository; + private $stockRepository; /** * @var SearchResultFactory @@ -38,7 +38,7 @@ class StockDataProvider extends DataProvider * @param SearchCriteriaBuilder $searchCriteriaBuilder * @param RequestInterface $request * @param FilterBuilder $filterBuilder - * @param SourceRepositoryInterface $sourceRepository + * @param StockRepositoryInterface $stockRepository * @param SearchResultFactory $searchResultFactory * @param array $meta * @param array $data @@ -52,7 +52,7 @@ public function __construct( SearchCriteriaBuilder $searchCriteriaBuilder, RequestInterface $request, FilterBuilder $filterBuilder, - StockRepositoryInterface $sourceRepository, + StockRepositoryInterface $stockRepository, SearchResultFactory $searchResultFactory, array $meta = [], array $data = [] @@ -68,7 +68,7 @@ public function __construct( $meta, $data ); - $this->sourceRepository = $sourceRepository; + $this->stockRepository = $stockRepository; $this->searchResultFactory = $searchResultFactory; } @@ -78,15 +78,14 @@ public function __construct( public function getData() { $data = parent::getData(); - if ('inventory_source_form_data_source' === $this->name) { + if ('inventory_stock_form_data_source' === $this->name) { // It is need for support of several fieldsets. - // For details see \Magento\Ui\Component\Form::getDataSourceData + // For details see \Magento\Ui\Component\Form::getDatastockData if ($data['totalRecords'] > 0) { - $sourceId = $data['items'][0][SourceInterface::SOURCE_ID]; - $sourceGeneralData = $data['items'][0]; - $sourceGeneralData['carrier_codes'] = $this->getAssignedCarrierCodes($sourceId); - $dataForSingle[$sourceId] = [ - 'general' => $sourceGeneralData, + $stockId = $data['items'][0][StockInterface::STOCK_ID]; + $stockGeneralData = $data['items'][0]; + $dataForSingle[$stockId] = [ + 'general' => $stockGeneralData, ]; $data = $dataForSingle; } else { @@ -102,29 +101,14 @@ public function getData() public function getSearchResult() { $searchCriteria = $this->getSearchCriteria(); - $result = $this->sourceRepository->getList($searchCriteria); + $result = $this->stockRepository->getList($searchCriteria); $searchResult = $this->searchResultFactory->create( $result->getItems(), $result->getTotalCount(), $searchCriteria, - SourceInterface::SOURCE_ID + StockInterface::STOCK_ID ); return $searchResult; } - - /** - * @param int $sourceId - * @return array - */ - private function getAssignedCarrierCodes($sourceId) - { - $source = $this->sourceRepository->get($sourceId); - - $carrierCodes = []; - foreach ($source->getCarrierLinks() as $carrierLink) { - $carrierCodes[] = $carrierLink->getCarrierCode(); - } - return $carrierCodes; - } } diff --git a/app/code/Magento/Inventory/etc/adminhtml/di.xml b/app/code/Magento/Inventory/etc/adminhtml/di.xml index f1989475949e..7b9d5eac2a8a 100644 --- a/app/code/Magento/Inventory/etc/adminhtml/di.xml +++ b/app/code/Magento/Inventory/etc/adminhtml/di.xml @@ -12,4 +12,9 @@ inventory_source_form.inventory_source_form + + + inventory_stock_form.inventory_stock_form + + diff --git a/app/code/Magento/Inventory/view/adminhtml/layout/inventory_stock_edit.xml b/app/code/Magento/Inventory/view/adminhtml/layout/inventory_stock_edit.xml new file mode 100644 index 000000000000..442b2d976bbc --- /dev/null +++ b/app/code/Magento/Inventory/view/adminhtml/layout/inventory_stock_edit.xml @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/app/code/Magento/Inventory/view/adminhtml/layout/inventory_stock_new.xml b/app/code/Magento/Inventory/view/adminhtml/layout/inventory_stock_new.xml new file mode 100644 index 000000000000..970c397db03c --- /dev/null +++ b/app/code/Magento/Inventory/view/adminhtml/layout/inventory_stock_new.xml @@ -0,0 +1,11 @@ + + + + + From 314a859b511c83a901313424066bb34cabb96ea2 Mon Sep 17 00:00:00 2001 From: astyczen Date: Mon, 26 Jun 2017 16:12:12 +0100 Subject: [PATCH 13/16] magento-engcom/magento#34 Stock for created --- .../ui_component/inventory_stock_form.xml | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_form.xml 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 new file mode 100644 index 000000000000..3f1843d1732e --- /dev/null +++ b/app/code/Magento/Inventory/view/adminhtml/ui_component/inventory_stock_form.xml @@ -0,0 +1,68 @@ + + +
+ + + inventory_stock_form.inventory_stock_form_data_source + + Stock Information + templates/form/collapsible + + + data + inventory_stock_form + + inventory_stock_form.inventory_stock_form_data_source + + + + +