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

Resolves #385 - Customer cart association support #412

Merged
merged 2 commits into from
Dec 29, 2023
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
3 changes: 3 additions & 0 deletions external/browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
)

func OpenUrl(url string) error {
if url == "" {
return fmt.Errorf("No url available")
}
switch runtime.GOOS {
case "linux":
exec.Command("xdg-open", url).Start()
Expand Down
12 changes: 6 additions & 6 deletions external/resources/resources_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
"suppress-reset-warning": {
"type": "boolean"
},
"docs": { "type": "string", "pattern": "^https://" },
"docs": { "type": "string", "pattern": "^https?://" },
"get-collection": {
"type": "object",
"additionalProperties": false,
"properties" : {
"docs": { "type": "string", "pattern": "^https://" },
"docs": { "type": "string", "pattern": "^https?://" },
"url": { "type": "string" },
"content-type": { "type": "string" },
"parent_resource_value_overrides": { "type": "object" },
Expand All @@ -46,7 +46,7 @@
"get-entity": {
"type": "object",
"properties" : {
"docs": { "type": "string", "pattern": "^https://" },
"docs": { "type": "string", "pattern": "^https?://" },
"url": { "type": "string" },
"content-type": { "type": "string" },
"parent_resource_value_overrides": { "type": "object" },
Expand All @@ -57,7 +57,7 @@
"update-entity": {
"type": "object",
"properties" : {
"docs": { "type": "string", "pattern": "^https://" },
"docs": { "type": "string", "pattern": "^https?://" },
"url": { "type": "string" },
"content-type": { "type": "string" },
"parent_resource_value_overrides": { "type": "object" }
Expand All @@ -67,7 +67,7 @@
"create-entity": {
"type": "object",
"properties" : {
"docs": { "type": "string", "pattern": "^https://" },
"docs": { "type": "string", "pattern": "^https?://" },
"url": { "type": "string" },
"content-type": { "type": "string" },
"parent_resource_value_overrides": { "type": "object" }
Expand All @@ -77,7 +77,7 @@
"delete-entity": {
"type": "object",
"properties" : {
"docs": { "type": "string", "pattern": "^https://" },
"docs": { "type": "string", "pattern": "^https?://" },
"url": { "type": "string" },
"min": { "type": "integer" }
},
Expand Down
22 changes: 20 additions & 2 deletions external/resources/yaml/resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ carts:
json-api-format: "legacy"
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/carts-and-orders/carts/index.html"
get-collection:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/carts-and-orders/carts/associations/get-customer-carts.html"
docs: "https://elasticpath.dev/docs/commerce-cloud/carts/customer-cart-associations/get-customer-carts#get-get-all-carts"
url: "/v2/carts"
get-entity:
docs: "https://documentation.elasticpath.com/commerce-cloud/docs/api/carts-and-orders/carts/get-a-cart.html"
Expand Down Expand Up @@ -491,6 +491,24 @@ customers:
autofill: FUNC:Email
password:
type: STRING
customer-cart-associations:
singular-name: customer-cart-association
json-api-type: customer-cart-relationship
json-api-format: "legacy"
no-wrapping: true
docs: "https://elasticpath.dev/docs/commerce-cloud/carts/customer-cart-associations/customer-cart-associations-overview"
delete-entity:
docs: "https://elasticpath.dev/docs/commerce-cloud/carts/customer-cart-associations/delete-an-association"
url: "/v2/carts/{carts}/relationships/customers"
create-entity:
docs: "https://elasticpath.dev/docs/commerce-cloud/carts/customer-cart-associations/create-an-association"
url: "/v2/carts/{carts}/relationships/customers"
content-type: application/json
attributes:
data[n].id:
type: RESOURCE_ID:customer
data[n].type:
type: ENUM:customer
customer-addresses:
singular-name: "customer-address"
json-api-type: "address"
Expand Down Expand Up @@ -797,7 +815,7 @@ entries-relationship:
data.id:
type: RESOURCE_ID:*
data.type:
type: SINGULAR_RESOURCE_TYPE
type: JSON_API_TYPE
integration-jobs:
singular-name: "integration-job"
json-api-type: "integration-job"
Expand Down
173 changes: 173 additions & 0 deletions external/runbooks/customer-cart-associations.epcc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
name: "customer-cart-associations"
description:
long: "Sample commands for using customer cart association"
short: "Sample commands for using customer cart association"
actions:
create-prerequisites:
description:
short: "Create necessary prerequisites"
commands:
- epcc create pcm-hierarchy name "Major Appliances" description "Free standing appliances" slug "Major-Appliances-MA0"
- epcc create pcm-node name=Major_Appliances name "Ranges" description "All stoves and ovens" slug "Ranges-MA1"
- |
epcc create pcm-node name=Major_Appliances name "Electric Ranges" description "Electric stoves and ovens" slug "Electric-Ranges-MA2" relationships.parent.data.type node relationships.parent.data.id name=Ranges
epcc create pcm-node name=Major_Appliances name "Gas Ranges" description "Gas stoves and ovens" slug "Gas-Ranges-MA2" relationships.parent.data.type node relationships.parent.data.id name=Ranges
- epcc create pcm-product name "BestEver Electric Range" sku "BE-Electric-Range-1a1a" slug "bestever-range-1a1a" description "This electric model offers an induction heating element and convection oven." status live commodity_type physical upc_ean \"111122223333\" mpn BE-R-1111-aaaa-1a1a
- epcc create pcm-node-product name=Major_Appliances name=Electric_Ranges data[0].type product data[0].id name=BestEver_Electric_Range
- epcc create pcm-product name "BestEver Gas Range" sku "BE-Gas-Range-2b2b" slug "bestever-range-2b2b" description "This gas model includes a convection oven." status live commodity_type physical upc_ean \"222233334444\" mpn BE-R-2222-bbbb-2b2b
- epcc create pcm-node-product name=Major_Appliances name=Gas_Ranges data[0].type product data[0].id name=BestEver_Gas_Range
- epcc get -s currencies
- epcc create currency --if-alias-does-not-exist code=GBP code GBP exchange_rate 1 format £{price} decimal_point "." thousand_separator , decimal_places 2 default false enabled true
- epcc create pcm-pricebook name "Preferred Pricing" description "Catalog with pricing suitable for high-volume customers."
- |
epcc create pcm-product-price name=Preferred_Pricing currencies.USD.amount 300000 currencies.USD.includes_tax false currencies.GBP.amount 250000 currencies.GBP.includes_tax false sku BE-Electric-Range-1a1a
epcc create pcm-product-price name=Preferred_Pricing currencies.USD.amount 350000 currencies.USD.includes_tax false currencies.GBP.amount 300000 currencies.GBP.includes_tax false sku BE-Gas-Range-2b2b
- epcc create pcm-catalog name "Ranges Catalog" description "Ranges Catalog" pricebook_id name=Preferred_Pricing hierarchy_ids[0] name=Major_Appliances
- epcc create pcm-catalog-release --save-as-alias pxm-how-to-create-catalog-and-publish-release name=Ranges_Catalog
# Wait for Catalog to be Published
- epcc get pcm-catalog-release --retry-while-jq '.data.meta.release_status != "PUBLISHED"' name=Ranges_Catalog pxm-how-to-create-catalog-and-publish-release
create-customers-and-carts-with-product-items:
description:
short: "Create the customers and carts"
ignore_errors: false
commands:
- |
epcc create customer --auto-fill email "[email protected]" password test
epcc create customer --auto-fill email "[email protected]" password test
epcc create customer --auto-fill email "[email protected]" password test
epcc create cart name "Customer 1 Cart" id cust1_only description "Customer 1 Cart"
epcc create cart name "Customer 1&2 Shared Cart" id cust1_and_2 description "Customer 1 & 2 Cart"
epcc create cart name "No Customer Cart" id no_cust_cart description "No Customer Cart"
- epcc create customer-cart-association id=cust1_only data[0].type customer data[0].id [email protected]
- epcc create customer-cart-association id=cust1_and_2 data[0].type customer data[0].id [email protected]
- epcc create customer-cart-association id=cust1_and_2 data[0].type customer data[0].id [email protected]
- epcc create cart-product-item id=cust1_only sku sku=BE-Gas-Range-2b2b quantity 1
- epcc create cart-product-item id=cust1_and_2 sku sku=BE-Gas-Range-2b2b quantity 2
- epcc create cart-product-item no_cust_cart sku sku=BE-Gas-Range-2b2b quantity 3

create-customers-and-carts-with-custom-items:
description:
short: "Create the customers and carts"
ignore_errors: false
commands:
- |
epcc create customer --auto-fill email "[email protected]" password test
epcc create customer --auto-fill email "[email protected]" password test
epcc create customer --auto-fill email "[email protected]" password test
epcc create cart name "Customer 4 Cart" id cust1_only description "Customer 4 Cart"
epcc create cart name "Customer 4&5 Shared Cart" id cust1_and_2 description "Customer 4 & 5 Cart"
epcc create cart name "No Customer Cart" id no_cust_cart_custom_items description "No Customer Cart (Custom Items)"
- epcc create customer-cart-association id=cust4_only data[0].type customer data[0].id [email protected]
- epcc create customer-cart-association id=cust4_and_5 data[0].type customer data[0].id [email protected]
- epcc create customer-cart-association id=cust4_and_5 data[0].type customer data[0].id [email protected]
- epcc create cart-custom-item id=cust4_only sku 123-456 quantity 1 price.amount 100000 price.includes_tax false name "Best Ever Electric Range"
- epcc create cart-custom-item id=cust4_and_5 sku 123-456 quantity 2 price.amount 100000 price.includes_tax false name "Best Ever Electric Range"
- epcc create cart-custom-item no_cust_cart_custom_items sku 123-789 quantity 3 price.amount 100000 price.includes_tax false name "Best Ever Gas Range"


delete-customer-and-carts-with-product-items:
description:
short: "Delete all the customers and their carts"
ignore_errors: false
commands:
- epcc get -s customers filter 'like(email,*@example.com)'
- epcc delete customer-cart-association id=cust1_only data[0].type customer data[0].id [email protected]
- epcc delete customer-cart-association id=cust1_and_2 data[0].type customer data[0].id [email protected]
- epcc delete customer-cart-association id=cust1_and_2 data[0].type customer data[0].id [email protected]
- |
epcc delete customer [email protected]
epcc delete customer [email protected]
epcc delete customer [email protected]
- |
epcc delete cart cust1_only
epcc delete cart cust1_and_2
epcc delete cart no_cust_cart

try-and-delete-all-carts:
description:
short: "Try and delete all carts"
ignore_errors: true
commands:
- epcc get -s customers filter 'like(email,*@example.com)'
- epcc delete customer-cart-association id=cust1_only data[0].type customer data[0].id [email protected]
- epcc delete customer-cart-association id=cust1_and_2 data[0].type customer data[0].id [email protected]
- epcc delete customer-cart-association id=cust1_and_2 data[0].type customer data[0].id [email protected]
- epcc delete customer-cart-association id=cust4_only data[0].type customer data[0].id [email protected]
- epcc delete customer-cart-association id=cust4_and_5 data[0].type customer data[0].id [email protected]
- epcc delete customer-cart-association id=cust4_and_5 data[0].type customer data[0].id [email protected]
- |
epcc delete cart cust1_only
epcc delete cart cust1_and_2
epcc delete cart no_cust_cart
epcc delete cart cust4_only
epcc delete cart cust4_and_5
epcc delete cart no_cust_cart_custom_items



delete-customer-and-carts-with-custom-items:
description:
short: "Delete all the customers and their carts"
ignore_errors: false
commands:
- epcc get -s customers filter 'like(email,*@example.com)'
- epcc delete customer-cart-association id=cust4_only data[0].type customer data[0].id [email protected]
- epcc delete customer-cart-association id=cust4_and_5 data[0].type customer data[0].id [email protected]
- epcc delete customer-cart-association id=cust4_and_5 data[0].type customer data[0].id [email protected]
- |
epcc delete customer [email protected]
epcc delete customer [email protected]
epcc delete customer [email protected]
- |
epcc delete cart cust4_only
epcc delete cart cust4_and_5
epcc delete cart no_cust_cart_custom_items

reset:
description:
short: "Reset the store to the initial state"
ignore_errors: true
commands:
# Retrieve a bunch of data (not all), so that aliases can be populated
- |
epcc get -s pcm-products
epcc get -s pcm-catalogs
epcc get -s pcm-hierarchies
epcc get -s pcm-pricebooks
epcc get -s pcm-catalog-rules
epcc get -s customers filter 'like(email,*@example.com)'
- epcc delete customer-cart-association id=cust1_only data[0].type customer data[0].id [email protected]
- epcc delete customer-cart-association id=cust1_and_2 data[0].type customer data[0].id [email protected]
- epcc delete customer-cart-association id=cust1_and_2 data[0].type customer data[0].id [email protected]
- epcc delete customer-cart-association id=cust4_only data[0].type customer data[0].id [email protected]
- epcc delete customer-cart-association id=cust4_and_5 data[0].type customer data[0].id [email protected]
- epcc delete customer-cart-association id=cust4_and_5 data[0].type customer data[0].id [email protected]
- |
epcc get -s pcm-catalog-releases name=Ranges_Catalog
epcc get -s pcm-catalog-releases name=Ranges_Catalog_for_Special_Customers
- |
epcc delete customer [email protected] --if-alias-exists [email protected]
epcc delete customer [email protected] --if-alias-exists [email protected]
epcc delete customer [email protected] --if-alias-exists [email protected]
epcc delete customer [email protected] --if-alias-exists [email protected]
epcc delete customer [email protected] --if-alias-exists [email protected]
epcc delete customer [email protected] --if-alias-exists [email protected]
epcc delete currency code=GBP --if-alias-exists code=GBP
epcc delete pcm-catalog-release name=Ranges_Catalog name=Ranges_Catalog
epcc delete pcm-catalog-release name=Ranges_Catalog_for_Special_Customers name=Ranges_Catalog_for_Special_Customers
epcc delete pcm-catalog-rule name=Catalog_Rule_for_Civil_Servants --if-alias-exists name=Catalog_Rule_for_Civil_Servants
epcc delete pcm-product name=BestEver_Gas_Range --if-alias-exists name=BestEver_Gas_Range
epcc delete pcm-product name=BestEver_Electric_Range --if-alias-exists name=BestEver_Electric_Range
epcc delete pcm-hierarchy name=Major_Appliances --if-alias-exists name=Major_Appliances
epcc delete pcm-pricebook name=Preferred_Pricing --if-alias-exists name=Preferred_Pricing
epcc delete pcm-pricebook name=Loyal_Civil_Servants_Pricing --if-alias-exists name=Loyal_Civil_Servants_Pricing
- |
epcc delete pcm-catalog name=Ranges_Catalog_for_Special_Customers --if-alias-exists name=Ranges_Catalog_for_Special_Customers
epcc delete pcm-catalog name=Ranges_Catalog --if-alias-exists name=Ranges_Catalog
- |
epcc delete cart cust1_only
epcc delete cart cust1_and_2
epcc delete cart no_cust_cart
epcc delete cart cust4_only
epcc delete cart cust4_and_5
epcc delete cart no_cust_cart_custom_items
11 changes: 10 additions & 1 deletion external/runbooks/run-all-runbooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set -x
#Let's test that epcc command works after an embarrassing bug that caused it to panic :(
epcc


epcc reset-store .+

echo "Starting Misc Runbook"
Expand Down Expand Up @@ -61,7 +62,15 @@ epcc runbooks run manual-gateway-how-to capture-payment
epcc runbooks run manual-gateway-how-to reset-cart
epcc runbooks run manual-gateway-how-to reset


echo "Starting Customer Cart Association Tests"
epcc reset-store .+
epcc runbooks run customer-cart-associations try-and-delete-all-carts
epcc runbooks run customer-cart-associations create-prerequisites
epcc runbooks run customer-cart-associations create-customers-and-carts-with-product-items
epcc runbooks run customer-cart-associations delete-customer-and-carts-with-product-items
epcc runbooks run customer-cart-associations create-customers-and-carts-with-custom-items
epcc runbooks run customer-cart-associations delete-customer-and-carts-with-custom-items
epcc runbooks run customer-cart-associations reset

echo "SUCCESS"

Expand Down
Loading