diff --git a/README.md b/README.md index 9c969e1..c993d22 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ -# Sage 9.0.1 Woocommerce (3.3.5) Integration -How to use Woocommerce (3.3.5) with Sage 9.0.1 (Blade + SoberWP controllers) +# Sage 9.0.1 Woocommerce (3.4.3) Integration +How to use Woocommerce (3.4.3) with Sage 9.0.1 (Blade + SoberWP controllers), WP 4.9.7 (17/07/2018) + +Check dev branches for latest updates. Check dev branches for latest updates. @@ -21,21 +23,33 @@ Check dev branches for latest updates. - [discourse.roots.io](https://discourse.roots.io/t/woocommerce-blade-sage-9/8449/17) - [discourse.roots.io](https://discourse.roots.io/t/any-working-example-of-sage-9-latest-sage-9-0-0-beta-4-with-woocommerce-3-1-1/10099/17) - [github](https://github.com/MarekVrofski/Sage-Woocommerce) (much thanks again to [@MarekVrofski](https://github.com/MarekVrofski/) for his improvements) - + - [github sage PR](https://github.com/roots/sage/pull/1923) + ## Changelog -- 09/07/2018 - test in progress +- 17/07/2018 - test still in progress - Sage 9.0.1 - Woocommerce 3.4.3 - [SoberWP controller 9.0.0-beta.4](https://github.com/soberwp/controller/releases) ([Sage 9.0.1 uses SoberWP controller 9.0.0-beta.4](https://github.com/roots/sage/blob/master/composer.json), not latest [SoberWP controller 2.0.1](https://github.com/soberwp/controller/releases)) - PHP 7.2.5 (fpm), Nginx, Debian (& Windows 10 - Laragon PHP 7.1) + - Something changed, Woocommerce didn't use anymore our `woocommerce.blade.php`. Had to force the template path into the Woocommerce default template array. See `woocommerce_template_loader_files` filter code comment in `filters.php` - 18/05/2018 - tested with - Woocommerce 3.3.5 - Sage 9.0.1 - [SoberWP controller 9.0.0-beta.4](https://github.com/soberwp/controller/releases) ([Sage 9.0.1 uses SoberWP controller 9.0.0-beta.4](https://github.com/roots/sage/blob/master/composer.json), not latest [SoberWP controller 2.0.1](https://github.com/soberwp/controller/releases)) - PHP 7.2.5 (fpm), Nginx, Debian (& Windows 10 - Laragon PHP 7.1) - + +## What I usualy do + +**Editing shop page** + +- I prefer not use the default woocommerce shop page. So I do my own template/controller (wp_query) and pagination (will publish soon, really easy) and redirect official shop page to this custom one. As this template is mostly managed by our App\woocommerce_content() and sub-templated. But it is doable, updating woocommerce_content and related sub-template. Longer maybe ? Cleaner for sure :) +- Single product page, my account, checkout templates should be easy to override +- I'll publish another repo with "how to's" and helpers for Sage (time, time, time...) + + ## How ### Blade for Woocommerce +- Since V1.1, we force `/resources/views/woocommerce.blade.php` as first in woocommerce default template file array (see changelog) - we add_filter on - `template_include`: edit `single-product.php` and `archive-product.php` template path to `/resources/views/woocommerce/*.blade.php` (then retrieve controller data and render blade as usual) - `wc_get_template_part`: edit woocommerce template method to look for blade files then php files diff --git a/your-sage-theme/app/filters.php b/your-sage-theme/app/filters.php index 3db863f..d847148 100644 --- a/your-sage-theme/app/filters.php +++ b/your-sage-theme/app/filters.php @@ -2,9 +2,29 @@ namespace App; +/** + * Use our woocommerce.blade.php as default woocommerce root template + * 17.07.18: tested and required for Woocommerce 3.4.3 integration with sage 9.0.1 (WP 4.9.7) + * + * It seems that since woocommerce 3.4.X (not sure since, but was not needed on my latest tests): + * - woocommerce don't see our /ressources/views/woocommerce.blade.php + * - it search and correctly find a /ressources/woocommerce.php + * And so, you got your resources/views/content-single-product.blade.php working, but not using your blade app main layout + * - here we put the path of our 'woocommerce.blade.php' as first into the Woocommerce default template array + * - wp-content/plugins/woocommerce/includes/class-wc-template-loader.php l68 template_loader() calls -> + * - wp-content/plugins/woocommerce/includes/class-wc-template-loader.php l129 get_template_loader_files() that uses 'woocommerce_template_loader_files' filter + * - but in template_loader() the call to locate_template() fails to find our woo.blade.php... only a /resources/woocommerce.php because of STYLESHEETPATH & TEMPLATEPATH templating variables (wp-includes/default-constants.php l344) + * - our override filter_templates() method will return a correct path for woocommerce.blade.php + * + * Added a comment here: https://github.com/roots/sage/issues/1429 + */ +add_filter( 'woocommerce_template_loader_files', function ( $templates, $default_file ) { + return filter_templates(array_merge($templates, array_filter([$default_file, 'woocommerce']))); +}, PHP_INT_MAX, 2 ); + /** * Render page using Blade (and get data from controller from sage/template/{$class}/data filter) - * 19.25.18: tested and required for Woocommerce 3.3.5 integration with sage 9.0.1 + * 19.05.18: tested and required for Woocommerce 3.3.5 integration with sage 9.0.1 * Changed: fix for single-product.php and archive-product to get correct template * todo: is there other "woocommerce root" template that should be hot fixed here ? */ @@ -28,7 +48,7 @@ /** * Render page using Blade - * 19.25.18: tested and required for Woocommerce 3.3.5 integration with sage 9.0.1 + * 19.05.18: tested and required for Woocommerce 3.3.5 integration with sage 9.0.1 * Changed: locate blade or php template file and render it * Triggers just before woocommerce actually render PHP template, but return blade and null, or php template like woocommerce would do * wp-content/plugins/woocommerce/includes/wc-core-functions.php:l158 @@ -65,7 +85,7 @@ /** * Render woocommerce template parts using Blade - * 19.25.18: tested and required for Woocommerce 3.3.5 integration with sage 9.0.1 + * 19.05.18: tested and required for Woocommerce 3.3.5 integration with sage 9.0.1 * Changed: Woocommerce support to use resources/views/woocommerce/* templates when using template parts * (wc_get_template_part & template_include filters will search for .blade.php) */ diff --git a/your-sage-theme/app/helpers.php b/your-sage-theme/app/helpers.php index f0cbefe..39313ee 100644 --- a/your-sage-theme/app/helpers.php +++ b/your-sage-theme/app/helpers.php @@ -1,7 +1,7 @@ - +