-
Notifications
You must be signed in to change notification settings - Fork 973
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
NEXT-19532: Custom document types cannot be used in the flow builder #2260
Comments
well, that's because shopware only cares about it's own document types. I can't say if it's a bug that the document is not generating or that the custom type is visible in the flow. <?php
declare(strict_types=1);
namespace SomeNamespace\Flow\Dispatching\Action;
use SomeNamespace\ProformaInvoiceGenerator;
use Shopware\Core\Checkout\Document\DocumentConfigurationFactory;
use Shopware\Core\Checkout\Document\DocumentService;
use Shopware\Core\Checkout\Document\FileGenerator\FileTypes;
use Shopware\Core\Content\Flow\Dispatching\Action\FlowAction;
use Shopware\Core\Defaults;
use Shopware\Core\Framework\Event\FlowEvent;
use Shopware\Core\Framework\Event\OrderAware;
use Shopware\Core\Framework\Event\SalesChannelAware;
use Shopware\Core\System\NumberRange\ValueGenerator\NumberRangeValueGeneratorInterface;
class GenerateDocument extends FlowAction
{
private NumberRangeValueGeneratorInterface $valueGenerator;
private DocumentService $documentService;
public function __construct(
DocumentService $documentService,
NumberRangeValueGeneratorInterface $valueGenerator
) {
$this->valueGenerator = $valueGenerator;
$this->documentService = $documentService;
}
public static function getName(): string
{
return 'action.generate.document';
}
public static function getSubscribedEvents(): array
{
return [
self::getName() => 'handle',
];
}
public function requirements(): array
{
return [OrderAware::class];
}
public function handle(FlowEvent $event): void
{
$baseEvent = $event->getEvent();
if (!$baseEvent instanceof OrderAware || !$baseEvent instanceof SalesChannelAware) {
return;
}
$eventConfig = $event->getConfig();
$documentType = $eventConfig['documentType'];
$documentRangerType = $eventConfig['documentRangerType'];
if ($documentType !== ProformaInvoiceGenerator::PROFORMA || !$documentRangerType) {
return;
}
$documentNumber = $this->valueGenerator->getValue(
$eventConfig['documentRangerType'],
$baseEvent->getContext(),
$baseEvent->getSalesChannelId()
);
$now = (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT);
$eventConfig['documentNumber'] = $documentNumber;
$eventConfig['documentDate'] = $now;
$eventConfig['custom'] = ['invoiceNumber' => $documentNumber];
$documentConfig = DocumentConfigurationFactory::createConfiguration($eventConfig);
$this->documentService->create(
$baseEvent->getOrderId(),
$documentType,
$eventConfig['fileType'] ?? FileTypes::PDF,
$documentConfig,
$baseEvent->getContext(),
null,
$eventConfig['static'] ?? false
);
}
} |
Hmm, I guess this is the way to go then. Sadly, the documentation does not mention anything about having to do this, even though every custom document type you create automatically appears in the 'Generate Document' action of the flow builder. Perhaps we then need an addition to these flow actions that determines which document types it can handle, similar to the |
yes, i think so too. |
Hey @dominikmank, it's been a year and Shopware has made some changes in the latest versions. It's now possible to specify multiple document types in a single flow action, but this means Shopware will also generate a document for our custom type, after we've already generated a document ourselves. Have you found a solution to this yet? |
hey @daniel-memo-ict , thanks for notifying me, but tbh, i don't know. I didn't searched for a solution and currently i don't have an explicit use case, but if you find something i would be pleased to know the solution. |
PHP Version
7.4
Shopware Version
6.4.6.1
Expected behaviour
A document should be generated using our custom document type
Actual behaviour
No document is being generated because the flow builder action only supports the default Shopware document types.
How to reproduce
The text was updated successfully, but these errors were encountered: