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

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

        $countryRepository = $this->manager->getRepository(Country::class);
        $taxRepository = $this->manager->getRepository(Tax::class);
        $taxRuleRepository = $this->manager->getRepository(TaxRule::class);

        foreach ($codes as $code) {
            $path = __DIR__ . '/data/' . $code . '_tax_rules.yml';
            if (!(file_exists($path) && is_readable($path))) {
                call_user_func($this->log, 'Tax rules 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 (null === $taxRuleRepository->findOneBy(['name' => $name])) {
                    $taxRule = new TaxRule();
                    $taxRule
                        ->setName($name)
                        ->setPriority($datum['priority'])
                        ->setCustomer($datum['customer'])
                        ->setBusiness($datum['business'])
                        ->setNotices($datum['notices']);

                    if (!empty($countryCodes = $datum['countries'])) {
                        $taxRule->setCountries($countryRepository->findBy(['code' => $countryCodes]));
                    }

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

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

                    $result = 'done';
                }

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

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

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

        $countryRepository = $this->manager->getRepository(Country::class);
        $taxRepository = $this->manager->getRepository(Tax::class);
        $taxRuleRepository = $this->manager->getRepository(TaxRule::class);

        foreach ($codes as $code) {
            $path = __DIR__ . '/data/' . $code . '_tax_rules.yml';
            if (!(file_exists($path) && is_readable($path))) {
                call_user_func($this->log, 'Tax rules 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 (null === $taxRuleRepository->findOneBy(['name' => $name])) {
                    $taxRule = new TaxRule();
                    $taxRule
                        ->setName($name)
                        ->setPriority($datum['priority'])
                        ->setCustomer($datum['customer'])
                        ->setBusiness($datum['business'])
                        ->setNotices($datum['notices']);

                    if (!empty($countryCodes = $datum['countries'])) {
                        $taxRule->setCountries($countryRepository->findBy(['code' => $countryCodes]));
                    }

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

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

                    $result = 'done';
                }

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

        $this->manager->flush();
    }
public function installTaxRules ( $ codes = [ 'US' ] ) { $ codes = ( array ) $ codes ; if ( empty ( $ codes ) ) { return ; } $ countryRepository = $ this -> manager -> getRepository ( Country :: class ) ; $ taxRepository = $ this -> manager -> getRepository ( Tax :: class ) ; $ taxRuleRepository = $ this -> manager -> getRepository ( TaxRule :: class ) ; foreach ( $ codes as $ code ) { $ path = __DIR__ . '/data/' . $ code . '_tax_rules.yml' ; if ( ! ( file_exists ( $ path ) && is_readable ( $ path ) ) ) { call_user_func ( $ this -> log , 'Tax rules 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 ( null === $ taxRuleRepository -> findOneBy ( [ 'name' => $ name ] ) ) { $ taxRule = new TaxRule ( ) ; $ taxRule -> setName ( $ name ) -> setPriority ( $ datum [ 'priority' ] ) -> setCustomer ( $ datum [ 'customer' ] ) -> setBusiness ( $ datum [ 'business' ] ) -> setNotices ( $ datum [ 'notices' ] ) ; if ( ! empty ( $ countryCodes = $ datum [ 'countries' ] ) ) { $ taxRule -> setCountries ( $ countryRepository -> findBy ( [ 'code' => $ countryCodes ] ) ) ; } if ( ! empty ( $ taxNames = $ datum [ 'taxes' ] ) ) { $ taxRule -> setTaxes ( $ taxRepository -> findBy ( [ 'name' => $ taxNames ] ) ) ; } $ this -> manager -> persist ( $ taxRule ) ; $ result = 'done' ; } call_user_func ( $ this -> log , $ name , $ result ) ; } } $ this -> manager -> flush ( ) ; }
Installs the tax rules for the given country codes.

@param array $codes The country codes to load the tax rules for
Installs the tax rules for the given country codes .