Skip to content

Commit 6351c74

Browse files
committed
init
0 parents  commit 6351c74

File tree

15 files changed

+693
-0
lines changed

15 files changed

+693
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
build
2+
composer.lock
3+
vendor
4+
.idea

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: php
2+
php:
3+
- 7.2
4+
- 7.3
5+
- 7.4
6+
env:
7+
matrix:
8+
- COMPOSER_FLAGS="--prefer-lowest"
9+
- COMPOSER_FLAGS=""
10+
branches:
11+
only:
12+
- master
13+
before_script:
14+
- travis_retry composer self-update
15+
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source
16+
script:
17+
- vendor/bin/phpunit

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Sage Woocommerce
2+
![CI](https://travis-ci.org/smarteist/sage-woocommerce.svg?branch=master)
3+
4+
This package enables WooCommerce integration for Sage 10 themes and Blade templates.
5+
6+
## Installation
7+
8+
```
9+
composer require hexbit/sage-woocommerce
10+
```
11+
12+
## Usage
13+
Add ```Hexbit\Woocommerce\Providers\WooCommerceServiceProvider``` to your providers array in ```yourtheme/config/app.php```
14+
```php
15+
...
16+
/*
17+
|--------------------------------------------------------------------------
18+
| Autoloaded Service Providers
19+
|--------------------------------------------------------------------------
20+
|
21+
| The service providers listed here will be automatically loaded on the
22+
| request to your application. Feel free to add your own services to
23+
| this array to grant expanded functionality to your applications.
24+
|
25+
*/
26+
27+
'providers' => [
28+
/**
29+
* Package Service Providers
30+
*/
31+
Hexbit\Woocommerce\Providers\WooCommerceServiceProvider::class
32+
]
33+
...
34+
```
35+
Or you can discover service provider by using wp cli.
36+
```
37+
wp acorn package:discover
38+
```
39+
Then create ```app/woocommerce.php``` in your ```app``` folder and override default blade files in ```resources/views/woocommerce```, or you can create automatically by running this command
40+
```
41+
wp acorn vendor:publish --tag="woocommerce"
42+
```
43+
& finally change view renderer in your index file like this:
44+
45+
```
46+
<?php echo \Roots\view(\Roots\app('sage.woocommerce'), \Roots\app('sage.data'))->render(); ?>
47+
```
48+
49+
50+
Done! now you will be able to override woocommerce templates with blade TE in ```yourtheme/resources/views/woocommerce/``` directory.
51+
52+
53+
## Contributing
54+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
55+
56+
Please make sure to update tests as appropriate.
57+
58+
## License
59+
[MIT](https://choosealicense.com/licenses/mit/)

composer.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "hexbit/sage-woocommerce",
3+
"description": "Woocommerce support for sage 10",
4+
"version": "1.0.0",
5+
"keywords": [
6+
"hexbit",
7+
"smarteist",
8+
"wordpress",
9+
"sage",
10+
"woocommerce",
11+
"blade"
12+
],
13+
"homepage": "https://github.com/smarteist/sage-woocommerce",
14+
"license": "MIT",
15+
"authors": [
16+
{
17+
"name": "Ali Hosseini",
18+
"email": "[email protected]",
19+
"homepage": "https://hexbit.dev/",
20+
"role": "Developer"
21+
}
22+
],
23+
"require": {
24+
"php": "^7.2",
25+
"roots/acorn": "*"
26+
},
27+
"require-dev": {
28+
"phpunit/phpunit": "^6.0"
29+
},
30+
"autoload": {
31+
"psr-4": {
32+
"Hexbit\\Woocommerce\\": "src"
33+
}
34+
},
35+
"autoload-dev": {
36+
"psr-4": {
37+
"Hexbit\\Woocommerce\\Tests\\": "tests"
38+
}
39+
},
40+
"scripts": {
41+
"test": "vendor/bin/phpunit"
42+
},
43+
"minimum-stability": "dev",
44+
"prefer-stable": true,
45+
"config": {
46+
"sort-packages": true
47+
},
48+
"extra": {
49+
"acorn": {
50+
"providers": [
51+
"Hexbit\\Woocommerce\\Providers\\WooCommerceServiceProvider"
52+
]
53+
}
54+
}
55+
}

phpunit.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="tests/bootstrap.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
14+
<testsuite name="Main Test Cases">
15+
<directory>tests</directory>
16+
</testsuite>
17+
</testsuites>
18+
19+
</phpunit>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Hexbit\Woocommerce\Providers;
4+
5+
use Hexbit\Woocommerce\WooCommerce;
6+
use Roots\Acorn\ServiceProvider;
7+
8+
9+
/**
10+
* Class WooCommerceServiceProvider
11+
* @package Hexbit\Woocommerce\Providers
12+
*/
13+
class WooCommerceServiceProvider extends ServiceProvider
14+
{
15+
/**
16+
* Register any application services.
17+
*
18+
* @return void
19+
*/
20+
public function register()
21+
{
22+
$this->app->singleton('sage.woocommerce', WooCommerce::class);
23+
}
24+
25+
/**
26+
* Bootstrap any application services.
27+
*
28+
* @return void
29+
*/
30+
public function boot()
31+
{
32+
if (defined('WC_ABSPATH')) {
33+
$this->app['sage.woocommerce']->loadThemeTemplateHooks();
34+
$this->bindSetupAction();
35+
$this->bindFilters();
36+
}
37+
38+
// publishing command
39+
$this->publishes([
40+
dirname(__DIR__) . '/Publishes/app/woocommerce.php' => $this->app->path('woocommerce.php'),
41+
dirname(__DIR__) . '/Publishes/resources/views' => $this->app->resourcePath('views'),
42+
], 'woocommerce');
43+
44+
}
45+
46+
/**
47+
* Appends all filters in wordpress actions
48+
* @hooks template_include
49+
* @hooks comments_template
50+
* @hooks woocommerce_locate_template
51+
* @hooks wc_get_template_part
52+
* @hooks wc_get_template
53+
*/
54+
public function bindFilters()
55+
{
56+
$woocommerce = $this->app['sage.woocommerce'];
57+
58+
add_filter('template_include', [$woocommerce, 'templateInclude'], 100, 1);
59+
add_filter('comments_template', [$woocommerce, 'templateInclude'], 100, 1);
60+
add_filter('woocommerce_locate_template', [$woocommerce, 'templatePart'], PHP_INT_MAX, 1);
61+
add_filter('wc_get_template_part', [$woocommerce, 'templatePart'], PHP_INT_MAX, 1);
62+
add_filter('wc_get_template', [$woocommerce, 'getTemplate'], 100, 3);
63+
64+
}
65+
66+
/**
67+
* WooCommerce support for theme
68+
*/
69+
public function bindSetupAction()
70+
{
71+
add_action('after_setup_theme', [$this->app['sage.woocommerce'], 'addThemeSupport']);
72+
}
73+
}

src/Publishes/app/woocommerce.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace App;
4+
5+
/*
6+
*
7+
* Add woocommerce hooks here
8+
*
9+
*/
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
@php
2+
/**
3+
* The Template for displaying product archives, including the main shop page which is a post type archive
4+
*
5+
* This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php.
6+
*
7+
* HOWEVER, on occasion WooCommerce will need to update template files and you
8+
* (the theme developer) will need to copy the new files to your theme to
9+
* maintain compatibility. We try to do this as little as possible, but it does
10+
* happen. When this occurs the version of the template file will be bumped and
11+
* the readme will list any important changes.
12+
*
13+
* @see https://docs.woocommerce.com/document/template-structure/
14+
* @package WooCommerce\Templates
15+
* @version 3.4.0
16+
*/
17+
@endphp
18+
19+
@extends('layouts.app')
20+
21+
@section('content')
22+
23+
<header class="woocommerce-products-header">
24+
25+
@if ( apply_filters( 'woocommerce_show_page_title', true ) )
26+
27+
<h1 class="woocommerce-products-header__title page-title">@php woocommerce_page_title(); @endphp</h1>
28+
29+
@endif
30+
31+
32+
@php
33+
/**
34+
* Hook: woocommerce_archive_description.
35+
*
36+
* @hooked woocommerce_taxonomy_archive_description - 10
37+
* @hooked woocommerce_product_archive_description - 10
38+
*/
39+
do_action( 'woocommerce_archive_description' );
40+
@endphp
41+
</header>
42+
43+
@if ( woocommerce_product_loop() )
44+
45+
@php
46+
/**
47+
* Hook: woocommerce_before_shop_loop.
48+
*
49+
* @hooked woocommerce_output_all_notices - 10
50+
* @hooked woocommerce_result_count - 20
51+
* @hooked woocommerce_catalog_ordering - 30
52+
*/
53+
do_action( 'woocommerce_before_shop_loop' );
54+
55+
woocommerce_product_loop_start();
56+
@endphp
57+
58+
@if ( wc_get_loop_prop( 'total' ) )
59+
@while ( have_posts() )
60+
@php
61+
the_post();
62+
63+
/**
64+
* Hook: woocommerce_shop_loop.
65+
*/
66+
do_action( 'woocommerce_shop_loop' );
67+
68+
wc_get_template_part( 'content', 'product' );
69+
@endphp
70+
@endwhile
71+
@endif
72+
@php
73+
woocommerce_product_loop_end();
74+
75+
/**
76+
* Hook: woocommerce_after_shop_loop.
77+
*
78+
* @hooked woocommerce_pagination - 10
79+
*/
80+
do_action( 'woocommerce_after_shop_loop' );
81+
@endphp
82+
@else
83+
84+
@php
85+
/**
86+
* Hook: woocommerce_no_products_found.
87+
*
88+
* @hooked wc_no_products_found - 10
89+
*/
90+
do_action( 'woocommerce_no_products_found' );
91+
@endphp
92+
93+
@endif
94+
95+
@php
96+
97+
/**
98+
* Hook: woocommerce_after_main_content.
99+
*
100+
* @hooked woocommerce_output_content_wrapper_end - 10 (outputs closing divs for the content)
101+
*/
102+
do_action( 'woocommerce_after_main_content' );
103+
104+
/**
105+
* Hook: woocommerce_sidebar.
106+
*
107+
* @hooked woocommerce_get_sidebar - 10
108+
*/
109+
do_action( 'woocommerce_sidebar' );
110+
@endphp
111+
@endsection

0 commit comments

Comments
 (0)