Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

product: Enhance price context to support delivery specific pricing, expose via GraphQL #326

Merged
merged 1 commit into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* Add new field `customAttributes` to the `Commerce_CartAdditionalData` type
* Add new field `additionalData` to the `Commerce_CartDeliveryInfo` type
* Add new type `Commerce_Cart_CustomAttributes` with method for getting key/value pairs
* **Breaking**: Change `activeBase` of `Commerce_Product_PriceInfo` from `Float` to `Commerce_Price`
* **Breaking**: Make naming convention consistent in graphql schema `Commerce_Cart_*`
* **Breaking**: Remove the fields `getAdditionalData, additionalDataKeys, additionalDeliveryInfoKeys` from the `Commerce_CartDeliveryInfo` type
* **Breaking**: `Commerce_Cart_UpdateDeliveryShippingOptions` mutation responded with slice of `Commerce_Cart_DeliveryAddressForm` which was incorrect as we don't process any form data within the mutation. It responds now rightly only with `processed` state.
Expand All @@ -42,6 +41,13 @@
**price**
* When marshalling `domain.Price` to JSON the amount is rounded.

**product**
* Enhance the `PriceContext` to allow potential delivery specific pricing
* GraphQL:
* **Breaking**: Change `activeBase` of `Commerce_Product_PriceInfo` from `Float` to `Commerce_Price`
* Add `availablePrices` to the `Commerce_Product` interface to display potential pricing options in the frontend
* Add `context` to the `Commerce_Product_PriceInfo` model to be able to differ between prices

## v3.4.0
**cart**
* Added desired time to DeliveryForm
Expand Down
5 changes: 4 additions & 1 deletion docs/openapi/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,9 @@ var doc = `{
"CustomerGroup": {
"type": "string"
},
"DeliveryCode": {
"type": "string"
},
"Locale": {
"type": "string"
}
Expand Down Expand Up @@ -2073,7 +2076,7 @@ var doc = `{
}
},
"LoyaltyEarnings": {
"description": "LoyaltyEarnings jolds optional infos about potential loyalty earnings",
"description": "LoyaltyEarnings holds optional infos about potential loyalty earnings",
"type": "array",
"items": {
"$ref": "#/definitions/domain.LoyaltyEarningInfo"
Expand Down
5 changes: 4 additions & 1 deletion docs/openapi/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1955,6 +1955,9 @@
"CustomerGroup": {
"type": "string"
},
"DeliveryCode": {
"type": "string"
},
"Locale": {
"type": "string"
}
Expand Down Expand Up @@ -2056,7 +2059,7 @@
}
},
"LoyaltyEarnings": {
"description": "LoyaltyEarnings jolds optional infos about potential loyalty earnings",
"description": "LoyaltyEarnings holds optional infos about potential loyalty earnings",
"type": "array",
"items": {
"$ref": "#/definitions/domain.LoyaltyEarningInfo"
Expand Down
4 changes: 3 additions & 1 deletion docs/openapi/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,8 @@ definitions:
type: string
CustomerGroup:
type: string
DeliveryCode:
type: string
Locale:
type: string
type: object
Expand Down Expand Up @@ -667,7 +669,7 @@ definitions:
type: string
type: array
LoyaltyEarnings:
description: LoyaltyEarnings jolds optional infos about potential loyalty earnings
description: LoyaltyEarnings holds optional infos about potential loyalty earnings
items:
$ref: '#/definitions/domain.LoyaltyEarningInfo'
type: array
Expand Down
2 changes: 1 addition & 1 deletion docs/swagger.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion product/domain/productBasics.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type (
AvailablePrices []PriceInfo
// LoyaltyPrices holds optional infos for products that can be paid in a loyalty program
LoyaltyPrices []LoyaltyPriceInfo
// LoyaltyEarnings jolds optional infos about potential loyalty earnings
// LoyaltyEarnings holds optional infos about potential loyalty earnings
LoyaltyEarnings []LoyaltyEarningInfo
}

Expand Down Expand Up @@ -130,6 +130,7 @@ type (

// PriceContext defines the scope in which the price was calculated
PriceContext struct {
DeliveryCode string
CustomerGroup string
ChannelCode string
Locale string
Expand Down
2 changes: 1 addition & 1 deletion product/interfaces/graphql/fs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions product/interfaces/graphql/product/dto/productdto.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type (
Identifier() string
Media() ProductMedia
Price() productDomain.PriceInfo
AvailablePrices() []productDomain.PriceInfo
Title() string
Categories() ProductCategories
Description() string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ func (avp ActiveVariantProduct) Price() productDomain.PriceInfo {
return avp.product.ActiveVariant.ActivePrice
}

// AvailablePrices of the active variant
func (avp ActiveVariantProduct) AvailablePrices() []productDomain.PriceInfo {
return avp.product.ActiveVariant.AvailablePrices
}

// Title of the active variant
func (avp ActiveVariantProduct) Title() string {
return avp.getActiveVariant().BaseData().Title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func getProductDomainConfigurableWithActiveVariantProduct() productDomain.Config
Context: productDomain.PriceContext{},
TaxClass: "",
},
AvailablePrices: []productDomain.PriceInfo{{
Default: priceDomain.NewFromFloat(10.00, "EUR"),
Context: productDomain.PriceContext{CustomerGroup: "gold-members"},
}},
},
},

Expand Down Expand Up @@ -285,6 +289,14 @@ func TestActiveVariantProduct_Price(t *testing.T) {
assert.Equal(t, priceDomain.NewFromFloat(23.23, "EUR").FloatAmount(), product.Price().Default.GetPayable().FloatAmount())
}

func TestActiveVariantProduct_AvailablePrices(t *testing.T) {
product := getActiveVariantProduct()
assert.Equal(t, []productDomain.PriceInfo{{
Default: priceDomain.NewFromFloat(10.00, "EUR"),
Context: productDomain.PriceContext{CustomerGroup: "gold-members"},
}}, product.AvailablePrices())
}

func TestActiveVariantProduct_Product(t *testing.T) {
product := getActiveVariantProduct()
assert.Equal(t, "active_variant_product_code_a", product.Product().BaseData().MarketPlaceCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func (cp ConfigurableProduct) Price() productDomain.PriceInfo {
return productDomain.PriceInfo{} // Price info is always empty for configurable products because they are not saleable
}

// AvailablePrices of the configurable
func (cp ConfigurableProduct) AvailablePrices() []productDomain.PriceInfo {
return nil // AvailablePrices is always empty for configurable products because they are not saleable
}

// Title of the configurable
func (cp ConfigurableProduct) Title() string {
return cp.product.BaseData().Title
Expand Down
Loading