<?php declare(strict_types=1);
namespace Swag\BasicExample\Migration;
use Doctrine\DBAL\Connection;
use Shopware\Core\Defaults;
use Shopware\Core\Framework\Migration\MigrationStep;
use Shopware\Core\Framework\Uuid\Uuid;
class Migration1616668698AddDocument extends MigrationStep
public function getCreationTimestamp(): int
public function update(Connection $connection): void
$documentConfigId = Uuid::randomBytes();
$documentTypeId = $this->getDocumentTypeId($connection);
$connection->insert('document_base_config', [
'id' => $documentConfigId,
'filename_prefix' => 'custom_',
'document_type_id' => $documentTypeId,
'config' => $this->getConfig(),
'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT)
$storefrontSalesChannelId = $this->getStorefrontSalesChannelId($connection);
if (!$storefrontSalesChannelId) {
$connection->insert('document_base_config_sales_channel', [
'id' => Uuid::randomBytes(),
'document_base_config_id' => $documentConfigId,
'sales_channel_id' => $storefrontSalesChannelId,
'document_type_id' => $documentTypeId,
'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT)
public function updateDestructive(Connection $connection): void
private function getDocumentTypeId(Connection $connection): string
WHERE technical_name = "delivery_note"
return $connection->fetchOne($sql);
private function getConfig(): string
'displayPrices' => false,
'displayLineItems' => true,
'displayLineItemPosition' => true,
'displayPageCount' => true,
'displayCompanyAddress' => true,
'pageOrientation' => 'portrait',
'companyName' => 'Example company',
'companyAddress' => 'Example company address',
return json_encode($config);
private function getStorefrontSalesChannelId(Connection $connection): ?string
$salesChannelId = $connection->fetchOne($sql, [
':typeId' => Uuid::fromHexToBytes(Defaults::SALES_CHANNEL_TYPE_STOREFRONT)