【问题标题】:Android : create customer in magento via SOAP APIAndroid:通过 SOAP API 在 magento 中创建客户
【发布时间】:2013-12-29 06:46:49
【问题描述】:

我试图在 android 应用程序中通过 SOAP API (customerCustomerCreate (SOAP V2)) 在 magento 中创建客户,但我收到此错误:

SoapFault - faultcode: '100' faultstring: 'Customer email is required' faultactor: 'null' detail: null

我使用此代码设置电子邮件地址:

 request = new SoapObject(NAMESPACE, "customerCustomerCreate");
        request.addProperty("sessionId", sessionId);

        SoapObject value = new SoapObject(NAMESPACE, "associativeEntity");
        value.addProperty("key", "in");
        value.addProperty("value", "xxxxx@xxxxx.com");

        SoapObject complexFilter = new SoapObject(NAMESPACE,
                "complexFilter");
        complexFilter.addProperty("key", "email");
        complexFilter.addProperty("value", value);
                    SoapObject filterArray = new SoapObject(NAMESPACE,
                "complexFilterArray");
        filterArray.addProperty("item", complexFilter);

        SoapObject filters = new SoapObject(NAMESPACE, "filters");
        filters.addProperty("complex_filter", filterArray);

        request.addProperty("filters", filters);

        env.setOutputSoapObject(request);

        androidHttpTransport.call("", env);
        result = env.getResponse();

有人知道我在这里做错了什么吗? 谢谢

【问题讨论】:

    标签: java android api magento soap


    【解决方案1】:

    如果你在使用这个之前没有得到答案..

    public void CreateNewCustomer(String email, String firstname, String lastname, String password) {
    
    
                try {
                    env.dotNet = false;
                    env.xsd = SoapSerializationEnvelope.XSD;
                    env.enc = SoapSerializationEnvelope.ENC;
                    request = new SoapObject(NAMESPACE, "login");
                    request.addProperty("username", "+++++");
                    request.addProperty("apiKey", "+++++");
                    env.setOutputSoapObject(request);
    
                   public static HttpTransportSE androidHttpTransport = new HttpTransportSE(URL)
                    androidHttpTransport.call("", env);
                    session = env.getResponse();
                    sessionId = session.toString();
    
                    Log.d("sessionId", sessionId.toString()); 
    
                    Log.d("Create "," Creating......");
                    request = new SoapObject(NAMESPACE,"customerCustomerCreate");
                    request.addProperty("sessionId", sessionId);
    //              request.addProperty("product", product_id);
    
                    //-----use Kvm Serializable class to serialize the key value data-------
    
                    CreateCustomerKVMserialize createcustomerkvm = new CreateCustomerKVMserialize();
    
                    createcustomerkvm.Email = email;
                    createcustomerkvm.Firstname = firstname;
                    createcustomerkvm.Lastname = lastname;
                    createcustomerkvm.Password = password;
    
                    PropertyInfo pi = new PropertyInfo();
                    pi.setName("customerData");
                    pi.setValue(createcustomerkvm);
                    pi.setType(createcustomerkvm.getClass());
                    request.addProperty(pi);
    
                    env.setOutputSoapObject(request);
                    env.addMapping(NAMESPACE, "customerData",new CreateCustomerKVMserialize().getClass());
    
                    androidHttpTransport.call("", env);
                    Object customer_create = env.getResponse();
                    Log.d("mainactivity "," "+customer_create.toString());
    
    
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (XmlPullParserException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
    
        }       
    

    ---------CreateCustomerKVMserialize 类-----------

    public class CreateCustomerKVMserialize implements KvmSerializable{
    
        public String Email;
        public String Firstname;
        public String Lastname;
        public String Password;
    //    public String Websiteid;
    //    public String Storeid;
    //    public String Groupid;
    
        public CreateCustomerKVMserialize(){}
    
        public CreateCustomerKVMserialize(String email, String firstname, String lastname,String password) {
    
            Email = email;
            Firstname = firstname;
            Lastname = lastname;
            Password = password;
        }
    
        @Override
        public Object getProperty(int arg0) {
            // TODO Auto-generated method stub
             switch(arg0)
                {
                case 0:
                    return Email;
                case 1:
                    return Firstname;
                case 2:
                    return Lastname;
                case 3:
                    return Password;    
    
                }
    
                return null;
    
        }
    
        @Override
        public int getPropertyCount() {
            // TODO Auto-generated method stub
            return 4;
        }
    
        @Override
        public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
            // TODO Auto-generated method stub
    
             switch(index)
                {
                case 0:
                    info.type = PropertyInfo.STRING_CLASS;
                    info.name = "email";
                    break;
                case 1:
                    info.type = PropertyInfo.STRING_CLASS;
                    info.name = "firstname";
                    break;
                case 2:
                     info.type = PropertyInfo.STRING_CLASS;
                     info.name = "lastname";
                    break;
                case 3:
                     info.type = PropertyInfo.STRING_CLASS;
                     info.name = "password";
                    break;
                default:break;
                }
        }
    
        @Override
        public void setProperty(int index, Object value) {
            // TODO Auto-generated method stub
    
            switch(index)
            {
            case 0:
                Email = value.toString();
                break;
            case 1:
                Firstname = value.toString();
                break;
            case 2:
                Lastname = value.toString();
                break;
            case 3:
                Password = value.toString();
                break;
    
            default:
                break;
            }
        }
    
    }
    

    【讨论】:

    • 感谢 Remees,它工作得很好,除了我必须指定您已注释掉的 WebsiteId、StoreId 和 GroupId。
    • @BabyinCoding ,对不起,我很久以前做过这个。无论如何,我会看看,如果有什么积极的事情,我会告诉你。
    • @RemeesMSyde 感谢您的支持。
    • @RemeesMSyde 我发布了新问题,请在此处查看:stackoverflow.com/questions/34720862/…
    【解决方案2】:

    使用下面的代码:

     SoapObject request = new SoapObject(NAMESPACE, "customerCustomerCreate");
                        request.addProperty("sessionId", sessionId);
    
                        SoapObject customerEntity = new SoapObject(NAMESPACE, "customerCustomerEntityToCreate");
    
    
                        customerEntity.addProperty("email", "abqpo@120.com");
                        customerEntity.addProperty("firstname", "firstname");
                        customerEntity.addProperty("lastname", "lastname");
    
                        request.addProperty("customerData", customerEntity);
    
    
                        env.setOutputSoapObject(request);
    
                        androidHttpTransport.call("", env);
                        Object result = env.getResponse();
                        String custId  = result.toString();
    

    其中 envSoapSerializationEnvelope

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-11
      • 1970-01-01
      • 1970-01-01
      • 2011-11-29
      • 2021-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多