DateTime example

'price' => new CalculatedPrice(200, 200, new CalculatedTaxCollection()new TaxRuleCollection()),
                        'priceDefinition' => new QuantityPriceDefinition(200, new TaxRuleCollection(), 2),
                    ],
                ],
                'deliveries' => [
                    [
                        'id' => $this->ids->create('delivery'),
                        'shippingOrderAddressId' => $this->ids->create('shipping-address'),
                        'shippingMethodId' => $this->getAvailableShippingMethod()->getId(),
                        'stateId' => $this->getStateId('open', 'order_delivery.state'),
                        'trackingCodes' => [],
                        'shippingDateEarliest' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
                        'shippingDateLatest' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
                        'shippingCosts' => new CalculatedPrice(0, 0, new CalculatedTaxCollection()new TaxRuleCollection()),
                        'positions' => [
                            [
                                'id' => $this->ids->create('position'),
                                'orderLineItemId' => $this->ids->create('line-item'),
                                'price' => new CalculatedPrice(200, 200, new CalculatedTaxCollection()new TaxRuleCollection()),
                            ],
                        ],
                    ],
                ],
                
return $totalCount;
    }

    /** * Helper to get the from date in the right format */
    private function getFromDate(): DateTime
    {
        $fromDate = $this->Request()->getParam('fromDate');
        if (empty($fromDate)) {
            $fromDate = new DateTime();
            $fromDate = $fromDate->sub(new DateInterval('P1Y'));
        } else {
            $fromDate = new DateTime($fromDate);
        }

        return $fromDate;
    }

    /** * helper to get the to date in the right format */
    
'id' => $id,
                'action_name' => MailSendSubscriberConfig::ACTION_NAME,
                'config' => json_encode([
                    'mail_template_id' => $mail['mail_template_id'],

                    // blue green deployment => mail send subscriber expects in blue state a type id without isset() condition                     'mail_template_type_id' => Uuid::randomHex(),
                ], \JSON_THROW_ON_ERROR),
                'event_name' => $mail['technical_name'],
                // will be set to true, after feature flag removed                 'active' => 1,
                'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
                'updated_at' => null,
            ];

            $connection->insert('event_action', $insert);

            if (isset($mail['sales_channel_id'])) {
                $connection->insert('event_action_sales_channel', [
                    'event_action_id' => $id,
                    'sales_channel_id' => $mail['sales_channel_id'],
                ]);
            }
        }

    public function testSeoLanguageInheritance(array $translations, string $pathInfo): void
    {
        $this->getContainer()->get(Connection::class)->insert('seo_url_template', [
            'id' => Uuid::randomBytes(),
            'route_name' => TestProductSeoUrlRoute::ROUTE_NAME,
            'entity_name' => ProductDefinition::ENTITY_NAME,
            'template' => '{{ product.translated.name }}',
            'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
        ]);

        $productBuilder = (new ProductBuilder($this->ids, 'p1'))
            ->price(100)
            ->name(self::DEFAULT);

        foreach ($translations as $translation) {
            $productBuilder->translation($this->ids->get($translation), 'name', $translation);
        }

        $this->getContainer()->get('product.repository')->create([
            
'name' => 'test',
                    'stock' => 1,
                    'price' => [['currencyId' => Defaults::CURRENCY, 'gross' => 10, 'net' => 8.10, 'linked' => false]],
                    'the_unknown_field' => 'do nothing?',
                    'tax' => ['name' => 'test', 'taxRate' => 5],
                    'manufacturer' => ['id' => Uuid::randomHex(), 'link' => 'https://shopware.com', 'name' => 'shopware AG'],
                    'mode' => 0,
                    'lastStock' => true,
                    'crossbundlelook' => 1,
                    'notification' => true,
                    'template' => 'foo',
                    'updatedAt' => new \DateTime(),
                    'active' => true,
                ],
            ],
            $this->createWriteContext()
        );

        $product = $this->connection->fetchAssociative('SELECT * FROM product WHERE id=:id', [
            'id' => $this->idBytes,
        ]);
        static::assertIsArray($product);

        
