Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Merge branch 'add/10822-new-flow-for-product-collection' into try/pro…
Browse files Browse the repository at this point in the history
…duct-recommendations-block
  • Loading branch information
imanish003 authored Oct 11, 2023
2 parents 8d0198f + 2c1a477 commit ff861eb
Show file tree
Hide file tree
Showing 6 changed files with 456 additions and 30 deletions.
4 changes: 4 additions & 0 deletions assets/js/blocks/product-collection/edit/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
border-radius: 4px;
padding-top: $gap;
}

.block-editor-block-patterns-list__list-item {
break-inside: avoid-column;
}
}

.wc-blocks-product-collection__selection-modal-subtitle {
Expand Down
23 changes: 9 additions & 14 deletions patterns/product-collection-featured-products-5-columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,17 @@
</h3>
<!-- /wp:heading -->

<!-- wp:woocommerce/product-collection {"query":{"perPage":5,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","author":"","search":"","exclude":[],"sticky":"","inherit":false,"taxQuery":{},"parents":[],"isProductCollectionBlock":true,"woocommerceOnSale":false,"woocommerceStockStatus":["instock","outofstock","onbackorder"],"woocommerceAttributes":[],"woocommerceHandPickedProducts":[]},"tagName":"div","displayLayout":{"type":"flex","columns":5},"align":"wide"} -->
<div class="wp-block-woocommerce-product-collection alignwide">
<!-- wp:woocommerce/product-template -->
<!-- wp:woocommerce/product-image {"imageSizing":"thumbnail","isDescendentOfQueryLoop":true} /-->
<!-- wp:woocommerce/product-collection {"query":{"perPage":5,"pages":0,"offset":0,"postType":"product","order":"asc","orderBy":"title","author":"","search":"","exclude":[],"sticky":"","inherit":false,"taxQuery":{},"parents":[],"isProductCollectionBlock":true,"woocommerceOnSale":false,"woocommerceStockStatus":["instock","outofstock","onbackorder"],"woocommerceAttributes":[],"woocommerceHandPickedProducts":[]},"tagName":"div","displayLayout":{"type":"flex","columns":5},"align":"wide"} -->
<div class="wp-block-woocommerce-product-collection alignwide">
<!-- wp:woocommerce/product-template -->
<!-- wp:woocommerce/product-image {"imageSizing":"thumbnail","isDescendentOfQueryLoop":true} /-->

<!-- wp:post-title {"textAlign":"left","level":3,"isLink":true,"style":{"spacing":{"margin":{"bottom":"0.75rem","top":"0"}}},"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->
<!-- wp:post-title {"textAlign":"left","level":3,"isLink":true,"style":{"spacing":{"margin":{"bottom":"0.75rem","top":"0"}}},"fontSize":"medium","__woocommerceNamespace":"woocommerce/product-collection/product-title"} /-->

<!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"left","fontSize":"small"} /-->
<!-- /wp:woocommerce/product-template -->

<!-- wp:query-no-results -->
<!-- wp:paragraph {"placeholder":"Add text or blocks that will display when a query returns no results."} -->
<p></p>
<!-- /wp:paragraph -->
<!-- /wp:query-no-results --></div>
<!-- /wp:woocommerce/product-collection -->
<!-- wp:woocommerce/product-price {"isDescendentOfQueryLoop":true,"textAlign":"left","fontSize":"small"} /-->
<!-- /wp:woocommerce/product-template -->
</div>
<!-- /wp:woocommerce/product-collection -->

<!-- wp:buttons {"align":"wide","layout":{"type":"flex","verticalAlignment":"center","justifyContent":"center"}} -->
<div class="wp-block-buttons alignwide">
Expand Down
4 changes: 3 additions & 1 deletion src/StoreApi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ Available resources in the Store API are listed below, with links to more detail
| | `GET`, `POST`, `PUT`, `DELETE` | [`/wc/store/v1/cart/items/:key`](docs/cart-items.md#single-cart-item) |
| [`Cart Coupons`](docs/cart-coupons.md) | `GET`, `POST`, `DELETE` | [`/wc/store/v1/cart/coupons`](docs/cart-coupons.md#list-cart-coupons) |
| | `GET`, `DELETE` | [`/wc/store/v1/cart/coupon/:code`](docs/cart-coupons.md#single-cart-coupon) |
| [`Checkout`](docs/checkout.md) | `GET`, `POST` | [`/wc/store/v1/checkout`](docs/checkout.md) |
| [`Checkout`](docs/checkout.md) | `GET`, `POST` | [`/wc/store/v1/checkout`](docs/checkout.md)
| [`Checkout order`](docs/checkout-order.md) | `POST` | [`/wc/store/v1/checkout/:id`](docs/checkout-order.md) |
| [`Order`](docs/order.md) | `GET` | [`/wc/store/v1/order/:id`](docs/order.md)
| [`Products`](docs/products.md) | `GET` | [`/wc/store/v1/products`](docs/products.md#list-products) |
| | `GET` | [`/wc/store/v1/products/:id`](docs/products.md#single-product) |
| [`Product Collection Data`](docs/product-collection-data.md) | `GET` | [`/wc/store/v1/products/collection-data`](docs/product-collection-data.md) |
Expand Down
32 changes: 17 additions & 15 deletions src/StoreApi/docs/cart.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

## Table of Contents <!-- omit in toc -->


- [Get Cart](#get-cart)
- [Responses](#responses)
- [Cart Response](#cart-response)
- [Error Response](#error-response)
- [Get Cart](#get-cart)
- [Add Item](#add-item)
- [Remove Item](#remove-item)
- [Update Item](#update-item)
Expand All @@ -18,6 +19,21 @@ The cart API returns the current state of the cart for the current session or lo

All POST endpoints require [Nonce Tokens](nonce-tokens.md) and return the updated state of the full cart once complete.


## Get Cart

```http
GET /cart
```

There are no parameters required for this endpoint.

```sh
curl "https://example-store.com/wp-json/wc/store/v1/cart"
```

Returns the full cart object response (see [Cart Response](#cart-response)).

## Responses

All endpoints under `/cart` (listed in this doc) return responses in the same format; a cart object which includes cart items, applied coupons, shipping addresses and rates, and non-sensitive customer data.
Expand Down Expand Up @@ -378,20 +394,6 @@ Some error responses indicate conflicts (error 409), for example, when an item c

This allows the client to remain in sync with the cart data without additional requests, should the cart change or become outdated.

## Get Cart

```http
GET /cart
```

There are no parameters required for this endpoint.

```sh
curl "https://example-store.com/wp-json/wc/store/v1/cart"
```

Returns the full cart object response (see [Cart Response](#cart-response)).

## Add Item

Add an item to the cart and return the full cart response, or an error.
Expand Down
167 changes: 167 additions & 0 deletions src/StoreApi/docs/checkout-order.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Checkout order API <!-- omit in toc -->

## Table of Contents <!-- omit in toc -->

- [Process Order and Payment](#process-order-and-payment)
- [Payment Data](#payment-data)

The checkout order API facilitates the processing of existing orders and handling payments.

All checkout order endpoints require [Nonce Tokens](nonce-tokens.md).

## Process Order and Payment

Accepts the final chosen payment method, and any additional payment data, then attempts payment and
returns the result.

This endpoint will return an error unless a valid [Nonce Token](nonce-tokens.md) is provided.

```http
POST /wc/store/v1/checkout/{ORDER_ID}
```

| Attribute | Type | Required | Description |
| :----------------- | :----- | :------: | :------------------------------------------------------------------ |
| `key` | string | Yes | The key for the order verification. |
| `billing_email` | string | No | The email address used to verify guest orders. |
| `billing_address` | object | Yes | Object of updated billing address data for the customer. |
| `shipping_address` | object | Yes | Object of updated shipping address data for the customer. |
| `payment_method` | string | Yes | The ID of the payment method being used to process the payment. |
| `payment_data` | array | No | Data to pass through to the payment method when processing payment. |

```sh
curl --header "Nonce: 12345" --request POST https://example-store.com/wp-json/wc/store/v1/checkout/{ORDER_ID} -d '{"key":"wc_order_oFmQYREzh9Tfv","billing_email":"admin@example.com","payment_method":"cheque","billing_address":{...},"shipping_address":{...}'
```

**Example request:**

```json
{
"key": "wc_order_oFmQYREzh9Tfv",
"billing_email": "admin@example.com",
"billing_address": {
"first_name": "Peter",
"last_name": "Venkman",
"company": "",
"address_1": "550 Central Park West",
"address_2": "Corner Penthouse Spook Central",
"city": "New York",
"state": "NY",
"postcode": "10023",
"country": "US",
"email": "admin@example.com",
"phone": "555-2368"
},
"shipping_address": {
"first_name": "Peter",
"last_name": "Venkman",
"company": "",
"address_1": "550 Central Park West",
"address_2": "Corner Penthouse Spook Central",
"city": "New York",
"state": "NY",
"postcode": "10023",
"country": "US",
"phone": "555-2368"
},
"payment_method": "cheque",
"payment_data": []
}
```

**Example response:**

```json
{
"order_id": 146,
"status": "on-hold",
"order_key": "wc_order_oFmQYREzh9Tfv",
"customer_note": "",
"customer_id": 1,
"billing_address": {
"first_name": "Peter",
"last_name": "Venkman",
"company": "",
"address_1": "550 Central Park West",
"address_2": "Corner Penthouse Spook Central",
"city": "New York",
"state": "NY",
"postcode": "10023",
"country": "US",
"email": "admin@example.com",
"phone": "555-2368"
},
"shipping_address": {
"first_name": "Peter",
"last_name": "Venkman",
"company": "",
"address_1": "550 Central Park West",
"address_2": "Corner Penthouse Spook Central",
"city": "New York",
"state": "NY",
"postcode": "10023",
"country": "US",
"phone": "555-2368"
},
"payment_method": "cheque",
"payment_result": {
"payment_status": "success",
"payment_details": [],
"redirect_url": "https://local.wordpress.test/block-checkout/order-received/146/?key=wc_order_VPffqyvgWVqWL"
}
}
```

## Payment Data

There are many payment gateways available for merchants to use, and each one will be expecting different `payment_data`. We cannot comprehensively list all expected requests for all payment gateways, and we would recommend reaching out to the authors of the payment gateway plugins you're working with for further information.

An example of the payment data sent to the Checkout Order endpoint when using the [WooCommerce Stripe Payment Gateway](https://wordpress.org/plugins/woocommerce-gateway-stripe/) is shown below.

For further information on generating a `stripe_source` please check [the Stripe documentation](https://stripe.com/docs).

```json
{
"payment_data": [
{
"key": "stripe_source",
"value": "src_xxxxxxxxxxxxx"
},
{
"key": "billing_email",
"value": "myemail@email.com"
},
{
"key": "billing_first_name",
"value": "Jane"
},
{
"key": "billing_last_name",
"value": "Doe"
},
{
"key": "paymentMethod",
"value": "stripe"
},
{
"key": "paymentRequestType",
"value": "cc"
},
{
"key": "wc-stripe-new-payment-method",
"value": true
}
]
}
```

<!-- FEEDBACK -->

---

[We're hiring!](https://woocommerce.com/careers/) Come work with us!

🐞 Found a mistake, or have a suggestion? [Leave feedback about this document here.](https://github.com/woocommerce/woocommerce-blocks/issues/new?assignees=&labels=type%3A+documentation&template=--doc-feedback.md&title=Feedback%20on%20./src/StoreApi/docs/checkout-order.md)

<!-- /FEEDBACK -->

Loading

0 comments on commit ff861eb

Please sign in to comment.