Skip to content

Commit

Permalink
chore(cart): expose bundle configuration on cart item level in graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Müller committed Oct 25, 2023
1 parent 69ba5b1 commit ebf2f2b
Show file tree
Hide file tree
Showing 9 changed files with 536 additions and 61 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 selected bundle configuration on the cart items

**checkout**
* initialize place order metrics with 0 on application start to follow prometheus best practices
Expand Down
36 changes: 36 additions & 0 deletions cart/interfaces/graphql/dto/cartItem.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package dto

import (
"context"

"flamingo.me/flamingo-commerce/v3/cart/domain/cart"
)

type (
BundleChoiceConfiguration struct {
Identifier string
MarketplaceCode string
VariantMarketplaceCode string
Qty int
}

CartItemResolver struct{}
)

func (c CartItemResolver) BundleConfiguration(ctx context.Context, item *cart.Item) ([]*BundleChoiceConfiguration, error) {
if item.BundleConfig == nil {
return nil, nil
}

choices := make([]*BundleChoiceConfiguration, 0)
for identifier, configuration := range item.BundleConfig {
choices = append(choices, &BundleChoiceConfiguration{
Identifier: string(identifier),
MarketplaceCode: configuration.MarketplaceCode,
VariantMarketplaceCode: configuration.MarketplaceCode,
Qty: configuration.Qty,
})
}

return choices, nil
}
9 changes: 8 additions & 1 deletion cart/interfaces/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,14 @@ type Commerce_Cart_Item {
rowPriceGross: Commerce_Price!
rowPriceNet: Commerce_Price!
appliedDiscounts: Commerce_Cart_AppliedDiscounts!
# rowTaxes: Commerce_Taxes!
bundleConfiguration: [Commerce_Cart_Item_BundleChoiceConfiguration]
}

type Commerce_Cart_Item_BundleChoiceConfiguration {
identifier: String
marketplaceCode: String
variantMarketplaceCode: String
qty: Int
}

type Commerce_Cart_Address {
Expand Down
2 changes: 2 additions & 0 deletions cart/interfaces/graphql/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ func (*Service) Types(types *graphql.Types) {
types.Resolve("Commerce_Cart_ShippingItem", "appliedDiscounts", dto.CartAppliedDiscountsResolver{}, "ForShippingItem")
types.Map("Commerce_Cart_DecoratedItem", dto.DecoratedCartItem{})
types.Map("Commerce_Cart_Item", cart.Item{})
types.Map("Commerce_Cart_Item_BundleChoiceConfiguration", dto.BundleChoiceConfiguration{})
types.Resolve("Commerce_Cart_Item", "appliedDiscounts", dto.CartAppliedDiscountsResolver{}, "ForItem")
types.Resolve("Commerce_Cart_Item", "bundleConfiguration", dto.CartItemResolver{}, "BundleConfiguration")
types.Map("Commerce_Cart_Address", cart.Address{})
types.Map("Commerce_Cart_Person", cart.Person{})
types.Map("Commerce_Cart_ExistingCustomerData", cart.ExistingCustomerData{})
Expand Down
Loading

0 comments on commit ebf2f2b

Please sign in to comment.