Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
f7ddb48
MSI: created additional table to store stock channel items
belinda-tschampel Oct 25, 2017
a259fa7
MSI: added foreign key to inventory sales stock channel table
belinda-tschampel Oct 25, 2017
ed01e65
WIP: implemented interfaces and attribute extension logic to link sal…
belinda-tschampel Oct 26, 2017
8952b43
WIP: improve namespace of factory class
hamplr Oct 27, 2017
fd196d5
WIP: improved code following reviewer requests
belinda-tschampel Oct 27, 2017
c5a3f3b
Merge branch 'msi-inventory-mapping' of github.com:magento-engcom/msi…
hamplr Oct 27, 2017
3ca6de9
WIP: added missing typecast to int for stock id
belinda-tschampel Oct 27, 2017
92e5937
WIP: followed review comments
belinda-tschampel Oct 27, 2017
9aa2d5e
WIP: improve code like review comments and add plugin for getList me…
hamplr Oct 27, 2017
03de324
Merge branch 'msi-inventory-mapping' of github.com:magento-engcom/msi…
hamplr Oct 27, 2017
932699a
WIP: another implementation of review comments
belinda-tschampel Oct 27, 2017
14cf3b4
remove obsolete collection and resource model
hamplr Oct 27, 2017
db4403a
Merge branch 'msi-inventory-mapping' of github.com:magento-engcom/msi…
belinda-tschampel Oct 27, 2017
b7d0b11
Merge branch 'msi-inventory-mapping' of github.com:magento-engcom/msi…
belinda-tschampel Oct 27, 2017
4c6f6f5
bugfix
hamplr Oct 27, 2017
57873d6
bugfix
hamplr Oct 27, 2017
1985acc
MSI: Introduce API interfaces for Assigning Stocks to Sales channels
Oct 28, 2017
ede56c5
MSI: Introduce API interfaces for Assigning Stocks to Sales channels
Oct 28, 2017
3e030af
removed old and unused id definition from interface
belinda-tschampel Oct 28, 2017
deb9889
MSI: Introduce API interfaces for Assigning Stocks to Sales channels
Oct 28, 2017
c1dfd97
Merge branch 'msi-inventory-mapping' of github.com:magento-engcom/msi…
belinda-tschampel Oct 28, 2017
afa2fa2
created replace functionality for sales channels
belinda-tschampel Oct 28, 2017
89ccf2e
MSI: Introduce API interfaces for Assigning Stocks to Sales channels.…
belinda-tschampel Oct 28, 2017
c91f2a6
MSI: Introduce API interfaces for Assigning Stocks to Sales channels.…
belinda-tschampel Oct 28, 2017
33df249
MSI: Introduce API interfaces for Assigning Stocks to Sales channels.…
belinda-tschampel Oct 28, 2017
08e9c97
MSI: Introduce API interfaces for Assigning Stocks to Sales channels.…
belinda-tschampel Oct 28, 2017
3c7e465
MSI: Introduce API interfaces for Assigning Stocks to Sales channels.…
belinda-tschampel Oct 28, 2017
68bbd24
MSI: Introduce API interfaces for Assigning Stocks to Sales channels.…
belinda-tschampel Oct 29, 2017
a1e6f1c
Merge branch 'develop' into msi-inventory-mapping
Oct 29, 2017
0cfb6a2
MSI: Introduce API interfaces for Assigning Stocks to Sales channels.…
belinda-tschampel Oct 29, 2017
64844dd
Merge branch 'msi-inventory-mapping' of github.com:magento-engcom/msi…
belinda-tschampel Oct 29, 2017
643a0c0
MSI: Introduce API interfaces for Assigning Stocks to Sales channels
Oct 29, 2017
9717141
Merge branch 'msi-inventory-mapping' of github.com:magento-engcom/msi…
belinda-tschampel Oct 29, 2017
2387b38
MSI: Introduce API interfaces for Assigning Stocks to Sales channels.…
belinda-tschampel Oct 29, 2017
eca0775
MSI: Introduce API interfaces for Assigning Stocks to Sales channels
Oct 31, 2017
dd34411
MSI: Introduce API interfaces for Assigning Stocks to Sales channels
Oct 31, 2017
e7d7f56
MSI: Introduce API interfaces for Assigning Stocks to Sales channels
Oct 31, 2017
94fc80a
MSI: Introduce API interfaces for Assigning Stocks to Sales channels
Oct 31, 2017
2b2d1aa
MSI: Introduce API interfaces for Assigning Stocks to Sales channels
Oct 31, 2017
5ab2060
MSI: Introduce API interfaces for Assigning Stocks to Sales channels
Oct 31, 2017
d414201
MSI: Introduce API interfaces for Assigning Stocks to Sales channels
Oct 31, 2017
58ad448
MSI: Introduce API interfaces for Assigning Stocks to Sales channels
Nov 1, 2017
c17ecbb
MSI: Introduce API interfaces for Assigning Stocks to Sales channels
Nov 1, 2017
2ec3519
MSI: Introduce API interfaces for Assigning Stocks to Sales channels
Nov 1, 2017
77d66a0
MSI: Assign Website at the time of Creation to the Default Stock
Nov 2, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions app/code/Magento/InventoryApi/Api/Data/StockExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventoryApi\Api\Data;

