Skip to content

Commit

Permalink
[*] LO : FR now has a Corse Zone defined
Browse files Browse the repository at this point in the history
[*] LO : CA Taxes
  • Loading branch information
fBrignoli committed Sep 19, 2011
1 parent f046afd commit c57b593
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 34 deletions.
60 changes: 34 additions & 26 deletions classes/LocalizationPack.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,33 @@ public function loadLocalisationPack($file, $selection, $install_mode = false)
protected function _installStates($xml)
{
if (isset($xml->states->state))
foreach ($xml->states->state AS $data)
foreach ($xml->states->state as $data)
{
$attributes = $data->attributes();

if (!$id_state = State::getIdByName($attributes['name']))
{
$state = new State();
$state->name = strval($attributes['name']);
$state->iso_code = strval($attributes['iso_code']);
$state->id_country = Country::getByIso(strval($attributes['country']));
$state->id_zone = (int)(Zone::getIdByName(strval($attributes['zone'])));

$id_zone = (int)Zone::getIdByName(strval($attributes['zone']));
if (!$id_zone)
{
$zone = new Zone();
$zone->name = (string)$attributes['zone'];
$zone->active = true;

if (!$zone->add())
{
$this->_errors[] = Tools::displayError('Invalid Zone name.');
return false;
}

$id_zone = $zone->id;
}

$state->id_zone = $id_zone;

if (!$state->validateFields())
{
Expand Down Expand Up @@ -126,9 +142,8 @@ protected function _installTaxes($xml)
{
if (isset($xml->taxes->tax))
{
$available_behavior = array(PS_PRODUCT_TAX, PS_STATE_TAX, PS_BOTH_TAX);
$assoc_taxes = array();
foreach ($xml->taxes->tax AS $taxData)
foreach ($xml->taxes->tax as $taxData)
{
$attributes = $taxData->attributes();
if (Tax::getTaxIdByName($attributes['name']))
Expand All @@ -153,7 +168,7 @@ protected function _installTaxes($xml)
$assoc_taxes[(int)$attributes['id']] = $tax->id;
}

foreach ($xml->taxes->taxRulesGroup AS $group)
foreach ($xml->taxes->taxRulesGroup as $group)
{
$group_attributes = $group->attributes();
if (!Validate::isGenericName($group_attributes['name']))
Expand All @@ -172,7 +187,7 @@ protected function _installTaxes($xml)
return false;
}

foreach($group->taxRule as $rule)
foreach ($group->taxRule as $rule)
{
$rule_attributes = $rule->attributes();

Expand All @@ -188,25 +203,17 @@ protected function _installTaxes($xml)
continue;

// Default values
$id_state = (int) isset($rule_attributes['iso_code_state']) ? State::getIdByIso(strtoupper($rule_attributes['iso_code_state'])) : 0;
$id_state = (int)isset($rule_attributes['iso_code_state']) ? State::getIdByIso(strtoupper($rule_attributes['iso_code_state'])) : 0;
$id_county = 0;
$state_behavior = 0;
$county_behavior = 0;
$zipcode_from = 0;
$zipcode_to = 0;
$behavior = $rule_attributes['behavior'];

if ($id_state)
if (isset($rule_attributes['zipcode_from']))
{
if (isset($rule_attributes['state_behavior']) && in_array($rule_attributes['state_behavior'], $available_behavior))
$state_behavior = (int)$rule_attributes['state_behavior'];

if (isset($rule_attributes['county_name']))
{
$id_county = County::getIdCountyByNameAndIdState($rule_attributes['county_name'], (int)$id_state);
if (!$id_county)
continue;
}

if (isset($rule_attributes['county_behavior']) && in_array($rule_attributes['state_behavior'], $available_behavior))
$county_behavior = (int)$rule_attributes['county_behavior'];
$zipcode_from = $rule_attributes['zipcode_from'];
if (isset($rule_attributes['zipcode_to']))
$zipcode_to = $rule_attributes['zipcode_to'];
}

// Creation
Expand All @@ -215,14 +222,15 @@ protected function _installTaxes($xml)
$tr->id_country = $id_country;
$tr->id_state = $id_state;
$tr->id_county = $id_county;
$tr->state_behavior = $state_behavior;
$tr->county_behavior = $county_behavior;
$tr->zipcode_from = $zipcode_from;
$tr->zipcode_to = $zipcode_to;
$tr->behavior = $behavior;
$tr->description = $description;
$tr->id_tax = $assoc_taxes[strval($rule_attributes['id_tax'])];
$tr->save();
}
}
}

return true;
}

Expand Down
44 changes: 36 additions & 8 deletions localization/ca.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,44 @@
<language iso_code="fr" />
<language iso_code="en" />
</languages>
<states>
<state name="Alberta" iso_code="AB" country="CA" zone="North America" />
<state name="British Columbia" iso_code="BC" country="CA" zone="North America" />
<state name="Manitoba" iso_code="MB" country="CA" zone="North America" />
<state name="New Brunswick" iso_code="NB" country="CA" zone="North America" />
<state name="Newfoundland" iso_code="NL" country="CA" zone="North America" />
<state name="Nova Scotia" iso_code="NS" country="CA" zone="North America" />
<state name="Nunavut" iso_code="NU" country="CA" zone="North America" />
<state name="Ontario" iso_code="ON" country="CA" zone="North America" />
<state name="Prince Edward Island" iso_code="PE" country="CA" zone="North America" />
<state name="Quebec" iso_code="QC" country="CA" zone="North America" />
<state name="Saskatchewan" iso_code="SK" country="CA" zone="North America" />
</states>
<taxes>
<tax id="1" name="GST CA 5%" rate="5" />
<tax id="2" name="HST CA 10%" rate="10" />
<tax id="1" name="GST 5%" rate="5" />
<tax id="2" name="HST 12%" rate="12" />
<tax id="3" name="HST 13%" rate="13" />
<tax id="4" name="HST 15%" rate="15" />
<tax id="5" name="PST 7%" rate="7" />
<tax id="6" name="PST 10%" rate="10" />
<tax id="7" name="PST 8.5%" rate="8.5" />
<tax id="8" name="PST 5%" rate="5" />

<taxRulesGroup name="CA Standard Rate (10%)">
<taxRule iso_code_country="ca" id_tax="1" />
</taxRulesGroup>

<taxRulesGroup name="CA Reduced Rate (5%)">
<taxRule iso_code_country="ca" id_tax="2" />
<taxRulesGroup name="CA Standard Rate">
<taxRule iso_code_country="ca" iso_code_state="ab" id_tax="1" />
<taxRule iso_code_country="ca" iso_code_state="bc" id_tax="2" />
<taxRule iso_code_country="ca" iso_code_state="mb" id_tax="1" />
<taxRule iso_code_country="ca" iso_code_state="mb" id_tax="5" />
<taxRule iso_code_country="ca" iso_code_state="nb" id_tax="3" />
<taxRule iso_code_country="ca" iso_code_state="nf" id_tax="3" />
<taxRule iso_code_country="ca" iso_code_state="ns" id_tax="4" />
<taxRule iso_code_country="ca" iso_code_state="on" id_tax="3" />
<taxRule iso_code_country="ca" iso_code_state="pe" id_tax="1" behavior="2" />
<taxRule iso_code_country="ca" iso_code_state="pe" id_tax="6" behavior="2" />
<taxRule iso_code_country="ca" iso_code_state="qc" id_tax="1" behavior="2" />
<taxRule iso_code_country="ca" iso_code_state="qc" id_tax="7" behavior="2" />
<taxRule iso_code_country="ca" iso_code_state="sk" id_tax="1" />
<taxRule iso_code_country="ca" iso_code_state="sk" id_tax="8" />
</taxRulesGroup>
</taxes>
<units>
Expand Down
4 changes: 4 additions & 0 deletions localization/fr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<languages>
<language iso_code="fr" />
</languages>

<states>
<state name="Corse" iso_code="CO" country="FR" zone="France Corse" />
</states>
<taxes>
<tax id="1" name="TVA FR 19.6%" rate="19.6" />
<tax id="2" name="TVA FR 5.5%" rate="5.5" />
Expand Down

0 comments on commit c57b593

Please sign in to comment.