Skip to content

Commit

Permalink
magento-engcom/magento2#25 made changes from codereview in pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Kreidenhuber committed May 21, 2017
1 parent c1fe56b commit d9aefac
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,4 @@ protected function _construct()
{
$this->_init(SourceModel::class, ResourceSource::class);
}

/**
* @inheritdoc
*/
public function getIdFieldName()
{
return SourceInterface::SOURCE_ID;
}
}
11 changes: 4 additions & 7 deletions app/code/Magento/Inventory/Model/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
use \Magento\InventoryApi\Api\Data\SourceInterface;

/**
* Class Source
* @package Magento\Inventory\Model
* Class Source,
* provides implementation of the SourceInterface which adds the possibilty
* for a Merchant to map existing physical sources to some particular sales channels
* this model holds the information like name and description of this physical sources
*/
class Source extends AbstractExtensibleModel implements SourceInterface
{
/**
* @inheritdoc
*/
protected $_collectionName = \Magento\Inventory\Model\Resource\Source\Collection::class;

/**
* @inheritdoc
*/
Expand Down
8 changes: 0 additions & 8 deletions app/code/Magento/Inventory/Model/SourceCarrierLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@

class SourceCarrierLink extends AbstractExtensibleModel implements SourceCarrierLinkInterface
{
/**
* Name of the resource collection model
*
* @codingStandardsIgnore
* @var string
*/
protected $_collectionName = \Magento\Inventory\Model\Resource\SourceCarrierLink\Collection::class;

/**
* Initialize resource model
*
Expand Down
41 changes: 28 additions & 13 deletions app/code/Magento/Inventory/Model/SourceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
use Magento\Inventory\Model\SourceSearchResultsFactory;
use Magento\Inventory\Model\Resource\Source as ResourceSource;
use Magento\Inventory\Model\Resource\Source\CollectionFactory;
use Magento\Inventory\Model\SourceFactory;
use Magento\Inventory\Model\SourceFactoryInterface;
use \Psr\Log\LoggerInterface;

/**
* Class SourceRepository
* @package Magento\Inventory\Model
*
* Provides implementation of CQRS for sourcemodel
*
*/
class SourceRepository implements SourceRepositoryInterface
{
Expand All @@ -31,7 +34,7 @@ class SourceRepository implements SourceRepositoryInterface
private $resource;

/**
* @var SourceFactory
* @var SourceFactoryInterface
*/
private $sourceFactory;

Expand All @@ -50,26 +53,34 @@ class SourceRepository implements SourceRepositoryInterface
*/
private $sourceSearchResultsFactory;

/**
* @var LoggerInterface
*/
private $logger;

/**
* SourceRepository constructor.
* @param ResourceSource $resource
* @param SourceFactory $sourceFactory
* @param SourceFactoryInterface $sourceFactory
* @param CollectionProcessorInterface $collectionProcessor
* @param CollectionFactory $collectionFactory
* @param SourceSearchResultsFactory $sourceSearchResultsFactory
* @param LoggerInterface $logger
*/
public function __construct(
ResourceSource $resource,
SourceFactory $sourceFactory,
SourceFactoryInterface $sourceFactory,
CollectionProcessorInterface $collectionProcessor,
CollectionFactory $collectionFactory,
SourceSearchResultsFactory $sourceSearchResultsFactory
SourceSearchResultsFactory $sourceSearchResultsFactory,
LoggerInterface $logger
) {
$this->resource = $resource;
$this->sourceFactory = $sourceFactory;
$this->collectionProcessor = $collectionProcessor;
$this->collectionFactory = $collectionFactory;
$this->sourceSearchResultsFactory = $sourceSearchResultsFactory;
$this->logger = $logger;
}

/**
Expand All @@ -80,9 +91,9 @@ public function save(SourceInterface $source)
try {
$this->resource->save($source);
} catch (\Exception $exception) {
throw new CouldNotSaveException(__($exception->getMessage()));
$this->logger->error($exception->getMessage());
throw new CouldNotSaveException(__('Could not save source'));
}
return $source;
}

/**
Expand All @@ -91,14 +102,14 @@ public function save(SourceInterface $source)
public function get($sourceId)
{
/** @var SourceInterface|AbstractModel $model */
$model = $this->sourceFactory->create();
$this->resource->load($model, SourceInterface::SOURCE_ID, $sourceId);
$source = $this->sourceFactory->create();
$this->resource->load($source, SourceInterface::SOURCE_ID, $sourceId);

if (!$model->getSourceId()) {
if (!$source->getSourceId()) {
throw NoSuchEntityException::singleField(SourceInterface::SOURCE_ID, $sourceId);
}

return $model;
return $source;
}

/**
Expand All @@ -108,7 +119,11 @@ public function getList(SearchCriteriaInterface $searchCriteria = null)
{
/** @var \Magento\Inventory\Model\Resource\Source\Collection $collection */
$collection = $this->collectionFactory->create();
$this->collectionProcessor->process($searchCriteria, $collection);

// if there is a searchCriteria defined, use it to add its creterias to the collection
if (!is_null($searchCriteria)) {
$this->collectionProcessor->process($searchCriteria, $collection);
}

/** @var SourceSearchResultsInterface $searchResults */
$searchResults = $this->sourceSearchResultsFactory->create();
Expand Down
4 changes: 0 additions & 4 deletions app/code/Magento/Inventory/Model/SourceSearchResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
use Magento\Framework\Api\SearchResults;
use Magento\InventoryApi\Api\Data\SourceSearchResultsInterface;

/**
* Class SourceSearchResults
* @package Magento\Inventory\Model
*/
class SourceSearchResults extends SearchResults implements SourceSearchResultsInterface
{

Expand Down
Loading

0 comments on commit d9aefac

Please sign in to comment.