Skip to content

Commit 6f9c7cc

Browse files
authored
TT-9792 Add support to blocks based checkout (#47)
* chore: updated makefile * chore: added blocks based checkout support * chore: added env example * chore: added eslint rules * docs: added section for blocks checkout in readme * chore: updated publish workflow * chore: updated woocommerce setup * fix: mounting of autosuggest component for blocks based checkout * chore: addressed issue when selecting suggestion * fix: extra w3w prefix on thank you page * chore: added docker compose env var * chore: removed matrix env vars for docker compose file * chore: added missing env var for github action * chore: updated test workflow github action * chore: updated docker compose * tests: ignoring resizeobserver loop error * chore: updated managed spec * chore: updated tests * fix: w3w on blocks based order confirmation * chore: removed blocks based tests from matrix * chore: updated env example * chore: bumped alpha version * chore: fixed missing w3w on admin order * chore: linting change * chore: updated version
1 parent dbd84b0 commit 6f9c7cc

34 files changed

+26772
-170
lines changed

.env.example

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Blocks based checkout started on version 8.3.2 onwards
2+
WOOCOMMERCE_VERSION=9.6.2
3+
WORDPRESS_VERSION=6.7.2
4+
WORDPRESS_THEME=twentytwentyfive
5+
PHP_VERSION=8.1
6+
7+
8+
# WOOCOMMERCE_VERSION: 8.0.4 # Not using blocks
9+
# WOOCOMMERCE_VERSION=5.7.1
10+
# WORDPRESS_VERSION=5.9.0
11+
# WORDPRESS_THEME=twentytwentyone
12+
# PHP_VERSION=7.4
13+
14+
API_KEY=YOUR_W3W_API_KEY

.github/workflows/publish.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,26 @@ jobs:
1111
steps:
1212
- name: Install SVN
1313
run: |
14-
sudo apt-get install subversion -y
14+
sudo apt-get install subversion nodejs -y
1515
- uses: actions/checkout@v4
1616
- name: Setup version env
1717
run: |
1818
VERSION=${GITHUB_REF_NAME#v}
1919
echo Version: $VERSION
2020
echo "VERSION=$VERSION" >> $GITHUB_ENV
21+
- name: Update version
22+
run: |
23+
sed -i 's/define(.W3W_PLUGIN_VERSION.,\s*.*)/define('\''W3W_PLUGIN_VERSION'\'', '\'$VERSION\'');/' w3w-autosuggest/w3w-autosuggest.php
24+
sed -i 's/\* Version:\s*.*/* Version: '$VERSION'/' w3w-autosuggest/w3w-autosuggest.php
25+
sed -i 's/Stable tag: .*/Stable tag: '$VERSION'/' w3w-autosuggest/README.txt
26+
sed -i 's/"version": "[^"]*"/"version": "'$VERSION'"/' w3w-autosuggest-blocks/package.json
27+
sed -i 's/"version": "[^"]*"/"version": "'$VERSION'"/' w3w-autosuggest-blocks/src/block.json
28+
- name: Build w3w-autosuggest-blocks
29+
run: |
30+
pushd w3w-autosuggest-blocks
31+
npm install
32+
npm run build
33+
popd
2134
- name: Checkout from Wordpress SVN
2235
run: |
2336
svn co https://plugins.svn.wordpress.org:443/3-word-address-validation-field "$HOME/svn" --trust-server-cert --non-interactive

.github/workflows/test.yaml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,30 @@ jobs:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
node-version: ['14.x']
11+
include:
12+
- node-version: '14.x'
13+
WORDPRESS_VERSION: 5.7.2
14+
PHP_VERSION: 7.4
15+
WOOCOMMERCE_VERSION: 5.7.1
16+
WORDPRESS_THEME: twentytwenty
1217
steps:
1318
- name: Checkout
1419
uses: actions/checkout@v4
15-
- run: |
20+
- name: Start WordPress
21+
run: |
1622
docker compose -f ./docker-compose.yaml up -d
23+
env:
24+
WORDPRESS_VERSION: ${{ matrix.WORDPRESS_VERSION }}
25+
PHP_VERSION: ${{ matrix.PHP_VERSION }}
26+
WOOCOMMERCE_VERSION: ${{ matrix.WOOCOMMERCE_VERSION }}
27+
WORDPRESS_THEME: ${{ matrix.WORDPRESS_THEME }}
28+
- name: Show Docker logs on failure
29+
if: failure()
30+
run: |
31+
echo "=== Docker Compose ps ==="
32+
docker compose -f ./docker-compose.yaml ps
33+
echo "=== Docker Compose logs ==="
34+
docker compose -f ./docker-compose.yaml logs --no-color
1735
- name: Use Node.js
1836
uses: actions/setup-node@v4
1937
with:

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,17 @@ intermediate
208208
.idea
209209
cache
210210
test/database/data/*
211+
test/wordpress/*
211212
node_modules
212213
autosuggest
213214
videos
214215
screenshots
215216
*.zip
216217
*.env
217-
3-word-address-validation-field
218+
3-word-address-validation-field
219+
220+
221+
test/wordpress*
222+
test/database/data*
223+
224+
w3w-autosuggest/public/blocks/*

Dockerfile

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
1+
ARG WORDPRESS_VERSION=5.9.0
2+
ARG PHP_VERSION=7.4
3+
14
FROM alpine:3.19.0 AS build-dependencies
25

36
WORKDIR /dependencies
47

58
ARG WOOCOMMERCE_VERSION=5.4.1
69

7-
RUN apk add wget unzip
8-
RUN wget https://downloads.wordpress.org/plugin/woocommerce.${WOOCOMMERCE_VERSION}.zip -O woocommerce.zip
9-
RUN unzip woocommerce.zip
10+
RUN apk add --no-cache wget unzip
11+
12+
RUN wget https://downloads.wordpress.org/plugin/woocommerce.${WOOCOMMERCE_VERSION}.zip -O woocommerce.zip \
13+
&& unzip woocommerce.zip \
14+
&& rm woocommerce.zip
1015

11-
FROM wordpress:5.9.0-php7.4-apache
16+
FROM wordpress:${WORDPRESS_VERSION}-php${PHP_VERSION}-apache AS development
1217

1318
ENV WORDPRESS_DB_NAME=wordpress
1419
ENV WORDPRESS_DB_USER=root
1520
ENV WORDPRESS_DB_PASSWORD=wordpress
1621
ENV WORDPRESS_DB_HOST=mysql:3306
1722
ENV WORDPRESS_DEBUG=1
1823

24+
RUN apt update && apt install -y less
25+
26+
RUN groupadd -g 1000 wp_user && \
27+
useradd -m -u 1000 -g wp_user wp_user
28+
29+
# Set proper permissions for WordPress directories
30+
RUN chown -R wp_user:wp_user /var/www/html && \
31+
chown -R wp_user:wp_user /usr/src/wordpress
32+
1933
RUN sed -i "11i php_value upload_max_filesize 256M" /usr/src/wordpress/.htaccess && \
2034
sed -i "12i php_value post_max_size 256M" /usr/src/wordpress/.htaccess
2135

@@ -24,4 +38,6 @@ WORKDIR /usr/src/wordpress
2438
COPY --from=build-dependencies \
2539
/dependencies/woocommerce ./wp-content/plugins/woocommerce
2640

41+
USER wp_user
42+
2743
WORKDIR /var/www/html

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ In order to contribute to this project you should follow the guide to modifying
5656

5757
3. Commit your changes to a suitably named branch and open a PR with the relevant details of your changes included. If you are working from a JIRA ticket you should try to include the name of the JIRA ticket in your commit in square braces, e.g. _"[TT-1234] My PR which resolves issues X"_
5858

59-
**TODO**
59+
4. Once your PR has been reviewed and merged the CI pipeline should automatically deploy your changes to the WordPress plugin version control repository (SVN) once a release with a tag is created.
6060

61-
4. Once your PR has been reviewed and merged the CI pipeline should automatically deploy your changes to the WordPress plugin version control repository (SVN).
61+
### Notes
62+
63+
WooCommerce has introduced blocks based checkout starting v8.3 omnwards. If you're working on any features related to blocks based checkout, there's a specific directory dedicated to it under `w3w-autosuggest-blocks`. This project needs to be bundled using webpack via `wp-scripts` tooling. During development you can run `npm run start` and `npm run build` to bundle the scripts which will be added to `w3w-autosuggest` directory and will be included once the extension is published.
6264

6365
### Testing changes
6466

@@ -69,3 +71,5 @@ docker compose up -d
6971
cd test
7072
npm t
7173
```
74+
75+
> :bulb: Ensure that you have a `.env` file (use the `.env.example` as a reference) before running the docker compose command above.

docker-compose.yaml

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
version: '3.8'
2-
31
services:
4-
wordpress:
2+
app:
53
platform: linux/amd64
64
build:
75
dockerfile: Dockerfile
86
context: .
7+
target: development
8+
args:
9+
WOOCOMMERCE_VERSION: $WOOCOMMERCE_VERSION
10+
WORDPRESS_VERSION: $WORDPRESS_VERSION
11+
PHP_VERSION: $PHP_VERSION
912
container_name: w3w-wp
1013
healthcheck:
1114
test: ['CMD', 'curl', '-f', 'http://localhost:80']
@@ -22,13 +25,41 @@ services:
2225
WORDPRESS_CONFIG_EXTRA: |
2326
define('DISABLE_WP_CRON', 'true');
2427
volumes:
25-
- ./w3w-autosuggest:/var/www/html/wp-content/plugins/w3w-autosuggest
28+
- wordpress_data:/var/www/html
29+
- ./w3w-autosuggest:/var/www/html/wp-content/plugins/w3w-autosuggest:rw
2630
ports:
2731
- 8080:80
2832
depends_on:
2933
mysql:
3034
condition: service_healthy
3135

36+
woocommerce:
37+
platform: linux/amd64
38+
build:
39+
dockerfile: test/woocommerce/Dockerfile
40+
context: .
41+
target: setup-woocommerce
42+
container_name: w3w-wp-setup
43+
depends_on:
44+
app:
45+
condition: service_healthy
46+
volumes:
47+
- wordpress_data:/var/www/html
48+
environment:
49+
WORDPRESS_LOCALE: en_GB
50+
WORDPRESS_DB_HOST: mysql:3306
51+
WORDPRESS_DB_NAME: wordpress
52+
WORDPRESS_DB_USER: wordpress
53+
WORDPRESS_DB_PASSWORD: wordpress
54+
WORDPRESS_WEBSITE_TITLE: 'what3words'
55+
WORDPRESS_WEBSITE_URL: 'http://localhost:8080'
56+
WORDPRESS_WEBSITE_URL_WITHOUT_HTTP: 'localhost:8080'
57+
WORDPRESS_WEBSITE_POST_URL_STRUCTURE: '/%year%/%monthnum%/%day%/%postname%/'
58+
WORDPRESS_ADMIN_USER: 'what3words'
59+
WORDPRESS_ADMIN_PASSWORD: 'what3words'
60+
WORDPRESS_ADMIN_EMAIL: 'developer@what3words.com'
61+
WORDPRESS_THEME: $WORDPRESS_THEME
62+
3263
mysql:
3364
platform: linux/amd64
3465
image: mysql:5.7
@@ -47,5 +78,8 @@ services:
4778
MYSQL_PASSWORD: wordpress
4879
MYSQL_DATABASE: wordpress
4980
volumes:
50-
- ./test/database/data:/var/lib/mysql
51-
- ./test/database/sql/wordpress-5.7.2.sql:/docker-entrypoint-initdb.d/wordpress-5.7.2.sql
81+
- db_data:/var/lib/mysql
82+
83+
volumes:
84+
wordpress_data:
85+
db_data:

makefile

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
PLUGIN := 3-word-address-validation-field
22

3+
# Define the version (this is your single source of truth)
4+
VERSION := 4.0.17
5+
6+
# Define file paths
7+
PLUGIN_FILE := w3w-autosuggest/w3w-autosuggest.php
8+
README_FILE := w3w-autosuggest/README.txt
9+
310
.PHONY: check_wp_compatibility
411
check_wp_compatibility:
512
@echo "Checking plugin: $(PLUGIN)"
@@ -9,20 +16,34 @@ check_wp_compatibility:
916
TESTED_VERSION=$$(echo $$PLUGIN_INFO_CLEAN | grep -o '"tested":"[^"]*"' | cut -d '"' -f 4); \
1017
LATEST_VERSION=$$(echo $$PLUGIN_INFO_CLEAN | grep -o '"version":"[^"]*"' | cut -d '"' -f 4); \
1118
if [ -z "$$TESTED_VERSION" ] || [ "$$TESTED_VERSION" = "null" ]; then \
12-
echo "Could not retrieve plugin information for $(PLUGIN) or the plugin has not been tested."; \
19+
echo "::error::Could not retrieve plugin information for $(PLUGIN) or the plugin has not been tested."; \
20+
exit 1; \
1321
elif [ -z "$$LATEST_VERSION" ] || [ "$$LATEST_VERSION" = "null" ]; then \
14-
echo "Could not retrieve the latest version for $(PLUGIN)."; \
22+
echo "::error::Could not retrieve the latest version for $(PLUGIN)."; \
23+
exit 1; \
1524
else \
1625
echo "Plugin version: $$LATEST_VERSION"; \
1726
echo "Tested up to: $$TESTED_VERSION"; \
18-
echo "Current WordPress version: $$CURRENT_WP_VERSION"; \
1927
if [ "$$(echo $$CURRENT_WP_VERSION | cut -d '.' -f 1)" -gt "$$(echo $$TESTED_VERSION | cut -d '.' -f 1)" ]; then \
20-
echo "Warning: The plugin hasn't been tested with the latest WordPress major release."; \
28+
echo "::error::The plugin hasn't been tested with the latest WordPress major release."; \
2129
exit 1; \
2230
elif [ "$$(echo $$CURRENT_WP_VERSION | cut -d '.' -f 2)" -gt "$$(echo $$TESTED_VERSION | cut -d '.' -f 2)" ]; then \
23-
echo "Warning: The plugin hasn't been tested with the latest minor release of WordPress."; \
31+
echo "::error::The plugin hasn't been tested with the latest minor release of WordPress - $$CURRENT_WP_VERSION"; \
2432
exit 1; \
2533
else \
26-
echo "The plugin is tested with your current version of WordPress."; \
34+
echo "::notice::The plugin is tested with your current version of WordPress"; \
2735
fi; \
2836
fi
37+
38+
39+
.PHONY: update-version
40+
update-version:
41+
@echo "Updating version to $(VERSION)..."
42+
@sed -i '' -e 's/define(.W3W_PLUGIN_VERSION.,\s*.*)/define('\''W3W_PLUGIN_VERSION'\'', '\''$(VERSION)'\'')/' $(PLUGIN_FILE)
43+
@sed -i '' -e 's/\* Version:\s*.*/* Version: $(VERSION)/' $(PLUGIN_FILE)
44+
@sed -i '' -e 's/Stable tag: .*/Stable tag: $(VERSION)/' $(README_FILE)
45+
@sed -i '' -e 's/"version": "[^"]*"/"version": "$(VERSION)"/' w3w-autosuggest-blocks/package.json
46+
@sed -i '' -e 's/"version": "[^"]*"/"version": "$(VERSION)"/' w3w-autosuggest-blocks/src/block.json
47+
@echo "Version updated to $(VERSION)"
48+
49+

test/cypress/integration/common/step_definitions/cart.steps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { Given, When } from 'cypress-cucumber-preprocessor/steps';
33
Given('a customer has an item in their cart', () => {
44
cy.visit('/shop')
55
.get('a.button')
6-
.click()
6+
.click({ force: true })
77
.get('.added_to_cart')
88
.should('be.visible');
99
});
1010

1111
When('they go to checkout', () => {
1212
cy.visit('/cart')
1313
.get('a.checkout-button')
14-
.click()
14+
.click({ force: true })
1515
});

test/cypress/integration/fluidcheckout/plugin.steps.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,51 +27,51 @@ Then('they see autosuggest when they open shipping', () => {
2727
);
2828

2929
cy.wait(500);
30-
cy.get('#shipping_first_name').click().type(fname);
31-
cy.get('#shipping_last_name').click().type(lname);
32-
cy.get('#shipping_address_1').click().type(add1);
33-
cy.get('#shipping_city').click().type(city);
34-
cy.get('#shipping_postcode').click().type(postcode);
30+
cy.get('#shipping_first_name').click({ force: true }).type(fname);
31+
cy.get('#shipping_last_name').click({ force: true }).type(lname);
32+
cy.get('#shipping_address_1').click({ force: true }).type(add1);
33+
cy.get('#shipping_city').click({ force: true }).type(city);
34+
cy.get('#shipping_postcode').click({ force: true }).type(postcode);
3535

3636
// Start cruft - due to setTimeouts and other Fluid Checkout weirdness, this bit of cruft is necessary here
3737
cy.wait(500);
3838
cy.get(
3939
'#fc-expansible-form-section__toggle--shipping_w3w > .collapsible-content__inner > .expansible-section__toggle-plus'
4040
)
4141
.focus()
42-
.click();
42+
.click({ force: true });
4343
cy.wait('@update');
4444
cy.get(
4545
'#fc-expansible-form-section__toggle--shipping_w3w > .collapsible-content__inner > .expansible-section__toggle-plus'
4646
)
4747
.focus()
48-
.click();
48+
.click({ force: true });
4949
cy.wait(500);
5050
// end cruft
5151

5252
cy.get('#w3w-shipping').scrollIntoView().type(hint);
53-
cy.get('[data-testid="suggestion-0"]').click();
53+
cy.get('[data-testid="suggestion-0"]').click({ force: true });
5454
cy.get('#w3w-shipping')
5555
.invoke('val')
5656
.should('match', /^\/\/\/(\w+.){2}\w+$/i);
5757
cy.get(
5858
'[data-step-id="shipping"] > .fc-step__actions > .fc-step__next-step'
59-
).click();
59+
).click({ force: true });
6060
});
6161

6262
And('they see autosuggest when they open billing', () => {
6363
const hint = 'm.a.s';
6464

6565
cy.wait(200);
66-
cy.get('#billing_same_as_shipping').click();
66+
cy.get('#billing_same_as_shipping').click({ force: true });
6767
cy.get(
6868
'#fc-expansible-form-section__toggle--billing_w3w > .collapsible-content__inner > .expansible-section__toggle-plus'
6969
)
7070
.scrollIntoView()
71-
.click();
71+
.click({ force: true });
7272
cy.get(`#w3w-billing`).focus().wait(300);
73-
cy.get('#w3w-billing').click().type(hint, { delay: 300 });
74-
cy.get('[data-testid="suggestion-0"]').click();
73+
cy.get('#w3w-billing').click({ force: true }).type(hint, { delay: 300 });
74+
cy.get('[data-testid="suggestion-0"]').click({ force: true });
7575
cy.get('#w3w-billing')
7676
.invoke('val')
7777
.should('match', /^\/\/\/(\w+.){2}\w+$/i);

0 commit comments

Comments
 (0)