Skip to content

Commit

Permalink
Merge pull request #14 from henkelund/1.3.0
Browse files Browse the repository at this point in the history
1.3.0
  • Loading branch information
henkelund authored Mar 2, 2017
2 parents 51f52f9 + 981a915 commit 81f1db0
Show file tree
Hide file tree
Showing 43 changed files with 779 additions and 59 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ php:
- 7.0
- 5.6
env:
- M2_VERSION=2.1.5
- M2_VERSION=2.1.3
- M2_VERSION=2.1.2
- M2_VERSION=2.1.1
- M2_VERSION=2.1.0
- M2_VERSION=2.0.10
- M2_VERSION=2.0.13
matrix:
include:
- php: 5.5
env: M2_VERSION=2.0.10
env: M2_VERSION=2.0.13
cache:
directories:
- $HOME/.composer/cache
script:
- dev/ci/build.sh

2 changes: 1 addition & 1 deletion Block/Piwik.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2016 Henrik Hedelund
* Copyright 2016-2017 Henrik Hedelund
*
* This file is part of Henhed_Piwik.
*
Expand Down
2 changes: 1 addition & 1 deletion CustomerData/Checkout/CartPlugin.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2016 Henrik Hedelund
* Copyright 2016-2017 Henrik Hedelund
*
* This file is part of Henhed_Piwik.
*
Expand Down
112 changes: 112 additions & 0 deletions CustomerData/Customer/CustomerPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php
/**
* Copyright 2016-2017 Henrik Hedelund
*
* This file is part of Henhed_Piwik.
*
* Henhed_Piwik is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Henhed_Piwik is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Henhed_Piwik. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Henhed\Piwik\CustomerData\Customer;

/**
* Plugin for \Magento\Customer\CustomerData\Customer
*
*/
class CustomerPlugin
{

/**
* Current customer helper
*
* @var \Magento\Customer\Helper\Session\CurrentCustomer $_currentCustomer
*/
protected $_currentCustomer;

/**
* Piwik data helper
*
* @var \Henhed\Piwik\Helper\Data $_dataHelper
*/
protected $_dataHelper;

/**
* User ID provider pool
*
* @var \Henhed\Piwik\UserId\Provider\Pool $_uidProviderPool
*/
protected $_uidProviderPool;

/**
* Constructor
*
* @param \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer
* @param \Henhed\Piwik\Helper\Data $dataHelper
* @param \Henhed\Piwik\UserId\Provider\Pool $uidProviderPool
*/
public function __construct(
\Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer,
\Henhed\Piwik\Helper\Data $dataHelper,
\Henhed\Piwik\UserId\Provider\Pool $uidProviderPool
) {
$this->_currentCustomer = $currentCustomer;
$this->_dataHelper = $dataHelper;
$this->_uidProviderPool = $uidProviderPool;
}

/**
* Get configured Piwik User ID provider or NULL
*
* @return \Henhed\Piwik\UserId\Provider\ProviderInterface|null
*/
protected function _getUserIdProvider()
{
$code = $this->_dataHelper->getUserIdProviderCode();
return $code ? $this->_uidProviderPool->getProviderByCode($code) : null;
}

/**
* Get Piwik User ID for current customer
*
* @return string
*/
protected function _getUserId()
{
$provider = $this->_getUserIdProvider();
$customerId = $this->_currentCustomer->getCustomerId();
return ($provider && $customerId)
? (string) $provider->getUserId($customerId)
: '';
}

/**
* Add visitor related tracker information to customer section data.
*
* @param \Magento\Customer\CustomerData\Customer $subject
* @param array $result
* @return array
*/
public function afterGetSectionData(
\Magento\Customer\CustomerData\Customer $subject,
$result
) {
if ($this->_dataHelper->isTrackingEnabled()) {
$userId = $this->_getUserId();
if ($userId !== '') {
$result['piwikUserId'] = $userId;
}
}
return $result;
}
}
18 changes: 17 additions & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2016 Henrik Hedelund
* Copyright 2016-2017 Henrik Hedelund
*
* This file is part of Henhed_Piwik.
*
Expand Down Expand Up @@ -40,6 +40,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
const XML_PATH_SITE_ID = 'piwik/tracking/site_id';
const XML_PATH_LINK_ENABLED = 'piwik/tracking/link_enabled';
const XML_PATH_LINK_DELAY = 'piwik/tracking/link_delay';
const XML_PATH_UID_PROVIDER = 'piwik/tracking/uid_provider';

