-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
no central "export" function anymore #134
Comments
May be something like this: class ExportService
{
protected $storeManager;
protected $storeEmulation;
protected $channelProvider;
protected $csvFactory;
protected $feedFactory;
protected $ftpUploader;
protected $pushImport;
protected $feedType;
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Omikron\Factfinder\Model\StoreEmulation $storeEmulation,
\Omikron\Factfinder\Api\Config\ChannelProviderInterface $channelProvider,
\Omikron\Factfinder\Model\Stream\CsvFactory $csvFactory,
\Omikron\Factfinder\Model\Export\FeedFactory $feedFactory,
\Omikron\Factfinder\Model\FtpUploader $ftpUploader,
\Omikron\Factfinder\Model\Api\PushImport $pushImport,
string $feedType
) {
$this->storeManager = $storeManager;
$this->storeEmulation = $storeEmulation;
$this->channelProvider = $channelProvider;
$this->csvFactory = $csvFactory;
$this->feedFactory = $feedFactory;
$this->ftpUploader = $ftpUploader;
$this->pushImport = $pushImport;
$this->feedType = $feedType;
}
public function exportAllEnabledFeeds(bool $pushImport = false): void
{
foreach ($this->storeManager->getStores() as $store) {
if ($this->channelProvider->isChannelEnabled((int) $store->getId())) {
$this->exportFeedForStore((int) $store->getId(), $pushImport);
}
}
}
public function exportFeedForStore(int $storeId, bool $pushImport = false): void
{
$this->storeEmulation->runInStore($storeId, function () use ($storeId, $pushImport) {
$filename = "export.{$this->channelProvider->getChannel()}.csv";
$stream = $this->csvFactory->create(['filename' => "factfinder/{$filename}"]);
$this->feedGeneratorFactory->create($this->feedType)->generate($stream);
$this->ftpUploader->upload($filename, $stream);
$this->pushImport->execute($storeId);
});
}
} |
Hi @fritzmg |
Hm, I understand, but it still seems odd to have duplicate code because of that, doesn't it? And it already produced an error: #135 |
May be the class name "…Helper" caused some confusion ;). I consider this class to be another service - that can be used by the cron, a controller or a command etc. |
Previously in the beta versions of the extension, the
Omikron\Factfinder\Model\Export\Product
class provided anexportProducts
function which could simply be called from anywhere, if you want to manually trigger an export of the product feed.In the current version no such method seems to exist. Instead, the cron and the backend controller have to use duplicated code, where the following happens:
To avoid code duplication, this should be transferred to some form of helper service instead.
The text was updated successfully, but these errors were encountered: