Skip to content

Commit

Permalink
feat: cleaned up business units and associate roles, added project se…
Browse files Browse the repository at this point in the history
…ttings
  • Loading branch information
demeyerthom committed Aug 13, 2024
1 parent f525ee1 commit 0d59952
Show file tree
Hide file tree
Showing 39 changed files with 3,683 additions and 2,612 deletions.
4 changes: 4 additions & 0 deletions .changes/unreleased/Added-20240813-121838.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind: Added
body: Added resources for associate role and business units and extended project setting
options
time: 2024-08-13T12:18:38.233827008+02:00
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ tasks:
CTP_CLIENT_SECRET: x
CTP_PROJECT_KEY: unittest
CTP_SCOPES: manage_project:projectkey
CTP_API_URL: http://localhost:8989
CTP_AUTH_URL: http://localhost:8989
CTP_API_URL: http://localhost:3000
CTP_AUTH_URL: http://localhost:3000
44 changes: 15 additions & 29 deletions commercetools/resource_shipping_zone_rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func findShippingZoneRate(shippingMethod *platform.ShippingMethod, shippingZoneI
for _, zoneRate := range shippingMethod.ZoneRates {
if zoneRate.Zone.ID == shippingZoneID {
for _, shippingRate := range zoneRate.ShippingRates {
if shippingRate.Price.(platform.CentPrecisionMoney).CurrencyCode == currencyCode {
if shippingRate.Price.CurrencyCode == currencyCode {
return &shippingRate, nil
}
}
Expand All @@ -435,36 +435,22 @@ func setShippingZoneRateState(d *schema.ResourceData, shippingMethod *platform.S
tiers := flattenShippingZoneRateTiers(shippingRate)
_ = d.Set("shipping_rate_price_tier", tiers)

if typedPrice, ok := shippingRate.Price.(platform.CentPrecisionMoney); ok {
price := map[string]any{
"currency_code": typedPrice.CurrencyCode,
"cent_amount": typedPrice.CentAmount,
}
err = d.Set("price", []any{price})
if err != nil {
return err
}
} else {
_ = d.Set("price", nil)
if err != nil {
return err
}
price := map[string]any{
"currency_code": shippingRate.Price.CurrencyCode,
"cent_amount": shippingRate.Price.CentAmount,
}
err = d.Set("price", []any{price})
if err != nil {
return err
}

if typedFreeAbove, ok := (shippingRate.FreeAbove).(platform.CentPrecisionMoney); ok {
freeAbove := map[string]any{
"currency_code": typedFreeAbove.CurrencyCode,
"cent_amount": typedFreeAbove.CentAmount,
}
err = d.Set("free_above", []any{freeAbove})
if err != nil {
return err
}
} else {
_ = d.Set("free_above", nil)
if err != nil {
return err
}
freeAbove := map[string]any{
"currency_code": shippingRate.FreeAbove.CurrencyCode,
"cent_amount": shippingRate.FreeAbove.CentAmount,
}
err = d.Set("free_above", []any{freeAbove})
if err != nil {
return err
}
return nil
}
Expand Down
50 changes: 41 additions & 9 deletions docs/resources/associate_role.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,44 @@ resource "commercetools_associate_role" "regional_manager" {
name = "Regional Manager - Europe"
permissions = [
"AddChildUnits",
"UpdateBusinessUnitDetails",
"UpdateAssociates",
"UpdateBusinessUnitDetails",
"UpdateParentUnit",
"ViewMyCarts",
"ViewOthersCarts",
"UpdateMyCarts",
"UpdateOthersCarts",
"CreateMyCarts",
"CreateOthersCarts",
"DeleteMyCarts",
"UpdateMyCarts",
"ViewMyCarts",
"DeleteOthersCarts",
"ViewMyOrders",
"ViewOthersOrders",
"UpdateMyOrders",
"UpdateOthersOrders",
"CreateMyOrdersFromMyCarts",
"CreateMyOrdersFromMyQuotes",
"CreateOrdersFromOthersCarts",
"CreateOrdersFromOthersQuotes",
"ViewMyQuotes",
"ViewOthersQuotes",
"AcceptMyQuotes",
"AcceptOthersQuotes",
"DeclineMyQuotes",
"DeclineOthersQuotes",
"RenegotiateMyQuotes",
"RenegotiateOthersQuotes",
"ReassignMyQuotes",
"ReassignOthersQuotes",
"ViewMyQuoteRequests",
"ViewOthersQuoteRequests",
"UpdateMyQuoteRequests",
"UpdateOthersQuoteRequests",
"CreateMyQuoteRequestsFromMyCarts",
"CreateQuoteRequestsFromOthersCarts",
"CreateApprovalRules",
"UpdateApprovalRules",
"UpdateApprovalFlows",
]
}
```
Expand All @@ -37,15 +69,15 @@ resource "commercetools_associate_role" "regional_manager" {

### Required

- `key` (String) User-defined unique identifier of the AssociateRole.
- `permissions` (List of String) List of Permissions for the AssociateRole.
- `key` (String) User-defined unique identifier of the associate role.
- `permissions` (List of String) List of permissions for the associate role. See the [Associate Role API Documentation](https://docs.commercetools.com/api/projects/associate-roles#ctp:api:type:Permission) for more information.

### Optional

- `buyer_assignable` (Boolean) Whether the AssociateRole can be assigned to an Associate by a buyer. If false, the AssociateRole can only be assigned using the general endpoint.
- `name` (String) Name of the AssociateRole.
- `buyer_assignable` (Boolean) Whether the associate role can be assigned to an associate by a buyer. If false, the associate role can only be assigned using the general endpoint. Defaults to true.
- `name` (String) Name of the associate role.

### Read-Only

- `id` (String) Unique identifier of the AssociateRole.
- `version` (Number) Current version of the AssociateRole.
- `id` (String) Unique identifier of the associate role.
- `version` (Number) Current version of the associate role.
137 changes: 137 additions & 0 deletions docs/resources/business_unit_company.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "commercetools_business_unit_company Resource - terraform-provider-commercetools"
subcategory: ""
description: |-
Business Unit type to represent the top level of a business. Contains specific fields and values that differentiate a Company from the generic BusinessUnit.
See also the [Business Unit API Documentation](https://docs.commercetools.com/api/projects/business-units
---

# commercetools_business_unit_company (Resource)

Business Unit type to represent the top level of a business. Contains specific fields and values that differentiate a Company from the generic BusinessUnit.

See also the [Business Unit API Documentation](https://docs.commercetools.com/api/projects/business-units

## Example Usage

```terraform
resource "commercetools_store" "my-store" {
key = "my-store"
name = {
en-US = "My store"
}
countries = ["NL", "BE"]
languages = ["en-GB"]
}
resource "commercetools_business_unit_company" "my-company" {
key = "my-company"
name = "My company"
contact_email = "[email protected]"
address {
key = "my-company-address-1"
country = "NL"
state = "Noord-Holland"
city = "Amsterdam"
street_name = "Keizersgracht"
street_number = "3"
additional_street_info = "4th floor"
postal_code = "1015 CJ"
}
address {
key = "my-company-address-2"
country = "NL"
state = "Utrecht"
city = "Utrecht"
street_name = "Oudegracht"
street_number = "1"
postal_code = "3511 AA"
additional_street_info = "Main floor"
}
store {
key = commercetools_store.my-store.key
}
billing_address_keys = ["my-company-address-1"]
shipping_address_keys = ["my-company-address-1", "my-company-address-2"]
default_billing_address_key = "my-company-address-1"
default_shipping_address_key = "my-company-address-1"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `key` (String) User-defined unique identifier for the Company.
- `name` (String) The name of the Company.

### Optional

- `address` (Block List) Addresses used by the Business Unit. (see [below for nested schema](#nestedblock--address))
- `billing_address_keys` (Set of String) Indexes of entries in addresses to set as billing addresses. The billingAddressIds of the [Customer](https://docs.commercetools.com/api/projects/customers) will be replaced by these addresses.
- `contact_email` (String) The email address of the Company.
- `default_billing_address_key` (String) Index of the entry in addresses to set as the default billing address.
- `default_shipping_address_key` (String) Index of the entry in addresses to set as the default shipping address.
- `shipping_address_keys` (Set of String) Indexes of entries in addresses to set as shipping addresses. The shippingAddressIds of the [Customer](https://docs.commercetools.com/api/projects/customers) will be replaced by these addresses.
- `status` (String) The status of the Company.
- `store` (Block List) Sets the Stores the Business Unit is associated with.

If the Business Unit has Stores defined, then all of its Carts, Orders, Quotes, or Quote Requests must belong to one of the Business Unit's Stores.

If the Business Unit has no Stores, then all of its Carts, Orders, Quotes, or Quote Requests must not belong to any Store. (see [below for nested schema](#nestedblock--store))

### Read-Only

- `id` (String) Unique identifier of the Company.
- `version` (Number) The current version of the Company.

<a id="nestedblock--address"></a>
### Nested Schema for `address`

Required:

- `country` (String) Name of the country
- `key` (String) User-defined identifier of the Address that must be unique when multiple addresses are referenced in BusinessUnits, Customers, and itemShippingAddresses (LineItem-specific addresses) of a Cart, Order, QuoteRequest, or Quote.

Optional:

- `additional_address_info` (String) Further information on the Address
- `additional_street_info` (String) Further information on the street address
- `apartment` (String) Name or number of the apartment
- `building` (String) Name or number of the building
- `city` (String) Name of the city
- `company` (String) Name of the company
- `department` (String) Name of the department
- `email` (String) Email address
- `external_id` (String) ID for the contact used in an external system
- `fax` (String) Fax number
- `first_name` (String) First name of the contact
- `last_name` (String) Last name of the contact
- `mobile` (String) Mobile phone number
- `phone` (String) Phone number
- `po_box` (String) Post office box number
- `postal_code` (String) Postal code
- `region` (String) Name of the region
- `salutation` (String) Salutation of the contact, for example Ms., Mr.
- `state` (String) Name of the state
- `street_name` (String) Name of the street
- `street_number` (String) Street number
- `title` (String) Title of the contact, for example Dr., Prof.

Read-Only:

- `id` (String) Unique identifier of the Address


<a id="nestedblock--store"></a>
### Nested Schema for `store`

Optional:

- `key` (String) User-defined unique identifier of the Store
Loading

0 comments on commit 0d59952

Please sign in to comment.