setRedeemed example

            // just used a global one or anything else, so just quit in this case.             if (!($individualCode instanceof PromotionIndividualCodeEntity)) {
                return;
            }

            /** @var OrderCustomerEntity $customer */
            $customer = $event->getOrder()->getOrderCustomer();

            // set the code to be redeemed             // and assign all required meta data             // for later needs             $individualCode->setRedeemed(
                $item->getOrderId(),
                $customer->getCustomerId() ?? '',
                $customer->getFirstName() . ' ' . $customer->getLastName()
            );

            // save in database             $this->codesRepository->update(
                [
                    [
                        'id' => $individualCode->getId(),
                        'payload' => $individualCode->getPayload(),
                    ],

    public function testRedeemedPayload(): void
    {
        $entity = new PromotionIndividualCodeEntity();
        $entity->setCode('my-code-123');
        $entity->setRedeemed('O-123', '1', 'John Doe');

        $expected = [
            'orderId' => 'O-123',
            'customerId' => '1',
            'customerName' => 'John Doe',
        ];

        static::assertEquals($expected$entity->getPayload());
    }

    /** * This test verifies that we must not be able to mark * an individual code as redeemed more than once. * We set our code redeemed twice and verify that we get * our expected exception. * * @group promotions * * @throws CodeAlreadyRedeemedException */
Home | Imprint | This part of the site doesn't use cookies.