Skip to content

Commit

Permalink
Merge branch 'dev-woo-3.4.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
mtx-z committed Jul 24, 2018
2 parents 8ae0f46 + 4bbc8b8 commit f527ea0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
24 changes: 19 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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
Expand Down
26 changes: 23 additions & 3 deletions your-sage-theme/app/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?
*/
Expand All @@ -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
Expand Down Expand Up @@ -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)
*/
Expand Down
2 changes: 1 addition & 1 deletion your-sage-theme/app/helpers.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* 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
*
* changes: added 'resources/views/woocommerce' to paths array
*
Expand Down
11 changes: 7 additions & 4 deletions your-sage-theme/app/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
add_action('after_setup_theme', function () {
/**
* ...Add following to the existing add_action('after_setup_theme')
* 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
*/
add_theme_support('woocommerce');
/**
Expand All @@ -23,9 +23,12 @@
* which people can add to their themes to add basic woocommerce support.
* without hooks or modifying core templates.
*
* 19.25.18: tested and required for Woocommerce 3.3.5 integration with sage 9.0.1
* 17.07.18: tested, required and updated for Woocommerce 3.4.3 integration with sage 9.0.1 (WP 4.9.7)
* 19.05.18: tested and required for Woocommerce 3.3.5 integration with sage 9.0.1
* Changed: added $args parameter, and edited wc_get_template_part() to use $args
* from: wp-content/plugins/woocommerce/includes/wc-template-functions.php:l549 (v3.3.5)
*
* from: wp-content/plugins/woocommerce/includes/wc-template-functions.php:l863 (Woo v3.4.3)
* from: wp-content/plugins/woocommerce/includes/wc-template-functions.php:l549 (Woo v3.3.5)
*/
function woocommerce_content($args = [])
{
Expand All @@ -47,7 +50,7 @@ function woocommerce_content($args = [])

<?php do_action( 'woocommerce_archive_description' ); ?>

<?php if ( have_posts() ) : ?>
<?php if ( woocommerce_product_loop() ) : ?>

<?php do_action( 'woocommerce_before_shop_loop' ); ?>

Expand Down

0 comments on commit f527ea0

Please # to comment.