/**
  * Customer Transactions Section. Track account balance transactions.
  * Return customer account balance in customer currency based on debit/credit calcualtion
  *
  * @return float|bool
  */
 public function getBalance()
 {
     if (!$this->isLogged()) {
         return false;
     }
     $cache_name = 'balance.' . (int) $this->getId();
     $balance = $this->cache->get($cache_name);
     if (is_null($balance)) {
         $query = $this->db->query("SELECT sum(credit) - sum(debit) as balance\n\t\t\t\t\t\t\t\t\t\tFROM " . $this->db->table("customer_transactions") . "\n\t\t\t\t\t\t\t\t\t\tWHERE customer_id = '" . (int) $this->getId() . "'");
         $balance = $query->row['balance'];
         $this->cache->set($cache_name, $balance);
     }
     return $balance;
 }
예제 #2
0
 /**
  * Get available tax classes for country ID and zone ID
  * Storefront use only!!!
  * @param $country_id
  * @param $zone_id
  * @return mixed|null
  */
 public function getTaxes($country_id, $zone_id)
 {
     $country_id = (int) $country_id;
     $zone_id = (int) $zone_id;
     $language = $this->registry->get('language');
     $language_id = $language->getLanguageID();
     $cache_name = 'tax_class.' . $country_id . '.' . $zone_id;
     $results = $this->cache->get($cache_name, $language_id);
     if (is_null($results)) {
         //Note: Default language text is picked up if no selected language available
         $sql = "SELECT tr.tax_class_id,\n\t\t\t\t\t\t\ttr.rate AS rate, tr.rate_prefix AS rate_prefix, \n\t\t\t\t\t\t\ttr.threshold_condition AS threshold_condition, tr.threshold AS threshold,\n\t\t\t\t\t\t\tCOALESCE( td1.title,td2.title) as title,\n\t\t\t\t\t\t\tCOALESCE( NULLIF(trd1.description, ''),\n\t\t\t\t\t\t\t\t\t  NULLIF(td1.description, ''),\n\t\t\t\t\t\t\t\t\t  NULLIF(trd2.description, ''),\n\t\t\t\t\t\t\t\t\t  NULLIF(td2.description, ''),\n\t\t\t\t\t\t\t\t\t  COALESCE( td1.title,td2.title)\n\t\t\t\t\t\t\t) as description,\n\t\t\t\t\t\t\ttr.priority\t\n\t\t\t\t\tFROM " . $this->db->table("tax_rates") . " tr\n\t\t\t\t\tLEFT JOIN " . $this->db->table("tax_rate_descriptions") . " trd1 ON \n\t\t\t\t\t\t(tr.tax_rate_id = trd1.tax_rate_id AND trd1.language_id = '" . (int) $language_id . "')\n\t\t\t\t\tLEFT JOIN " . $this->db->table("tax_rate_descriptions") . " trd2 ON \n\t\t\t\t\t\t(tr.tax_rate_id = trd2.tax_rate_id AND trd2.language_id = '" . (int) $default_lang_id . "')\n\t\t\t\t\tLEFT JOIN " . $this->db->table("tax_classes") . " tc ON tc.tax_class_id = tr.tax_class_id\n\t\t\t\t\tLEFT JOIN " . $this->db->table("tax_class_descriptions") . " td1 ON \n\t\t\t\t\t\t(tc.tax_class_id = td1.tax_class_id AND td1.language_id = '" . (int) $language_id . "')\n\t\t\t\t\tLEFT JOIN " . $this->db->table("tax_class_descriptions") . " td2 ON \n\t\t\t\t\t\t(tc.tax_class_id = td2.tax_class_id AND td2.language_id = '" . (int) $default_lang_id . "')\n\t\t\t\t\tWHERE (tr.zone_id = '0' OR tr.zone_id = '" . $zone_id . "')\n\t\t\t\t\t\tAND tr.location_id in (SELECT z2l.location_id\n\t\t\t\t\t\t\t\t\t\t\t   FROM " . $this->db->table("zones_to_locations") . " z2l, " . $this->db->table("locations") . " l\n\t\t\t\t\t\t\t\t\t\t\t   WHERE z2l.location_id = l.location_id and z2l.zone_id = '" . $zone_id . "')\n\t\t\t\t\tORDER BY tr.priority ASC";
         $tax_rate_query = $this->db->query($sql);
         $results = $tax_rate_query->rows;
         $this->cache->set($cache_name, $results, $language_id);
     }
     return $results;
 }