generated from autonomic-cooperative/wordpress-starter
Compare commits
20 Commits
7563c632f5
...
main
Author | SHA1 | Date | |
---|---|---|---|
8a17a922ac | |||
960d6a22f2 | |||
9e049f7fa6 | |||
2e30e12488 | |||
a9b655e04f | |||
5832b48479 | |||
7890a955ce | |||
986f7d8856 | |||
52e97d16d8 | |||
45c13bf515 | |||
70886ea67d | |||
83be51bf32 | |||
6f3069bee9 | |||
cd14c04689 | |||
dfdf13cf6f | |||
39ba56eca6 | |||
d6004d6cb3 | |||
e7f5673a19 | |||
0852986599 | |||
b3f48f098c |
15
.drone.yml
15
.drone.yml
@ -2,7 +2,7 @@
|
||||
kind: pipeline
|
||||
name: deploy main branch to live site
|
||||
steps:
|
||||
- name: docker cp deploy
|
||||
- name: copy theme files to staging
|
||||
image: git.coopcloud.tech/coop-cloud/docker-cp-deploy:latest
|
||||
settings:
|
||||
host: smol-wp.autonomic.zone
|
||||
@ -12,6 +12,19 @@ steps:
|
||||
dest: /var/www/html/
|
||||
deploy_key:
|
||||
from_secret: drone_ssh_smol-wp.autonomic.zone
|
||||
when:
|
||||
branch:
|
||||
- staging
|
||||
- name: copy theme files to live
|
||||
image: appleboy/drone-scp
|
||||
settings:
|
||||
host: web1.mont58coffee.com
|
||||
username: autonomic
|
||||
overwrite: true
|
||||
key:
|
||||
from_secret: drone_ssh_mont58coffee.com
|
||||
target: /var/www/production.mont58coffee.com/web/
|
||||
source: wp-content/themes/mont58-coffee/
|
||||
when:
|
||||
branch:
|
||||
- main
|
||||
|
@ -2,6 +2,10 @@
|
||||
# REQUIRED SETTINGS (you will need these) #
|
||||
##############################################################################
|
||||
|
||||
# run `make fetch_db_info` to find these out
|
||||
DB_USER=
|
||||
DB_PASSWORD=
|
||||
DB_NAME=
|
||||
|
||||
##############################################################################
|
||||
# COMMON SETTINGS (you may need these) #
|
||||
@ -37,5 +41,10 @@ PROJECT_NAME=mont58
|
||||
# Site URL, also just needs to be set once per project
|
||||
SITE_URL=mont58-staging.smol-wp.autonomic.zone
|
||||
|
||||
SSH_USER=autonomic
|
||||
SSH_HOST=web1.mont58coffee.com
|
||||
SSH_PATH=/var/www/production.mont58coffee.com/web/
|
||||
SSH_PORT=22
|
||||
|
||||
# Multi-site config
|
||||
#WORDPRESS_CONFIG_EXTRA="define('MULTISITE', true); define('SUBDOMAIN_INSTALL', true); define('DOMAIN_CURRENT_SITE', 'frms.localhost'); define('PATH_CURRENT_SITE', '/'); define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1); define('SUNRISE', true);"
|
||||
|
@ -22,12 +22,14 @@ services:
|
||||
- WORDPRESS_DB_NAME=wordpress
|
||||
- WORDPRESS_CONFIG_EXTRA=${WORDPRESS_CONFIG_EXTRA}
|
||||
- WORDPRESS_DEBUG=${WORDPRESS_DEBUG}
|
||||
- WORDPRESS_TABLE_PREFIX=kM7KXt7HQ_
|
||||
- PHP_EXTENSIONS=calendar
|
||||
- PAGER=more
|
||||
container_name: "${PROJECT_NAME}_wordpress"
|
||||
|
||||
db:
|
||||
image: "mariadb:10.6"
|
||||
command: --innodb-buffer-pool-size=10G
|
||||
volumes:
|
||||
- "${MARIADB_VOLUME:-mariadb}:/var/lib/mysql"
|
||||
networks:
|
||||
|
@ -8,6 +8,8 @@ if [ -n "$PHP_EXTENSIONS" ]; then
|
||||
done
|
||||
fi
|
||||
|
||||
echo 'memory_limit = 2048M' >> /usr/local/etc/php/conf.d/docker-php-memlimit.ini;
|
||||
|
||||
if ! id -u "user" >/dev/null ; then
|
||||
useradd -u 1000 -m user
|
||||
mkdir /var/www/html/vendor
|
||||
|
63
makefile
63
makefile
@ -109,14 +109,53 @@ uploads_load:
|
||||
## Sync wp-content from site
|
||||
uploads_pull: uploads_fetch uploads_load
|
||||
|
||||
fetch_db_info:
|
||||
ssh -p$(SSH_PORT) $(SSH_USER)@$(SSH_HOST) grep DB $(SSH_PATH)/wp-config.php
|
||||
|
||||
## Download database from dev site
|
||||
db_fetch:
|
||||
$(ABRA) app run $(SITE_URL) db bash -c 'mariadb-dump -u root -p"$$(cat /run/secrets/db_root_password)" wordpress' | gzip > data/dbdump.sql.gz
|
||||
ssh -p$(SSH_PORT) autonomic@web1.mont58coffee.com mysqldump -u $(DB_USER) -p$(DB_PASSWORD) "$(DB_NAME)" | gzip > data/dbdump.sql.gz
|
||||
|
||||
## Load latest database from ~/.abra/backups
|
||||
db_load:
|
||||
zcat data/dbdump.sql.gz | $(_DOCKER_COMPOSE) exec -T db mysql -u wordpress -pwordpress wordpress
|
||||
|
||||
db_pull: db_fetch db_load fix_url
|
||||
|
||||
define SQL_HEADER
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8mb4 */;
|
||||
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
|
||||
/*!40103 SET TIME_ZONE='+00:00' */;
|
||||
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
||||
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
||||
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
||||
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
||||
endef
|
||||
export SQL_HEADER
|
||||
|
||||
define SQL_FOOTER
|
||||
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
||||
|
||||
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
||||
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
||||
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
||||
endef
|
||||
export SQL_FOOTER
|
||||
|
||||
db_convert:
|
||||
gunzip data/database.sql.gz
|
||||
sed -i -e 's/SERVMASK_PREFIX/wp/g' -e 's/,0x,/,0,/g' data/database.sql
|
||||
echo "$$SQL_HEADER" | cat - data/database.sql > data/database_wrapped.sql
|
||||
echo "$$SQL_FOOTER" >> data/database_wrapped.sql
|
||||
mv data/database_wrapped.sql data/database.sql
|
||||
|
||||
## Replace site URL
|
||||
fix_url:
|
||||
$(_DOCKER_COMPOSE) exec -u user wordpress wp --url=https://$(SITE_URL) search-replace --all-tables-with-prefix 'https://$(SITE_URL)' 'http://$(PROJECT_NAME).localhost'
|
||||
@ -125,18 +164,8 @@ fix_url:
|
||||
set_local_password:
|
||||
$(_DOCKER_COMPOSE) exec -u user wordpress wp user update $(USERNAME) --user_pass=password
|
||||
|
||||
db_pull: db_fetch db_load fix_url
|
||||
|
||||
## Download wp-content files from site
|
||||
plugins_fetch:
|
||||
$(ABRA) app run --no-tty $(SITE_URL) app tar --owner=0 --group=0 --no-same-owner --no-same-permissions -czf- /var/www/html/wp-content/plugins/ > data/plugins.tar.gz
|
||||
|
||||
## Load latest plugins from data/plugins.tar.gz
|
||||
plugins_load:
|
||||
tar -C wp-content --strip-components=4 -xzf data/plugins.tar.gz
|
||||
|
||||
## Sync plugins from site
|
||||
plugins_pull: plugins_fetch plugins_load
|
||||
plugins_pull:
|
||||
rsync -Pavz -e 'ssh -p$(SSH_PORT)' $(SSH_USER)@$(SSH_HOST):$(SSH_PATH)/wp-content/plugins/ wp-content/plugins/
|
||||
|
||||
## Download parent theme from site
|
||||
theme_fetch:
|
||||
@ -149,6 +178,14 @@ theme_load:
|
||||
## Sync wp-content from site
|
||||
theme_pull: theme_fetch theme_load
|
||||
|
||||
#######################################
|
||||
# Releases
|
||||
#######################################
|
||||
|
||||
# Generate ZIP of theme
|
||||
theme_export:
|
||||
cd wp-content/themes/mont58-coffee/ && zip -r ../../../data/mont58-theme_2024-07-09.zip . && cd -
|
||||
|
||||
# "Arguments" for makefiles..
|
||||
# https://stackoverflow.com/a/6273809/1826109
|
||||
%:
|
||||
|
@ -63,13 +63,6 @@ add_filter(
|
||||
* License: GPL2
|
||||
*/
|
||||
|
||||
/**
|
||||
* Process coffee items for an order
|
||||
*
|
||||
* @param WC_Order $order The order to process
|
||||
* @param array &$order_coffees Reference to array to store processed coffees
|
||||
* @param array &$seen_subscriptions Reference to array tracking seen subscriptions
|
||||
*/
|
||||
function process_coffee_items($order, &$order_coffees, &$seen_subscriptions)
|
||||
{
|
||||
// Iterate through all items in the order
|
||||
@ -77,9 +70,12 @@ function process_coffee_items($order, &$order_coffees, &$seen_subscriptions)
|
||||
// Check if the item is a subscription (based on name containing "subscription")
|
||||
if (stripos($order_item->get_name(), "subscription") !== false) {
|
||||
// Get the coffee list associated with the subscription item
|
||||
$coffee_list = get_field("coffee_list", $order_item->get_product_id());
|
||||
$coffee_list = get_field(
|
||||
"coffee_list",
|
||||
$order_item->get_product_id()
|
||||
);
|
||||
|
||||
// Skip this item if no coffee list is found
|
||||
// TODO log or display this error
|
||||
if (!$coffee_list) {
|
||||
continue;
|
||||
}
|
||||
@ -93,24 +89,26 @@ function process_coffee_items($order, &$order_coffees, &$seen_subscriptions)
|
||||
for ($x = 0; $x < $item_quantity; $x++) {
|
||||
$coffee_list_id = $coffee_list->ID;
|
||||
|
||||
// Initialize the seen count for this coffee list if not set
|
||||
if (!isset($seen_subscriptions[$coffee_list_id])) {
|
||||
$seen_subscriptions[$coffee_list_id] = 0;
|
||||
}
|
||||
|
||||
// Check if this coffee list has been seen before in this order
|
||||
if (array_key_exists($coffee_list_id, $seen_subscriptions)) {
|
||||
// Increment the count of times this coffee list has been encountered
|
||||
$seen_subscriptions[$coffee_list_id]++;
|
||||
// Calculate the index to select a coffee from the list
|
||||
$index = $seen_subscriptions[$coffee_list_id];
|
||||
// Select the coffee using the calculated index
|
||||
$coffee = $coffees_in_list[$index % count($coffees_in_list)];
|
||||
$coffee =
|
||||
$coffees_in_list[$index % sizeof($coffees_in_list)];
|
||||
} else {
|
||||
// If this coffee list is encountered for the first time in this order
|
||||
$seen_subscriptions[$coffee_list_id] = 0;
|
||||
// Select the last coffee from the list
|
||||
$coffee = array_pop(array_reverse($coffees_in_list));
|
||||
}
|
||||
|
||||
// Add the selected coffee with its associated coffee list to the order_coffees array
|
||||
array_push($order_coffees, [
|
||||
"coffee_list" => $coffee_list,
|
||||
"coffee" => $coffee,
|
||||
]);
|
||||
|
||||
// Increment the seen count for this coffee list
|
||||
$seen_subscriptions[$coffee_list_id]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -133,22 +131,20 @@ function action_woocommerce_new_order($order_id, $order)
|
||||
add_action("woocommerce_new_order", "action_woocommerce_new_order", 10, 2);
|
||||
|
||||
// Handle renewal order creation event
|
||||
/**
|
||||
* Handle renewal order creation event
|
||||
*
|
||||
* @param WC_Order $order The new renewal order
|
||||
* @param WC_Subscription $subscription The subscription object
|
||||
*/
|
||||
function action_wcs_renewal_order_created($order, $subscription)
|
||||
{
|
||||
// Retrieve related orders of the subscription excluding the current renewal order
|
||||
$last_orders = wcs_get_subscription($subscription)->get_related_orders("ids", ["parent", "renewal"]);
|
||||
$last_orders = wcs_get_subscription($subscription)->get_related_orders(
|
||||
"ids",
|
||||
["parent", "renewal"]
|
||||
);
|
||||
unset($last_orders[$order->get_ID()]);
|
||||
|
||||
// If there are previous orders related to the subscription
|
||||
if (sizeof($last_orders) > 0) {
|
||||
// Get the ID of the most recent previous order
|
||||
$last_order_id = max($last_orders);
|
||||
$last_order = wc_get_order($last_order_id);
|
||||
// Get the processed coffees from the most recent previous order
|
||||
$last_order_coffees = get_field("coffees", $last_order_id);
|
||||
|
||||
@ -156,31 +152,47 @@ function action_wcs_renewal_order_created($order, $subscription)
|
||||
$order_coffees = [];
|
||||
$seen_subscriptions = [];
|
||||
|
||||
// Initialize $seen_subscriptions based on the last order's coffees
|
||||
foreach ($last_order_coffees as $last_order_coffee) {
|
||||
$coffee_list_id = $last_order_coffee["coffee_list"]->ID;
|
||||
if (!isset($seen_subscriptions[$coffee_list_id])) {
|
||||
// Find the position of the last coffee in its list
|
||||
if ($last_order_coffees) { // Check last_order_coffees isn't null or false
|
||||
// Get the latest coffee seen in each coffee list from the previous order
|
||||
foreach (array_reverse($last_order_coffees) as $last_order_coffee) {
|
||||
if (
|
||||
array_key_exists(
|
||||
$last_order_coffee["coffee_list"]->ID,
|
||||
$seen_subscriptions
|
||||
)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
$position_in_list = array_search(
|
||||
$last_order_coffee["coffee"]->ID,
|
||||
get_field("coffees", $last_order_coffee["coffee_list"]->ID)
|
||||
$last_order_coffee["coffee_list"]->coffees
|
||||
);
|
||||
// Set the next position (or 0 if not found)
|
||||
$seen_subscriptions[$coffee_list_id] = $position_in_list !== false ? $position_in_list + 1 : 0;
|
||||
if ($position_in_list === false) {
|
||||
// ignore this, can't find it in list anymore
|
||||
continue;
|
||||
}
|
||||
$seen_subscriptions[
|
||||
$last_order_coffee["coffee_list"]->ID
|
||||
] = $position_in_list;
|
||||
}
|
||||
}
|
||||
|
||||
// Process coffee items for the new renewal order
|
||||
process_coffee_items($order, $order_coffees, $seen_subscriptions);
|
||||
// Process coffee items based on the coffees in the last order
|
||||
process_coffee_items($last_order, $order_coffees, $seen_subscriptions);
|
||||
|
||||
// Update the custom field "coffees" with the processed coffee data for the current renewal order
|
||||
update_field("coffees", $order_coffees, $order->get_ID());
|
||||
}
|
||||
|
||||
return $order;
|
||||
}
|
||||
// Hook the above function to the 'wcs_renewal_order_created' action
|
||||
add_action("wcs_renewal_order_created", "action_wcs_renewal_order_created", 10, 2);
|
||||
|
||||
|
||||
add_action(
|
||||
"wcs_renewal_order_created",
|
||||
"action_wcs_renewal_order_created",
|
||||
10,
|
||||
2
|
||||
);
|
||||
|
||||
// Add a sidepanel on WooCommerce order pages
|
||||
add_action("add_meta_boxes", "mont58_coffee_label_add_sidepanel");
|
||||
|
@ -2,6 +2,6 @@
|
||||
Theme Name: Mont58 Coffee
|
||||
Description: Theme for mont58coffee.com - child theme of Bridge
|
||||
Template: bridge
|
||||
Version: 1.0.0
|
||||
Version: 1.1.0
|
||||
Text Domain: mont58coffee
|
||||
*/
|
@ -76,7 +76,6 @@ if(!is_user_logged_in()){
|
||||
min-height: 3mm;
|
||||
font-variation-settings: 'wdth' 70, 'wght' 600;
|
||||
margin-inline: auto;
|
||||
width: 90%;
|
||||
}
|
||||
|
||||
.label .product-details .origin.non-coffee {
|
||||
@ -100,16 +99,13 @@ if(!is_user_logged_in()){
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
||||
font-size: 2.2mm; /* so that names as long as 50 characters stay on one line */
|
||||
font-size: 2.9mm; /* so that names as long as 50 characters stay on one line */
|
||||
margin-top: 4.6mm; /* to center text inside white area */
|
||||
position: absolute;
|
||||
bottom: 8mm; /* Adjust this value to set the distance from the bottom of the label */
|
||||
bottom: 5.9mm; /* Adjust this value to set the distance from the bottom of the label */
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
.label .order-details p {
|
||||
margin-block: 0.5mm;
|
||||
@ -119,13 +115,25 @@ if(!is_user_logged_in()){
|
||||
<body>
|
||||
<div class="container">
|
||||
<?php
|
||||
$j = 0;
|
||||
|
||||
foreach ($_GET["order_ids"] as $order_id) {
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
// Check if shipping details exist
|
||||
$shipping_first_name = $order->get_shipping_first_name();
|
||||
$shipping_last_name = $order->get_shipping_last_name();
|
||||
$shipping_postcode = $order->get_shipping_postcode();
|
||||
|
||||
// If any shipping detail is empty, use billing details
|
||||
if (empty($shipping_first_name) || empty($shipping_last_name) || empty($shipping_postcode)) {
|
||||
$first_name = $order->get_billing_first_name();
|
||||
$last_name = $order->get_billing_last_name();
|
||||
$postcode = $order->get_billing_postcode();
|
||||
} else {
|
||||
$first_name = $shipping_first_name;
|
||||
$last_name = $shipping_last_name;
|
||||
$postcode = $shipping_postcode;
|
||||
}
|
||||
|
||||
$items = $order->get_items();
|
||||
$total_items = $order->get_item_count();
|
||||
$roast_date = (new DateTime())->modify("-3 days")->format("d/m/Y");
|
||||
@ -133,14 +141,17 @@ if(!is_user_logged_in()){
|
||||
|
||||
$order_subscription_coffees = get_field("coffees", $order_id);
|
||||
|
||||
$j = 0; // Reset $j for each order (claude suggested this)
|
||||
$is_new = false;
|
||||
|
||||
foreach ($items as $item) {
|
||||
$j = 0;
|
||||
|
||||
// checking if product is a coffee
|
||||
$product_id = $item->get_product_id();
|
||||
$product_categories = get_the_terms($product_id, "product_cat");
|
||||
$is_coffee = false;
|
||||
$is_subscription = false;
|
||||
$is_organic = false;
|
||||
|
||||
if (
|
||||
!empty($product_categories) &&
|
||||
@ -157,6 +168,9 @@ if(!is_user_logged_in()){
|
||||
}
|
||||
}
|
||||
|
||||
$product_name = '';
|
||||
$roast = '';
|
||||
|
||||
if ($is_coffee || $is_subscription) {
|
||||
$brew_method = $item->get_meta("pa_brew-method");
|
||||
$weight = $item->get_meta("weight");
|
||||
@ -186,11 +200,15 @@ if(!is_user_logged_in()){
|
||||
$quantity = $item->get_quantity();
|
||||
for ($i = 0; $i < $quantity; $i++) {
|
||||
if ($is_subscription) {
|
||||
if (($order_subscription_coffees !== null)
|
||||
&& (is_object($order_subscription_coffees[$i + $j]["coffee"]))){
|
||||
$coffee = $order_subscription_coffees[$i + $j]["coffee"];
|
||||
$product_name = $coffee->post_title;
|
||||
$roast = get_field("roast_level", $coffee->ID);
|
||||
$is_organic = get_field("is_organic", $coffee->ID);
|
||||
}
|
||||
} ?>
|
||||
|
||||
<div class="label">
|
||||
<div>
|
||||
<div class="product-details">
|
||||
|
Reference in New Issue
Block a user