Skip to content
This repository was archived by the owner on Feb 10, 2021. It is now read-only.

Commit 2447007

Browse files
committed
Merge branch 'release/1.0.5'
* release/1.0.5: Changelog for 1.0.5 More docblock fixing Docblock fixing Better Property declarations Changelog and Readme for product types Product Type context now working Load the JS on product types
2 parents e32b035 + 118c6bc commit 2447007

File tree

16 files changed

+99
-36
lines changed

16 files changed

+99
-36
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

77

8+
## Unreleased
9+
10+
11+
## 1.0.5 - 2018-09-27
12+
13+
### Added
14+
- Added support for Product Types if Commerce is installed
15+
16+
817
## 1.0.4 - 2018-09-26
918

1019
### Fixed
11-
- Fixed an error in composer.json where the version string was not matching the tag name.
20+
- Fixed an error in composer.json where the version string was not matching the tag name
1221

1322

1423
## 1.0.3 - 2018-09-25

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ return [
6161

6262
Targets are alternative templates that you want to make available to Live Preview, you can add them by going to the Portal tab in the main navigation.
6363

64-
If you have multiple Sites then you can load different templates for each Site, as well as restrict a Target to either a Section or Category Group.
64+
If you have multiple Sites then you can load different templates for each Site, as well as restrict a Target to either a Section, Category Group or Product Type.
6565

6666
Once you have a Target added you will see a select input appear in the Live Preview window allowing your users to efficiently preview their content across multiple templates.
6767

src/Portal.php

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,19 @@
1919
use craft\events\TemplateEvent;
2020
use craft\helpers\Json;
2121
use craft\services\Plugins;
22-
use craft\events\PluginEvent;
2322
use craft\web\UrlManager;
2423
use craft\events\RegisterUrlRulesEvent;
2524
use craft\web\View;
2625

26+
use craft\commerce\Plugin as CommercePlugin;
27+
2728
use yii\base\Event;
2829
use yii\web\NotFoundHttpException;
2930

3031
/**
31-
* Craft plugins are very much like little applications in and of themselves. We’ve made
32-
* it as simple as we can, but the training wheels are off. A little prior knowledge is
33-
* going to be required to write a plugin.
34-
*
35-
* For the purposes of the plugin docs, we’re going to assume that you know PHP and SQL,
36-
* as well as some semi-advanced concepts like object-oriented programming and PHP namespaces.
37-
*
38-
* https://craftcms.com/docs/plugins/introduction
39-
*
4032
* @author Angell & Co
4133
* @package Portal
42-
* @since 0.1.0
34+
* @since 1.0.0
4335
*
4436
* @property TargetsService $targets
4537
* @method Settings getSettings()
@@ -57,6 +49,14 @@ class Portal extends Plugin
5749
*/
5850
public static $plugin;
5951

52+
/**
53+
* Set to true if Craft Commerce is installed
54+
*
55+
* @var bool
56+
*/
57+
public static $commerceInstalled;
58+
59+
6060
// Public Properties
6161
// =========================================================================
6262

@@ -67,6 +67,7 @@ class Portal extends Plugin
6767
*/
6868
public $schemaVersion = '0.1.0';
6969

70+
7071
// Public Methods
7172
// =========================================================================
7273

@@ -86,6 +87,9 @@ public function init()
8687
parent::init();
8788
self::$plugin = $this;
8889

90+
// Check if Commerce is installed
91+
self::$commerceInstalled = class_exists(CommercePlugin::class);
92+
8993
// Register our CP routes
9094
Event::on(
9195
UrlManager::class,
@@ -143,6 +147,7 @@ function(TemplateEvent $event) {
143147
* Loads up the CP resources we need for Live Preview.
144148
*
145149
* @throws NotFoundHttpException
150+
* @throws \craft\errors\SiteNotFoundException
146151
* @throws \yii\base\InvalidConfigException
147152
*/
148153
private function _loadLivePreviewCpResources()
@@ -157,10 +162,10 @@ private function _loadLivePreviewCpResources()
157162
$context = false;
158163

159164
// Entries
160-
if (count($segments) >= 3 && $segments[ 0 ] == 'entries')
165+
if (count($segments) >= 3 && $segments[ 0 ] === 'entries')
161166
{
162167

163-
if ($segments[ 2 ] == 'new')
168+
if ($segments[ 2 ] === 'new')
164169
{
165170
$section = Craft::$app->sections->getSectionByHandle($segments[ 1 ]);
166171
}
@@ -183,14 +188,23 @@ private function _loadLivePreviewCpResources()
183188

184189
}
185190
// Category groups
186-
else if (count($segments) >= 3 && $segments[ 0 ] == 'categories')
191+
else if (count($segments) >= 3 && $segments[ 0 ] === 'categories')
187192
{
188193
$group = Craft::$app->categories->getGroupByHandle($segments[ 1 ]);
189194
if ($group)
190195
{
191196
$context = 'categoryGroup:'.$group->id;
192197
}
193198
}
199+
// Product Types
200+
else if ($this::$commerceInstalled && count($segments) >= 4 && $segments[ 0 ] === 'commerce' && $segments[ 1 ] === 'products')
201+
{
202+
$productType = CommercePlugin::getInstance()->productTypes->getProductTypeByHandle($segments[ 2 ]);
203+
if ($productType)
204+
{
205+
$context = 'productType:'.$productType->id;
206+
}
207+
}
194208

195209

196210
// Then, if we are we can get the data we need and run

src/assetbundles/livepreview/LivePreviewAsset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @author Angell & Co
2323
* @package Portal
24-
* @since 0.1.0
24+
* @since 1.0.0
2525
*/
2626
class LivePreviewAsset extends AssetBundle
2727
{

src/assetbundles/src/LivePreview.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @copyright Copyright (c) 2018 Angell & Co
1414
* @link https://angell.io
1515
* @package Portal
16-
* @since 0.1.0
16+
* @since 1.0.0
1717
*/
1818

1919
if (typeof Portal === 'undefined')

src/controllers/TargetsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
*
4040
* @author Angell & Co
4141
* @package Portal
42-
* @since 0.1.0
42+
* @since 1.0.0
4343
*/
4444
class TargetsController extends Controller
4545
{

src/errors/TargetNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* @author Angell & Co
1919
* @package Portal
20-
* @since 0.1.0
20+
* @since 1.0.0
2121
*/
2222
class TargetNotFoundException extends Exception
2323
{

src/migrations/Install.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*
2929
* @author Angell & Co
3030
* @package Portal
31-
* @since 0.1.0
31+
* @since 1.0.0
3232
*/
3333
class Install extends Migration
3434
{

src/models/Settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
* @author Angell & Co
2222
* @package Portal
23-
* @since 0.1.0
23+
* @since 1.0.0
2424
*/
2525
class Settings extends Model
2626
{

src/models/Target.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
/**
2222
* Target Model
2323
*
24-
* @property Target_SiteSettings[] $siteSettings Site-specific settings
24+
* @property int|null $id ID
25+
* @property string|null $name Name
26+
* @property string|null $context Context
27+
* @property Target_SiteSettings[] $siteSettings Site settings
2528
*
2629
* @author Angell & Co
2730
* @package Portal
28-
* @since 0.1.0
31+
* @since 1.0.0
2932
*/
3033
class Target extends Model
3134
{
@@ -52,6 +55,10 @@ class Target extends Model
5255
*/
5356
public $siteSettings;
5457

58+
59+
// Private Properties
60+
// =========================================================================
61+
5562
/**
5663
* @var array|null Context Options
5764
*/

0 commit comments

Comments
 (0)