-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from jonfres/source-item-management
source item management
- Loading branch information
Showing
10 changed files
with
668 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
app/code/Magento/Inventory/Model/ResourceModel/SourceItem.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Magento\Inventory\Model\ResourceModel; | ||
|
||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb; | ||
use Magento\Inventory\Setup\InstallSchema; | ||
use Magento\InventoryApi\Api\Data\SourceItemInterface; | ||
|
||
class SourceItem extends AbstractDb | ||
{ | ||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function _construct() | ||
{ | ||
$this->_init(InstallSchema::TABLE_NAME_SOURCE_ITEM, SourceItemInterface::SOURCE_ITEM_ID); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
app/code/Magento/Inventory/Model/ResourceModel/SourceItem/Collection.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Magento\Inventory\Model\ResourceModel\SourceItem; | ||
|
||
use Magento\Framework\Data\Collection\EntityFactoryInterface; | ||
use Magento\Framework\DB\Adapter\AdapterInterface; | ||
use Magento\Framework\Event\ManagerInterface; | ||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb; | ||
use Magento\Inventory\Model\ResourceModel\SourceItem as ResourceSource; | ||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; | ||
use Magento\Inventory\Model\SourceItem as SourceItemModel; | ||
use Magento\InventoryApi\Api\Data\SourceItemInterface; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class Collection extends AbstractCollection | ||
{ | ||
/** | ||
* Collection constructor | ||
* | ||
* @param EntityFactoryInterface $entityFactory | ||
* @param LoggerInterface $logger | ||
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy | ||
* @param ManagerInterface $eventManager | ||
* @param AdapterInterface $connection | ||
* @param AbstractDb $resource | ||
*/ | ||
public function __construct( | ||
EntityFactoryInterface $entityFactory, | ||
LoggerInterface $logger, | ||
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, | ||
ManagerInterface $eventManager, | ||
AdapterInterface $connection = null, | ||
AbstractDb $resource = null | ||
) { | ||
parent::__construct( | ||
$entityFactory, | ||
$logger, | ||
$fetchStrategy, | ||
$eventManager, | ||
$connection, | ||
$resource | ||
); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function _construct() | ||
{ | ||
$this->_init(SourceItemModel::class, ResourceSource::class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace Magento\Inventory\Model; | ||
|
||
use Magento\Framework\Model\AbstractExtensibleModel; | ||
use \Magento\InventoryApi\Api\Data\SourceItemInterface; | ||
|
||
class SourceItem extends AbstractExtensibleModel implements SourceItemInterface | ||
{ | ||
/** | ||
* @return int | ||
*/ | ||
public function getSku() | ||
{ | ||
return $this->getData(SourceItemInterface::SKU); | ||
} | ||
|
||
/** | ||
* @param $sku | ||
* @return int | ||
*/ | ||
public function setSku($sku) | ||
{ | ||
$this->setData(SourceItemInterface::SKU, $sku); | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getSourceId() | ||
{ | ||
return $this->getData(SourceItemInterface::SOURCE_ID); | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getSourceItemId() | ||
{ | ||
return $this->getData(SourceItemInterface::SOURCE_ITEM_ID); | ||
} | ||
|
||
/** | ||
* @return float | ||
*/ | ||
public function getQuantity() | ||
{ | ||
return $this->getData(SourceItemInterface::QUANTITY); | ||
} | ||
|
||
/** | ||
* @param $quantity | ||
* @return float | ||
*/ | ||
public function setQuantity($quantity) | ||
{ | ||
$this->setData(SourceItemInterface::QUANTITY, $quantity); | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getStatus() | ||
{ | ||
return $this->getData(SourceItemInterface::STATUS); | ||
} | ||
|
||
public function setStatus($status) | ||
{ | ||
$this->setData(SourceItemInterface::STATUS, $status); | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
app/code/Magento/Inventory/Model/SourceItemRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
|
||
namespace Magento\Inventory\Model; | ||
|
||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface; | ||
use Magento\Framework\Api\SearchCriteriaBuilder; | ||
use Magento\Framework\Api\SearchCriteriaInterface; | ||
use Magento\Framework\Exception\CouldNotSaveException; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Inventory\Model\ResourceModel\SourceItem as ResourceSource; | ||
use Magento\Inventory\Model\ResourceModel\SourceItem\CollectionFactory; | ||
use Magento\InventoryApi\Api\Data\SourceItemInterface; | ||
use Magento\InventoryApi\Api\Data\SourceItemInterfaceFactory; | ||
use Magento\InventoryApi\Api\Data\SourceItemSearchResultsInterfaceFactory; | ||
use Psr\Log\LoggerInterface; | ||
use Magento\InventoryApi\Api\SourceItemRepositoryInterface; | ||
|
||
class SourceItemRepository implements SourceItemRepositoryInterface | ||
{ | ||
/** | ||
* @var ResourceSource | ||
*/ | ||
private $resourceSource; | ||
|
||
/** | ||
* @var SourceItemInterfaceFactory | ||
*/ | ||
private $sourceItemFactory; | ||
|
||
/** | ||
* @var CollectionProcessorInterface | ||
*/ | ||
private $collectionProcessor; | ||
|
||
/** | ||
* @var CollectionFactory | ||
*/ | ||
private $sourceItemCollectionFactory; | ||
|
||
/** | ||
* @var SourceItemSearchResultsInterfaceFactory | ||
*/ | ||
private $sourceItemSearchResultsFactory; | ||
|
||
/** | ||
* @var SearchCriteriaBuilder | ||
*/ | ||
private $searchCriteriaBuilder; | ||
|
||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* SourceRepository constructor | ||
* | ||
* @param ResourceSource $resourceSource | ||
* @param SourceItemInterfaceFactory $sourceItemFactory | ||
* @param CollectionProcessorInterface $collectionProcessor | ||
* @param CollectionFactory $sourceItemCollectionFactory | ||
* @param SourceItemSearchResultsInterfaceFactory $sourceItemSearchResultsFactory | ||
* @param SearchCriteriaBuilder $searchCriteriaBuilder | ||
* @param LoggerInterface $logger | ||
*/ | ||
public function __construct( | ||
ResourceSource $resourceSource, | ||
SourceItemInterfaceFactory $sourceItemFactory, | ||
CollectionProcessorInterface $collectionProcessor, | ||
CollectionFactory $sourceItemCollectionFactory, | ||
SourceItemSearchResultsInterfaceFactory $sourceItemSearchResultsFactory, | ||
SearchCriteriaBuilder $searchCriteriaBuilder, | ||
LoggerInterface $logger | ||
) { | ||
$this->resourceSource = $resourceSource; | ||
$this->sourceItemFactory = $sourceItemFactory; | ||
$this->collectionProcessor = $collectionProcessor; | ||
$this->sourceItemCollectionFactory = $sourceItemCollectionFactory; | ||
$this->sourceItemSearchResultsFactory = $sourceItemSearchResultsFactory; | ||
$this->searchCriteriaBuilder = $searchCriteriaBuilder; | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* @param SourceItemInterface $sourceItem | ||
* @return int | ||
* @throws CouldNotSaveException | ||
*/ | ||
public function save(SourceItemInterface $sourceItem) | ||
{ | ||
try { | ||
$this->resourceSource->save($sourceItem); | ||
return $sourceItem->getSourceItemId(); | ||
} catch (\Exception $e) { | ||
$this->logger->error($e->getMessage()); | ||
throw new CouldNotSaveException(__('Could not save source item'), $e); | ||
} | ||
} | ||
|
||
public function get($sourceItemId) | ||
{ | ||
$sourceItem = $this->sourceItemFactory->create(); | ||
$this->resourceSource->load($sourceItem, $sourceItemId, SourceItemInterface::SOURCE_ITEM_ID); | ||
|
||
if (!$sourceItem->getSourceItemId()) { | ||
throw NoSuchEntityException::singleField(SourceItemInterface::SOURCE_ITEM_ID, $sourceItemId); | ||
} | ||
|
||
return $sourceItem; | ||
} | ||
|
||
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null) | ||
{ | ||
|
||
} | ||
|
||
public function delete($sourceItemId) | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.