Install/Installer.php
public function installTaxGroups($codes = ['US'])
    {
        $codes = (array)$codes;

        if (empty($codes)) {
            return;
        }

        $taxGroupRepository = $this->manager->getRepository(TaxGroup::class);
        $taxRepository = $this->manager->getRepository(Tax::class);

        foreach ($codes as $code) {
            $path = __DIR__ . '/data/' . $code . '_tax_groups.yml';
            if (!(file_exists($path) && is_readable($path))) {
                call_user_func($this->log, 'Tax groups data', 'not found');
                continue;
            }

            $data = Yaml::parse(file_get_contents($path));
            if (!is_array($data) || empty($data)) {
                continue;
            }

            foreach ($data as $datum) {
                $name = $datum['name'];
                $result = 'already exists';

                if ($datum['default']) {
                    $taxGroup = $this
                        ->manager
                        ->getRepository(TaxGroup::class)
                        ->findOneBy(['default' => true]);
                    if (null !== $taxGroup) {
                        call_user_func($this->log, $name, 'skipped');
                        continue;
                    }
                }

                if (null === $taxGroupRepository->findOneBy(['name' => $name])) {
                    $taxGroup = new TaxGroup();
                    $taxGroup
                        ->setName($name)
                        ->setDefault($datum['default']);

                    if (!empty($taxNames = $datum['taxes'])) {
                        $taxGroup->setTaxes($taxRepository->findBy(['name' => $taxNames]));
                    }

                    $this->manager->persist($taxGroup);

                    $result = 'done';
                }

                call_user_func($this->log, $name, $result);
            }
        }

        $this->manager->flush();
    }
public function installTaxGroups($codes = ['US'])
    {
        $codes = (array)$codes;

        if (empty($codes)) {
            return;
        }

        $taxGroupRepository = $this->manager->getRepository(TaxGroup::class);
        $taxRepository = $this->manager->getRepository(Tax::class);

        foreach ($codes as $code) {
            $path = __DIR__ . '/data/' . $code . '_tax_groups.yml';
            if (!(file_exists($path) && is_readable($path))) {
                call_user_func($this->log, 'Tax groups data', 'not found');
                continue;
            }

            $data = Yaml::parse(file_get_contents($path));
            if (!is_array($data) || empty($data)) {
                continue;
            }

            foreach ($data as $datum) {
                $name = $datum['name'];
                $result = 'already exists';

                if ($datum['default']) {
                    $taxGroup = $this
                        ->manager
                        ->getRepository(TaxGroup::class)
                        ->findOneBy(['default' => true]);
                    if (null !== $taxGroup) {
                        call_user_func($this->log, $name, 'skipped');
                        continue;
                    }
                }

                if (null === $taxGroupRepository->findOneBy(['name' => $name])) {
                    $taxGroup = new TaxGroup();
                    $taxGroup
                        ->setName($name)
                        ->setDefault($datum['default']);

                    if (!empty($taxNames = $datum['taxes'])) {
                        $taxGroup->setTaxes($taxRepository->findBy(['name' => $taxNames]));
                    }

                    $this->manager->persist($taxGroup);

                    $result = 'done';
                }

                call_user_func($this->log, $name, $result);
            }
        }

        $this->manager->flush();
    }
Installs the default tax groups.

@param array $codes The country codes to load the taxes for