change example

throw ProductException::invalidCheapestPriceFacade($this->item->getUniqueIdentifier());
        }
    }

    /** * `reset()` allows to reset the cheapest price to the original price of the product. * * @example pricing-cases/product-pricing.twig 64 1 Reset the product price to default */
    public function reset(): void
    {
        $this->change(null);
    }

    /** * `change()` allows to overwrite the cheapest price of the current price scope. The provided price will be recalculated * over the quantity price calculator to consider quantity, tax rule and cash rounding configurations. * * @example pricing-cases/product-pricing.twig 60 5 Overwrite prices with a static defined collection * @example pricing-cases/product-pricing.twig 92 1 Overwrite the cheapest price with the original price * @example pricing-cases/product-pricing.twig 72 1 Discount the cheapest price by 10% * * @param PriceFacade|PriceCollection|CalculatedPrice|null $price You can provide different values to overwrite the cheapest price. In case of null, it uses the original single price of the product. * @param bool $range Allows to switch the `hasRange` attribute of the cheapest price */
$this->hook(new AccountPaymentMethodPageLoadedHook($page$context));

        return $this->renderStorefront('@Storefront/storefront/page/account/payment/index.html.twig', ['page' => $page]);
    }

    #[Route(path: '/account/payment', name: 'frontend.account.payment.save', defaults: ['_loginRequired' => true], methods: ['POST'])]     public function savePayment(RequestDataBag $requestDataBag, SalesChannelContext $context, CustomerEntity $customer): Response
    {
        try {
            $paymentMethodId = $requestDataBag->getAlnum('paymentMethodId');

            $this->changePaymentMethodRoute->change(
                $paymentMethodId,
                $requestDataBag,
                $context,
                $customer
            );
        } catch (UnknownPaymentMethodException|InvalidUuidException|PaymentException $exception) {
            $this->addFlash(self::DANGER, $this->trans('error.' . $exception->getErrorCode()));

            return $this->forwardToRoute('frontend.account.payment.page', ['success' => false]);
        }

        
$storeApiCustomFieldMapper,
            $this->createMock(EntityRepository::class),
        );

        $customer = new CustomerEntity();
        $customer->setId('customer1');
        $data = new RequestDataBag([
            'customFields' => $customFields,
            'salutationId' => '1',
        ]);

        $change->change($data$this->createMock(SalesChannelContext::class)$customer);
    }

    public function testAccountTypeGetPassed(): void
    {
        $customerRepository = $this->createMock(EntityRepository::class);
        $customerRepository
            ->method('update')
            ->with(static::callback(function Darray $data) {
                static::assertCount(1, $data);
                static::assertIsArray($data[0]);
                static::assertArrayHasKey('accountType', $data[0]);

                

class PriceFacadeTest extends TestCase
{
    public function testLineItemsGetUpdatePriceDefinition(): void
    {
        $item = new LineItem('test', 'test', 'temp');

        $original = new CalculatedPrice(1, 1, new CalculatedTaxCollection()new TaxRuleCollection());
        $price = new PriceFacade($item$original$this->createMock(ScriptPriceStubs::class)$this->createMock(SalesChannelContext::class));

        $price->change(new PriceCollection([
            new Price(Defaults::CURRENCY, 2, 2, false),
        ]));

        static::assertInstanceOf(QuantityPriceDefinition::class$item->getPriceDefinition());
        static::assertEquals(2, $item->getPriceDefinition()->getPrice());
        static::assertNull($item->getPrice());
    }

    public function testChangesAreAppliedDirectlyForEntities(): void
    {
        $item = new Entity();
        
return $this->renderStorefront('@Storefront/storefront/page/account/profile/index.html.twig', [
            'page' => $page,
            'passwordFormViolation' => $request->get('passwordFormViolation'),
            'emailFormViolation' => $request->get('emailFormViolation'),
        ]);
    }

    #[Route(path: '/account/profile', name: 'frontend.account.profile.save', defaults: ['_loginRequired' => true], methods: ['POST'])]     public function saveProfile(RequestDataBag $data, SalesChannelContext $context, CustomerEntity $customer): Response
    {
        try {
            $this->changeCustomerProfileRoute->change($data$context$customer);

            $this->addFlash(self::SUCCESS, $this->trans('account.profileUpdateSuccess'));
        } catch (ConstraintViolationException $formViolations) {
            return $this->forwardToRoute('frontend.account.profile.page', ['formViolations' => $formViolations]);
        } catch (\Exception $exception) {
            $this->logger->error($exception->getMessage()['e' => $exception]);
            $this->addFlash(self::DANGER, $this->trans('error.message-default'));
        }

        return $this->redirectToRoute('frontend.account.profile.page');
    }

    
/** @var CustomerEntity $customer */
        $customer = $this->customerRepository->search(
            (new Criteria())->addFilter(new EqualsFilter('email', $email)),
            $this->salesChannelContext->getContext()
        )->first();

        $this->salesChannelContext->assign(['customer' => $customer]);

        static::assertNotNull($customer = $this->salesChannelContext->getCustomer());
        static::assertSame($email$customer->getEmail());

        $this->changePaymentMethodRoute->change(
            $customer->getDefaultPaymentMethodId(),
            new RequestDataBag(),
            $this->salesChannelContext,
            $customer
        );
        static::assertTrue($eventDidRun, 'Event "' . CustomerChangedPaymentMethodEvent::class D '" did not run');

        $dispatcher->removeListener(CustomerChangedPaymentMethodEvent::class$listenerClosure);
    }

    /** * @return callable(CustomerBeforeLoginEvent): void */
$oldVatIds = $customer->getVatIds() ?? [];
        if (!array_diff($newVatIds$oldVatIds) && !array_diff($oldVatIds$newVatIds)) {
            return;
        }

        $dataCustomer = CustomerTransformer::transform($customer);
        $dataCustomer['vatIds'] = $newVatIds;
        $dataCustomer['accountType'] = $customer->getCompany() === null ? CustomerEntity::ACCOUNT_TYPE_PRIVATE : CustomerEntity::ACCOUNT_TYPE_BUSINESS;

        $newDataBag = new RequestDataBag($dataCustomer);

        $this->updateCustomerProfileRoute->change($newDataBag$context$customer);
    }
}
/** * @param array<string|int, mixed>[] $items * * @throws CartException */
    public function update(Cart $cart, array $items, SalesChannelContext $context): Cart
    {
        $request = new Request();
        $request->request->set('items', $items);

        $cart = $this->itemUpdateRoute->change($request$cart$context)->getCart();

        return $this->cart[$cart->getToken()] = $cart;
    }

    /** * @throws CartException */
    public function remove(Cart $cart, string $identifier, SalesChannelContext $context): Cart
    {
        return $this->removeItems($cart[$identifier]$context);
    }

    
'default' => Defaults::CURRENCY,
            'usd' => Uuid::randomHex(),
        ]);

        $price = $this->rampUpPriceFacade($ids$currencyKey$taxState);

        $update = new PriceCollection([
            new Price(Defaults::CURRENCY, 2, 5, false),
            new Price($ids->get('usd'), 1, 4, false),
        ]);

        $price->change($update);

        static::assertEquals($unit$price->getUnit());
        static::assertEquals($tax$price->getTaxes()->getAmount());
    }

    public function testChangeWithPriceFacade(): void
    {
        $ids = new IdsCollection([
            'default' => Defaults::CURRENCY,
            'usd' => Uuid::randomHex(),
        ]);

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