예제 #1
0
 /**
  * @param array $result
  *
  * @return array Returns an array of tax objects
  */
 public static function getTaxes($result = [])
 {
     $taxItemsMdl = new TaxItemsModel();
     $taxItemsArr = $taxItemsMdl->get();
     if (is_array($taxItemsArr)) {
         $taxItems = [];
         foreach ($taxItemsArr as $taxItem) {
             $taxItems[$taxItem['id']] = $taxItem;
         }
         $result['data'] = [];
         $result['data']['items'] = $taxItems;
         $taxRulesMdl = new TaxRulesModel();
         $taxRulesArr = $taxRulesMdl->get();
         if (is_array($taxRulesArr)) {
             $taxRules = [];
             foreach ($taxRulesArr as $taxRule) {
                 $ruleData = json_decode($taxRule['data']);
                 $ruleData->id = $taxRule['id'];
                 $taxRules[$taxRule['id']] = $ruleData;
             }
             $result['data']['rules'] = $taxRules;
         } else {
             $result['error'] = "Tax data could not be retrieved: " . $taxRulesMdl->errorInfo;
         }
     } else {
         $result['error'] = "Tax data could not be retrieved: " . $taxItemsMdl->errorInfo;
     }
     return $result;
 }