コード例 #1
0
ファイル: trace.go プロジェクト: foomo/shop
func (c Callers) String() string {
	s := ""
	for i, caller := range c {
		s += caller + utils.IteString(i != len(c)-1, "\n", "")
	}
	return s
}
コード例 #2
0
ファイル: customer.go プロジェクト: foomo/shop
// NewCustomer creates a new Customer in the database and returns it.
// Email must be unique for a customer. customerProvider may be nil at this point.
func NewCustomer(email, password string, customProvider CustomerCustomProvider) (*Customer, error) {
	log.Println("=== Creating new customer ", email)
	isGuest := password == ""
	if email == "" {
		return nil, errors.New(shop_error.ErrorRequiredFieldMissing)
	}
	//var err error
	// We only create credentials if a customer is available.
	// A guest customer gets a new entry in the customer db for each order!
	// if !isGuest {
	// 	// Check is desired Email is available
	// 	available, err := CheckLoginAvailable(email)
	// 	if err != nil {
	// 		return nil, err
	// 	}
	// 	if !available {
	// 		return nil, errors.New(shop_error.ErrorNotFound + " Login " + email + " is already taken!")
	// 	}

	// 	// These credentials are not used at the moment
	// 	// err = CreateCustomerCredentials(email, password)
	// 	// if err != nil {
	// 	// 	return nil, err
	// 	// }
	// }

	customer := &Customer{
		Flags:          &Flags{},
		Version:        version.NewVersion(),
		Id:             unique.GetNewID(),
		Email:          utils.IteString(isGuest, "", lc(email)), // If Customer is a guest, we do not set the email address. This field should be unique in the database (and would not be if the guest ordered twice).
		CreatedAt:      utils.TimeNow(),
		LastModifiedAt: utils.TimeNow(),
		Person: &address.Person{
			Contacts: &address.Contacts{
				Email: email,
			},
		},
		Localization: &Localization{},
		Tracking:     &Tracking{},
	}

	trackingId, err := crypto.CreateHash(customer.GetID())
	if err != nil {
		return nil, err
	}
	customer.Tracking.TrackingID = "tid" + trackingId

	if isGuest {
		customer.IsGuest = true
	}

	if customProvider != nil {
		customer.Custom = customProvider.NewCustomerCustom()
	}
	// Store order in database
	err = customer.insert()
	if err != nil {
		log.Println("Could not insert customer", email)
		return nil, err
	}
	// Retrieve customer again from. (Otherwise upserts on customer would fail because of missing mongo ObjectID)
	return GetCustomerById(customer.Id, customProvider)
}