forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
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 magento#202 from magento-engcom/install-data-code-…
…quality @SuppressWarnings removing
- Loading branch information
Showing
5 changed files
with
299 additions
and
142 deletions.
There are no files selected for viewing
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
61 changes: 61 additions & 0 deletions
61
app/code/Magento/InventoryCatalog/Setup/Operation/AssignSourceToStock.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,61 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryCatalog\Setup\Operation; | ||
|
||
use Magento\InventoryCatalog\Api\DefaultSourceProviderInterface; | ||
use Magento\InventoryCatalog\Api\DefaultStockProviderInterface; | ||
use Magento\InventoryApi\Api\AssignSourcesToStockInterface; | ||
|
||
/** | ||
* Assign default source to stock processor | ||
*/ | ||
class AssignSourceToStock | ||
{ | ||
/** | ||
* @var DefaultStockProviderInterface | ||
*/ | ||
private $defaultStockProvider; | ||
|
||
/** | ||
* @var DefaultSourceProviderInterface | ||
*/ | ||
private $defaultSourceProvider; | ||
|
||
/** | ||
* @var AssignSourcesToStockInterface | ||
*/ | ||
private $assignSourcesToStock; | ||
|
||
/** | ||
* @param DefaultStockProviderInterface $defaultStockProvider | ||
* @param DefaultSourceProviderInterface $defaultSourceProvider | ||
* @param AssignSourcesToStockInterface $assignSourcesToStock | ||
*/ | ||
public function __construct( | ||
DefaultStockProviderInterface $defaultStockProvider, | ||
DefaultSourceProviderInterface $defaultSourceProvider, | ||
AssignSourcesToStockInterface $assignSourcesToStock | ||
) { | ||
$this->defaultStockProvider = $defaultStockProvider; | ||
$this->defaultSourceProvider = $defaultSourceProvider; | ||
$this->assignSourcesToStock = $assignSourcesToStock; | ||
} | ||
|
||
/** | ||
* Assign default source to stock | ||
* | ||
* @return void | ||
*/ | ||
public function execute() | ||
{ | ||
$this->assignSourcesToStock->execute( | ||
[$this->defaultSourceProvider->getId()], | ||
$this->defaultStockProvider->getId() | ||
); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
app/code/Magento/InventoryCatalog/Setup/Operation/CreateDefaultSource.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,81 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryCatalog\Setup\Operation; | ||
|
||
use Magento\InventoryApi\Api\Data\SourceInterface; | ||
use Magento\InventoryCatalog\Model\DefaultSourceProvider; | ||
use Magento\InventoryApi\Api\Data\SourceInterfaceFactory; | ||
use Magento\Framework\Api\DataObjectHelper; | ||
use Magento\InventoryApi\Api\SourceRepositoryInterface; | ||
|
||
/** | ||
* Create default source during installation | ||
*/ | ||
class CreateDefaultSource | ||
{ | ||
/** | ||
* @var DefaultSourceProvider | ||
*/ | ||
private $defaultSourceProvider; | ||
|
||
/** | ||
* @var SourceInterfaceFactory | ||
*/ | ||
private $sourceFactory; | ||
|
||
/** | ||
* @var DataObjectHelper | ||
*/ | ||
private $dataObjectHelper; | ||
|
||
/** | ||
* @var SourceRepositoryInterface | ||
*/ | ||
private $sourceRepository; | ||
|
||
/** | ||
* @param DefaultSourceProvider $defaultSourceProvider | ||
* @param SourceInterfaceFactory $sourceFactory | ||
* @param DataObjectHelper $dataObjectHelper | ||
* @param SourceRepositoryInterface $sourceRepository | ||
*/ | ||
public function __construct( | ||
DefaultSourceProvider $defaultSourceProvider, | ||
SourceInterfaceFactory $sourceFactory, | ||
DataObjectHelper $dataObjectHelper, | ||
SourceRepositoryInterface $sourceRepository | ||
) { | ||
$this->defaultSourceProvider = $defaultSourceProvider; | ||
$this->sourceFactory = $sourceFactory; | ||
$this->dataObjectHelper = $dataObjectHelper; | ||
$this->sourceRepository = $sourceRepository; | ||
} | ||
|
||
/** | ||
* Create default source | ||
* | ||
* @return void | ||
*/ | ||
public function execute() | ||
{ | ||
$data = [ | ||
SourceInterface::SOURCE_ID => $this->defaultSourceProvider->getId(), | ||
SourceInterface::NAME => 'Default Source', | ||
SourceInterface::ENABLED => 1, | ||
SourceInterface::DESCRIPTION => 'Default Source', | ||
SourceInterface::LATITUDE => 0, | ||
SourceInterface::LONGITUDE => 0, | ||
SourceInterface::PRIORITY => 0, | ||
SourceInterface::COUNTRY_ID => 'US', | ||
SourceInterface::POSTCODE => '00000' | ||
]; | ||
$source = $this->sourceFactory->create(); | ||
$this->dataObjectHelper->populateWithArray($source, $data, SourceInterface::class); | ||
$this->sourceRepository->save($source); | ||
} | ||
} |
Oops, something went wrong.