示例#1
0
 /**
  * @return array of addresses to check for duplicates and reuse the address_id.
  */
 public function getExistingAddresses($customer_id)
 {
     $db = self::$_msql = SafeMySQL::getInstance();
     $sql = "SELECT  *\n                FROM `addresses`\n                WHERE `customer_id` = ?i";
     return $db->getAll($sql, $customer_id);
 }
示例#2
0
 private function buildAddress($address_type = "shipping")
 {
     $aType = $address_type . 'Address';
     $this->{$aType} = new Address();
     // do we need to pull out the data from different named form fields?
     if ($this->wsType == 'x1') {
         $sd = array();
         $offset = $address_type == 'shipping' ? 9 : 8;
         foreach ($this->post as $k => $v) {
             if (stripos($k, $address_type) !== false) {
                 $i = stripos($k, $address_type) + $offset;
                 $sd[substr($k, +$offset, strlen($k) - $offset)] = $v;
             }
         }
         $this->{$aType}->fillAddressFromArray($sd, $address_type);
         unset($sd);
     } else {
         $this->{$aType}->fillAddressFromArray($this->post, $address_type);
     }
     $this->{$aType}->customer_id = $this->customer->getPkvalue();
     $this->{$aType}->created = $this->{$aType}->updated = 'NOW():sql';
     //date("Y-m-d H:i:s");
     // is this an existing customer?  if so check addresses against DB
     if (!$this->newCustomer) {
         $ea = new Addresss('Address');
         $existing = $ea->compareExistingAddresses($this->{$aType});
         if ($existing) {
             $this->{$aType}->address_id = $existing;
         }
     }
     if (empty($this->{$aType}->address_id)) {
         $this->{$aType}->address_type = $address_type;
         if (!$this->{$aType}->save()) {
             fb($this->{$aType}->getErrors());
             $this->apiError('error6 ' . $this->{$aType}->geterrors2string());
         }
     }
 }