示例#1
0
文件: customer.go 项目: foomo/shop
// checkFields Checks if all required fields are specified
// @TODO which are teh required fields
func CheckRequiredAddressFields(address *address.Address) error {
	// Return error if required field is missing
	if address.Person == nil || address.Person.Salutation == "" || address.Person.FirstName == "" || address.Person.LastName == "" || address.Street == "" || address.StreetNumber == "" || address.ZIP == "" || address.City == "" || address.Country == "" {
		return errors.New(shop_error.ErrorRequiredFieldMissing + "\n" + utils.ToJSON(address))
	}
	return nil
}
示例#2
0
文件: persistor.go 项目: foomo/shop
// findOneCustomer returns one Customer from the customer database or from the customer history database
func findOneCustomer(find *bson.M, selection *bson.M, sort string, customProvider CustomerCustomProvider, fromHistory bool) (*Customer, error) {
	var p *persistence.Persistor
	if fromHistory {
		p = GetCustomerVersionsPersistor()
	} else {
		p = GetCustomerPersistor()
	}
	customer := &Customer{}
	if find == nil {
		find = &bson.M{}
	}
	if selection == nil {
		selection = &bson.M{}
	}
	if sort != "" {
		err := p.GetCollection().Find(find).Select(selection).Sort(sort).One(customer)
		if err != nil {
			return nil, err
		}
	} else {
		err := p.GetCollection().Find(find).Select(selection).One(customer)
		if err != nil {
			return nil, err
		}
	}
	if customProvider != nil {
		var err error
		customer, err = mapDecode(customer, customProvider)
		if err != nil {
			return nil, err
		}
	}
	if customer == nil {
		return nil, errors.New("No result for " + utils.ToJSON(find))
	}
	//event_log.SaveShopEvent(event_log.ActionRetrieveCustomer, customer.GetID(), nil, customer.GetEmail())
	return customer, nil
}