store

package
v0.0.0-...-fa9325b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2018 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const NoItemsInCart = "No items in shopping cart"

NoItemsInCart is the fixed message for logging when a cart has zero items

View Source
const OutOfStock = "Out of stock"

OutOfStock is the fixed message for logging when an item is out of stock

View Source
const ZeroItemCountInCart = "Item with zero count in cart"

ZeroItemCountInCart is the fixed message for logging when a cart has an item with zero items added

Variables

This section is empty.

Functions

This section is empty.

Types

type Cart

type Cart struct {
	Items map[string]int
}

Cart contains a map of items to item count

func New

func New() *Cart

New returns a fully initilized shopping cart

func (Cart) AddItem

func (c Cart) AddItem(id string) error

AddItem adds a product id to the shopping cart. If one already exists it increments this number

func (Cart) ApplyPromotions

func (c Cart) ApplyPromotions() (float32, string)

func (Cart) BuyXGetYFree

func (c Cart) BuyXGetYFree(x, y string) (float32, string)

BuyXGetYFree will add items to the cart.

func (Cart) Checkout

func (c Cart) Checkout()

Checkout prints the final listing of contents and the total price of the shopping cart

func (Cart) OverXDiscountY

func (c Cart) OverXDiscountY(x int, y float32, id string) float32

OverXDiscountY will check that there are more than X items of ID and then apply Y discount

func (Cart) ScannedItemsLabels

func (c Cart) ScannedItemsLabels() string

ScannedItemsLabels returns a slice of product names from the shopping cart

func (Cart) ScannedItemsTotalPrices

func (c Cart) ScannedItemsTotalPrices() float32

ScannedItemsTotalPrices returns the float32 sum of all products in the shopping cart

func (Cart) XForPriceOfY

func (c Cart) XForPriceOfY(x, y int, id string) float32

XForPriceOfY scans the cart for groups of X to return a lowered price

type Inventory

type Inventory struct {
	ProductListing map[string]Product
}

Inventory is a map of sku to product

type Product

type Product struct {
	Details ProductDetails
	Stock   int
}

Product is a container for a product item and its stock level

type ProductDetails

type ProductDetails struct {
	SKU         string
	ProductName string
	ListedPrice float32
}

ProductDetails contains the product details

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL