<?php

namespace KupShop\GTMBundle\Tests;

use KupShop\ContentBundle\View\CartView;
use KupShop\ContentBundle\View\OrderView;
use KupShop\DevelopmentBundle\Util\Tests\CartTestTrait;
use KupShop\DevelopmentBundle\Util\Tests\RequestSessionTrait;
use KupShop\GTMBundle\Utils\GTMLoader;
use KupShop\KupShopBundle\Context\CurrencyContext;
use Query\Operator;
use Symfony\Component\HttpFoundation\Request;

class GTMEcommerceTest extends \DatabaseTestCase
{
    use CartTestTrait;
    use GTMTestHelper;
    use RequestSessionTrait;

    protected function setUp(): void
    {
        parent::setUp();

        $this->prepareRequestStackSession();

        $dbcfg = \Settings::getDefault();
        $dbcfg->analytics['google_tag_manager']['gtm_dl_version'] = '2';
        $dbcfg->saveToDB();
    }

    public function testCheckout()
    {
        $this->prepareCart();
        $this->insertProduct(10, null, 1);
        $this->visitStep('summary');
        $this->cart->max_step = 3;
        $this->saveCart();

        $cartView = $this->get(CartView::class);
        $cartView->setRequest(new Request());
        $cartView->setStepName('user');
        $cart = $cartView->getBodyVariables();

        /** @var GTMLoader $gtm */
        $gtm = $this->get(GTMLoader::class);
        $data = $gtm->getEcommerceData('Checkout', ['body' => $cart], $cartView);

        $exp_res = [
            'checkout' => [
                'discounts' => [],
                'option' => 'Hotově - Osobní odběr',
                'products' => [
                    [
                        'id' => '10',
                        'idProduct' => '10',
                        'EAN' => '',
                        'code' => 'RD102velmidlouhykodproduktuprotest',
                        'productCode' => 'RD102velmidlouhykodproduktuprotest',
                        'variationCode' => null,
                        'variationName' => null,
                        'hasVariations' => false,
                        'idAll' => [],
                        'variationsIds' => [],
                        'idVariation' => null,
                        'imageUrl' => 'https://www.kupshop.local/data/tmp/0/4/14_0.jpg?',
                        'url' => 'https://www.kupshop.local/black-and-decker-core-egbl108k-aku-vrtacka_z10/',
                        'soldOut' => null,
                        'categoryMain' => [
                            [
                                'id' => 1,
                                'name' => 'Aku vrtačky',
                            ],
                            [
                                'id' => 3,
                                'name' => 'Aku vrtačky',
                            ],
                        ],
                        'categoryCurrent' => [
                            [
                                'id' => '',
                                'name' => 'Dodací údaje',
                            ],
                        ],
                        'producer' => 'Black & Decker',
                        'campaigns' => [],
                        'name' => 'Black and Decker Core EGBL108K aku vrtačka',
                        'vat' => \Decimal::fromString('15', 16),
                        'price' => '1609',
                        'priceWithVat' => '1609',
                        'priceWithoutVat' => '1399.13',
                        'priceVat' => '209.87',
                        'priceWithoutDiscount' => '2011',
                        'discount' => 20.0,
                        'hasDiscount' => true,
                        'availability' => 'na objednávku',
                        'quantity' => '1',
                    ],
                ],
                'step' => 3,
                'stepName' => 'user',
            ],
            'event' => 'checkout',
        ];

        $this->assertEquals($exp_res, $this->recursivelyChangeType($data));
    }

