getTable($this->tableAlias . 'Address')->saveRelations($addresses, $key); } public function saveMailingAddress(array $address, array $key) { $key['type'] = Entity::TYPE_MAILING; return $this->getTable($this->tableAlias . 'Address')->saveBy($address, $key); } public function saveBillingAddress(array $address, array $key) { $key['type'] = Entity::TYPE_BILLING; return $this->getTable($this->tableAlias . 'Address')->saveBy($address, $key); } public function saveShippingAddress(array $address, array $key) { $key['type'] = Entity::TYPE_SHIPPING; return $this->getTable($this->tableAlias . 'Address')->saveBy($address, $key); } public function getAddresses(array $key) { $select = $this->db->select(); $select->from(Qs_Db::getPair($this->tableAlias . 'Address', 'a')); $select->join(Qs_Db::getPair('DState', 's'), '`s`.`id` = `a`.`state`', ['stateName' => 'title']); Qs_Db::filter($select, $key, 'a'); $list = $this->db->fetchAll($select); return Qs_Array::group($list, ['type'], []); } public function getBillingAddress(array $key) { $key['type'] = Entity::TYPE_BILLING; return $this->getAddress($key); } public function getMailingAddress(array $key) { $key['type'] = Entity::TYPE_MAILING; return $this->getAddress($key); } private function getAddress(array $key) { $select = $this->db->select(); $columns = ['address', 'address2', 'city', 'state', 'zip']; if ($key['type'] == Entity::TYPE_BILLING) { $columns = array_merge(['firstName', 'lastName'], $columns); } $select->from(Qs_Db::getPair($this->tableAlias . 'Address', 'a'), $columns); $select->join(Qs_Db::getPair('DState', 's'), '`s`.`id` = `a`.`state`', ['stateName' => 'title']); Qs_Db::filter($select, $key, 'a', Qs_Db::FILTER_THROW_UNKNOWN); return $this->db->fetchRow($select); } }