示例#1
0
 protected function getInstance($record, CsvImportProfile $profile)
 {
     pp('User address import get instance');
     $fields = $profile->getSortedFields();
     if (isset($fields['UserAddress']['ID'])) {
         $instance = ActiveRecordModel::getInstanceByID('UserAddress', $record[$fields['UserAddress']['ID']], true);
     } else {
         if (isset($fields['AddressUser']['ID'])) {
             $owner = User::getInstanceByID($record[$fields['AddressUser']['ID']], true);
         } else {
             if (isset($fields['AddressUser']['email'])) {
                 $owner = User::getInstanceByEmail($record[$fields['AddressUser']['email']]);
             }
         }
     }
     if (isset($owner)) {
         if ($profile->isColumnSet('AddressUser.isShipping')) {
             $type = $this->evalBool(strtolower($record[$profile->getColumnIndex('AddressUser.isShipping')])) ? 'ShippingAddress' : 'BillingAddress';
         } else {
             $type = 'BillingAddress';
         }
         $owner->loadAddresses();
     }
     if (empty($instance)) {
         if (empty($owner)) {
             return;
         }
         $isDefault = $profile->isColumnSet('AddressUser.isDefault') && $this->evalBool(strtolower($record[$profile->getColumnIndex('AddressUser.isDefault')]));
         if ($isDefault) {
             $field = 'default' . $type;
             $addressType = $owner->{$field}->get();
             $instance = $addressType->userAddress->get();
         }
         if (empty($addressType)) {
             $instance = UserAddress::getNewInstance();
             $addressType = call_user_func_array(array($type, 'getNewInstance'), array($owner, $instance));
             if ($isDefault) {
                 $owner->{$field}->set($addressType);
             }
         }
         $addressType->userAddress->set($instance);
         $instance->addressType = $addressType;
     }
     return $instance;
 }
示例#2
0
 public function getColumnValue($record, CsvImportProfile $profile, $fieldName)
 {
     if ($profile->isColumnSet($fieldName)) {
         return $record[$profile->getColumnIndex($fieldName)];
     }
 }