updateFields()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
cc 4
nc 4
nop 1
1
<?php
2
3
4
class CountryPrice_OrderFormAddressExtension extends Extension
5
{
6
    public function updateFields($fields)
7
    {
8
        $shippingField = $fields->dataFieldByName('ShippingCountry');
9
        $originalSource = $shippingField->getSource();
10
        $newSource = $originalSource;
11
        $allowedCountries = CountryPrice_EcommerceCountry::get_sibling_countries();
12
        $allowedCountries = $allowedCountries->exclude('OnlyShowChildrenInDropdowns', true);
13
        if ($allowedCountries->count()) {
14
            $allowedCountryCodes = $allowedCountries->column('Code');
15
            foreach ($newSource as $key => $value) {
16
                if (! in_array($key, $allowedCountryCodes)) {
17
                    unset($newSource[$key]);
18
                }
19
            }
20
            $shippingField->setSource($newSource);
21
            $js = '
22
                var CountryPrice_SetCountriesForDelivery_Original = '.Convert::array2json($originalSource).';
23
                var CountryPrice_SetCountriesForDelivery_New      = '.Convert::array2json($newSource).';';
24
            Requirements::customScript($js, 'CountryPrice_OrderFormAddressExtension_updateFields');
25
        }
26
    }
27
}
28