    public function testCheckoutWithoutVat()
    {
        \Settings::getDefault()->saveValue('analytics', ['google_tag_manager' => ['withoutVAT' => 'Y']]);
        \Settings::getDefault()->updateValue('analytics', ['google_tag_manager' => ['withoutVAT' => 'Y']]);

        $this->prepareCart();
        $this->insertProduct(10, null, 1);
        $this->visitStep('summary');
        $this->saveCart();

        $cartView = $this->get(CartView::class);
        $cartView->setRequest(new Request());
        $cartView->setStepName('user');
        $cart = $cartView->getBodyVariables();

        /** @var GTMLoader $gtm */
        $gtm = $this->get(GTMLoader::class);
        $data = $gtm->getEcommerceData('Checkout', ['body' => $cart], $cartView);

        $exp_res = [
            'checkout' => [
                'discounts' => [],
                'option' => 'Hotově - Osobní odběr',
                'products' => [
                    [
                        'id' => '10',
                        'idProduct' => '10',
                        'EAN' => '',
                        'code' => 'RD102velmidlouhykodproduktuprotest',
                        'productCode' => 'RD102velmidlouhykodproduktuprotest',
                        'variationCode' => null,
                        'variationName' => null,
                        'hasVariations' => false,
                        'idAll' => [],
                        'variationsIds' => [],
                        'idVariation' => null,
                        'categoryMain' => [
                            [
                                'id' => 1,
                                'name' => 'Aku vrtačky',
                            ],
                            [
                                'id' => 3,
                                'name' => 'Aku vrtačky',
                            ],
                        ],
                        'categoryCurrent' => [
                            [
                                'id' => '',
                                'name' => 'Dodací údaje',
                            ],
                        ],
                        'producer' => 'Black & Decker',
                        'campaigns' => [],
                        'name' => 'Black and Decker Core EGBL108K aku vrtačka',
                        'vat' => \Decimal::fromString('15', 16),
                        'price' => '1399.13',
                        'priceWithVat' => '1609',
                        'priceWithoutVat' => '1399.13',
                        'priceVat' => '209.87',
                        'priceWithoutDiscount' => '1748.7',
                        'discount' => 20.0,
                        'hasDiscount' => true,
                        'availability' => 'na objednávku',
                        'quantity' => '1',
                        'imageUrl' => 'https://www.kupshop.local/data/tmp/0/4/14_0.jpg?',
                        'url' => 'https://www.kupshop.local/black-and-decker-core-egbl108k-aku-vrtacka_z10/',
                        'soldOut' => null,
                    ],
                ],
                'step' => 3,
                'stepName' => 'user',
            ],
            'event' => 'checkout',
        ];

        $this->assertEquals($exp_res, $this->recursivelyChangeType($data));
    }