/**
* Check if Piwik is enabled
Expand Down Expand Up @@ -233,4 +234,19 @@ public function getLinkTrackingDelay($store = null)
$store
);
}

/**
* Get provider code for Piwik user ID tracking
*
* @param null|string|bool|int|Store $store
* @return string
*/
public function getUserIdProviderCode($store = null)
{
return $this->scopeConfig->getValue(
self::XML_PATH_UID_PROVIDER,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$store
);
}
}
2 changes: 1 addition & 1 deletion Helper/Tracker.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2016 Henrik Hedelund
* Copyright 2016-2017 Henrik Hedelund
*
* This file is part of Henhed_Piwik.
*
Expand Down
63 changes: 63 additions & 0 deletions Model/Config/Source/UserId/Provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Copyright 2016-2017 Henrik Hedelund
*
* This file is part of Henhed_Piwik.
*
* Henhed_Piwik is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Henhed_Piwik is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Henhed_Piwik. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Henhed\Piwik\Model\Config\Source\UserId;

/**
* User ID provider config source model
*
*/
class Provider implements \Magento\Framework\Option\ArrayInterface
{

/**
* User ID provider pool
*
* @var \Henhed\Piwik\UserId\Provider\Pool $_pool
*/
protected $_pool;

/**
* Constructor
*
* @param \Henhed\Piwik\UserId\Provider\Pool $pool
*/
public function __construct(\Henhed\Piwik\UserId\Provider\Pool $pool)
{
$this->_pool = $pool;
}

/**
* Return array of user ID providers as value-label pairs
*
* @return array
*/
public function toOptionArray()
{
$options = [['value' => '', 'label' => __('No')]];
foreach ($this->_pool->getAllProviders() as $code => $provider) {
$options[] = [
'value' => $code,
'label' => sprintf('%s (%s)', __('Yes'), $provider->getTitle())
];
}
return $options;
}
}
2 changes: 1 addition & 1 deletion Model/Tracker.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2016 Henrik Hedelund
* Copyright 2016-2017 Henrik Hedelund
*
* This file is part of Henhed_Piwik.
*
Expand Down
2 changes: 1 addition & 1 deletion Model/Tracker/Action.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2016 Henrik Hedelund
* Copyright 2016-2017 Henrik Hedelund
*
* This file is part of Henhed_Piwik.
*
Expand Down
2 changes: 1 addition & 1 deletion Observer/BeforeTrackPageViewObserver.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2016 Henrik Hedelund
* Copyright 2016-2017 Henrik Hedelund
*
* This file is part of Henhed_Piwik.
*
Expand Down
2 changes: 1 addition & 1 deletion Observer/CartViewObserver.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2016 Henrik Hedelund
* Copyright 2016-2017 Henrik Hedelund
*
* This file is part of Henhed_Piwik.
*
Expand Down
2 changes: 1 addition & 1 deletion Observer/CategoryViewObserver.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2016 Henrik Hedelund
* Copyright 2016-2017 Henrik Hedelund
*
* This file is part of Henhed_Piwik.
*
Expand Down
2 changes: 1 addition & 1 deletion Observer/CheckoutSuccessObserver.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2016 Henrik Hedelund
* Copyright 2016-2017 Henrik Hedelund
*
* This file is part of Henhed_Piwik.
*
Expand Down
2 changes: 1 addition & 1 deletion Observer/ProductViewObserver.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2016 Henrik Hedelund
* Copyright 2016-2017 Henrik Hedelund
*
* This file is part of Henhed_Piwik.
*
Expand Down
2 changes: 1 addition & 1 deletion Observer/SearchResultObserver.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2016 Henrik Hedelund
* Copyright 2016-2017 Henrik Hedelund
*
* This file is part of Henhed_Piwik.
*
Expand Down
2 changes: 1 addition & 1 deletion Test/Unit/CustomerData/Checkout/CartPluginTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2016 Henrik Hedelund
* Copyright 2016-2017 Henrik Hedelund
*
* This file is part of Henhed_Piwik.
*
Expand Down
Loading

0 comments on commit 81f1db0

Please sign in to comment.