Skip to content

Commit

Permalink
only calculate totals when tracking cart changes if they have not alr…
Browse files Browse the repository at this point in the history
…eady been calculated
  • Loading branch information
diosmosis committed Jan 7, 2025
1 parent fdebfdc commit 3038499
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
6 changes: 5 additions & 1 deletion classes/WpMatomo/Ecommerce/Woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,13 @@ public function on_cart_updated_safe( $val = null ) {
public function on_cart_updated( $val = null, $is_coupon_update = false ) {
global $woocommerce;

$is_total_caluclated = ! empty( $cart->total ) || ! empty( $cart->cart_contents_total );
$force_recalculate_totals = define( 'MATOMO_FORCE_RECALCULATE_CART_TOALS' ) && MATOMO_FORCE_RECALCULATE_CART_TOALS;
$should_calculate_totals = ! $is_coupon_update && ( ! $is_total_caluclated || $force_recalculate_totals );

/** @var \WC_Cart $cart */
$cart = $woocommerce->cart;
if ( ! $is_coupon_update ) {
if ( $should_calculate_totals ) {
// can cause cart coupon not to be applied when WooCommerce Subscriptions is used.
$cart->calculate_totals();
}
Expand Down
18 changes: 0 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ services:
depends_on:
- $BACKEND
- mailer
deploy:
restart_policy:
condition: on-failure
extra_hosts:
- "host.docker.internal:host-gateway"

Expand All @@ -63,9 +60,6 @@ services:
entrypoint: /usr/src/entrypoint.sh
depends_on:
- "$BACKEND"
deploy:
restart_policy:
condition: on-failure
nginx:
image: nginx
volumes:
Expand All @@ -76,9 +70,6 @@ services:
- fpm
ports:
- "$PORT:80"
deploy:
restart_policy:
condition: on-failure

# service for running CLI utilities including wp-cli, the matomo console and phpunit
exec:
Expand Down Expand Up @@ -115,25 +106,16 @@ services:
volumes:
- ./docker/mariadb:/var/lib/mysql:delegated
- ./docker/maria_custom_my.cnf:/etc/mysql/conf.d/mycustom.cnf
deploy:
restart_policy:
condition: on-failure
mysql:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: pass
volumes:
- ./docker/mysql:/var/lib/mysql:delegated
- ./docker/container-files/mysql_custom_my.cnf:/etc/mysql/conf.d/mycustom.cnf
deploy:
restart_policy:
condition: on-failure

mailer:
image: axllent/mailpit
deploy:
restart_policy:
condition: on-failure
volumes:
- ./docker/mailer:/data
ports:
Expand Down
4 changes: 2 additions & 2 deletions scripts/local-dev-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,9 @@ EOF
IMAGE_ID=$( /var/www/html/wp-cli.phar --path=/var/www/html/$WORDPRESS_FOLDER --allow-root --user=$WP_ADMIN_USER media import "/var/www/html/matomo-for-wordpress/tests/resources/products/tripod.jpg" | grep -o 'attachment ID [0-9][0-9]*' | awk '{print $3}' )
/var/www/html/wp-cli.phar --path=/var/www/html/$WORDPRESS_FOLDER --allow-root --user=$WP_ADMIN_USER wc product create --name="Small camera tripod in red" --short_description="Small camera tripod in red" --description="Small portable tripod for your camera. Available colors: red." --slug="camera-tripod-small" --regular_price="13.99" --sku="PROD_5" --images="[{\"id\":$IMAGE_ID}]" || true
else
/var/www/html/wp-cli.phar --path=/var/www/html/$WORDPRESS_FOLDER --allow-root theme activate oceanwp
/var/www/html/wp-cli.phar --path=/var/www/html/$WORDPRESS_FOLDER --allow-root theme activate oceanwp || true
/var/www/html/wp-cli.phar --path=/var/www/html/$WORDPRESS_FOLDER --allow-root plugin activate woocommerce
/var/www/html/wp-cli.phar --path=/var/www/html/$WORDPRESS_FOLDER --allow-root plugin activate woocommerce-gateway-stripe
/var/www/html/wp-cli.phar --path=/var/www/html/$WORDPRESS_FOLDER --allow-root plugin activate woocommerce-gateway-stripe || true
fi
fi

Expand Down

0 comments on commit 3038499

Please sign in to comment.