    public function testPurchase()
    {
        $this->prepareCart();
        $this->insertProduct(10, null, 1);
        $this->insertProduct(11, 20, 1);
        $this->cart->max_step = 3;
        $this->saveCart();

        $this->checkOrderPriceIsSameAsCart();

        sqlQuery("INSERT INTO orders (source, order_no, id_language, currency, currency_rate, id_user, date_created, date_accept, date_handle, date_delivered, date_updated, date_due, status, status_payed, status_dispatch, status_storno, total_price, total_price_without_vat, invoice_name, invoice_surname, invoice_firm, invoice_ico, invoice_dic, invoice_street, invoice_city, invoice_zip, invoice_country, invoice_phone, invoice_email, delivery_name, delivery_surname, delivery_firm, delivery_street, delivery_city, delivery_zip, delivery_country, delivery_type, id_delivery, delivery_complete, note_user, note_admin, flags, admin, note_invoice, package_id, invoice_state, invoice_custom_address, delivery_state, delivery_custom_address, delivery_phone, pohoda_sync_date,user_order_no, total_weight) VALUES ( 'shop', '23687024', 'sk', 'EUR', 23.90000000, null, '2023-05-05 10:29:14', '2023-06-07 10:29:25', null, null, '2023-06-07 10:29:25', null, 1, 0, 0, 0, 34.9000, 29.0800, 'Mária', 'Bc. Dobrovičová', '', '', '', 'Sládkovičova 36', 'Sabinov', '08301', 'SK', '+421123456789', 'test@wpj.cz', 'Mária', 'vfdsfds', 'erferre', 'hybf', 'Sabinov', '083 01', 'SK', 'Bezpečná online platba - Packeta.sk',null, '', '', '', 'OSS', null, null, null, '', '', '', '', '', '2023-06-07 10:29:25',  null, 0.700000);");
        sqlQuery("INSERT INTO orders (source, order_no, id_language, currency, currency_rate, id_user, date_created, date_accept, date_handle, date_delivered, date_updated, date_due, status, status_payed, status_dispatch, status_storno, total_price, total_price_without_vat, invoice_name, invoice_surname, invoice_firm, invoice_ico, invoice_dic, invoice_street, invoice_city, invoice_zip, invoice_country, invoice_phone, invoice_email, delivery_name, delivery_surname, delivery_firm, delivery_street, delivery_city, delivery_zip, delivery_country, delivery_type, id_delivery, delivery_complete, note_user, note_admin, flags, admin, note_invoice, package_id, invoice_state, invoice_custom_address, delivery_state, delivery_custom_address, delivery_phone, pohoda_sync_date,user_order_no, total_weight) VALUES ( 'shop', '23687025', 'sk', 'EUR', 23.90000000, null, '2023-06-06 10:29:14', '2023-06-07 10:29:25', null, null, '2023-06-07 10:29:25', null, 1, 0, 0, 0, 34.9000, 29.0800, 'Mária', 'Bc. Dobrovičová', '', '', '', 'Sládkovičova 36', 'Sabinov', '08301', 'SK', '+421123456789', 'test@wpj.cz', 'Mária', 'vfdsfds', 'erferre', 'hybf', 'Sabinov', '083 01', 'SK', 'Bezpečná online platba - Packeta.sk',null, '', '', '', 'OSS', null, null, null, '', '', '', '', '', '2023-06-07 10:29:25',  null, 0.700000);");

        $orderView = $this->get(OrderView::class);
        $orderView->setIDo($this->order->id);
        $data = $orderView->getBodyVariables();

        $gtm = $this->get(GTMLoader::class);
        $data = $gtm->getEcommerceData('Purchase', ['body' => $data], $orderView);

        $exp_res = [
            'event' => 'orderSuccess',
            'user' => [
                'name' => 'Wpj',
                'surname' => 'Wpj',
                'email' => 'test@wpj.cz',
                'phone' => '+420123456789',
                'shaEmail' => '63b2911182da44aa29a8d2c0422645c82eefeacc2ff5a65c20a0c6923a867809',
                'firstOrderDate' => '2023-05-05',
                'lastOrderDate' => '2023-06-06',
                'countOrders' => '2',
                'address' => [
                    'street' => 'Wpj 123',
                    'city' => 'Vrchlabi',
                    'region' => '',
                    'postalCode' => '12345',
                    'country' => 'CZ',
                ],
            ],
            'purchase' => [
                'charges' => [],
                'id' => $this->order->order_no,
                'affiliation' => 'Osobní odběr | Hotovost | cs',
                'currency' => 'CZK',
                'deliveryType' => 'Osobní odběr',
                'paymentType' => 'Hotovost',
                'payment' => [
                    'type' => 'Hotovost',
                    'method' => [
                        'id' => null,
                    ],
                ],
                'total' => '1709',
                'totalWithVat' => '1709',
                'totalWithoutVat' => '1482',
                'totalWithoutVatAndShipping' => '1482',
                'vat' => '227',
                'flags' => [],
                'coupons' => '',
                'shipping' => '0',
                'shippingWithVat' => '0',
                'shippingWithOutVat' => '0',
                'discounts' => [],
                'heurekaDisagree' => false,
                'products' => [
                    [
                        'id' => '10',
                        'idProduct' => '10',
                        'EAN' => '',
                        'code' => 'RD102velmidlouhykodproduktuprotest',
                        'productCode' => 'RD102velmidlouhykodproduktuprotest',
                        'variationCode' => null,
                        'variationName' => null,
                        'hasVariations' => false,
                        'idAll' => [],
                        'variationsIds' => [],
                        'idVariation' => null,
                        'categoryMain' => [
                            [
                                'id' => 1,
                                'name' => 'Aku vrtačky',
                            ],
                            [
                                'id' => 3,
                                'name' => 'Aku vrtačky',
                            ],
                        ],
                        'categoryCurrent' => [
                            [
                                'id' => '',
                                'name' => 'Objednávka: '.$this->order->order_no,
                            ],
                        ],
                        'producer' => 'Black & Decker',
                        'campaigns' => [],
                        'name' => 'Black and Decker Core EGBL108K aku vrtačka',
                        'vat' => \Decimal::fromString('15', 16),
                        'price' => '1609',
                        'priceWithVat' => '1609',
                        'priceWithoutVat' => '1399.13',
                        'priceVat' => '209.87',
                        'priceWithoutDiscount' => '2011',
                        'discount' => 20.0,
                        'hasDiscount' => true,
                        'availability' => 'na objednávku',
                        'quantity' => '1',
                        'imageUrl' => 'https://www.kupshop.local/data/tmp/0/4/14_0.jpg?',
                        'url' => 'https://www.kupshop.local/black-and-decker-core-egbl108k-aku-vrtacka_z10/',
                        'soldOut' => null,
                    ],
                    [
                        'id' => '11_20',
                        'idProduct' => '11',
                        'EAN' => '',
                        'code' => 'GR573',
                        'productCode' => 'GR573',
                        'variationCode' => null,
                        'variationName' => null,
                        'hasVariations' => true,
                        'variationsIds' => ['20'],
                        'idAll' => ['11_20'],
                        'idVariation' => '20',
                        'variationName' => 'Velikost: 41',
                        'categoryMain' => [
                            [
                                'id' => 1,
                                'name' => 'Aku vrtačky',
                            ],
                            [
                                'id' => 2,
                                'name' => 'Aku baterie',
                            ],
                        ],
                        'categoryCurrent' => [
                            [
                                'id' => '',
                                'name' => 'Objednávka: '.$this->order->order_no,
                            ],
                        ],
                        'producer' => 'wpj',
                        'campaigns' => [
                            'N' => [
                                'id' => 'N',
                                'name' => 'Novinka',
                            ],
                            'S' => [
                                'id' => 'S',
                                'name' => 'Set',
                            ],
                            'Z' => [
                                'id' => 'Z',
                                'name' => 'Zlevněno',
                            ],
                        ],
                        'name' => 'iPhone wpj',
                        'vat' => \Decimal::fromString('21', 16),
                        'price' => '100',
                        'priceWithVat' => '100',
                        'priceWithoutVat' => '82.64',
                        'priceVat' => '17.36',
                        'priceWithoutDiscount' => '499',
                        'discount' => 80.04,
                        'hasDiscount' => true,
                        'availability' => 'skladem',
                        'quantity' => '1',
                        'imageUrl' => 'https://www.kupshop.local/data/tmp/0/6/26_0.jpg?',
                        'url' => 'https://www.kupshop.local/iphone-wpj_z11/',
                        'soldOut' => null,
                    ],
                ],
            ],
        ];

        $this->assertEquals($exp_res, $this->recursivelyChangeType($data));
    }

