init
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Controller\Adminhtml\Price;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
class Import extends \Magento\Backend\App\Action implements HttpGetActionInterface
|
||||
{
|
||||
const ADMIN_RESOURCE = 'Stemcell_Catalog::catalog_index';
|
||||
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
protected PageFactory $resultPageFactory
|
||||
)
|
||||
{
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute view action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
return $this->resultPageFactory->create();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Controller\Adminhtml\Price;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\ResourceModel\Product\Collection;
|
||||
use Magento\CatalogInventory\Api\StockRegistryInterface;
|
||||
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableProductType;
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface;
|
||||
use Magento\Framework\Controller\ResultFactory;
|
||||
use Magento\Framework\Exception\FileSystemException;
|
||||
use Magento\Framework\Filesystem\Driver\File;
|
||||
use Magento\Framework\Module\Dir;
|
||||
use Magento\InventoryApi\Api\Data\SourceItemInterfaceFactory;
|
||||
use Magento\InventoryApi\Api\SourceItemsSaveInterface;
|
||||
use Magento\MediaStorage\Model\File\UploaderFactory;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Stemcell\ProductImport\Model\Import\TypeId;
|
||||
use Stemcell\ProductImport\Model\ImportTaskFactory;
|
||||
use Magento\Indexer\Model\Indexer\CollectionFactory as IndexerCollectionFactory;
|
||||
use Stemcell\ProductImport\Model\ResourceModel\ImportTask as ImportTaskResource;
|
||||
|
||||
/**
|
||||
* 由于生产服务器是两台,只有media目录是两台服务器共享,因此将文件上传到media下面
|
||||
*/
|
||||
class ImportPost extends \Magento\Backend\App\Action implements HttpPostActionInterface
|
||||
{
|
||||
private UploaderFactory $fileUploaderFactory;
|
||||
private Filesystem\Directory\WriteInterface $mediaDirectory;
|
||||
|
||||
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
UploaderFactory $fileUploaderFactory,
|
||||
Filesystem $filesystem,
|
||||
File $driverFile,
|
||||
protected ProductRepositoryInterface $productRepository,
|
||||
protected LoggerInterface $logger,
|
||||
protected Collection $collection,
|
||||
protected Dir $dir,
|
||||
protected SourceItemsSaveInterface $sourceItemsSave,
|
||||
protected SourceItemInterfaceFactory $sourceItemFactory,
|
||||
protected ConfigurableProductType $configurableProductType,
|
||||
protected StockRegistryInterface $stockRegistry,
|
||||
protected IndexerCollectionFactory $indexerCollectionFactory,
|
||||
protected ImportTaskFactory $importTaskFactory,
|
||||
protected ImportTaskResource $importTaskResource,
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->fileUploaderFactory = $fileUploaderFactory;
|
||||
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
try {
|
||||
$fileUploader = $this->fileUploaderFactory->create([
|
||||
'fileId' => 'stock[import]'
|
||||
]);
|
||||
|
||||
$fileUploader->setAllowedExtensions(['xls', 'xlsx']);
|
||||
$fileUploader->setAllowRenameFiles(true);
|
||||
$fileUploader->setAllowCreateFolders(true);
|
||||
$fileUploader->setFilesDispersion(false);
|
||||
|
||||
$dir = $this->mediaDirectory->getAbsolutePath(DirectoryList::VAR_IMPORT_EXPORT.'/stock');
|
||||
!is_dir($dir) && mkdir($dir, 0755, true);
|
||||
$fileUploader->save($dir);
|
||||
$importTask = $this->importTaskFactory->create()->setData([
|
||||
'file_path' => $dir.'/'.$fileUploader->getUploadedFileName(),
|
||||
'type_id' => TypeId::PRICE->value,
|
||||
]);
|
||||
|
||||
$this->importTaskResource->save($importTask);
|
||||
$this->messageManager->addSuccessMessage(__('产品价格导入任务创建成功.'));
|
||||
return $this->resultRedirectFactory->create()->setPath('stemcell_catalog/price/index');
|
||||
} catch (LocalizedException | \Exception $error) {
|
||||
$this->logger->critical($error);
|
||||
$this->messageManager->addErrorMessage('产品价格导入任务创建失败. 原因:'.$error->getMessage());
|
||||
return $this->resultRedirectFactory->create()->setPath('stemcell_catalog/price/import');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Controller\Adminhtml\Price;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
class Index extends \Magento\Backend\App\Action implements HttpGetActionInterface
|
||||
{
|
||||
const ADMIN_RESOURCE = 'Stemcell_Catalog::catalog_index';
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
protected PageFactory $resultPageFactory
|
||||
)
|
||||
{
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute view action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
return $this->resultPageFactory->create();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Controller\Adminhtml\Price;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
|
||||
class Sample extends \Magento\Backend\App\Action implements HttpGetActionInterface
|
||||
{
|
||||
protected \Magento\Framework\App\Response\Http\FileFactory $fileFactory;
|
||||
private \Magento\Framework\Module\Dir $moduleDir;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
|
||||
\Magento\Framework\Module\Dir $moduleDir,
|
||||
Context $context
|
||||
) {
|
||||
$this->fileFactory = $fileFactory;
|
||||
$this->moduleDir = $moduleDir;
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$file = $this->moduleDir->getDir('Stemcell_Catalog').'/data/sample/price.xlsx';
|
||||
$content['type'] = 'filename';
|
||||
$content['value'] = $file;
|
||||
$content['rm'] = 0;
|
||||
return $this->fileFactory->create('price.xlsx', $content);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Controller\Adminhtml\Stock;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
class Import extends \Magento\Backend\App\Action implements HttpGetActionInterface
|
||||
{
|
||||
const ADMIN_RESOURCE = 'Stemcell_Catalog::catalog_index';
|
||||
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
protected PageFactory $resultPageFactory
|
||||
)
|
||||
{
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute view action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
return $this->resultPageFactory->create();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Controller\Adminhtml\Stock;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Catalog\Api\ProductRepositoryInterface;
|
||||
use Magento\Catalog\Model\ResourceModel\Product\Collection;
|
||||
use Magento\CatalogInventory\Api\StockRegistryInterface;
|
||||
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableProductType;
|
||||
use Magento\Framework\App\Action\HttpPostActionInterface;
|
||||
use Magento\Framework\Controller\ResultFactory;
|
||||
use Magento\Framework\Exception\FileSystemException;
|
||||
use Magento\Framework\Filesystem\Driver\File;
|
||||
use Magento\Framework\Module\Dir;
|
||||
use Magento\InventoryApi\Api\Data\SourceItemInterfaceFactory;
|
||||
use Magento\InventoryApi\Api\SourceItemsSaveInterface;
|
||||
use Magento\MediaStorage\Model\File\UploaderFactory;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Stemcell\ProductImport\Model\Import\TypeId;
|
||||
use Stemcell\ProductImport\Model\ImportTaskFactory;
|
||||
use Magento\Indexer\Model\Indexer\CollectionFactory as IndexerCollectionFactory;
|
||||
use Stemcell\ProductImport\Model\ResourceModel\ImportTask as ImportTaskResource;
|
||||
|
||||
/**
|
||||
* 由于生产服务器是两台,只有media目录是两台服务器共享,因此将文件上传到media下面
|
||||
*/
|
||||
class ImportPost extends \Magento\Backend\App\Action implements HttpPostActionInterface
|
||||
{
|
||||
private UploaderFactory $fileUploaderFactory;
|
||||
private Filesystem\Directory\WriteInterface $mediaDirectory;
|
||||
|
||||
|
||||
/**
|
||||
* @throws FileSystemException
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
UploaderFactory $fileUploaderFactory,
|
||||
Filesystem $filesystem,
|
||||
File $driverFile,
|
||||
protected ProductRepositoryInterface $productRepository,
|
||||
protected LoggerInterface $logger,
|
||||
protected Collection $collection,
|
||||
protected Dir $dir,
|
||||
protected SourceItemsSaveInterface $sourceItemsSave,
|
||||
protected SourceItemInterfaceFactory $sourceItemFactory,
|
||||
protected ConfigurableProductType $configurableProductType,
|
||||
protected StockRegistryInterface $stockRegistry,
|
||||
protected IndexerCollectionFactory $indexerCollectionFactory,
|
||||
protected ImportTaskFactory $importTaskFactory,
|
||||
protected ImportTaskResource $importTaskResource,
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->fileUploaderFactory = $fileUploaderFactory;
|
||||
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$jsonResult = $this->resultFactory->create(ResultFactory::TYPE_JSON);
|
||||
try {
|
||||
$fileUploader = $this->fileUploaderFactory->create([
|
||||
'fileId' => 'stock[import]'
|
||||
]);
|
||||
|
||||
$fileUploader->setAllowedExtensions(['xls', 'xlsx']);
|
||||
$fileUploader->setAllowRenameFiles(true);
|
||||
$fileUploader->setAllowCreateFolders(true);
|
||||
$fileUploader->setFilesDispersion(false);
|
||||
|
||||
$dir = $this->mediaDirectory->getAbsolutePath(DirectoryList::VAR_IMPORT_EXPORT.'/stock');
|
||||
!is_dir($dir) && mkdir($dir, 0755, true);
|
||||
$fileUploader->save($dir);
|
||||
$importTask = $this->importTaskFactory->create()->setData([
|
||||
'file_path' => $dir.'/'.$fileUploader->getUploadedFileName(),
|
||||
'type_id' => $this->_request->getParam('type_id', TypeId::STOCK->value),
|
||||
]);
|
||||
|
||||
$this->importTaskResource->save($importTask);
|
||||
$this->messageManager->addSuccessMessage(__('库存导入任务创建成功.'));
|
||||
return $this->resultRedirectFactory->create()->setPath('stemcell_catalog/stock/index');
|
||||
} catch (LocalizedException | \Exception $error) {
|
||||
$this->logger->critical($error);
|
||||
$this->messageManager->addErrorMessage('库存导入任务创建失败. 原因:'.$error->getMessage());
|
||||
return $this->resultRedirectFactory->create()->setPath('stemcell_catalog/stock/import');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Controller\Adminhtml\Stock;
|
||||
|
||||
use Magento\Backend\App\Action\Context;
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
use Magento\Framework\Controller\ResultInterface;
|
||||
use Magento\Framework\View\Result\PageFactory;
|
||||
|
||||
class Index extends \Magento\Backend\App\Action implements HttpGetActionInterface
|
||||
{
|
||||
const ADMIN_RESOURCE = 'Stemcell_Catalog::catalog_index';
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
protected PageFactory $resultPageFactory
|
||||
)
|
||||
{
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute view action
|
||||
*
|
||||
* @return ResultInterface
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
return $this->resultPageFactory->create();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Catalog\Controller\Adminhtml\Stock;
|
||||
|
||||
use Magento\Framework\App\Action\HttpGetActionInterface;
|
||||
|
||||
class Sample extends \Magento\Backend\App\Action implements HttpGetActionInterface
|
||||
{
|
||||
protected \Magento\Framework\App\Response\Http\FileFactory $fileFactory;
|
||||
private \Magento\Framework\Module\Dir $moduleDir;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Framework\App\Response\Http\FileFactory $fileFactory,
|
||||
\Magento\Framework\Module\Dir $moduleDir,
|
||||
\Magento\Backend\App\Action\Context $context
|
||||
) {
|
||||
$this->fileFactory = $fileFactory;
|
||||
$this->moduleDir = $moduleDir;
|
||||
parent::__construct($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$file = $this->moduleDir->getDir('Stemcell_Catalog').'/data/sample/stock.xlsx';
|
||||
$content['type'] = 'filename';
|
||||
$content['value'] = $file;
|
||||
$content['rm'] = 0;
|
||||
return $this->fileFactory->create('stock.xlsx', $content);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user