init
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Model\Api;
|
||||
|
||||
use Magento\Catalog\Model\Product\Attribute\Source\Status;
|
||||
use Magento\Catalog\Model\Product\Type as ProductType;
|
||||
use Magento\Framework\Module\Dir;
|
||||
use Magento\Framework\UrlInterface;
|
||||
use Magento\Framework\Webapi\Rest\Request;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use Stemcell\Catalog\Helper\Excel;
|
||||
use Magento\Eav\Model\Config as EavConfig;
|
||||
use Stemcell\Catalog\Setup\Patch\Data\AddChineseEditionCellSeparationOption;
|
||||
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
|
||||
|
||||
/**
|
||||
* 分选说明书接口
|
||||
*/
|
||||
class CellSeparation
|
||||
{
|
||||
public function __construct(
|
||||
private Dir $dir,
|
||||
private StoreManagerInterface $storeManager,
|
||||
private Request $restRequest,
|
||||
protected EavConfig $eavConfig,
|
||||
protected ProductCollectionFactory $productCollectionFactory,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Worksheet $sheet
|
||||
* @param string $cell
|
||||
* @return string
|
||||
*/
|
||||
protected function getCellValue(Worksheet $sheet, string $cell)
|
||||
{
|
||||
return trim((string)$sheet->getCell($cell)->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
protected function getResourceTypeChinesePisOptionId()
|
||||
{
|
||||
$attribute = $this->eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'resource_type');
|
||||
$attribute->setStoreId(0);
|
||||
$optionId = 0;
|
||||
foreach ($attribute->getOptions() as $option) {
|
||||
if ($option->getLabel() == AddChineseEditionCellSeparationOption::RESOURCE_TYPE_ENGLISH_LABEL) {
|
||||
$optionId = (int)$option->getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $optionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分选说明书接口
|
||||
* @return string
|
||||
* @throws \Magento\Framework\Exception\NoSuchEntityException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$pageSize = 10;
|
||||
$page = $this->restRequest->getParam('page', 1);
|
||||
$start = ($page - 1) * $pageSize;
|
||||
|
||||
$keyword = trim($this->restRequest->getParam('keyword', ''));
|
||||
|
||||
$isSku = preg_match('/^\d+[A-Za-z]*$/', $keyword) !==0 ;
|
||||
//['sku' => $sku, 'label' => $name, 'pdf'=>$mediaUrl.$pdfPath, 'url'=>$mediaUrl.$sku.'/'.$pdfPath]
|
||||
$data = [];
|
||||
$mediaUrl = $this->storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_WEB);
|
||||
$chinesePisCollection = $this->productCollectionFactory->create()
|
||||
->addAttributeToSelect(['parent_skus', 'document_path', 'parent_names'])
|
||||
->addAttributeToFilter('status', Status::STATUS_ENABLED)
|
||||
->addAttributeToFilter('type_id', ProductType::TYPE_VIRTUAL)
|
||||
->addAttributeToFilter('resource_type', $this->getResourceTypeChinesePisOptionId());
|
||||
|
||||
if ($keyword) {
|
||||
$chinesePisCollection->addAttributeToFilter([
|
||||
['attribute' => 'parent_skus', 'finset' => $keyword],
|
||||
['attribute' => 'parent_names', 'like' => '%'.$keyword.'%'],
|
||||
]);
|
||||
}
|
||||
|
||||
$parentSkus = '';
|
||||
foreach ($chinesePisCollection as $item) {
|
||||
|
||||
$parentSkus .= $item->getData('parent_skus').',';
|
||||
}
|
||||
$parentSkus = trim($parentSkus, ',');
|
||||
|
||||
$productNames = [];
|
||||
$collection = $this->productCollectionFactory->create()
|
||||
->addAttributeToSelect(['name'])
|
||||
->addAttributeToFilter('status', Status::STATUS_ENABLED)
|
||||
->addAttributeToFilter('sku', ['in' => array_unique(explode(',', $parentSkus))]);
|
||||
foreach ($collection as $item) {
|
||||
$productNames[$item->getSku()] = $item->getName();
|
||||
}
|
||||
|
||||
foreach ($chinesePisCollection as $item) {
|
||||
|
||||
$pdfPath = $mediaUrl.ltrim($item->getData('document_path'), '/');
|
||||
if ($item->getData('parent_skus')) {
|
||||
foreach (explode(',', $item->getData('parent_skus')) as $sku) {
|
||||
if (($isSku && $keyword && $sku && strtolower($keyword)==strtolower($sku))
|
||||
|| (!$isSku && $item->getData('parent_names') && str_contains(strtolower($item->getData('parent_names')), strtolower($keyword)))) {
|
||||
if (isset($productNames[$sku])){
|
||||
$data[$item->getSku()] = [
|
||||
'sku' => $sku,
|
||||
'label' => $productNames[$sku],
|
||||
'pdf'=>ltrim($pdfPath, '/'),
|
||||
'url'=>ltrim($pdfPath, '/')
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data = array_values($data);
|
||||
$count = count($data);
|
||||
// $pages = ceil($count / $pageSize);
|
||||
// $page = min($page, $pages);
|
||||
// $end = $page * $pageSize - 1;
|
||||
// $rows = [];
|
||||
// foreach ($data as $index => $row) {
|
||||
// if ($index >= $start && $index <= $end) {
|
||||
// $rows[] = $row;
|
||||
// }
|
||||
// if ($index > $end) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
$result = [
|
||||
'items' => $data,
|
||||
'filter_code' => 'keyword',
|
||||
'filters' => [],
|
||||
'pages' => $page,
|
||||
'total_count' => $count,
|
||||
];
|
||||
return json_encode($result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Model\Api;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Framework\Api\FilterBuilder;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\Webapi\Rest\Request as RestRequest;
|
||||
use Stemcell\Catalog\Api\Data\CellSortSearchResultsInterface;
|
||||
use Stemcell\Catalog\Model\ResourceModel\CellSort\Collection as CellSortCollection;
|
||||
use Stemcell\Catalog\Model\ResourceModel\CellSort\CollectionFactory as CellSortCollectionFactory;
|
||||
use Stemcell\Catalog\Model\ResourceModel\Species\Collection as SpeciesCollection;
|
||||
use Stemcell\Catalog\Model\ResourceModel\CellType\Collection as CellTypeCollection;
|
||||
use Stemcell\Catalog\Model\ResourceModel\CellSubType\Collection as CellSubTypeCollection;
|
||||
use Stemcell\Catalog\Model\ResourceModel\Tissue\Collection as TissueCollection;
|
||||
|
||||
/**
|
||||
* 此接口依赖cell:sort:import命令和app/code/Stemcell/Catalog/data/cell-select-tool.xlsx。
|
||||
* 如果ell-select-tool.xlsx中的数据有改动,就需要重新跑cell:sort:import命令
|
||||
*/
|
||||
class CellSortTool
|
||||
{
|
||||
protected array $labels = [
|
||||
'species' => '物种',
|
||||
'cellTypes' => '细胞',
|
||||
'cellSubTypes' => '细胞亚型',
|
||||
'tissues' => '样本',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
private CellSortCollection $cellSortCollection,
|
||||
private CellSortCollectionFactory $cellSortCollectionFactory,
|
||||
private RestRequest $restRequest,
|
||||
private ProductRepositoryInterface $productRepository,
|
||||
private CellSortSearchResultsInterface $cellSortSearchResults,
|
||||
private SearchCriteriaBuilder $searchCriteriaBuilder,
|
||||
private SpeciesCollection $speciesCollection,
|
||||
private CellTypeCollection $cellTypeCollection,
|
||||
private CellSubTypeCollection $cellSubTypeCollection,
|
||||
private TissueCollection $tissueCollection,
|
||||
) {
|
||||
}
|
||||
|
||||
protected function addFilter()
|
||||
{
|
||||
$species = intval($this->restRequest->getParam('species'));
|
||||
$cellTypeId = intval($this->restRequest->getParam('cellTypes'));
|
||||
$cellSubTypeId = intval($this->restRequest->getParam('cellSubTypes'));
|
||||
$tissueId = intval($this->restRequest->getParam('tissues'));
|
||||
|
||||
if ($species) {
|
||||
$this->cellSortCollection->addFieldToFilter('species_id', $species);
|
||||
}
|
||||
if ($cellTypeId) {
|
||||
$this->cellSortCollection->addFieldToFilter('cell_type_id', $cellTypeId);
|
||||
}
|
||||
if ($cellSubTypeId) {
|
||||
$this->cellSortCollection->addFieldToFilter('cell_subtype_id', $cellSubTypeId);
|
||||
}
|
||||
if ($tissueId) {
|
||||
$this->cellSortCollection->addFieldToFilter('tissue_id', $tissueId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected function getSpecies()
|
||||
{
|
||||
$species = [];
|
||||
$items = $this->speciesCollection->setOrder('species_sort', 'asc')->load()->getItems();
|
||||
foreach ($items as $specie) {
|
||||
|
||||
/* @var $specie \Stemcell\Catalog\Model\Species */
|
||||
$species[$specie->getSpeciesId()] = $specie->toArray();
|
||||
}
|
||||
return $species;
|
||||
}
|
||||
|
||||
protected function getCellTypes()
|
||||
{
|
||||
$speciesId = intval($this->restRequest->getParam('species'));
|
||||
$data = [];
|
||||
if ($speciesId) {
|
||||
$cellTypes = $this->cellSortCollectionFactory->create()->addFieldToFilter('species_id', $speciesId)->setOrder('cell_type_sort', 'asc');
|
||||
foreach ($cellTypes as $cellType) {
|
||||
/* @var $cellType \Stemcell\Catalog\Model\CellSort */
|
||||
if (!isset($data[$cellType->getCellTypeId()])) {
|
||||
$data[$cellType->getCellTypeId()] = ['cell_type_id' => $cellType->getCellTypeId(), 'cell_type_name' => $cellType->getCellTypeName(), 'cell_type_sort'=>$cellType->getData('cell_type_sort')];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$data = $this->cellTypeCollection->setOrder('cell_type_sort', 'asc')->load()->getData();
|
||||
}
|
||||
return array_values($data);
|
||||
}
|
||||
|
||||
protected function getCellSubTypes()
|
||||
{
|
||||
$cellTypesId = intval($this->restRequest->getParam('cellTypes'));
|
||||
$speciesId = intval($this->restRequest->getParam('species'));
|
||||
$data = [];
|
||||
if ($cellTypesId) {
|
||||
$cellTypes = $this->cellSortCollectionFactory->create()
|
||||
->addFieldToFilter('species_id', $speciesId)
|
||||
->addFieldToFilter('cell_type_id', $cellTypesId)
|
||||
->setOrder('cell_subtype_sort', 'asc');
|
||||
foreach ($cellTypes as $cellType) {
|
||||
/* @var $cellType \Stemcell\Catalog\Model\CellSort */
|
||||
if (!isset($data[$cellType->getCellSubTypeId()])) {
|
||||
$data[$cellType->getCellSubTypeId()] = ['cell_subtype_id' => $cellType->getCellSubTypeId(), 'cell_subtype_name' => $cellType->getCellSubTypeName()];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$data = $this->cellSubTypeCollection->setOrder('cell_subtype_sort', 'asc')->load()->getData();
|
||||
}
|
||||
return array_values($data);
|
||||
}
|
||||
|
||||
protected function getTissues()
|
||||
{
|
||||
$cellTypesId = intval($this->restRequest->getParam('cellTypes'));
|
||||
$speciesId = intval($this->restRequest->getParam('species'));
|
||||
$cellSubTypeId = intval($this->restRequest->getParam('cellSubTypes'));
|
||||
$data = [];
|
||||
|
||||
if ($cellSubTypeId) {
|
||||
$cellTypes = $this->cellSortCollectionFactory->create()
|
||||
->addFieldToFilter('species_id', $speciesId)
|
||||
->addFieldToFilter('cell_type_id', $cellTypesId)
|
||||
->addFieldToFilter('cell_subtype_id', $cellSubTypeId);
|
||||
foreach ($cellTypes as $cellType) {
|
||||
/* @var $cellType \Stemcell\Catalog\Model\CellSort */
|
||||
if (!isset($data[$cellType->getTissueId()])) {
|
||||
$data[$cellType->getTissueId()] = ['tissue_id' => $cellType->getTissueId(), 'tissue_name' => $cellType->getTissueName()];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$data = $this->tissueCollection->load()->getData();
|
||||
}
|
||||
|
||||
return array_values($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
private function getFilters()
|
||||
{
|
||||
$species = $this->getSpecies();
|
||||
|
||||
return ['species' => array_values($species), 'cellTypes' => $this->getCellTypes(), 'cellSubTypes' => $this->getCellSubTypes(), 'tissues' => $this->getTissues()];
|
||||
}
|
||||
/**
|
||||
* @return \Stemcell\Catalog\Api\Data\CellSortSearchResultsInterface
|
||||
*/
|
||||
public function getProducts() {
|
||||
|
||||
$this->addFilter();
|
||||
$skus = $flags = [];
|
||||
foreach ($this->cellSortCollection as $cellSort) {
|
||||
/* @var $cellSort \Stemcell\Catalog\Model\CellSort */
|
||||
|
||||
if (!isset($skus[$cellSort->getSku()])) {
|
||||
$skus[$cellSort->getSku()] = $cellSort->getSku();
|
||||
}
|
||||
if (!isset($flags[$cellSort->getSku()])) {
|
||||
$flags[$cellSort->getSku()] = $cellSort->getFlag();
|
||||
}
|
||||
}
|
||||
|
||||
$pageSize = 10;
|
||||
$page = intval($this->restRequest->getParam('page'));
|
||||
$criteria = $this->searchCriteriaBuilder
|
||||
->addFilter('sku', $skus, 'in')
|
||||
->addFilter('visibility', [2,3,4], 'in')
|
||||
->setPageSize($pageSize)
|
||||
->setCurrentPage($page)
|
||||
->create();
|
||||
$products = $this->productRepository->getList($criteria);
|
||||
foreach ($products->getItems() as $product) {
|
||||
$sku = $product->getSku();
|
||||
$product->getExtensionAttributes()?->setCellFlag(isset($flags[$sku]) && $flags[$sku]==1? true:false);
|
||||
}
|
||||
return $this->cellSortSearchResults->setFilters(json_encode($this->getFilters()))
|
||||
->setLabels(json_encode($this->labels))
|
||||
->setItems($products->getItems())
|
||||
->setTotalCount($products->getTotalCount());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Model\Api\Data;
|
||||
|
||||
use Magento\Framework\Api\SearchResults;
|
||||
use Stemcell\Catalog\Api\Data\CellSortSearchResultsInterface;
|
||||
|
||||
class CellSortSearchResults extends SearchResults implements CellSortSearchResultsInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return $this->_get(self::FILTERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setFilters(string $filters)
|
||||
{
|
||||
return $this->setData(self::FILTERS, $filters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getLabels()
|
||||
{
|
||||
return $this->_get(self::LABELS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setLabels(string $labels)
|
||||
{
|
||||
return $this->setData(self::LABELS, $labels);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Model\Api\Data;
|
||||
|
||||
use Stemcell\Catalog\Api\Data\ProductListWithFilterInterface;
|
||||
use Magento\Framework\Api\SearchResults;
|
||||
|
||||
class ProductListWithFilter extends SearchResults implements ProductListWithFilterInterface
|
||||
{
|
||||
const FILTERS = 'filters';
|
||||
const FILTER_CODE = 'filterCode';
|
||||
|
||||
/**
|
||||
* @param string $filter
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilters(string $filter)
|
||||
{
|
||||
$this->setData(self::FILTERS, $filter);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
if (empty($this->_get(self::FILTERS))) {
|
||||
$this->setData(self::FILTERS, []);
|
||||
}
|
||||
|
||||
return $this->_get(self::FILTERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filterCode
|
||||
* @return $this
|
||||
*/
|
||||
public function setFilterCode(string $filterCode)
|
||||
{
|
||||
$this->setData(self::FILTER_CODE, $filterCode);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFilterCode()
|
||||
{
|
||||
return (string)$this->_get(self::FILTER_CODE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Model\Api;
|
||||
|
||||
use Magento\Framework\Webapi\Rest\Request as RestRequest;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Stemcell\Catalog\Model\ResourceModel\ExperimentalScheme\CollectionFactory as CollectionFactory;
|
||||
|
||||
/**
|
||||
* 实验方案
|
||||
*/
|
||||
class ExperimentalScheme
|
||||
{
|
||||
const PAGE_SIZE = 10;
|
||||
public function __construct(
|
||||
private RestRequest $restRequest,
|
||||
private CollectionFactory $collectionFactory,
|
||||
private StoreManagerInterface $storeManager,
|
||||
) {
|
||||
}
|
||||
|
||||
protected function getFilters() : array
|
||||
{
|
||||
$collection = $this->collectionFactory->create();
|
||||
$table = $collection->getMainTable();
|
||||
$rows = $collection->getConnection()->fetchAll(
|
||||
'select MIN(collection_name) AS collection_name, collection_sort from '.$table
|
||||
.' group by collection_sort order by collection_sort asc'
|
||||
);
|
||||
$data = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$data[] = ['collection_name'=>$row['collection_name']];
|
||||
}
|
||||
|
||||
return array_values($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$collectionName = trim((string)$this->restRequest->getParam('collection'));
|
||||
$page = intval($this->restRequest->getParam('page', 1));
|
||||
$collection = $this->collectionFactory->create();
|
||||
if (!empty($collectionName)) {
|
||||
$collection->addFieldToFilter('collection_name', $collectionName);
|
||||
}
|
||||
$collection->setPageSize(self::PAGE_SIZE)->setCurPage($page)->setOrder('collection_sort', 'asc');
|
||||
$mediaUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
|
||||
$data = $collection->getData();
|
||||
foreach ($data as &$item) {
|
||||
$item['image'] = $mediaUrl . $item['image'];
|
||||
}
|
||||
return json_encode([
|
||||
'data'=>['items' => $data, 'total_count'=>$collection->getSize()],
|
||||
'filters' => ['collection'=>$this->getFilters()]
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,387 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Model\Api;
|
||||
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Layer\Category as CategoryLayer;
|
||||
use Magento\Catalog\Model\Layer\Resolver;
|
||||
use Magento\Framework\Api\FilterBuilder;
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\Api\SortOrder;
|
||||
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
|
||||
use Magento\Framework\Api\Search\SearchInterface;
|
||||
use \Magento\Framework\Api\Search\SearchCriteriaInterface;
|
||||
use Magento\Framework\Api\Search\FilterGroupBuilder;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\Module\Dir;
|
||||
use Magento\Framework\Webapi\Rest\Request;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Stemcell\Catalog\Helper\Configuration as ConfigurationHelper;
|
||||
use Magento\Eav\Model\Config as EavConfig;
|
||||
use Stemcell\Catalog\Api\Data\ProductListWithFilterInterface;
|
||||
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
|
||||
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
|
||||
use Magento\Store\Model\StoreManagerInterface;
|
||||
use Stemcell\Catalog\Helper\Excel;
|
||||
use \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use Stemcell\Catalog\Model\ProductManualSearch;
|
||||
use Stemcell\Catalog\Setup\Patch\Data\AddChineseEditionCellSeparationOption;
|
||||
|
||||
class Product
|
||||
{
|
||||
private CategoryLayer $_categoryLayer;
|
||||
|
||||
private array $filters = [
|
||||
'e-book' => ['attribute' => 'area_of_interest', 'optionsLabel' => ['免疫', '嵌合体', '类器官', '脐带血库', 'HLA']],
|
||||
'product-information-sheets' => ['attribute' => 'resource_type', 'optionsLabel' => ['产品信息表', '技术手册']],
|
||||
'protocol' => ['attribute' => 'area_of_interest', 'optionsLabel' =>
|
||||
[
|
||||
'上皮细胞研究', '免疫', '内皮细胞研究', '呼吸系统研究', '干细胞生物学', '感染性疾病(传染病)', '疾病建模', '癌症',
|
||||
'神经科学', '类器官', '细胞治疗开发', '细胞系制备', '药物发现和毒理检测'
|
||||
]
|
||||
],
|
||||
'product-manual' => ['attribute' => 'area_of_interest', 'optionsLabel' =>
|
||||
[
|
||||
'HIV', '上皮细胞研究', '免疫', '内皮细胞研究', '呼吸系统研究', '嵌合体', '干细胞生物学', '感染性疾病(传染病)',
|
||||
'抗体制备', '杂交瘤制备', '疾病建模', '癌症', '神经科学', '移植研究', '类器官', '细胞治疗开发', '细胞系制备',
|
||||
'脐带血库', '药物发现和毒理检测', '血管生成细胞研究', 'HLA'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
private ProductRepositoryInterface $productRepository,
|
||||
private SearchCriteriaBuilder $searchCriteriaBuilder,
|
||||
private FilterBuilder $filterBuilder,
|
||||
private SearchInterface $search,
|
||||
private SearchCriteriaInterface $searchCriteria,
|
||||
private FilterGroupBuilder $filterGroupBuilder,
|
||||
private ConfigurationHelper $configurationHelper,
|
||||
private SortOrder $sortOrder,
|
||||
private Resolver $layerResolver,
|
||||
private Request $restRequest,
|
||||
private EavConfig $eavConfig,
|
||||
private ProductListWithFilterInterface $productListWithFilter,
|
||||
private ProductCollectionFactory $productCollectionFactory,
|
||||
private Dir $dir,
|
||||
private StoreManagerInterface $storeManager,
|
||||
private ProductManualSearch $productManualSearch,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $categoryId
|
||||
* @param int $page
|
||||
* @return \Magento\Catalog\Api\Data\ProductSearchResultsInterface
|
||||
*/
|
||||
public function getList(int $categoryId, int $page = 1)
|
||||
{
|
||||
$statusFilter = $this->filterBuilder
|
||||
->setField('status')
|
||||
->setConditionType('eq')
|
||||
->setValue(1)
|
||||
->create();
|
||||
|
||||
$visibilityFilter = $this->filterBuilder
|
||||
->setField('visibility')
|
||||
->setConditionType('in')
|
||||
->setValue([2,3,4])
|
||||
->create();
|
||||
|
||||
$categoryFilter = $this->filterBuilder
|
||||
->setField('category_id')
|
||||
->setConditionType('eq')
|
||||
->setValue($categoryId)
|
||||
->create();
|
||||
|
||||
$criteria = $this->searchCriteriaBuilder
|
||||
->addFilters([$visibilityFilter, $categoryFilter])
|
||||
->setPageSize(10)
|
||||
->setCurrentPage($page)
|
||||
->addSortOrder($this->sortOrder->setField('entity_id')->setDirection('DESC'))
|
||||
->create();
|
||||
return $this->productRepository->getList($criteria);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sku
|
||||
* @return \Magento\Catalog\Api\Data\ProductInterface|void
|
||||
* @throws \Magento\Framework\Exception\NoSuchEntityException
|
||||
*/
|
||||
public function getBySku(string $sku){
|
||||
|
||||
$product = $this->productRepository->get($sku);
|
||||
|
||||
if ($product->getTypeId() == Configurable::TYPE_CODE) {
|
||||
$attributes = $this->configurationHelper->getConfigurableAttributeProducts($product);
|
||||
|
||||
/* @var $productTypeInstance \Magento\ConfigurableProduct\Model\Product\Type\Configurable */
|
||||
$productTypeInstance = $product->getTypeInstance();
|
||||
$configurableAttributes = $productTypeInstance->getConfigurableAttributesAsArray($product);
|
||||
|
||||
foreach ($product->getExtensionAttributes()->getConfigurableProductOptions() as $option) {
|
||||
|
||||
$options = array_column($option->getOptions(), null, 'value_index');
|
||||
if (isset($configurableAttributes[$option->getAttributeId()])) {
|
||||
$option->setLabel($configurableAttributes[$option->getAttributeId()]['frontend_label']);
|
||||
}
|
||||
foreach ($option->getValues() as $value) {
|
||||
if (isset($options[$value->getValueIndex()])) {
|
||||
$value->getExtensionAttributes()
|
||||
->setLabel($options[$value->getValueIndex()]['label'])
|
||||
->setProducts($attributes[$option->getAttributeId()][$value->getValueIndex()]??[]);
|
||||
}
|
||||
}
|
||||
}
|
||||
list($childrenImages, $childrenDescription) = $this->configurationHelper->getOptionImages($product);
|
||||
$product->getExtensionAttributes()
|
||||
->setChildrenImages(json_encode($childrenImages))
|
||||
->setChildrenShortDescription(json_encode($childrenDescription));
|
||||
}
|
||||
|
||||
return $product;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $term
|
||||
* @param int $page
|
||||
* @return \Magento\Catalog\Api\Data\ProductSearchResultsInterface
|
||||
*/
|
||||
public function search(string $term, int $page = 1)
|
||||
{
|
||||
$pageSize = 10;
|
||||
$termFilter = $this->filterBuilder
|
||||
->setField('search_term')
|
||||
->setValue($term)
|
||||
->setConditionType('like')
|
||||
->create();
|
||||
|
||||
$criteria = $this->searchCriteria
|
||||
->setFilterGroups([$this->filterGroupBuilder->addFilter($termFilter)->create()])
|
||||
->setRequestName('quick_search_container');
|
||||
|
||||
$result = $this->search->search($criteria);
|
||||
$productIds = [];
|
||||
|
||||
foreach ($result->getItems() as $product) {
|
||||
/* @var $product \Magento\Framework\Api\Search\Document */
|
||||
if ($product->getCustomAttribute('score')->getValue() < 10) {
|
||||
continue;
|
||||
}
|
||||
$productIds[] = $product->getId();
|
||||
}
|
||||
|
||||
$filter = $this->filterBuilder
|
||||
->setField('entity_id')
|
||||
->setConditionType('in')
|
||||
->setValue(array_values($productIds))
|
||||
->create();
|
||||
$criteria = $this->searchCriteriaBuilder
|
||||
->addFilters([$filter])
|
||||
->setPageSize($pageSize)
|
||||
->setCurrentPage($page)
|
||||
->create();
|
||||
|
||||
return $this->productRepository->getList($criteria);
|
||||
}
|
||||
|
||||
protected function getProductOptions(string $attribute, array $optionsLabel)
|
||||
{
|
||||
$attribute = $this->eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $attribute);
|
||||
$options = [];
|
||||
|
||||
foreach ($attribute->getSource()->getAllOptions() as $option) {
|
||||
|
||||
if (in_array($option['label'], $optionsLabel)) {
|
||||
$options[] = $option;
|
||||
}
|
||||
}
|
||||
return [$options, $attribute->getFrontendInput() == 'multiselect'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据产品说明书分类下的产品parent_skus, 获取对应产品的name、sku,通过parents返回给前端显示
|
||||
* @param ProductCollection $productCollection
|
||||
* @return void
|
||||
*/
|
||||
protected function setParent(ProductCollection $productCollection)
|
||||
{
|
||||
foreach ($productCollection as $product) {
|
||||
|
||||
/* @var $product \Magento\Catalog\Api\Data\ProductInterface */
|
||||
if ($parentSkus = $product->getData('parent_skus')) {
|
||||
$collection = $this->productCollectionFactory->create()->addAttributeToSelect('name')
|
||||
->addAttributeToFilter('sku', ['in' => explode(',', $parentSkus)]);
|
||||
$parents = [];
|
||||
foreach ($collection as $item) {
|
||||
$parents[] = ['sku' => $item->getSku(), 'name' => $item->getName()];
|
||||
}
|
||||
|
||||
$product->getExtensionAttributes()->setParents(json_encode($parents));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
protected function getResourceTypeChinesePisOptionId()
|
||||
{
|
||||
$attribute = $this->eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'resource_type');
|
||||
$attribute->setStoreId(0);
|
||||
$optionId = 0;
|
||||
foreach ($attribute->getOptions() as $option) {
|
||||
if ($option->getLabel() == AddChineseEditionCellSeparationOption::RESOURCE_TYPE_ENGLISH_LABEL) {
|
||||
$optionId = (int)$option->getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $optionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 小程序技术资源
|
||||
* @param int $categoryId
|
||||
* @param string $type
|
||||
* @param int $page
|
||||
* @return ProductListWithFilterInterface
|
||||
* @throws \Magento\Framework\Exception\LocalizedException
|
||||
*/
|
||||
public function categoryProduct(int $categoryId, $type = 'e-book', int $page = 1)
|
||||
{
|
||||
$pageSize = 10;
|
||||
$attribute = $this->filters[$type]['attribute'];
|
||||
$this->_categoryLayer = $this->layerResolver->get();
|
||||
$this->_categoryLayer->setCurrentCategory($categoryId);
|
||||
|
||||
$this->_categoryLayer->apply();
|
||||
$collection = $this->_categoryLayer->getProductCollection();
|
||||
|
||||
list($filters, $isMultiselect) = $this->getProductOptions($attribute, $this->filters[$type]['optionsLabel']);
|
||||
if ($this->restRequest->getParam($attribute)) {
|
||||
if ($isMultiselect) {
|
||||
$collection->addAttributeToFilter($attribute, ['finset' => explode(',', trim($this->restRequest->getParam($attribute)))]);
|
||||
} else {
|
||||
$collection->addAttributeToFilter($attribute, trim($this->restRequest->getParam($attribute)));
|
||||
}
|
||||
|
||||
}
|
||||
$collection->addAttributeToSelect('*')->setOrder('position', 'asc')
|
||||
->addAttributeToFilter('visibility', ['in' => [2,3,4]]);
|
||||
if ($type == 'product-information-sheets') {
|
||||
$collection->addAttributeToFilter('parent_skus', array('notnull' => true) )
|
||||
->addAttributeToFilter('parent_names', array('notnull' => true) )
|
||||
->addAttributeToFilter('resource_type', ['neq' => $this->getResourceTypeChinesePisOptionId()]);
|
||||
$keyword = $this->restRequest->getParam('keyword');
|
||||
if ($keyword) {
|
||||
$collection->addAttributeToFilter([
|
||||
['attribute' => 'parent_skus', 'like' => '%' . $keyword . '%'],
|
||||
['attribute' => 'parent_names', 'like' => '%' . $keyword . '%'],
|
||||
]);
|
||||
}
|
||||
$logger = ObjectManager::getInstance()->get(LoggerInterface::class);
|
||||
$logger->info($collection->getSelectSql(true));
|
||||
}
|
||||
|
||||
$collection->setPage($page, $pageSize);
|
||||
$this->setParent($collection);
|
||||
|
||||
return $this->productListWithFilter->setFilters(json_encode($filters))
|
||||
->setItems($collection->getItems())
|
||||
->setTotalCount($collection->getSize())
|
||||
->setFilterCode($attribute);
|
||||
}
|
||||
|
||||
/**
|
||||
* 实验方案
|
||||
* @return string
|
||||
* @throws \Magento\Framework\Exception\NoSuchEntityException
|
||||
*/
|
||||
public function experimentalScheme()
|
||||
{
|
||||
$path = $this->dir->getDir('Stemcell_Catalog').'/data/experimental-scheme.csv';
|
||||
$file = fopen($path, "r");
|
||||
$data = [];
|
||||
$mediaUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
|
||||
while (($row = fgetcsv($file)) !== FALSE) {
|
||||
if (isset($row[1])) {
|
||||
$row[0] = preg_replace('/^\xEF\xBB\xBF/', '', $row[0]);
|
||||
$data[$row[0]]['label'] = $row[0];
|
||||
$data[$row[0]]['list'][] = ['label' => $row[1], 'url' => $row[2], 'image'=>$mediaUrl.$row[3]];
|
||||
}
|
||||
}
|
||||
|
||||
return json_encode(array_values($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Worksheet $sheet
|
||||
* @param string $cell
|
||||
* @return string
|
||||
*/
|
||||
protected function getCellValue(Worksheet $sheet, string $cell)
|
||||
{
|
||||
return trim((string)$sheet->getCell($cell)->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* 产品手册接口
|
||||
* @return string
|
||||
* @throws \Magento\Framework\Exception\NoSuchEntityException
|
||||
*/
|
||||
public function productManual()
|
||||
{
|
||||
$path = $this->dir->getDir('Stemcell_Catalog').'/data/product-manual.xlsx';
|
||||
|
||||
$data = [];
|
||||
$sheet = Excel::getExcelSheet($path);
|
||||
$mediaUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA);
|
||||
foreach ($sheet->getRowIterator() as $row) {
|
||||
if ($row->getRowIndex() == 1) {
|
||||
continue;
|
||||
}
|
||||
$researchFiled = $this->getCellValue($sheet, 'A'.$row->getRowIndex());
|
||||
$name = $this->getCellValue($sheet, 'B'.$row->getRowIndex());
|
||||
$imagePath = $this->getCellValue($sheet, 'C'.$row->getRowIndex());
|
||||
$pdfPath = $this->getCellValue($sheet, 'D'.$row->getRowIndex());
|
||||
if (!empty($name)) {
|
||||
$data[$researchFiled]['label'] = $researchFiled;
|
||||
$data[$researchFiled]['list'][] = ['label' => $name, 'url' => $mediaUrl.$imagePath, 'pdf'=>$mediaUrl.$pdfPath];
|
||||
}
|
||||
}
|
||||
return json_encode(array_values($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 操作视频
|
||||
* @return string
|
||||
*/
|
||||
public function videos()
|
||||
{
|
||||
$path = $this->dir->getDir('Stemcell_Catalog').'/data/operation-videos.xlsx';
|
||||
|
||||
$data = [];
|
||||
$sheet = Excel::getExcelSheet($path);
|
||||
|
||||
foreach ($sheet->getRowIterator() as $row) {
|
||||
if ($row->getRowIndex() == 1) {
|
||||
continue;
|
||||
}
|
||||
$categoryName = $this->getCellValue($sheet, 'A'.$row->getRowIndex());
|
||||
$categorySort = intval($this->getCellValue($sheet, 'B'.$row->getRowIndex()));
|
||||
// $duration = $this->getCellValue($sheet, 'C'.$row->getRowIndex());
|
||||
$duration = $sheet->getCell('C'.$row->getRowIndex())->getValue();
|
||||
|
||||
$videoTitle = $this->getCellValue($sheet, 'D'.$row->getRowIndex());
|
||||
$videoId = $this->getCellValue($sheet, 'E'.$row->getRowIndex());
|
||||
if (!empty($videoTitle)) {
|
||||
$data[$categoryName]['label'] = $categoryName;
|
||||
$data[$categoryName]['list'][] = ['name' => $videoTitle, 'duration' => $duration, 'video_id'=>$videoId];
|
||||
}
|
||||
}
|
||||
|
||||
return json_encode(array_values($data));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Model\Api;
|
||||
|
||||
use Magento\Framework\Webapi\Rest\Request as RestRequest;
|
||||
use Stemcell\Catalog\Model\ResourceModel\Cryopreserve\CollectionFactory as CryopreserveCollectionFactory;
|
||||
|
||||
/**
|
||||
* 样本冻存参考小工具接口
|
||||
*/
|
||||
class SampleCryopreserve
|
||||
{
|
||||
public function __construct(
|
||||
private CryopreserveCollectionFactory $cryopreserveCollectionFactory,
|
||||
private RestRequest $restRequest
|
||||
) {
|
||||
}
|
||||
|
||||
protected function getSamples() {
|
||||
$samples = [];
|
||||
$data = $this->cryopreserveCollectionFactory->create()->addFieldToSelect('sample')->load()->getData();
|
||||
foreach ($data as $item) {
|
||||
if (!isset($samples[$item['sample']])) {
|
||||
$samples[$item['sample']] = ['sample' => $item['sample']];
|
||||
}
|
||||
}
|
||||
return array_values($samples);
|
||||
}
|
||||
|
||||
protected function getTypes()
|
||||
{
|
||||
$sample = trim((string)$this->restRequest->getParam("sample"));
|
||||
$collection = $this->cryopreserveCollectionFactory->create();
|
||||
if (!empty($sample)) {
|
||||
$collection->addFieldToFilter('sample', $sample);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
foreach ($collection->getItems() as $item) {
|
||||
/* @var $item \Stemcell\Catalog\Model\Cryopreserve */
|
||||
if (!isset($data[$item->getType()])) {
|
||||
$data[$item->getType()] = ['type' => $item->getType()];
|
||||
}
|
||||
}
|
||||
|
||||
return array_values($data);
|
||||
}
|
||||
|
||||
protected function getCellTypes()
|
||||
{
|
||||
$sample = trim((string)$this->restRequest->getParam("sample"));
|
||||
$type = trim((string)$this->restRequest->getParam("type"));
|
||||
$collection = $this->cryopreserveCollectionFactory->create();
|
||||
if (!empty($type)) {
|
||||
$collection->addFieldToFilter('sample', $sample)
|
||||
->addFieldToFilter('type', $type);
|
||||
}
|
||||
|
||||
$data = [];
|
||||
foreach ($collection->getItems() as $item) {
|
||||
/* @var $item \Stemcell\Catalog\Model\Cryopreserve */
|
||||
if (!isset($data[$item->getCellType()])) {
|
||||
$data[$item->getCellType()] = ['cellType' => $item->getCellType()];
|
||||
}
|
||||
}
|
||||
|
||||
return array_values($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return ['samples'=>$this->getSamples(), 'types'=>$this->getTypes(), 'cellTypes'=>$this->getCellTypes()];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function execute() : string {
|
||||
$sample = trim((string)$this->restRequest->getParam("sample"));
|
||||
$type = trim((string)$this->restRequest->getParam("type"));
|
||||
$cellType = trim((string)$this->restRequest->getParam("cellType"));
|
||||
$collection = $this->cryopreserveCollectionFactory->create()
|
||||
->addFieldToSelect(['reference_density', 'desc', 'reference']);
|
||||
if (!empty($sample)) {
|
||||
$collection->addFieldToFilter('sample', $sample);
|
||||
}
|
||||
if (!empty($type)) {
|
||||
$collection->addFieldToFilter('type', $type);
|
||||
}
|
||||
if (!empty($cellType)) {
|
||||
$collection->addFieldToFilter('cell_type', $cellType);
|
||||
}
|
||||
|
||||
return json_encode(['filters' => $this->getFilters(), 'items' => $collection->getData()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Model\Api;
|
||||
|
||||
use Magento\Framework\Module\Dir;
|
||||
use Magento\Framework\Webapi\Rest\Request;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory;
|
||||
use Magento\Framework\App\CacheInterface;
|
||||
use Magento\Catalog\Helper\Image as ImageHelper;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\Product;
|
||||
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
|
||||
use Magento\Cms\Model\Template\FilterProvider;
|
||||
use Magento\Framework\App\Config\ScopeConfigInterface;
|
||||
use Magento\Store\Model\ScopeInterface;
|
||||
|
||||
/**
|
||||
* 小程序实用工具 - 多能干细胞维持培养工具
|
||||
*/
|
||||
class TesrProductFinder
|
||||
{
|
||||
protected array $filtersField = ['first', 'second', 'third', 'fourth'];
|
||||
const CACHE_IDENTIFIER = 'tesr_product_finder_cache';
|
||||
const IMAGE_PATH = 'catalog/product/cache/43f2e544b18f2e737c50422db3f53cf3/E/B/EB00005_8406f0a7325bcb2e1140145e13eef3cd_1_1.jpg';
|
||||
|
||||
const XML_PATH_WECHAT_TESR_PRODUCT_FINDER = 'commerce/wechat/tesr-product-finder';
|
||||
|
||||
public function __construct(
|
||||
protected Dir $dir,
|
||||
protected Request $restRequest,
|
||||
protected CacheInterface $cache,
|
||||
protected ImageHelper $imageHelper,
|
||||
protected ProductRepositoryInterface $productRepository,
|
||||
protected Product $product,
|
||||
protected ProductCollectionFactory $productCollectionFactory,
|
||||
protected ScopeConfigInterface $scopeConfig,
|
||||
protected FilterProvider $filterProvider,
|
||||
) {
|
||||
}
|
||||
|
||||
// 保存数据到缓存
|
||||
protected function saveToCache($data, $identifier, $tags = [], $lifeTime = null)
|
||||
{
|
||||
$tags = array_merge(['CUSTOM_TAG'], $tags);
|
||||
$lifeTime = $lifeTime ?: 3600; // 默认1小时
|
||||
|
||||
$this->cache->save(
|
||||
serialize($data),
|
||||
$identifier,
|
||||
$tags,
|
||||
$lifeTime
|
||||
);
|
||||
}
|
||||
|
||||
// 从缓存加载数据
|
||||
protected function loadFromCache($identifier)
|
||||
{
|
||||
$data = $this->cache->load($identifier);
|
||||
return $data ? unserialize($data) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getExcelData()
|
||||
{
|
||||
$data = $this->loadFromCache(self::CACHE_IDENTIFIER);
|
||||
if ($data !== false) {
|
||||
return $data;
|
||||
}
|
||||
$path = $this->dir->getDir('Stemcell_Catalog').'/data/tesr-product-finder.xlsx';
|
||||
$spreadsheet = IOFactory::load($path);
|
||||
$worksheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
// 获取所有数据
|
||||
$data = $worksheet->toArray();
|
||||
|
||||
// 第一行作为键名
|
||||
$headers = array_shift($data);
|
||||
|
||||
// 转换为关联数组
|
||||
$result = [];
|
||||
foreach ($data as $row) {
|
||||
$assocRow = [];
|
||||
foreach ($headers as $index => $header) {
|
||||
if ($header) {
|
||||
$assocRow[$header] = $row[$index] ?? null;
|
||||
if ($header=='skus') {
|
||||
$skus = array_map('trim', explode(',', $assocRow[$header]));
|
||||
$assocRow[$header] = $this->getProductsFromSku($skus);
|
||||
}
|
||||
}
|
||||
}
|
||||
$result[] = $assocRow;
|
||||
}
|
||||
$this->saveToCache($result, self::CACHE_IDENTIFIER);
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getProductsFromSku(array $skus)
|
||||
{
|
||||
$productCollection = $this->productCollectionFactory->create()
|
||||
->addAttributeToFilter('sku', ['in' => $skus])
|
||||
->addAttributeToSelect(['small_image', 'name']);
|
||||
|
||||
$data = [];
|
||||
foreach ($productCollection as $product) {
|
||||
$data[] = ['sku' => $product->getSku(), 'name' => $product->getName(), 'image' => $this->getImageUrl($product)];
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function getImageUrl(Product $product): string
|
||||
{
|
||||
return $this->imageHelper
|
||||
->init($product, 'category_page_list')
|
||||
->setImageFile($product->getSmallImage())
|
||||
->getUrl();
|
||||
}
|
||||
/**
|
||||
* @param array $data
|
||||
* @return array[]
|
||||
*/
|
||||
protected function getFilters(array $data) {
|
||||
$filters = [];
|
||||
foreach ($this->filtersField as $field) {
|
||||
$filters[$field] = [];
|
||||
}
|
||||
foreach ($data as $row) {
|
||||
foreach ($this->filtersField as $field) {
|
||||
!in_array($row[$field], $filters[$field]) && $filters[$field][] = $row[$field];
|
||||
}
|
||||
}
|
||||
return $filters;
|
||||
}
|
||||
|
||||
protected function getBanners()
|
||||
{
|
||||
$config = $this->scopeConfig->getValue(
|
||||
self::XML_PATH_WECHAT_TESR_PRODUCT_FINDER,
|
||||
ScopeInterface::SCOPE_STORE
|
||||
);
|
||||
|
||||
if (!$config) {
|
||||
$config = [];
|
||||
} else {
|
||||
try {
|
||||
$config = $this->filterProvider->getPageFilter()->filter($config);
|
||||
$config = json_decode($config, true);
|
||||
} catch (\Exception $e) {
|
||||
$config = [];
|
||||
}
|
||||
|
||||
}
|
||||
$config = is_array($config) ? $config : [];
|
||||
return $config['banners'] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$data = $this->getExcelData();
|
||||
$result = [];
|
||||
$criteria = $this->restRequest->getParams();
|
||||
foreach ($criteria as $key => $value) {
|
||||
$criteria[$key] = trim($value);
|
||||
}
|
||||
|
||||
$isFilterComplete = true;
|
||||
foreach ($this->filtersField as $field) {
|
||||
|
||||
if (empty($criteria[$field])) {
|
||||
$isFilterComplete = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($isFilterComplete) {
|
||||
foreach ($data as $row) {
|
||||
$notThisRow = false;
|
||||
foreach ($this->filtersField as $field) {
|
||||
if ($row[$field] != $criteria[$field]) {
|
||||
$notThisRow = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($notThisRow) {
|
||||
continue;
|
||||
} else {
|
||||
$result = $row;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$product = $this->productRepository->get('EB00005');
|
||||
return json_encode([
|
||||
'filters' => $this->getFilters($data),
|
||||
'result' => $result,
|
||||
'resources' => [
|
||||
[
|
||||
'id'=>2,
|
||||
'name'=>'诱导多能干细胞:标准化且易获取的究模型',
|
||||
'image_url' => $this->getImageUrl($product),
|
||||
],
|
||||
],
|
||||
'banners' => $this->getBanners(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model;
|
||||
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
use Stemcell\Catalog\Api\Data\CellSortInterface;
|
||||
|
||||
class CellSort extends AbstractModel implements CellSortInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function _construct()
|
||||
{
|
||||
$this->_init(\Stemcell\Catalog\Model\ResourceModel\CellSort::class);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCellSortId()
|
||||
{
|
||||
return $this->getData(self::CELLSORT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSpeciesName()
|
||||
{
|
||||
return $this->getData(self::SPECIES_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setSpeciesName(string $speciesName)
|
||||
{
|
||||
return $this->setData(self::SPECIES_NAME, $speciesName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTissueId()
|
||||
{
|
||||
return $this->getData(self::TISSUE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setTissueId(int $tissueId)
|
||||
{
|
||||
return $this->setData(self::TISSUE_ID, $tissueId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTissueName()
|
||||
{
|
||||
return $this->getData(self::TISSUE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setTissueName(string $tissueName)
|
||||
{
|
||||
return $this->setData(self::TISSUE_NAME, $tissueName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCellTypeId()
|
||||
{
|
||||
return $this->getData(self::CELL_TYPE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCellTypeId(int $cellTypeId)
|
||||
{
|
||||
return $this->setData(self::CELL_TYPE_ID, $cellTypeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCellTypeName()
|
||||
{
|
||||
return $this->getData(self::CELL_TYPE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCellTypeName(string $cellTypeName)
|
||||
{
|
||||
return $this->setData(self::CELL_TYPE_NAME, $cellTypeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getFlag()
|
||||
{
|
||||
return $this->getData(self::FLAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setFlag($flag)
|
||||
{
|
||||
return $this->setData(self::FLAG, $flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSku()
|
||||
{
|
||||
return $this->getData(self::SKU);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setSku(string $sku)
|
||||
{
|
||||
return $this->setData(self::FLAG, $sku);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSpeciesId()
|
||||
{
|
||||
return $this->getData(self::SPECIES_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setSpeciesId(int $speciesId)
|
||||
{
|
||||
return $this->setData(self::SPECIES_ID, $speciesId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCellSubTypeId()
|
||||
{
|
||||
return $this->getData(self::CELL_SUBTYPE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCellSubTypeId(int $cellSubTypeId)
|
||||
{
|
||||
return $this->setData(self::CELL_SUBTYPE_ID, $cellSubTypeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCellSubTypeName()
|
||||
{
|
||||
return $this->getData(self::CELL_SUBTYPE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCellSubTypeName(string $cellSubTypeName)
|
||||
{
|
||||
return $this->setData(self::CELL_SUBTYPE_NAME, $cellSubTypeName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
|
||||
use Magento\Framework\Exception\CouldNotDeleteException;
|
||||
use Magento\Framework\Exception\CouldNotSaveException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Stemcell\Catalog\Api\CellSortRepositoryInterface;
|
||||
use Stemcell\Catalog\Api\Data\CellSortInterface;
|
||||
use Stemcell\Catalog\Api\Data\CellSortInterfaceFactory;
|
||||
use Stemcell\Catalog\Api\Data\CellSortSearchResultsInterfaceFactory;
|
||||
use Stemcell\Catalog\Model\ResourceModel\CellSort as ResourceCellSort;
|
||||
use Stemcell\Catalog\Model\ResourceModel\CellSort\CollectionFactory as CellSortCollectionFactory;
|
||||
|
||||
class CellSortRepository implements CellSortRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var CellSortInterfaceFactory
|
||||
*/
|
||||
protected $cellSortFactory;
|
||||
|
||||
/**
|
||||
* @var CollectionProcessorInterface
|
||||
*/
|
||||
protected $collectionProcessor;
|
||||
|
||||
/**
|
||||
* @var ResourceCellSort
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var CellSortCollectionFactory
|
||||
*/
|
||||
protected $cellSortCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var CellSort
|
||||
*/
|
||||
protected $searchResultsFactory;
|
||||
|
||||
|
||||
/**
|
||||
* @param ResourceCellSort $resource
|
||||
* @param CellSortInterfaceFactory $cellSortFactory
|
||||
* @param CellSortCollectionFactory $cellSortCollectionFactory
|
||||
* @param CellSortSearchResultsInterfaceFactory $searchResultsFactory
|
||||
* @param CollectionProcessorInterface $collectionProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
ResourceCellSort $resource,
|
||||
CellSortInterfaceFactory $cellSortFactory,
|
||||
CellSortCollectionFactory $cellSortCollectionFactory,
|
||||
CellSortSearchResultsInterfaceFactory $searchResultsFactory,
|
||||
CollectionProcessorInterface $collectionProcessor
|
||||
) {
|
||||
$this->resource = $resource;
|
||||
$this->cellSortFactory = $cellSortFactory;
|
||||
$this->cellSortCollectionFactory = $cellSortCollectionFactory;
|
||||
$this->searchResultsFactory = $searchResultsFactory;
|
||||
$this->collectionProcessor = $collectionProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function save(CellSortInterface $cellSort)
|
||||
{
|
||||
try {
|
||||
$this->resource->save($cellSort);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotSaveException(__(
|
||||
'Could not save the cellSort: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return $cellSort;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get($cellSortId)
|
||||
{
|
||||
$cellSort = $this->cellSortFactory->create();
|
||||
$this->resource->load($cellSort, $cellSortId);
|
||||
if (!$cellSort->getId()) {
|
||||
throw new NoSuchEntityException(__('CellSort with id "%1" does not exist.', $cellSortId));
|
||||
}
|
||||
return $cellSort;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getList(
|
||||
\Magento\Framework\Api\SearchCriteriaInterface $criteria
|
||||
) {
|
||||
$collection = $this->cellSortCollectionFactory->create();
|
||||
|
||||
$this->collectionProcessor->process($criteria, $collection);
|
||||
|
||||
$searchResults = $this->searchResultsFactory->create();
|
||||
$searchResults->setSearchCriteria($criteria);
|
||||
|
||||
$items = [];
|
||||
foreach ($collection as $model) {
|
||||
$items[] = $model;
|
||||
}
|
||||
|
||||
$searchResults->setItems($items);
|
||||
$searchResults->setTotalCount($collection->getSize());
|
||||
return $searchResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(CellSortInterface $cellSort)
|
||||
{
|
||||
try {
|
||||
$cellSortModel = $this->cellSortFactory->create();
|
||||
$this->resource->load($cellSortModel, $cellSort->getCellsortId());
|
||||
$this->resource->delete($cellSortModel);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotDeleteException(__(
|
||||
'Could not delete the CellSort: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function deleteById($cellSortId)
|
||||
{
|
||||
return $this->delete($this->get($cellSortId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model;
|
||||
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
use Stemcell\Catalog\Api\Data\CellSubTypeInterface;
|
||||
|
||||
class CellSubType extends AbstractModel implements CellSubTypeInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function _construct()
|
||||
{
|
||||
$this->_init(\Stemcell\Catalog\Model\ResourceModel\CellSubType::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCellsubtypeId()
|
||||
{
|
||||
return $this->getData(self::CELLSUBTYPE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCellsubtypeId($cellsubtypeId)
|
||||
{
|
||||
return $this->setData(self::CELLSUBTYPE_ID, $cellsubtypeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->getData(self::NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
return $this->setData(self::NAME, $name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
|
||||
use Magento\Framework\Exception\CouldNotDeleteException;
|
||||
use Magento\Framework\Exception\CouldNotSaveException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Stemcell\Catalog\Api\CellSubTypeRepositoryInterface;
|
||||
use Stemcell\Catalog\Api\Data\CellSubTypeInterface;
|
||||
use Stemcell\Catalog\Api\Data\CellSubTypeInterfaceFactory;
|
||||
use Stemcell\Catalog\Api\Data\CellSubTypeSearchResultsInterfaceFactory;
|
||||
use Stemcell\Catalog\Model\ResourceModel\CellSubType as ResourceCellSubType;
|
||||
use Stemcell\Catalog\Model\ResourceModel\CellSubType\CollectionFactory as CellSubTypeCollectionFactory;
|
||||
|
||||
class CellSubTypeRepository implements CellSubTypeRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ResourceCellSubType
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var CellSubTypeInterfaceFactory
|
||||
*/
|
||||
protected $cellSubTypeFactory;
|
||||
|
||||
/**
|
||||
* @var CellSubTypeCollectionFactory
|
||||
*/
|
||||
protected $cellSubTypeCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var CellSubType
|
||||
*/
|
||||
protected $searchResultsFactory;
|
||||
|
||||
/**
|
||||
* @var CollectionProcessorInterface
|
||||
*/
|
||||
protected $collectionProcessor;
|
||||
|
||||
|
||||
/**
|
||||
* @param ResourceCellSubType $resource
|
||||
* @param CellSubTypeInterfaceFactory $cellSubTypeFactory
|
||||
* @param CellSubTypeCollectionFactory $cellSubTypeCollectionFactory
|
||||
* @param CellSubTypeSearchResultsInterfaceFactory $searchResultsFactory
|
||||
* @param CollectionProcessorInterface $collectionProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
ResourceCellSubType $resource,
|
||||
CellSubTypeInterfaceFactory $cellSubTypeFactory,
|
||||
CellSubTypeCollectionFactory $cellSubTypeCollectionFactory,
|
||||
CellSubTypeSearchResultsInterfaceFactory $searchResultsFactory,
|
||||
CollectionProcessorInterface $collectionProcessor
|
||||
) {
|
||||
$this->resource = $resource;
|
||||
$this->cellSubTypeFactory = $cellSubTypeFactory;
|
||||
$this->cellSubTypeCollectionFactory = $cellSubTypeCollectionFactory;
|
||||
$this->searchResultsFactory = $searchResultsFactory;
|
||||
$this->collectionProcessor = $collectionProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function save(CellSubTypeInterface $cellSubType)
|
||||
{
|
||||
try {
|
||||
$this->resource->save($cellSubType);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotSaveException(__(
|
||||
'Could not save the cellSubType: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return $cellSubType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get($cellSubTypeId)
|
||||
{
|
||||
$cellSubType = $this->cellSubTypeFactory->create();
|
||||
$this->resource->load($cellSubType, $cellSubTypeId);
|
||||
if (!$cellSubType->getId()) {
|
||||
throw new NoSuchEntityException(__('CellSubType with id "%1" does not exist.', $cellSubTypeId));
|
||||
}
|
||||
return $cellSubType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getList(
|
||||
\Magento\Framework\Api\SearchCriteriaInterface $criteria
|
||||
) {
|
||||
$collection = $this->cellSubTypeCollectionFactory->create();
|
||||
|
||||
$this->collectionProcessor->process($criteria, $collection);
|
||||
|
||||
$searchResults = $this->searchResultsFactory->create();
|
||||
$searchResults->setSearchCriteria($criteria);
|
||||
|
||||
$items = [];
|
||||
foreach ($collection as $model) {
|
||||
$items[] = $model;
|
||||
}
|
||||
|
||||
$searchResults->setItems($items);
|
||||
$searchResults->setTotalCount($collection->getSize());
|
||||
return $searchResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(CellSubTypeInterface $cellSubType)
|
||||
{
|
||||
try {
|
||||
$cellSubTypeModel = $this->cellSubTypeFactory->create();
|
||||
$this->resource->load($cellSubTypeModel, $cellSubType->getCellsubtypeId());
|
||||
$this->resource->delete($cellSubTypeModel);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotDeleteException(__(
|
||||
'Could not delete the CellSubType: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function deleteById($cellSubTypeId)
|
||||
{
|
||||
return $this->delete($this->get($cellSubTypeId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model;
|
||||
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
use Stemcell\Catalog\Api\Data\CellTypeInterface;
|
||||
|
||||
class CellType extends AbstractModel implements CellTypeInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function _construct()
|
||||
{
|
||||
$this->_init(\Stemcell\Catalog\Model\ResourceModel\CellType::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCelltypeId()
|
||||
{
|
||||
return $this->getData(self::CELL_TYPE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCellTypeName()
|
||||
{
|
||||
return $this->getData(self::CELL_TYPE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCellTypeName($cellTypeName)
|
||||
{
|
||||
return $this->setData(self::CELL_TYPE_NAME, $cellTypeName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
|
||||
use Magento\Framework\Exception\CouldNotDeleteException;
|
||||
use Magento\Framework\Exception\CouldNotSaveException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Stemcell\Catalog\Api\CellTypeRepositoryInterface;
|
||||
use Stemcell\Catalog\Api\Data\CellTypeInterface;
|
||||
use Stemcell\Catalog\Api\Data\CellTypeInterfaceFactory;
|
||||
use Stemcell\Catalog\Api\Data\CellTypeSearchResultsInterfaceFactory;
|
||||
use Stemcell\Catalog\Model\ResourceModel\CellType as ResourceCellType;
|
||||
use Stemcell\Catalog\Model\ResourceModel\CellType\CollectionFactory as CellTypeCollectionFactory;
|
||||
|
||||
class CellTypeRepository implements CellTypeRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ResourceCellType
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var CellTypeInterfaceFactory
|
||||
*/
|
||||
protected $cellTypeFactory;
|
||||
|
||||
/**
|
||||
* @var CellTypeCollectionFactory
|
||||
*/
|
||||
protected $cellTypeCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var CellType
|
||||
*/
|
||||
protected $searchResultsFactory;
|
||||
|
||||
/**
|
||||
* @var CollectionProcessorInterface
|
||||
*/
|
||||
protected $collectionProcessor;
|
||||
|
||||
|
||||
/**
|
||||
* @param ResourceCellType $resource
|
||||
* @param CellTypeInterfaceFactory $cellTypeFactory
|
||||
* @param CellTypeCollectionFactory $cellTypeCollectionFactory
|
||||
* @param CellTypeSearchResultsInterfaceFactory $searchResultsFactory
|
||||
* @param CollectionProcessorInterface $collectionProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
ResourceCellType $resource,
|
||||
CellTypeInterfaceFactory $cellTypeFactory,
|
||||
CellTypeCollectionFactory $cellTypeCollectionFactory,
|
||||
CellTypeSearchResultsInterfaceFactory $searchResultsFactory,
|
||||
CollectionProcessorInterface $collectionProcessor
|
||||
) {
|
||||
$this->resource = $resource;
|
||||
$this->cellTypeFactory = $cellTypeFactory;
|
||||
$this->cellTypeCollectionFactory = $cellTypeCollectionFactory;
|
||||
$this->searchResultsFactory = $searchResultsFactory;
|
||||
$this->collectionProcessor = $collectionProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function save(CellTypeInterface $cellType)
|
||||
{
|
||||
try {
|
||||
$this->resource->save($cellType);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotSaveException(__(
|
||||
'Could not save the cellType: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return $cellType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get($cellTypeId)
|
||||
{
|
||||
$cellType = $this->cellTypeFactory->create();
|
||||
$this->resource->load($cellType, $cellTypeId);
|
||||
if (!$cellType->getId()) {
|
||||
throw new NoSuchEntityException(__('CellType with id "%1" does not exist.', $cellTypeId));
|
||||
}
|
||||
return $cellType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getList(
|
||||
\Magento\Framework\Api\SearchCriteriaInterface $criteria
|
||||
) {
|
||||
$collection = $this->cellTypeCollectionFactory->create();
|
||||
|
||||
$this->collectionProcessor->process($criteria, $collection);
|
||||
|
||||
$searchResults = $this->searchResultsFactory->create();
|
||||
$searchResults->setSearchCriteria($criteria);
|
||||
|
||||
$items = [];
|
||||
foreach ($collection as $model) {
|
||||
$items[] = $model;
|
||||
}
|
||||
|
||||
$searchResults->setItems($items);
|
||||
$searchResults->setTotalCount($collection->getSize());
|
||||
return $searchResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(CellTypeInterface $cellType)
|
||||
{
|
||||
try {
|
||||
$cellTypeModel = $this->cellTypeFactory->create();
|
||||
$this->resource->load($cellTypeModel, $cellType->getCelltypeId());
|
||||
$this->resource->delete($cellTypeModel);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotDeleteException(__(
|
||||
'Could not delete the CellType: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function deleteById($cellTypeId)
|
||||
{
|
||||
return $this->delete($this->get($cellTypeId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model;
|
||||
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
use Stemcell\Catalog\Api\Data\CryopreserveInterface;
|
||||
|
||||
class Cryopreserve extends AbstractModel implements CryopreserveInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function _construct()
|
||||
{
|
||||
$this->_init(\Stemcell\Catalog\Model\ResourceModel\Cryopreserve::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCryopreserveId()
|
||||
{
|
||||
return $this->getData(self::CRYOPRESERVE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSample()
|
||||
{
|
||||
return $this->getData(self::SAMPLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setSample($sample)
|
||||
{
|
||||
return $this->setData(self::SAMPLE, $sample);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->getData(self::TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setType($type)
|
||||
{
|
||||
return $this->setData(self::TYPE, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCellType()
|
||||
{
|
||||
return $this->getData(self::CELL_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCellType($cellType)
|
||||
{
|
||||
return $this->setData(self::CELL_TYPE, $cellType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getReferenceDensity()
|
||||
{
|
||||
return $this->getData(self::REFERENCE_DENSITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setReferenceDensity($referenceDensity)
|
||||
{
|
||||
return $this->setData(self::REFERENCE_DENSITY, $referenceDensity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getDesc()
|
||||
{
|
||||
return $this->getData(self::DESC);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setDesc($desc)
|
||||
{
|
||||
return $this->setData(self::DESC, $desc);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getReference()
|
||||
{
|
||||
return $this->getData(self::REFERENCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setReference($reference)
|
||||
{
|
||||
return $this->setData(self::REFERENCE, $reference);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
|
||||
use Magento\Framework\Exception\CouldNotDeleteException;
|
||||
use Magento\Framework\Exception\CouldNotSaveException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Stemcell\Catalog\Api\CryopreserveRepositoryInterface;
|
||||
use Stemcell\Catalog\Api\Data\CryopreserveInterface;
|
||||
use Stemcell\Catalog\Api\Data\CryopreserveInterfaceFactory;
|
||||
use Stemcell\Catalog\Api\Data\CryopreserveSearchResultsInterfaceFactory;
|
||||
use Stemcell\Catalog\Model\ResourceModel\Cryopreserve as ResourceCryopreserve;
|
||||
use Stemcell\Catalog\Model\ResourceModel\Cryopreserve\CollectionFactory as CryopreserveCollectionFactory;
|
||||
|
||||
class CryopreserveRepository implements CryopreserveRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var CryopreserveInterfaceFactory
|
||||
*/
|
||||
protected $cryopreserveFactory;
|
||||
|
||||
/**
|
||||
* @var Cryopreserve
|
||||
*/
|
||||
protected $searchResultsFactory;
|
||||
|
||||
/**
|
||||
* @var ResourceCryopreserve
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var CollectionProcessorInterface
|
||||
*/
|
||||
protected $collectionProcessor;
|
||||
|
||||
/**
|
||||
* @var CryopreserveCollectionFactory
|
||||
*/
|
||||
protected $cryopreserveCollectionFactory;
|
||||
|
||||
|
||||
/**
|
||||
* @param ResourceCryopreserve $resource
|
||||
* @param CryopreserveInterfaceFactory $cryopreserveFactory
|
||||
* @param CryopreserveCollectionFactory $cryopreserveCollectionFactory
|
||||
* @param CryopreserveSearchResultsInterfaceFactory $searchResultsFactory
|
||||
* @param CollectionProcessorInterface $collectionProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
ResourceCryopreserve $resource,
|
||||
CryopreserveInterfaceFactory $cryopreserveFactory,
|
||||
CryopreserveCollectionFactory $cryopreserveCollectionFactory,
|
||||
CryopreserveSearchResultsInterfaceFactory $searchResultsFactory,
|
||||
CollectionProcessorInterface $collectionProcessor
|
||||
) {
|
||||
$this->resource = $resource;
|
||||
$this->cryopreserveFactory = $cryopreserveFactory;
|
||||
$this->cryopreserveCollectionFactory = $cryopreserveCollectionFactory;
|
||||
$this->searchResultsFactory = $searchResultsFactory;
|
||||
$this->collectionProcessor = $collectionProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function save(CryopreserveInterface $cryopreserve)
|
||||
{
|
||||
try {
|
||||
$this->resource->save($cryopreserve);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotSaveException(__(
|
||||
'Could not save the cryopreserve: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return $cryopreserve;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get($cryopreserveId)
|
||||
{
|
||||
$cryopreserve = $this->cryopreserveFactory->create();
|
||||
$this->resource->load($cryopreserve, $cryopreserveId);
|
||||
if (!$cryopreserve->getId()) {
|
||||
throw new NoSuchEntityException(__('cryopreserve with id "%1" does not exist.', $cryopreserveId));
|
||||
}
|
||||
return $cryopreserve;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getList(
|
||||
\Magento\Framework\Api\SearchCriteriaInterface $criteria
|
||||
) {
|
||||
$collection = $this->cryopreserveCollectionFactory->create();
|
||||
|
||||
$this->collectionProcessor->process($criteria, $collection);
|
||||
|
||||
$searchResults = $this->searchResultsFactory->create();
|
||||
$searchResults->setSearchCriteria($criteria);
|
||||
|
||||
$items = [];
|
||||
foreach ($collection as $model) {
|
||||
$items[] = $model;
|
||||
}
|
||||
|
||||
$searchResults->setItems($items);
|
||||
$searchResults->setTotalCount($collection->getSize());
|
||||
return $searchResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(CryopreserveInterface $cryopreserve)
|
||||
{
|
||||
try {
|
||||
$cryopreserveModel = $this->cryopreserveFactory->create();
|
||||
$this->resource->load($cryopreserveModel, $cryopreserve->getCryopreserveId());
|
||||
$this->resource->delete($cryopreserveModel);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotDeleteException(__(
|
||||
'Could not delete the cryopreserve: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function deleteById($cryopreserveId)
|
||||
{
|
||||
return $this->delete($this->get($cryopreserveId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model;
|
||||
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
use Stemcell\Catalog\Api\Data\ExperimentalSchemeInterface;
|
||||
|
||||
class ExperimentalScheme extends AbstractModel implements ExperimentalSchemeInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function _construct()
|
||||
{
|
||||
$this->_init(\Stemcell\Catalog\Model\ResourceModel\ExperimentalScheme::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getExperimentalschemeId()
|
||||
{
|
||||
return $this->getData(self::EXPERIMENTALSCHEME_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCollectionName()
|
||||
{
|
||||
return $this->getData(self::COLLECTION_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setCollectionName(string $collectionName)
|
||||
{
|
||||
return $this->setData(self::COLLECTION_NAME, $collectionName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->getData(self::TITLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setTitle(string $title)
|
||||
{
|
||||
return $this->setData(self::TITLE, $title);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getImage()
|
||||
{
|
||||
return $this->getData(self::IMAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setImage(string $image)
|
||||
{
|
||||
return $this->setData(self::IMAGE, $image);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getMpUrl()
|
||||
{
|
||||
return $this->getData(self::MP_URL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setMpUrl(string $mpUrl)
|
||||
{
|
||||
return $this->setData(self::MP_URL, $mpUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getCollectionSort()
|
||||
{
|
||||
return $this->getData(self::COLLECTION_SORT);
|
||||
}
|
||||
|
||||
public function setCollectionSort(int $collectionSort)
|
||||
{
|
||||
return $this->setData(self::COLLECTION_SORT, $collectionSort);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
|
||||
use Magento\Framework\Exception\CouldNotDeleteException;
|
||||
use Magento\Framework\Exception\CouldNotSaveException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Stemcell\Catalog\Api\Data\ExperimentalSchemeInterface;
|
||||
use Stemcell\Catalog\Api\Data\ExperimentalSchemeInterfaceFactory;
|
||||
use Stemcell\Catalog\Api\Data\ExperimentalSchemeSearchResultsInterfaceFactory;
|
||||
use Stemcell\Catalog\Api\ExperimentalSchemeRepositoryInterface;
|
||||
use Stemcell\Catalog\Model\ResourceModel\ExperimentalScheme as ResourceExperimentalScheme;
|
||||
use Stemcell\Catalog\Model\ResourceModel\ExperimentalScheme\CollectionFactory as ExperimentalSchemeCollectionFactory;
|
||||
|
||||
class ExperimentalSchemeRepository implements ExperimentalSchemeRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ResourceExperimentalScheme
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var ExperimentalSchemeInterfaceFactory
|
||||
*/
|
||||
protected $experimentalSchemeFactory;
|
||||
|
||||
/**
|
||||
* @var ExperimentalSchemeCollectionFactory
|
||||
*/
|
||||
protected $experimentalSchemeCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var CollectionProcessorInterface
|
||||
*/
|
||||
protected $collectionProcessor;
|
||||
|
||||
/**
|
||||
* @var ExperimentalScheme
|
||||
*/
|
||||
protected $searchResultsFactory;
|
||||
|
||||
|
||||
/**
|
||||
* @param ResourceExperimentalScheme $resource
|
||||
* @param ExperimentalSchemeInterfaceFactory $experimentalSchemeFactory
|
||||
* @param ExperimentalSchemeCollectionFactory $experimentalSchemeCollectionFactory
|
||||
* @param ExperimentalSchemeSearchResultsInterfaceFactory $searchResultsFactory
|
||||
* @param CollectionProcessorInterface $collectionProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
ResourceExperimentalScheme $resource,
|
||||
ExperimentalSchemeInterfaceFactory $experimentalSchemeFactory,
|
||||
ExperimentalSchemeCollectionFactory $experimentalSchemeCollectionFactory,
|
||||
ExperimentalSchemeSearchResultsInterfaceFactory $searchResultsFactory,
|
||||
CollectionProcessorInterface $collectionProcessor
|
||||
) {
|
||||
$this->resource = $resource;
|
||||
$this->experimentalSchemeFactory = $experimentalSchemeFactory;
|
||||
$this->experimentalSchemeCollectionFactory = $experimentalSchemeCollectionFactory;
|
||||
$this->searchResultsFactory = $searchResultsFactory;
|
||||
$this->collectionProcessor = $collectionProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function save(
|
||||
ExperimentalSchemeInterface $experimentalScheme
|
||||
) {
|
||||
try {
|
||||
$this->resource->save($experimentalScheme);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotSaveException(__(
|
||||
'Could not save the experimentalScheme: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return $experimentalScheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get($experimentalSchemeId)
|
||||
{
|
||||
$experimentalScheme = $this->experimentalSchemeFactory->create();
|
||||
$this->resource->load($experimentalScheme, $experimentalSchemeId);
|
||||
if (!$experimentalScheme->getId()) {
|
||||
throw new NoSuchEntityException(__('ExperimentalScheme with id "%1" does not exist.', $experimentalSchemeId));
|
||||
}
|
||||
return $experimentalScheme;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getList(
|
||||
\Magento\Framework\Api\SearchCriteriaInterface $criteria
|
||||
) {
|
||||
$collection = $this->experimentalSchemeCollectionFactory->create();
|
||||
|
||||
$this->collectionProcessor->process($criteria, $collection);
|
||||
|
||||
$searchResults = $this->searchResultsFactory->create();
|
||||
$searchResults->setSearchCriteria($criteria);
|
||||
|
||||
$items = [];
|
||||
foreach ($collection as $model) {
|
||||
$items[] = $model;
|
||||
}
|
||||
|
||||
$searchResults->setItems($items);
|
||||
$searchResults->setTotalCount($collection->getSize());
|
||||
return $searchResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(
|
||||
ExperimentalSchemeInterface $experimentalScheme
|
||||
) {
|
||||
try {
|
||||
$experimentalSchemeModel = $this->experimentalSchemeFactory->create();
|
||||
$this->resource->load($experimentalSchemeModel, $experimentalScheme->getExperimentalschemeId());
|
||||
$this->resource->delete($experimentalSchemeModel);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotDeleteException(__(
|
||||
'Could not delete the ExperimentalScheme: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function deleteById($experimentalSchemeId)
|
||||
{
|
||||
return $this->delete($this->get($experimentalSchemeId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Model\Product\Gallery;
|
||||
|
||||
use Magento\Framework\Api\Data\ImageContentInterface;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
|
||||
/**
|
||||
* 重写\Magento\Catalog\Model\Product\Gallery\Processor的原因写在97行
|
||||
*/
|
||||
class Processor extends \Magento\Catalog\Model\Product\Gallery\Processor
|
||||
{
|
||||
protected \Magento\Framework\File\Mime $mime;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository,
|
||||
\Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDb,
|
||||
\Magento\Catalog\Model\Product\Media\Config $mediaConfig,
|
||||
\Magento\Framework\Filesystem $filesystem,
|
||||
\Magento\Catalog\Model\ResourceModel\Product\Gallery $resourceModel,
|
||||
\Magento\Framework\File\Mime $mime = null
|
||||
)
|
||||
{
|
||||
parent::__construct(
|
||||
$attributeRepository,
|
||||
$fileStorageDb,
|
||||
$mediaConfig,
|
||||
$filesystem,
|
||||
$resourceModel,
|
||||
$mime
|
||||
);
|
||||
$this->mime = $mime ?: ObjectManager::getInstance()->get(\Magento\Framework\File\Mime::class);
|
||||
}
|
||||
|
||||
public function addImage(
|
||||
\Magento\Catalog\Model\Product $product,
|
||||
$file,
|
||||
$mediaAttribute = null,
|
||||
$move = false,
|
||||
$exclude = true
|
||||
) {
|
||||
|
||||
$file = $this->mediaDirectory->getRelativePath($file);
|
||||
|
||||
if (!$this->mediaDirectory->isFile($file)) {
|
||||
throw new LocalizedException(__("The image $file doesn't exist."));
|
||||
}
|
||||
// if (PHP_SAPI === 'cli') {
|
||||
// echo 'Magento\Catalog\Model\Product\Gallery\Processor argument $file: ' .$file . PHP_EOL;
|
||||
// echo 'Magento\Catalog\Model\Product\Gallery\Processor $file = $this->mediaDirectory->getRelativePath($file): ' .$file . PHP_EOL;
|
||||
// }
|
||||
// phpcs:ignore Magento2.Functions.DiscouragedFunction
|
||||
$pathinfo = pathinfo($file);
|
||||
$imgExtensions = ['jpg', 'jpeg', 'gif', 'png'];
|
||||
if (!isset($pathinfo['extension']) || !in_array(strtolower($pathinfo['extension']), $imgExtensions)) {
|
||||
throw new LocalizedException(
|
||||
__('The image type for the file is invalid. Enter the correct image type and try again.')
|
||||
);
|
||||
}
|
||||
|
||||
$fileName = \Magento\MediaStorage\Model\File\Uploader::getCorrectFileName($pathinfo['basename']);
|
||||
$dispersionPath = \Magento\MediaStorage\Model\File\Uploader::getDispersionPath($fileName);
|
||||
$fileName = $dispersionPath . '/' . $fileName;
|
||||
|
||||
$fileName = $this->getNotDuplicatedFilename($fileName, $dispersionPath);
|
||||
|
||||
$destinationFile = $this->mediaConfig->getTmpMediaPath($fileName);
|
||||
|
||||
try {
|
||||
/** @var $storageHelper \Magento\MediaStorage\Helper\File\Storage\Database */
|
||||
$storageHelper = $this->fileStorageDb;
|
||||
if ($move) {
|
||||
$this->mediaDirectory->renameFile($file, $destinationFile);
|
||||
|
||||
//If this is used, filesystem should be configured properly
|
||||
$storageHelper->saveFile($this->mediaConfig->getTmpMediaShortUrl($fileName));
|
||||
} else {
|
||||
$this->mediaDirectory->copyFile($file, $destinationFile);
|
||||
|
||||
$storageHelper->saveFile($this->mediaConfig->getTmpMediaShortUrl($fileName));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw new LocalizedException(__('The "%1" file couldn\'t be moved.', $e->getMessage()));
|
||||
}
|
||||
|
||||
$fileName = str_replace('\\', '/', $fileName);
|
||||
|
||||
$attrCode = $this->getAttribute()->getAttributeCode();
|
||||
$mediaGalleryData = $product->getData($attrCode);
|
||||
$position = 0;
|
||||
|
||||
$absoluteFilePath = $this->mediaDirectory->getAbsolutePath($destinationFile);
|
||||
$imageMimeType = $this->mime->getMimeType($absoluteFilePath);
|
||||
$imageContent = $this->mediaDirectory->readFile($absoluteFilePath);
|
||||
$imageBase64 = base64_encode($imageContent);
|
||||
/**
|
||||
* 这是Magento 2.4.7的原始代码,
|
||||
* 修改这个代码的原因是因为调用Magento\Catalog\Model\Product::addImageToMediaGallery()后,
|
||||
* 代码走到这里,filename不带extension(.jpg, .png),
|
||||
* 会导致\Magento\Framework\File\Uploader if (!$this->checkAllowedExtension($this->getFileExtension()))
|
||||
* 的$this->getFileExtension()拿到的是空
|
||||
*/
|
||||
$imageName = $pathinfo['filename'];
|
||||
if (empty(pathinfo($imageName, PATHINFO_EXTENSION))) {
|
||||
$imageName = $pathinfo['basename'];
|
||||
}
|
||||
|
||||
|
||||
if (!is_array($mediaGalleryData)) {
|
||||
$mediaGalleryData = ['images' => []];
|
||||
}
|
||||
|
||||
foreach ($mediaGalleryData['images'] as &$image) {
|
||||
if (isset($image['position']) && $image['position'] > $position) {
|
||||
$position = $image['position'];
|
||||
}
|
||||
}
|
||||
|
||||
$position++;
|
||||
$mediaGalleryData['images'][] = [
|
||||
'file' => $fileName,
|
||||
'position' => $position,
|
||||
'label' => '',
|
||||
'disabled' => (int)$exclude,
|
||||
'media_type' => 'image',
|
||||
'types' => $mediaAttribute,
|
||||
'content' => [
|
||||
'data' => [
|
||||
ImageContentInterface::NAME => $imageName,
|
||||
ImageContentInterface::BASE64_ENCODED_DATA => $imageBase64,
|
||||
ImageContentInterface::TYPE => $imageMimeType,
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$product->setData($attrCode, $mediaGalleryData);
|
||||
|
||||
if ($mediaAttribute !== null) {
|
||||
$this->setMediaAttribute($product, $mediaAttribute, $fileName);
|
||||
}
|
||||
|
||||
return $fileName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model;
|
||||
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
use Stemcell\Catalog\Api\Data\ProductManualSearchInterface;
|
||||
|
||||
class ProductManualSearch extends AbstractModel implements ProductManualSearchInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function _construct()
|
||||
{
|
||||
$this->_init(\Stemcell\Catalog\Model\ResourceModel\ProductManualSearch::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSearchId()
|
||||
{
|
||||
return $this->getData(self::SEARCH_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setSearchId($searchId)
|
||||
{
|
||||
return $this->setData(self::SEARCH_ID, $searchId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->getData(self::NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
return $this->setData(self::NAME, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSku()
|
||||
{
|
||||
return $this->getData(self::SKU);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setSku($sku)
|
||||
{
|
||||
return $this->setData(self::SKU, $sku);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSearchSku()
|
||||
{
|
||||
return $this->getData(self::SEARCH_SKU);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setSearchSku($searchSku)
|
||||
{
|
||||
return $this->setData(self::SEARCH_SKU, $searchSku);
|
||||
}
|
||||
|
||||
public function getSearchSkusByKeyword(string $keyword)
|
||||
{
|
||||
$keyword = trim($keyword);
|
||||
$sql = "SELECT DISTINCT search_sku
|
||||
FROM product_manual_search
|
||||
WHERE sku = '$keyword'
|
||||
OR MATCH(name) AGAINST('$keyword' IN BOOLEAN MODE)";
|
||||
|
||||
$result = $this->getResource()->getConnection()->fetchAll($sql);
|
||||
return array_column($result, 'search_sku');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
|
||||
use Magento\Framework\Exception\CouldNotDeleteException;
|
||||
use Magento\Framework\Exception\CouldNotSaveException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Stemcell\Catalog\Api\Data\ProductManualSearchInterface;
|
||||
use Stemcell\Catalog\Api\Data\ProductManualSearchInterfaceFactory;
|
||||
use Stemcell\Catalog\Api\Data\ProductManualSearchSearchResultsInterfaceFactory;
|
||||
use Stemcell\Catalog\Api\ProductManualSearchRepositoryInterface;
|
||||
use Stemcell\Catalog\Model\ResourceModel\ProductManualSearch as ResourceProductManualSearch;
|
||||
use Stemcell\Catalog\Model\ResourceModel\ProductManualSearch\CollectionFactory as ProductManualSearchCollectionFactory;
|
||||
|
||||
class ProductManualSearchRepository implements ProductManualSearchRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ProductManualSearchCollectionFactory
|
||||
*/
|
||||
protected $productManualSearchCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var ResourceProductManualSearch
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var ProductManualSearchInterfaceFactory
|
||||
*/
|
||||
protected $productManualSearchFactory;
|
||||
|
||||
/**
|
||||
* @var CollectionProcessorInterface
|
||||
*/
|
||||
protected $collectionProcessor;
|
||||
|
||||
/**
|
||||
* @var ProductManualSearch
|
||||
*/
|
||||
protected $searchResultsFactory;
|
||||
|
||||
|
||||
/**
|
||||
* @param ResourceProductManualSearch $resource
|
||||
* @param ProductManualSearchInterfaceFactory $productManualSearchFactory
|
||||
* @param ProductManualSearchCollectionFactory $productManualSearchCollectionFactory
|
||||
* @param ProductManualSearchSearchResultsInterfaceFactory $searchResultsFactory
|
||||
* @param CollectionProcessorInterface $collectionProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
ResourceProductManualSearch $resource,
|
||||
ProductManualSearchInterfaceFactory $productManualSearchFactory,
|
||||
ProductManualSearchCollectionFactory $productManualSearchCollectionFactory,
|
||||
ProductManualSearchSearchResultsInterfaceFactory $searchResultsFactory,
|
||||
CollectionProcessorInterface $collectionProcessor
|
||||
) {
|
||||
$this->resource = $resource;
|
||||
$this->productManualSearchFactory = $productManualSearchFactory;
|
||||
$this->productManualSearchCollectionFactory = $productManualSearchCollectionFactory;
|
||||
$this->searchResultsFactory = $searchResultsFactory;
|
||||
$this->collectionProcessor = $collectionProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function save(
|
||||
ProductManualSearchInterface $productManualSearch
|
||||
) {
|
||||
try {
|
||||
$this->resource->save($productManualSearch);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotSaveException(__(
|
||||
'Could not save the productManualSearch: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return $productManualSearch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get($productManualSearchId)
|
||||
{
|
||||
$productManualSearch = $this->productManualSearchFactory->create();
|
||||
$this->resource->load($productManualSearch, $productManualSearchId);
|
||||
if (!$productManualSearch->getId()) {
|
||||
throw new NoSuchEntityException(__('ProductManualSearch with id "%1" does not exist.', $productManualSearchId));
|
||||
}
|
||||
return $productManualSearch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getList(
|
||||
\Magento\Framework\Api\SearchCriteriaInterface $criteria
|
||||
) {
|
||||
$collection = $this->productManualSearchCollectionFactory->create();
|
||||
|
||||
$this->collectionProcessor->process($criteria, $collection);
|
||||
|
||||
$searchResults = $this->searchResultsFactory->create();
|
||||
$searchResults->setSearchCriteria($criteria);
|
||||
|
||||
$items = [];
|
||||
foreach ($collection as $model) {
|
||||
$items[] = $model;
|
||||
}
|
||||
|
||||
$searchResults->setItems($items);
|
||||
$searchResults->setTotalCount($collection->getSize());
|
||||
return $searchResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(
|
||||
ProductManualSearchInterface $productManualSearch
|
||||
) {
|
||||
try {
|
||||
$productManualSearchModel = $this->productManualSearchFactory->create();
|
||||
$this->resource->load($productManualSearchModel, $productManualSearch->getProductmanualsearchId());
|
||||
$this->resource->delete($productManualSearchModel);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotDeleteException(__(
|
||||
'Could not delete the ProductManualSearch: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function deleteById($productManualSearchId)
|
||||
{
|
||||
return $this->delete($this->get($productManualSearchId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model\ResourceModel;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
|
||||
class CellSort extends AbstractDb
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('cell_sort_product', 'cell_sort_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model\ResourceModel\CellSort;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
|
||||
|
||||
class Collection extends AbstractCollection
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected $_idFieldName = 'cellsort_id';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(
|
||||
\Stemcell\Catalog\Model\CellSort::class,
|
||||
\Stemcell\Catalog\Model\ResourceModel\CellSort::class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model\ResourceModel;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
|
||||
class CellSubType extends AbstractDb
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('cell_sort_cell_subtype', 'cell_subtype_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model\ResourceModel\CellSubType;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
|
||||
|
||||
class Collection extends AbstractCollection
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected $_idFieldName = 'cell_subtype_id';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(
|
||||
\Stemcell\Catalog\Model\CellSubType::class,
|
||||
\Stemcell\Catalog\Model\ResourceModel\CellSubType::class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model\ResourceModel;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
|
||||
class CellType extends AbstractDb
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('cell_sort_cell_type', 'cell_type_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model\ResourceModel\CellType;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
|
||||
|
||||
class Collection extends AbstractCollection
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected $_idFieldName = 'celltype_id';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(
|
||||
\Stemcell\Catalog\Model\CellType::class,
|
||||
\Stemcell\Catalog\Model\ResourceModel\CellType::class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model\ResourceModel;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
|
||||
class Cryopreserve extends AbstractDb
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('cryopreserve', 'cryopreserve_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model\ResourceModel\Cryopreserve;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
|
||||
|
||||
class Collection extends AbstractCollection
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected $_idFieldName = 'cryopreserve_id';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(
|
||||
\Stemcell\Catalog\Model\Cryopreserve::class,
|
||||
\Stemcell\Catalog\Model\ResourceModel\Cryopreserve::class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model\ResourceModel;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
|
||||
class ExperimentalScheme extends AbstractDb
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('experimental_scheme', 'experimental_scheme_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model\ResourceModel\ExperimentalScheme;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
|
||||
|
||||
class Collection extends AbstractCollection
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected $_idFieldName = 'experimental_scheme_id';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(
|
||||
\Stemcell\Catalog\Model\ExperimentalScheme::class,
|
||||
\Stemcell\Catalog\Model\ResourceModel\ExperimentalScheme::class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model\ResourceModel;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
|
||||
class ProductManualSearch extends AbstractDb
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('product_manual_search', 'search_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model\ResourceModel\ProductManualSearch;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
|
||||
|
||||
class Collection extends AbstractCollection
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected $_idFieldName = 'search_id';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(
|
||||
\Stemcell\Catalog\Model\ProductManualSearch::class,
|
||||
\Stemcell\Catalog\Model\ResourceModel\ProductManualSearch::class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model\ResourceModel;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
|
||||
class Species extends AbstractDb
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('cell_sort_species', 'species_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model\ResourceModel\Species;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
|
||||
|
||||
class Collection extends AbstractCollection
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected $_idFieldName = 'species_id';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(
|
||||
\Stemcell\Catalog\Model\Species::class,
|
||||
\Stemcell\Catalog\Model\ResourceModel\Species::class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model\ResourceModel;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
|
||||
|
||||
class Tissue extends AbstractDb
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init('cell_sort_tissue', 'tissue_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model\ResourceModel\Tissue;
|
||||
|
||||
use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
|
||||
|
||||
class Collection extends AbstractCollection
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected $_idFieldName = 'tissue_id';
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_init(
|
||||
\Stemcell\Catalog\Model\Tissue::class,
|
||||
\Stemcell\Catalog\Model\ResourceModel\Tissue::class
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Model\Source;
|
||||
|
||||
use Magento\Framework\Data\OptionSourceInterface;
|
||||
|
||||
class TaskStatus implements OptionSourceInterface
|
||||
{
|
||||
public function toOptionArray()
|
||||
{
|
||||
return [
|
||||
['value' => 'pending', 'label' => __('等待处理')],
|
||||
['value' => 'processing', 'label' => __('处理中')],
|
||||
['value' => 'success', 'label' => __('导入成功')],
|
||||
['value' => 'failed', 'label' => __('导入失败')],
|
||||
];
|
||||
}
|
||||
}
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model;
|
||||
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
use Stemcell\Catalog\Api\Data\SpeciesInterface;
|
||||
|
||||
class Species extends AbstractModel implements SpeciesInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function _construct()
|
||||
{
|
||||
$this->_init(\Stemcell\Catalog\Model\ResourceModel\Species::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSpeciesId()
|
||||
{
|
||||
return $this->getData(self::SPECIES_ID);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getSpeciesName()
|
||||
{
|
||||
return $this->getData(self::SPECIES_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setSpeciesName($speciesName)
|
||||
{
|
||||
return $this->setData(self::SPECIES_NAME, $speciesName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
|
||||
use Magento\Framework\Exception\CouldNotDeleteException;
|
||||
use Magento\Framework\Exception\CouldNotSaveException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Stemcell\Catalog\Api\Data\SpeciesInterface;
|
||||
use Stemcell\Catalog\Api\Data\SpeciesInterfaceFactory;
|
||||
use Stemcell\Catalog\Api\Data\SpeciesSearchResultsInterfaceFactory;
|
||||
use Stemcell\Catalog\Api\SpeciesRepositoryInterface;
|
||||
use Stemcell\Catalog\Model\ResourceModel\Species as ResourceSpecies;
|
||||
use Stemcell\Catalog\Model\ResourceModel\Species\CollectionFactory as SpeciesCollectionFactory;
|
||||
|
||||
class SpeciesRepository implements SpeciesRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var SpeciesInterfaceFactory
|
||||
*/
|
||||
protected $speciesFactory;
|
||||
|
||||
/**
|
||||
* @var CollectionProcessorInterface
|
||||
*/
|
||||
protected $collectionProcessor;
|
||||
|
||||
/**
|
||||
* @var ResourceSpecies
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var SpeciesCollectionFactory
|
||||
*/
|
||||
protected $speciesCollectionFactory;
|
||||
|
||||
/**
|
||||
* @var Species
|
||||
*/
|
||||
protected $searchResultsFactory;
|
||||
|
||||
|
||||
/**
|
||||
* @param ResourceSpecies $resource
|
||||
* @param SpeciesInterfaceFactory $speciesFactory
|
||||
* @param SpeciesCollectionFactory $speciesCollectionFactory
|
||||
* @param SpeciesSearchResultsInterfaceFactory $searchResultsFactory
|
||||
* @param CollectionProcessorInterface $collectionProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
ResourceSpecies $resource,
|
||||
SpeciesInterfaceFactory $speciesFactory,
|
||||
SpeciesCollectionFactory $speciesCollectionFactory,
|
||||
SpeciesSearchResultsInterfaceFactory $searchResultsFactory,
|
||||
CollectionProcessorInterface $collectionProcessor
|
||||
) {
|
||||
$this->resource = $resource;
|
||||
$this->speciesFactory = $speciesFactory;
|
||||
$this->speciesCollectionFactory = $speciesCollectionFactory;
|
||||
$this->searchResultsFactory = $searchResultsFactory;
|
||||
$this->collectionProcessor = $collectionProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function save(SpeciesInterface $species)
|
||||
{
|
||||
try {
|
||||
$this->resource->save($species);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotSaveException(__(
|
||||
'Could not save the species: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return $species;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get($speciesId)
|
||||
{
|
||||
$species = $this->speciesFactory->create();
|
||||
$this->resource->load($species, $speciesId);
|
||||
if (!$species->getId()) {
|
||||
throw new NoSuchEntityException(__('Species with id "%1" does not exist.', $speciesId));
|
||||
}
|
||||
return $species;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getList(
|
||||
\Magento\Framework\Api\SearchCriteriaInterface $criteria
|
||||
) {
|
||||
$collection = $this->speciesCollectionFactory->create();
|
||||
|
||||
$this->collectionProcessor->process($criteria, $collection);
|
||||
|
||||
$searchResults = $this->searchResultsFactory->create();
|
||||
$searchResults->setSearchCriteria($criteria);
|
||||
|
||||
$items = [];
|
||||
foreach ($collection as $model) {
|
||||
$items[] = $model;
|
||||
}
|
||||
|
||||
$searchResults->setItems($items);
|
||||
$searchResults->setTotalCount($collection->getSize());
|
||||
return $searchResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(SpeciesInterface $species)
|
||||
{
|
||||
try {
|
||||
$speciesModel = $this->speciesFactory->create();
|
||||
$this->resource->load($speciesModel, $species->getSpeciesId());
|
||||
$this->resource->delete($speciesModel);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotDeleteException(__(
|
||||
'Could not delete the Species: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function deleteById($speciesId)
|
||||
{
|
||||
return $this->delete($this->get($speciesId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model;
|
||||
|
||||
use Magento\Framework\Model\AbstractModel;
|
||||
use Stemcell\Catalog\Api\Data\TissueInterface;
|
||||
|
||||
class Tissue extends AbstractModel implements TissueInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function _construct()
|
||||
{
|
||||
$this->_init(\Stemcell\Catalog\Model\ResourceModel\Tissue::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTissueId()
|
||||
{
|
||||
return $this->getData(self::TISSUE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTissueName()
|
||||
{
|
||||
return $this->getData(self::TISSUE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setTissueName($tissueName)
|
||||
{
|
||||
return $this->setData(self::TISSUE_NAME, $tissueName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stemcell\Catalog\Model;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
|
||||
use Magento\Framework\Exception\CouldNotDeleteException;
|
||||
use Magento\Framework\Exception\CouldNotSaveException;
|
||||
use Magento\Framework\Exception\NoSuchEntityException;
|
||||
use Stemcell\Catalog\Api\Data\TissueInterface;
|
||||
use Stemcell\Catalog\Api\Data\TissueInterfaceFactory;
|
||||
use Stemcell\Catalog\Api\Data\TissueSearchResultsInterfaceFactory;
|
||||
use Stemcell\Catalog\Api\TissueRepositoryInterface;
|
||||
use Stemcell\Catalog\Model\ResourceModel\Tissue as ResourceTissue;
|
||||
use Stemcell\Catalog\Model\ResourceModel\Tissue\CollectionFactory as TissueCollectionFactory;
|
||||
|
||||
class TissueRepository implements TissueRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var TissueInterfaceFactory
|
||||
*/
|
||||
protected $tissueFactory;
|
||||
|
||||
/**
|
||||
* @var Tissue
|
||||
*/
|
||||
protected $searchResultsFactory;
|
||||
|
||||
/**
|
||||
* @var CollectionProcessorInterface
|
||||
*/
|
||||
protected $collectionProcessor;
|
||||
|
||||
/**
|
||||
* @var ResourceTissue
|
||||
*/
|
||||
protected $resource;
|
||||
|
||||
/**
|
||||
* @var TissueCollectionFactory
|
||||
*/
|
||||
protected $tissueCollectionFactory;
|
||||
|
||||
|
||||
/**
|
||||
* @param ResourceTissue $resource
|
||||
* @param TissueInterfaceFactory $tissueFactory
|
||||
* @param TissueCollectionFactory $tissueCollectionFactory
|
||||
* @param TissueSearchResultsInterfaceFactory $searchResultsFactory
|
||||
* @param CollectionProcessorInterface $collectionProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
ResourceTissue $resource,
|
||||
TissueInterfaceFactory $tissueFactory,
|
||||
TissueCollectionFactory $tissueCollectionFactory,
|
||||
TissueSearchResultsInterfaceFactory $searchResultsFactory,
|
||||
CollectionProcessorInterface $collectionProcessor
|
||||
) {
|
||||
$this->resource = $resource;
|
||||
$this->tissueFactory = $tissueFactory;
|
||||
$this->tissueCollectionFactory = $tissueCollectionFactory;
|
||||
$this->searchResultsFactory = $searchResultsFactory;
|
||||
$this->collectionProcessor = $collectionProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function save(TissueInterface $tissue)
|
||||
{
|
||||
try {
|
||||
$this->resource->save($tissue);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotSaveException(__(
|
||||
'Could not save the tissue: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return $tissue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get($tissueId)
|
||||
{
|
||||
$tissue = $this->tissueFactory->create();
|
||||
$this->resource->load($tissue, $tissueId);
|
||||
if (!$tissue->getId()) {
|
||||
throw new NoSuchEntityException(__('Tissue with id "%1" does not exist.', $tissueId));
|
||||
}
|
||||
return $tissue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getList(
|
||||
\Magento\Framework\Api\SearchCriteriaInterface $criteria
|
||||
) {
|
||||
$collection = $this->tissueCollectionFactory->create();
|
||||
|
||||
$this->collectionProcessor->process($criteria, $collection);
|
||||
|
||||
$searchResults = $this->searchResultsFactory->create();
|
||||
$searchResults->setSearchCriteria($criteria);
|
||||
|
||||
$items = [];
|
||||
foreach ($collection as $model) {
|
||||
$items[] = $model;
|
||||
}
|
||||
|
||||
$searchResults->setItems($items);
|
||||
$searchResults->setTotalCount($collection->getSize());
|
||||
return $searchResults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(TissueInterface $tissue)
|
||||
{
|
||||
try {
|
||||
$tissueModel = $this->tissueFactory->create();
|
||||
$this->resource->load($tissueModel, $tissue->getTissueId());
|
||||
$this->resource->delete($tissueModel);
|
||||
} catch (\Exception $exception) {
|
||||
throw new CouldNotDeleteException(__(
|
||||
'Could not delete the Tissue: %1',
|
||||
$exception->getMessage()
|
||||
));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function deleteById($tissueId)
|
||||
{
|
||||
return $this->delete($this->get($tissueId));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user