72 lines
1.8 KiB
PHP
Executable File
72 lines
1.8 KiB
PHP
Executable File
<?php
|
|
|
|
namespace JR\NetSuite\Model\Config\Source;
|
|
|
|
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
|
|
use Magento\Eav\Model\Entity\Attribute\Source\SourceInterface;
|
|
use Magento\Framework\Data\OptionSourceInterface;
|
|
use Magento\InventoryApi\Api\SourceRepositoryInterface;
|
|
use Magento\Framework\Api\SearchCriteriaBuilder;
|
|
|
|
class InventorySource extends AbstractSource implements SourceInterface, OptionSourceInterface
|
|
{
|
|
protected $sourceRepository;
|
|
protected $searchCriteriaBuilder;
|
|
|
|
public function __construct(
|
|
SourceRepositoryInterface $sourceRepository,
|
|
SearchCriteriaBuilder $searchCriteriaBuilder
|
|
) {
|
|
$this->sourceRepository = $sourceRepository;
|
|
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
|
|
}
|
|
|
|
|
|
/**
|
|
* Retrieve option array
|
|
*
|
|
* @return string[]
|
|
*/
|
|
public function getOptionArray()
|
|
{
|
|
$searchCriteria = $this->searchCriteriaBuilder->create();
|
|
$sources = $this->sourceRepository->getList($searchCriteria)->getItems();
|
|
|
|
$options = [];
|
|
foreach ($sources as $source) {
|
|
$options[$source->getSourceCode()] = $source->getName();
|
|
}
|
|
return $options;
|
|
}
|
|
|
|
/**
|
|
* Get options
|
|
*
|
|
* @return array
|
|
*/
|
|
public function getAllOptions()
|
|
{
|
|
$searchCriteria = $this->searchCriteriaBuilder->create();
|
|
$sources = $this->sourceRepository->getList($searchCriteria)->getItems();
|
|
|
|
$options = [];
|
|
foreach ($sources as $source) {
|
|
$options[] = [
|
|
'value' => $source->getSourceCode(),
|
|
'label' => $source->getName()
|
|
];
|
|
}
|
|
|
|
return $options;
|
|
}
|
|
|
|
/**
|
|
* Retrieve option text by option value
|
|
*
|
|
* @return array
|
|
*/
|
|
public function toOptionArray()
|
|
{
|
|
return $this->getAllOptions();
|
|
}
|
|
} |