/**
* TODO: temporal fix of extension classes generation during installation
* Extension class for @see \Magento\InventoryApi\Api\Data\StockInterface
*/
class StockExtension extends \Magento\Framework\Api\AbstractSimpleObject implements StockExtensionInterface
{
/**
* @return \Magento\InventorySalesApi\Api\Data\SalesChannelInterface[]|null
*/
public function getSalesChannels()
{
return $this->_get('sales_channels');
}

/**
* @param \Magento\InventorySalesApi\Api\Data\SalesChannelInterface[] $salesChannels
* @return $this
*/
public function setSalesChannels($salesChannels)
{
$this->setData('sales_channels', $salesChannels);
return $this;
}
}
26 changes: 26 additions & 0 deletions app/code/Magento/InventoryApi/Api/Data/StockExtensionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventoryApi\Api\Data;

/**
* TODO: temporal fix of extension classes generation during installation
* ExtensionInterface class for @see \Magento\InventoryApi\Api\Data\StockInterface
*/
interface StockExtensionInterface extends \Magento\Framework\Api\ExtensionAttributesInterface
{
/**
* @return \Magento\InventorySalesApi\Api\Data\SalesChannelInterface[]|null
*/
public function getSalesChannels();

/**
* @param \Magento\InventorySalesApi\Api\Data\SalesChannelInterface[] $salesChannels
* @return $this
*/
public function setSalesChannels($salesChannels);
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function tearDown()
{
/** @var ResourceConnection $connection */
$connection = Bootstrap::getObjectManager()->get(ResourceConnection::class);
$connection->getConnection()->delete('inventory_source', [
$connection->getConnection()->delete($connection->getTableName('inventory_source'), [
SourceInterface::NAME . ' IN (?)' => ['source-name-1'],
]);
parent::tearDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function tearDown()
{
/** @var ResourceConnection $connection */
$connection = Bootstrap::getObjectManager()->get(ResourceConnection::class);
$connection->getConnection()->delete('inventory_source', [
$connection->getConnection()->delete($connection->getTableName('inventory_source'), [
SourceInterface::NAME . ' IN (?)' => ['source-name-1'],
]);
parent::tearDown();
Expand Down
6 changes: 5 additions & 1 deletion app/code/Magento/InventoryCatalog/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_InventoryCatalog" setup_version="1.0.0" />
<module name="Magento_InventoryCatalog" setup_version="2.0.0">
<sequence>
<module name="InventorySales"/>
</sequence>
</module>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventorySales\Model;

use Magento\InventorySales\Model\ResourceModel\GetAssignedSalesChannelsDataForStock;
use Magento\InventorySalesApi\Api\Data\SalesChannelInterfaceFactory;
use Magento\InventorySalesApi\Api\Data\SalesChannelInterface;

/**
* @inheritdoc
*/
class GetAssignedSalesChannelsForStock implements GetAssignedSalesChannelsForStockInterface
{
/**
* @var GetAssignedSalesChannelsDataForStock
*/
private $getAssignedSalesChannelsDataForStock;

/**
* @var SalesChannelInterfaceFactory
*/
private $salesChannelFactory;

/**
* @param GetAssignedSalesChannelsDataForStock $getAssignedSalesChannelsDataForStock
* @param SalesChannelInterfaceFactory $salesChannelFactory
*/
public function __construct(
GetAssignedSalesChannelsDataForStock $getAssignedSalesChannelsDataForStock,
SalesChannelInterfaceFactory $salesChannelFactory
) {
$this->getAssignedSalesChannelsDataForStock = $getAssignedSalesChannelsDataForStock;
$this->salesChannelFactory = $salesChannelFactory;
}

/**
* @inheritdoc
*/
public function execute(int $stockId) : array
{
$salesChannelsData = $this->getAssignedSalesChannelsDataForStock->execute($stockId);

$salesChannels = [];
foreach ($salesChannelsData as $salesChannelData) {
/** @var SalesChannelInterface $salesChannel */
$salesChannel = $this->salesChannelFactory->create();
$salesChannel->setType($salesChannelData[SalesChannelInterface::TYPE]);
$salesChannel->setCode($salesChannelData[SalesChannelInterface::CODE]);
$salesChannels[] = $salesChannel;
}
return $salesChannels;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventorySales\Model;

use Magento\InventorySalesApi\Api\Data\SalesChannelInterface;

/**
* Get assigned Sales Channels for Stock (Service Provider Interface - SPI)
* Provide own implementation of this interface if you would like to replace channels management strategy
*
* @api
*/
interface GetAssignedSalesChannelsForStockInterface
{
/**
* Get linked sales channels for Stock
*
* @param int $stockId
* @return SalesChannelInterface[]
*/
public function execute(int $stockId): array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function toOptionArray(): array
}
$websites[] = [
'value' => $website->getCode(),
'label' => $website->getName()
'label' => $website->getName(),
];
}
return $websites;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventorySales\Model;

/**
* Implementation of links replacement between Stock and Sales Channels (Service Provider Interface - SPI)
* Provide own implementation of this interface if you would like to replace channels management strategy
*
* @api
*/
interface ReplaceSalesChannelsForStockInterface
{
/**
* Replace Sales Channels for Stock
*
* @param array $salesChannels
* @param int $stockId
* @return void
*/
public function execute(array $salesChannels, int $stockId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventorySales\Model\ResourceModel;

use Magento\Framework\App\ResourceConnection;
use Magento\InventorySales\Setup\Operation\CreateSalesChannelTable;

/**
* Provides linked sales channels by given stock id
*/
class GetAssignedSalesChannelsDataForStock
{
/**
* @var ResourceConnection
*/
private $resourceConnection;

/**
* @param ResourceConnection $resourceConnection
*/
public function __construct(
ResourceConnection $resourceConnection
) {
$this->resourceConnection = $resourceConnection;
}

/**
* Given a stock id, return array of sales channels assigned to it
*
* @param int $stockId
* @return array
*/
public function execute(int $stockId): array
{
$connection = $this->resourceConnection->getConnection();
$tableName = $this->resourceConnection->getTableName(CreateSalesChannelTable::TABLE_NAME_SALES_CHANNEL);

$select = $connection->select()
->from($tableName)
->where(CreateSalesChannelTable::STOCK_ID . ' = ?', $stockId);

return $connection->fetchAll($select);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventorySales\Model\ResourceModel;

use Magento\Framework\App\ResourceConnection;
use Magento\InventorySales\Model\ReplaceSalesChannelsForStockInterface;
use Magento\InventorySales\Setup\Operation\CreateSalesChannelTable;
use Magento\InventorySalesApi\Api\Data\SalesChannelInterface;

/**
* Implementation of links replacement between Stock and Sales Channels for specific db layer
*
* There is no additional business logic on SPI (Service Provider Interface) level so could use resource model as
* SPI implementation directly
*/
class ReplaceSalesChannelsDataForStock implements ReplaceSalesChannelsForStockInterface
{
/**
* @var ResourceConnection
*/
private $resourceConnection;

/**
* @param ResourceConnection $resourceConnection
*/
public function __construct(
ResourceConnection $resourceConnection
) {
$this->resourceConnection = $resourceConnection;
}

/**
* Replace Sales Channels for Stock
*
* @param SalesChannelInterface[] $salesChannels
* @param int $stockId
* @return void
*/
public function execute(array $salesChannels, int $stockId)
{
$connection = $this->resourceConnection->getConnection();
$tableName = $this->resourceConnection->getTableName(CreateSalesChannelTable::TABLE_NAME_SALES_CHANNEL);

$connection->delete($tableName, [CreateSalesChannelTable::STOCK_ID . ' = ?' => $stockId]);

if (count($salesChannels)) {
$salesChannelsToInsert = [];
foreach ($salesChannels as $salesChannel) {
$salesChannelsToInsert[] = [
SalesChannelInterface::TYPE => $salesChannel->getType(),
SalesChannelInterface::CODE => $salesChannel->getCode(),
CreateSalesChannelTable::STOCK_ID => $stockId,
];
}
$connection->insertMultiple($tableName, $salesChannelsToInsert);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\InventorySales\Model\ResourceModel;

use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\InventorySales\Setup\Operation\CreateSalesChannelTable;
use Magento\InventorySalesApi\Api\Data\SalesChannelInterface;

/**
* This resource model is responsible for retrieving Stock items by sales channel type and code
* Used by Service Contracts that are agnostic to the Data Access Layer
*/
class StockIdResolver
{
/**
* @var ResourceConnection
*/
private $resourceConnection;

/**
* @param ResourceConnection $resourceConnection
*/
public function __construct(
ResourceConnection $resourceConnection
) {
$this->resourceConnection = $resourceConnection;
}

/**
* Returns the linked stock id by given a sales channel type and code
*
* @param string $type
* @param string $code
* @throws NoSuchEntityException
* @return int|null
*/
public function resolve(string $type, string $code)
{
$connection = $this->resourceConnection->getConnection();
$tableName = $this->resourceConnection->getTableName(CreateSalesChannelTable::TABLE_NAME_SALES_CHANNEL);

$select = $connection->select()
->from($tableName, CreateSalesChannelTable::STOCK_ID)
->where(SalesChannelInterface::TYPE . ' = ?', $type)
->where(SalesChannelInterface::CODE . ' = ?', $code);

$stockId = $connection->fetchOne($select);
return false === $stockId ? null : (int)$stockId;
}
}
Loading