class Migration1635230747UpdateProductExportTemplate extends MigrationStep
{
    public function getCreationTimestamp(): int
    {
        return 1635230747;
    }

    public function update(Connection $connection): void
    {
        $templates = require __DIR__ . '/../Fixtures/productComparison-export-profiles/templates.php';

        $connection->update('product_export', ['body_template' => $templates['idealo_new'],   'updated_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT)]['body_template' => $templates['idealo_old']]);
        $connection->update('product_export', ['body_template' => $templates['billiger_new'], 'updated_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT)]['body_template' => $templates['billiger_old']]);
        $connection->update('product_export', ['body_template' => $templates['google_new'],   'updated_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT)]['body_template' => $templates['google_old']]);
    }

    public function updateDestructive(Connection $connection): void
    {
        // implement update destructive     }
}
return RuleComparison::isNegativeOperator($this->operator);
        }

        if (!$this->age && $this->operator !== self::OPERATOR_EMPTY) {
            throw new UnsupportedValueException(\gettype($this->age), self::class);
        }

        if (!$birthday = $customer->getBirthday()) {
            return RuleComparison::isNegativeOperator($this->operator);
        }

        $birthday = (new \DateTime())->setTimestamp($birthday->getTimestamp());
        $now = new \DateTime();

        $age = $now->diff($birthday)->y;

        return RuleComparison::numeric($age$this->age, $this->operator);
    }

    public function getConstraints(): array
    {
        $constraints = [
            'operator' => RuleConstraints::numericOperators(true),
        ];
$expiredPlugins
        );

        try {
            $plugins = $this->get(PluginStoreService::class)->getPlugins($context);

            foreach ($plugins as $plugin) {
                if (isset($installDates[$plugin->getTechnicalName()])) {
                    $date = $installDates[$plugin->getTechnicalName()]['installation_date'];

                    if ($date) {
                        $plugin->setInstallationDate(new DateTime($date));
                    }
                    $plugin->setCapabilitySecureUninstall($installDates[$plugin->getTechnicalName()]['capability_secure_uninstall']);
                }
            }

            $this->View()->assign(['success' => true, 'data' => array_values($plugins)]);
        } catch (Exception $e) {
            $this->View()->assign(['success' => false, 'message' => $e->getMessage()]);
        }
    }

    
if ($pattern === null) {
            $pattern = '';
        }

        $trimmedCode = trim($code);

        // if we have both a date from and until, make sure that         // the dateUntil is always in the future.         if ($validFrom !== null && $validUntil !== null) {
            // now convert into real date times             // and start comparing them             $dateFrom = new \DateTime($validFrom);
            $dateUntil = new \DateTime($validUntil);
            if ($dateUntil < $dateFrom) {
                $violationList->add($this->buildViolation(
                    'Expiration Date of Promotion must be after Start of Promotion',
                    $payload['valid_until'],
                    'validUntil',
                    'PROMOTION_VALID_UNTIL_VIOLATION',
                    $index
                ));
            }
        }

        
$connection->insert(
            'flow',
            [
                'id' => $flowId,
                'name' => $mailTemplate['flowName'],
                'event_name' => $mailTemplate['event'],
                'active' => true,
                'payload' => null,
                'invalid' => 0,
                'custom_fields' => null,
                'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
            ]
        );

        if ($mailTemplate['mailTemplateId'] !== null) {
            $connection->insert(
                'flow_sequence',
                [
                    'id' => Uuid::randomBytes(),
                    'flow_id' => $flowId,
                    'rule_id' => null,
                    'parent_id' => null,
                    
$salesChannelId1 = Uuid::randomHex();
        $salesChannelId2 = Uuid::randomHex();

        $userConfigRepository = $this->getContainer()->get('user_config.repository');
        $userConfigId = Uuid::randomHex();
        $userConfigRepository->create([
            [
                'id' => $userConfigId,
                'userId' => $admin->getUserId(),
                'key' => SalesChannelUserConfigSubscriber::CONFIG_KEY,
                'value' => [$salesChannelId1$salesChannelId2],
                'createdAt' => new \DateTime(),
            ],
        ]$context);

        static::assertCount(2, $userConfigRepository->search(new Criteria([$userConfigId])$context)->first()->getValue());

        $this->createSalesChannel(['id' => $salesChannelId1]);
        $this->createSalesChannel(['id' => $salesChannelId2]);

        $salesChannelRepository = $this->getContainer()->get('sales_channel.repository');
        $salesChannelRepository->delete([['id' => $salesChannelId1]['id' => $salesChannelId2]]$context);

        
$this->getContainer()->get(Connection::class)->insert('user', [
            'id' => Uuid::randomBytes(),
            'first_name' => $username,
            'last_name' => '',
            'email' => 'test@example.com',
            'username' => $username,
            'password' => TestDefaults::HASHED_PASSWORD,
            'locale_id' => Uuid::fromHexToBytes($this->getLocaleIdOfSystemLanguage()),
            'active' => 1,
            'admin' => 1,
            'created_at' => (new \DateTime())->format(Defaults::STORAGE_DATE_TIME_FORMAT),
        ]);

        $this->apiUsernames[] = $username;

        /** * Auth the api client first */
        $authPayload = [
            'grant_type' => 'password',
            'client_id' => 'administration',
            'username' => $username,
            
try {
            $pluginData['id'] = $plugin->getId();

            // Makes sure the version is updated in the db after a re-installation             $updateVersion = $plugin->getUpgradeVersion();
            if ($updateVersion !== null && $this->hasPluginUpdate($updateVersion$pluginVersion)) {
                $pluginData['version'] = $updateVersion;
                $plugin->setVersion($updateVersion);
                $pluginData['upgradeVersion'] = null;
                $plugin->setUpgradeVersion(null);
                $upgradeDate = new \DateTime();
                $pluginData['upgradedAt'] = $upgradeDate->format(Defaults::STORAGE_DATE_TIME_FORMAT);
                $plugin->setUpgradedAt($upgradeDate);
            }

            $this->eventDispatcher->dispatch(new PluginPreInstallEvent($plugin$installContext));

            $this->systemConfigService->savePluginConfiguration($pluginBaseClass, true);

            $pluginBaseClass->install($installContext);

            $this->customEntityLifecycleService->updatePlugin($plugin->getId()$plugin->getPath() ?? '');

            
// queue a task         $repo = $this->getContainer()->get('scheduled_task.repository');
        $taskId = Uuid::randomHex();
        $repo->create([
            [
                'id' => $taskId,
                'name' => 'test',
                'scheduledTaskClass' => TestTask::class,
                'runInterval' => 300,
                'defaultRunInterval' => 300,
                'status' => ScheduledTaskDefinition::STATUS_SCHEDULED,
                'nextExecutionTime' => (new \DateTime())->modify('-1 second'),
            ],
        ], Context::createDefaultContext());

        $url = '/api/_action/scheduled-task/run';
        $client = $this->getBrowser();
        $client->request('POST', $url);

        // consume the queued task         $url = '/api/_action/message-queue/consume';
        $client = $this->getBrowser();
        $client->request('POST', $url['receiver' => 'async']);

        
/** * @var int * * @ORM\Column(name="id", type="integer", nullable=false) * @ORM\Id() * @ORM\GeneratedValue(strategy="IDENTITY") */
    private $id;

    public function __construct()
    {
        $this->createdAt = new DateTime();
    }

    /** * Gets the id of the payment * * @return int */
    public function getId()
    {
        return $this->id;
    }

    
Home | Imprint | This part of the site doesn't use cookies.