    public function testPurchaseWithoutVat()
    {
        \Settings::getDefault()->saveValue('analytics', ['google_tag_manager' => ['withoutVAT' => 'Y']]);
        \Settings::getDefault()->updateValue('analytics', ['google_tag_manager' => ['withoutVAT' => 'Y']]);

        $this->prepareCart();
        $this->insertProduct(10, null, 1);
        $this->insertProduct(11, 20, 1);
        $this->visitStep('summary');
        $this->saveCart();

        $this->checkOrderPriceIsSameAsCart();

        $orderView = $this->get(OrderView::class);
        $orderView->setIDo($this->order->id);
        $data = $orderView->getBodyVariables();

        $gtm = $this->get(GTMLoader::class);
        $data = $gtm->getEcommerceData('Purchase', ['body' => $data], $orderView);

        $exp_res = [
            'event' => 'orderSuccess',
            'user' => [
                'countOrders' => null,
                'email' => 'test@wpj.cz',
                'firstOrderDate' => null,
                'lastOrderDate' => null,
                'shaEmail' => '63b2911182da44aa29a8d2c0422645c82eefeacc2ff5a65c20a0c6923a867809',
                'name' => 'Wpj',
                'surname' => 'Wpj',
                'phone' => '+420123456789',
                'address' => [
                    'street' => 'Wpj 123',
                    'city' => 'Vrchlabi',
                    'region' => '',
                    'postalCode' => '12345',
                    'country' => 'CZ',
                ],
            ],
            'purchase' => [
                'charges' => [],
                'id' => $this->order->order_no,
                'affiliation' => 'Osobní odběr | Hotovost | cs',
                'currency' => 'CZK',
                'deliveryType' => 'Osobní odběr',
                'paymentType' => 'Hotovost',
                'payment' => [
                    'type' => 'Hotovost',
                    'method' => [
                        'id' => null,
                    ],
                ],
                'total' => '1482',
                'totalWithVat' => '1709',
                'totalWithoutVat' => '1482',
                'totalWithoutVatAndShipping' => '1482',
                'vat' => '227',
                'flags' => [],
                'coupons' => '',
                'shipping' => '0',
                'shippingWithVat' => '0',
                'shippingWithOutVat' => '0',
                'discounts' => [],
                'heurekaDisagree' => false,
                'products' => [
                    [
                        'id' => '10',
                        'idProduct' => '10',
                        'EAN' => '',
                        'code' => 'RD102velmidlouhykodproduktuprotest',
                        'productCode' => 'RD102velmidlouhykodproduktuprotest',
                        'variationCode' => null,
                        'variationName' => null,
                        'hasVariations' => false,
                        'idAll' => [],
                        'variationsIds' => [],
                        'idVariation' => null,
                        'categoryMain' => [
                            [
                                'id' => 1,
                                'name' => 'Aku vrtačky',
                            ],
                            [
                                'id' => 3,
                                'name' => 'Aku vrtačky',
                            ],
                        ],
                        'categoryCurrent' => [
                            [
                                'id' => '',
                                'name' => 'Objednávka: '.$this->order->order_no,
                            ],
                        ],
                        'producer' => 'Black & Decker',
                        'campaigns' => [],
                        'name' => 'Black and Decker Core EGBL108K aku vrtačka',
                        'vat' => \Decimal::fromString('15', 16),
                        'price' => '1399.13',
                        'priceWithVat' => '1609',
                        'priceWithoutVat' => '1399.13',
                        'priceVat' => '209.87',
                        'priceWithoutDiscount' => '1748.7',
                        'discount' => 20.0,
                        'hasDiscount' => true,
                        'availability' => 'na objednávku',
                        'quantity' => '1',
                        'imageUrl' => 'https://www.kupshop.local/data/tmp/0/4/14_0.jpg?',
                        'url' => 'https://www.kupshop.local/black-and-decker-core-egbl108k-aku-vrtacka_z10/',
                        'soldOut' => null,
                    ],
                    [
                        'id' => '11_20',
                        'idProduct' => '11',
                        'EAN' => '',
                        'code' => 'GR573',
                        'productCode' => 'GR573',
                        'variationCode' => null,
                        'variationName' => null,
                        'hasVariations' => true,
                        'idAll' => ['11_20'],
                        'variationsIds' => ['20'],
                        'idVariation' => '20',
                        'variationName' => 'Velikost: 41',
                        'categoryMain' => [
                            [
                                'id' => 1,
                                'name' => 'Aku vrtačky',
                            ],
                            [
                                'id' => 2,
                                'name' => 'Aku baterie',
                            ],
                        ],
                        'categoryCurrent' => [
                            [
                                'id' => '',
                                'name' => 'Objednávka: '.$this->order->order_no,
                            ],
                        ],
                        'producer' => 'wpj',
                        'campaigns' => [
                            'N' => [
                                'id' => 'N',
                                'name' => 'Novinka',
                            ],
                            'S' => [
                                'id' => 'S',
                                'name' => 'Set',
                            ],
                            'Z' => [
                                'id' => 'Z',
                                'name' => 'Zlevněno',
                            ],
                        ],
                        'name' => 'iPhone wpj',
                        'vat' => \Decimal::fromString('21', 16),
                        'price' => '82.64',
                        'priceWithVat' => '100',
                        'priceWithoutVat' => '82.64',
                        'priceVat' => '17.36',
                        'priceWithoutDiscount' => '412.4',
                        'discount' => 80.04,
                        'hasDiscount' => true,
                        'availability' => 'skladem',
                        'quantity' => '1',
                        'imageUrl' => 'https://www.kupshop.local/data/tmp/0/6/26_0.jpg?',
                        'url' => 'https://www.kupshop.local/iphone-wpj_z11/',
                        'soldOut' => null,
                    ],
                ],
            ],
        ];

        $this->assertEquals($exp_res, $this->recursivelyChangeType($data));
    }

