【问题标题】:Combined complex filter for ranges in NodejsNodejs中范围的组合复杂过滤器
【发布时间】:2016-11-10 13:54:59
【问题描述】:

在 Magento 1.8 SOAP APIv2 上,我正在寻找一种方法来获取日期范围以从 SOAP API 中检索信息。我已经咨询了来自 stackoverflow 本身的查询,即Combined complex filter for ranges。需要在我的节点项目中应用相同类型的复杂过滤器。 目前使用 magento 节点包装器,即https://github.com/MadisonReed/magentoapi

exports.find = function (req, res) {
  async.waterfall([
    function (done) {
      magento.login(function(err, sessId) {
        if (err) {
          // deal with error
          console.log('login error:' + err);
          return;
        }
        done(err, done);
        // http://localhost/api/rest/customers
      });
    },

    function (filteredCustomer, done) {
      var attributes = [];
      var filteredCustomer = [];
      magento.customer.list({filters: [  ]},function(err, customerCollection) {
        _.forEach(customerCollection, function(customer, key) {
          var attributes = _.pick(customer, [
            'customer_id',
            'created_at',
            'updated_at',
            'firstname',
            'lastname',
            'gender',
            'credit_value',
            'customer_referral_code',
          ]);
          var customerDocument = {
            'email': customer.email,
            'number': customer.contact_no,
            'created_at': Date.now(),
            'initialSource': 'magento',
            'attributes': attributes
          };
          filteredCustomer.push(customerDocument);
        });
        done(filteredCustomer);
      });
    },
    function (filteredCustomer, done) {
      console.log(filteredCustomer);
      if(!err){
        done(filteredCustomer);
      }
    }
  ],
  function (err) {
    if (err) {
      console.log(err);
    }
  });
};

输出:

[ 
 { 
    email: 'rht.rai2@gmail.com',
    number: '1313543132',
    created_at: 1478785224233,
    initialSource: 'magento',
    attributes: 
     { customer_id: '1',
       created_at: '2016-03-10 04:39:16',
       updated_at: '2016-10-03 10:09:21',
       firstname: 'rohit',
       lastname: 'Rai',
       gender: '1',
       credit_value: '0.0000',
       customer_referral_code: 'dS518' 
     } 
 },   
 {
    email: 'rajveer@gmailj.com',
    number: '9088694978',
    created_at: 1478785224233,
    initialSource: 'magento',
    attributes: 
     { 
       customer_id: '2',
       created_at: '2016-04-10 23:52:05',
       updated_at: '2016-11-04 05:22:09',
       firstname: 'rajveer',
       gender: '1',
       credit_value: '0.0000',
       customer_referral_code: 'Cw624' 
     } 
 },
 { 
    email: 'rohit@happilyunmarried.com',
    number: '1321321231',
    created_at: 1478785224233,
    initialSource: 'magento',
    attributes: 
     { 
       customer_id: '3',
       created_at: '2016-07-11 05:00:55',
       updated_at: '2016-11-07 10:03:54',
       firstname: 'rohit',
       gender: '1',
       credit_value: '0.0000',
       customer_referral_code: 'aj318' 
     } 
 } 
]

【问题讨论】:

    标签: node.js soap magento-1.9


    【解决方案1】:

    我想出了在 magento 中发送数据并在 Node.js 中获得所需结果的方法。它的工作顺利。希望对您有所帮助。

    'use strict';
    
    /**
     * Module dependencies.
     */
    var path = require('path'),
      mongoose = require('mongoose'),
      errorHandler = require(path.resolve('./modules/core/server/controllers/errors.server.controller')),
      _ = require('lodash'),
      Customers = mongoose.model('Customers'),
        async = require('async'),
          moment = require('moment');
    
    var MagentoAPI = require('magento');
    
    var magento = new MagentoAPI({
      host: 'localhost',
      port: 80,
      path: '/happilyustraa/api/xmlrpc/',
      login: 'rhtrai',
      pass: 'rohitisla'
    });
    
    
    
    
    
    exports.find = function (req, res) {
      async.waterfall([
        function (done) {
          magento.login(function(err, sessId) {
            if (err) {
              // deal with error
              console.log('login error:' + err);
              return;
            }
            done(err, done);
            // http://localhost/api/rest/customers
          });
        },
    
        function (filteredCustomer, done) {
          var attributes = [];
          var filteredCustomer = [];
          magento.customer.list({filters: {"CREATED_AT": {'from': "2016-03-10 04:39:16"}, "created_at":{ 'to': "2016-04-10 23:52:05"}   } },function(err, customerCollection) {
            _.forEach(customerCollection, function(customer, key) {
              // var attributes = _.pick(customer, [
              //   'customer_id',
              //   'created_at',
              //   'updated_at',
              //   'firstname',
              //   'lastname',
              //   'gender',
              //   'credit_value',
              //   'customer_referral_code',
              // ]);
              // var customerDocument = {
              //   'email': customer.email,
              //   'number': customer.contact_no,
              //   'created_at': Date.now(),
              //   'initialSource': 'magento',
              //   'attributes': attributes
              // };
              // filteredCustomer.push(customerDocument);
              console.log(customer);
            });
            done(filteredCustomer);
          });
        },
        function (filteredCustomer, done) {
          // console.log(filteredCustomer);
          if(!err){
            done(filteredCustomer);
          }
        }
      ],
      function (err) {
        if (err) {
          console.log(err);
        }
      });
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-28
      • 2015-06-17
      • 1970-01-01
      • 1970-01-01
      • 2015-06-19
      • 1970-01-01
      • 1970-01-01
      • 2013-04-19
      相关资源
      最近更新 更多