Skip to content

Commit

Permalink
chore(cart): expose active option (product+qty) for bundle products w…
Browse files Browse the repository at this point in the history
…ithin the cart items
  • Loading branch information
Stanislav Müller committed Oct 26, 2023
1 parent 69ba5b1 commit bd23c20
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 98 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* **Breaking**(In case you have implemented a custom cart service): Extend the cart service interface with `UpdateItemBundleConfig` to allow updating bundles that have already been placed inside the cart.
* GraphQL:
* Add new mutation `Commerce_Cart_UpdateItemBundleConfig` to update bundle configs for existing cart items
* Expose Active Option (product+qty) for bundle products within the cart items

**checkout**
* initialize place order metrics with 0 on application start to follow prometheus best practices
Expand Down
12 changes: 10 additions & 2 deletions product/interfaces/graphql/product/dto/productdto_bundleproduct.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ type (
Required bool
Label string
Options []Option
Active Product

// Deprecated: ActiveOption provides the product and quantity of the active choice
Active Product
ActiveOption Option
}

Option struct {
Expand Down Expand Up @@ -128,7 +131,12 @@ func mapWithActiveChoices(domainChoices []productDomain.Choice, activeChoices ma
for i, choice := range choices {
activeChoice, ok := activeChoices[productDomain.Identifier(choice.Identifier)]
if ok {
choices[i].Active = NewGraphqlProductDto(activeChoice.Product, nil, nil)
product := NewGraphqlProductDto(activeChoice.Product, nil, nil)
choices[i].Active = product
choices[i].ActiveOption = Option{
Product: product,
Qty: activeChoice.Qty,
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion product/interfaces/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ type Commerce_Product_Choice {
required: Boolean!
label: String!
options: [Commerce_Product_Option!]
active: Commerce_Product
active: Commerce_Product @deprecated(reason: "use activeOption instead")
activeOption: Commerce_Product_Option
}

type Commerce_Product_Option {
Expand Down
73 changes: 68 additions & 5 deletions test/integrationtest/projecttest/graphql/generated.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ type Commerce_Product_Choice {
required: Boolean!
label: String!
options: [Commerce_Product_Option!]
active: Commerce_Product
active: Commerce_Product @deprecated(reason: "use activeOption instead")
activeOption: Commerce_Product_Option
}

type Commerce_Product_Option {
Expand Down
150 changes: 88 additions & 62 deletions test/integrationtest/projecttest/tests/graphql/cart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,37 +223,50 @@ func TestAddBundleProductToCart(t *testing.T) {
body := response.Expect().Body()

expected := `{
"data": {
"Commerce_Cart_AddToCart": {
"decoratedDeliveries": [
{
"decoratedItems": [
{
"product": {
"marketPlaceCode": "fake_bundle",
"choices": [
{
"identifier": "identifier1",
"active": {
"marketPlaceCode": "simple_option1"
}
},
{
"identifier": "identifier2",
"active": {
"marketPlaceCode": "configurable_option2",
"variantMarketPlaceCode": "shirt-red-s"
}
}
]
}
}
]
}
]
}
}
}`
"data": {
"Commerce_Cart_AddToCart": {
"decoratedDeliveries": [
{
"decoratedItems": [
{
"product": {
"marketPlaceCode": "fake_bundle",
"choices": [
{
"identifier": "identifier1",
"active": {
"marketPlaceCode": "simple_option1"
},
"activeOption": {
"product": {
"marketPlaceCode": "simple_option1"
},
"qty": 1
}
},
{
"identifier": "identifier2",
"active": {
"marketPlaceCode": "configurable_option2",
"variantMarketPlaceCode": "shirt-red-s"
},
"activeOption": {
"product": {
"marketPlaceCode": "configurable_option2",
"variantMarketPlaceCode": "shirt-red-s"
},
"qty": 1
}
}
]
}
}
]
}
]
}
}
}`

expected = spaceMap(expected)
body.IsEqual(expected)
Expand Down Expand Up @@ -395,37 +408,50 @@ func TestUpdateBundleConfiguration(t *testing.T) {
body := updateResponse.Expect().Body()

expected := `{
"data": {
"Commerce_Cart_UpdateItemBundleConfig": {
"decoratedDeliveries": [
{
"decoratedItems": [
{
"product": {
"marketPlaceCode": "fake_bundle",
"choices": [
{
"identifier": "identifier1",
"active": {
"marketPlaceCode": "simple_option2"
}
},
{
"identifier": "identifier2",
"active": {
"marketPlaceCode": "configurable_option1",
"variantMarketPlaceCode": "shirt-red-m"
}
}
]
}
}
]
}
]
}
}
}`
"data": {
"Commerce_Cart_UpdateItemBundleConfig": {
"decoratedDeliveries": [
{
"decoratedItems": [
{
"product": {
"marketPlaceCode": "fake_bundle",
"choices": [
{
"identifier": "identifier1",
"active": {
"marketPlaceCode": "simple_option2"
},
"activeOption": {
"product": {
"marketPlaceCode": "simple_option2"
},
"qty": 1
}
},
{
"identifier": "identifier2",
"active": {
"marketPlaceCode": "configurable_option1",
"variantMarketPlaceCode": "shirt-red-m"
},
"activeOption": {
"product": {
"marketPlaceCode": "configurable_option1",
"variantMarketPlaceCode": "shirt-red-m"
},
"qty": 1
}
}
]
}
}
]
}
]
}
}
}`

expected = spaceMap(expected)
body.IsEqual(expected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ mutation {
variantMarketPlaceCode
}
}
activeOption {
product {
marketPlaceCode
... on Commerce_Product_ActiveVariantProduct {
variantMarketPlaceCode
}
}
qty
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ mutation {
variantMarketPlaceCode
}
}
activeOption {
product {
marketPlaceCode
... on Commerce_Product_ActiveVariantProduct {
variantMarketPlaceCode
}
}
qty
}
}
}
}
Expand Down
Loading

0 comments on commit bd23c20

Please sign in to comment.