    public function testConvertedPrices()
    {
        \Settings::getDefault()->saveValue('analytics', [
            'google_tag_manager' => ['withoutVAT' => 'Y',
                'currency' => 'EUR', ],
        ]);
        \Settings::getDefault()->updateValue('analytics', [
            'google_tag_manager' => ['withoutVAT' => 'Y',
                'currency' => 'EUR', ],
        ]);

        $currencyContext = $this->get(CurrencyContext::class);
        $currencyContext->activate('CZK');

        sqlQueryBuilder()->update('products')->set('campaign', 'NULL')->where(Operator::inIntArray([11, 10], 'id'))->execute();

        $this->prepareCart();
        $this->insertProduct(10, null, 1);
        $this->insertProduct(11, 20, 1);
        $this->setDeliveryType(2);
        $this->visitStep('summary');
        $this->saveCart();

        $this->checkOrderPriceIsSameAsCart();

        $orderView = $this->get(OrderView::class);
        $orderView->setIDo($this->order->id);
        $data = $orderView->getBodyVariables();

        $gtm = $this->get(GTMLoader::class);
        $data = $gtm->getEcommerceData('Purchase', ['body' => $data], $orderView);

        $exp_res = [
            'event' => 'orderSuccess',
            'user' => [
                'countOrders' => null,
                'firstOrderDate' => null,
                'lastOrderDate' => null,
                'name' => 'Wpj',
                'surname' => 'Wpj',
                'email' => 'test@wpj.cz',
                'phone' => '+420123456789',
                'shaEmail' => '63b2911182da44aa29a8d2c0422645c82eefeacc2ff5a65c20a0c6923a867809',
                'address' => [
                    'street' => 'Wpj 123',
                    'city' => 'Vrchlabi',
                    'region' => '',
                    'postalCode' => '12345',
                    'country' => 'CZ',
                ],
            ],
            'purchase' => [
                'charges' => [],
                'id' => $this->order->order_no,
                'affiliation' => 'Česká pošta - Balík do ruky | Dobirka | cs',
                'deliveryType' => 'Česká pošta - Balík do ruky',
                'paymentType' => 'Dobirka',
                'payment' => [
                    'type' => 'Dobirka',
                    'method' => [
                        'id' => null,
                    ],
                ],
                'currency' => 'EUR',
                'total' => '59.2',
                'totalWithVat' => '68.4',
                'totalWithoutVat' => '59.2',
                'totalWithoutVatAndShipping' => '57',
                'vat' => '9.2',
                'flags' => [],
                'coupons' => '',
                'heurekaDisagree' => false,
                'shipping' => \Decimal::fromString('2.23', 4),
                'shippingWithVat' => \Decimal::fromString('2.7', 4),
                'shippingWithOutVat' => \Decimal::fromString('2.25', 4),
                'discounts' => [],
                'products' => [
                    [
                        'id' => '10',
                        'idProduct' => '10',
                        'EAN' => '',
                        'code' => 'RD102velmidlouhykodproduktuprotest',
                        'productCode' => 'RD102velmidlouhykodproduktuprotest',
                        'variationCode' => null,
                        'variationName' => null,
                        'hasVariations' => false,
                        'idAll' => [],
                        'variationsIds' => [],
                        'idVariation' => null,
                        'categoryMain' => [
                            [
                                'id' => 1,
                                'name' => 'Aku vrtačky',
                            ],
                            [
                                'id' => 3,
                                'name' => 'Aku vrtačky',
                            ],
                        ],
                        'categoryCurrent' => [
                            [
                                'id' => '',
                                'name' => 'Objednávka: '.$this->order->order_no,
                            ],
                        ],
                        'producer' => 'Black & Decker',
                        'campaigns' => [],
                        'name' => 'Black and Decker Core EGBL108K aku vrtačka',
                        'vat' => \Decimal::fromString('15', 16),
                        'price' => '53.83',
                        'priceWithVat' => '61.9',
                        'priceWithoutVat' => '53.83',
                        'priceVat' => '8.07',
                        'priceWithoutDiscount' => '67.26',
                        'discount' => 20.0,
                        'hasDiscount' => true,
                        'availability' => 'na objednávku',
                        'quantity' => '1',
                        'imageUrl' => 'https://www.kupshop.local/data/tmp/0/4/14_0.jpg?',
                        'url' => 'https://www.kupshop.local/black-and-decker-core-egbl108k-aku-vrtacka_z10/',
                        'soldOut' => null,
                    ],
                    [
                        'id' => '11_20',
                        'idProduct' => '11',
                        'EAN' => '',
                        'code' => 'GR573',
                        'productCode' => 'GR573',
                        'variationCode' => null,
                        'variationName' => null,
                        'hasVariations' => true,
                        'idAll' => ['11_20'],
                        'variationsIds' => ['20'],
                        'idVariation' => '20',
                        'variationName' => 'Velikost: 41',
                        'categoryMain' => [
                            [
                                'id' => 1,
                                'name' => 'Aku vrtačky',
                            ],
                            [
                                'id' => 2,
                                'name' => 'Aku baterie',
                            ],
                        ],
                        'categoryCurrent' => [
                            [
                                'id' => '',
                                'name' => 'Objednávka: '.$this->order->order_no,
                            ],
                        ],
                        'producer' => 'wpj',
                        'campaigns' => [],
                        'name' => 'iPhone wpj',
                        'vat' => \Decimal::fromString('21', 16),
                        'price' => '3.18',
                        'priceWithVat' => '3.85',
                        'priceWithoutVat' => '3.18',
                        'priceVat' => '0.67',
                        'priceWithoutDiscount' => '15.87',
                        'discount' => 80.04,
                        'hasDiscount' => true,
                        'availability' => 'skladem',
                        'quantity' => '1',
                        'imageUrl' => 'https://www.kupshop.local/data/tmp/0/6/26_0.jpg?',
                        'url' => 'https://www.kupshop.local/iphone-wpj_z11/',
                        'soldOut' => null,
                    ],
                ],
            ],
        ];

        // Sort products by ID, so test is not dependent on order of products
        $idsExp = array_column($exp_res['purchase']['products'], 'id');
        array_multisort($idsExp, SORT_ASC, $exp_res['purchase']['products']);

        $changed = $this->recursivelyChangeType($data);
        $idsChanged = array_column($changed['purchase']['products'], 'id');
        array_multisort($idsChanged, SORT_ASC, $changed['purchase']['products']);

        $this->assertEquals($exp_res, $changed);
    }
}
