-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Affirm/dev_v2.0.9
Dev v2.0.9
- Loading branch information
Showing
26 changed files
with
966 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,39 @@ | ||
<?php | ||
/** | ||
* Astound | ||
* NOTICE OF LICENSE | ||
* This source file is subject to the Open Software License (OSL 3.0) | ||
* that is bundled with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://opensource.org/licenses/osl-3.0.php | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* @category Affirm | ||
* @package Astound_Affirm | ||
* @copyright Copyright (c) 2016 Astound, Inc. (http://www.astoundcommerce.com) | ||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
* * BSD 3-Clause License | ||
* * | ||
* * Copyright (c) 2018, Affirm | ||
* * All rights reserved. | ||
* * | ||
* * Redistribution and use in source and binary forms, with or without | ||
* * modification, are permitted provided that the following conditions are met: | ||
* * | ||
* * Redistributions of source code must retain the above copyright notice, this | ||
* * list of conditions and the following disclaimer. | ||
* * | ||
* * Redistributions in binary form must reproduce the above copyright notice, | ||
* * this list of conditions and the following disclaimer in the documentation | ||
* * and/or other materials provided with the distribution. | ||
* * | ||
* * Neither the name of the copyright holder nor the names of its | ||
* * contributors may be used to endorse or promote products derived from | ||
* * this software without specific prior written permission. | ||
* * | ||
* * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
*/ | ||
|
||
|
||
namespace Astound\Affirm\Block\Promotion; | ||
|
||
use Magento\Store\Model\ScopeInterface; | ||
|
@@ -279,4 +297,22 @@ public function getMFPValue() | |
return $this->fpHelper->getFinancingProgramValue(); | ||
} | ||
} | ||
|
||
/** | ||
* Get Page type | ||
* | ||
* @return string | ||
*/ | ||
public function getPageType() | ||
{ | ||
if ($this->isCartPage()) { | ||
return 'cart'; | ||
} else if ($this->isCategoryPage()) { | ||
return 'category'; | ||
} else if ($this->isProductPage()) { | ||
return 'product'; | ||
} else { | ||
return 'homepage'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
<?php | ||
/** | ||
* | ||
* * BSD 3-Clause License | ||
* * | ||
* * Copyright (c) 2018, Affirm | ||
* * All rights reserved. | ||
* * | ||
* * Redistribution and use in source and binary forms, with or without | ||
* * modification, are permitted provided that the following conditions are met: | ||
* * | ||
* * Redistributions of source code must retain the above copyright notice, this | ||
* * list of conditions and the following disclaimer. | ||
* * | ||
* * Redistributions in binary form must reproduce the above copyright notice, | ||
* * this list of conditions and the following disclaimer in the documentation | ||
* * and/or other materials provided with the distribution. | ||
* * | ||
* * Neither the name of the copyright holder nor the names of its | ||
* * contributors may be used to endorse or promote products derived from | ||
* * this software without specific prior written permission. | ||
* * | ||
* * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
* * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
* * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
*/ | ||
|
||
|
||
namespace Astound\Affirm\Block\Promotion\Pixel; | ||
|
||
use Magento\Store\Model\ScopeInterface; | ||
use Magento\Framework\View\Element\Template; | ||
use Astound\Affirm\Model\Ui\ConfigProvider; | ||
use Astound\Affirm\Gateway\Helper\Util; | ||
use Astound\Affirm\Helper\Pixel; | ||
|
||
/** | ||
* Class Confirm | ||
* | ||
* @package Astound\Affirm\Block\Promotion | ||
*/ | ||
class Confirm extends \Magento\Framework\View\Element\Template | ||
{ | ||
/** | ||
* @var \Magento\Sales\Model\ResourceModel\Order\CollectionFactory | ||
*/ | ||
protected $_salesOrderCollection; | ||
|
||
protected $affirmPixelHelper; | ||
|
||
/** | ||
* @param Template\Context $context | ||
* @param ConfigProvider $configProvider | ||
* @param \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $salesOrderCollection | ||
* @param Pixel $helperPixelAffirm | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Template\Context $context, | ||
ConfigProvider $configProvider, | ||
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $salesOrderCollection, | ||
Pixel $helperPixelAffirm, | ||
array $data = [] | ||
) { | ||
$this->affirmPixelHelper = $helperPixelAffirm; | ||
$this->_salesOrderCollection = $salesOrderCollection; | ||
$this->configProvider = $configProvider; | ||
parent::__construct($context, $data); | ||
} | ||
|
||
/** | ||
* Render information about specified orders and their items | ||
* | ||
* | ||
* @return string|void | ||
*/ | ||
public function getOrdersTrackingCode() | ||
{ | ||
$orderIds = $this->getOrderIds(); | ||
if (empty($orderIds) || !is_array($orderIds)) { | ||
return; | ||
} | ||
|
||
$collection = $this->_salesOrderCollection->create(); | ||
$collection->addFieldToFilter('entity_id', ['in' => $orderIds]); | ||
$result = []; | ||
|
||
foreach ($collection as $order) { | ||
if ($order->getIsVirtual()) { | ||
$address = $order->getBillingAddress(); | ||
} else { | ||
$address = $order->getShippingAddress(); | ||
} | ||
|
||
$result[] = sprintf("affirm.analytics.trackOrderConfirmed({ | ||
'affiliation': '%s', | ||
'orderId': '%s', | ||
'currency': '%s', | ||
'total': '%s', | ||
'tax': '%s', | ||
'shipping': '%s', | ||
'paymentMethod': '%s' | ||
});", | ||
$this->escapeJsQuote($this->_storeManager->getStore()->getFrontendName()), | ||
$order->getIncrementId(), | ||
$order->getOrderCurrencyCode(), | ||
Util::formatToCents($order->getBaseGrandTotal()), | ||
Util::formatToCents($order->getBaseTaxAmount()), | ||
Util::formatToCents($order->getBaseShippingAmount()), | ||
$order->getPayment()->getMethod() | ||
); | ||
} | ||
return implode("\n", $result); | ||
} | ||
|
||
/** | ||
* Render GA tracking scripts | ||
* | ||
* @return string | ||
*/ | ||
protected function _toHtml() | ||
{ | ||
if (!$this->affirmPixelHelper->isAffirmAnalyticsAvailable()) { | ||
return ''; | ||
} | ||
|
||
return parent::_toHtml(); | ||
} | ||
|
||
/** | ||
* Get options for | ||
* | ||
* @return string | ||
*/ | ||
public function getOptions() | ||
{ | ||
$options = []; | ||
$configProvider = $this->configProvider->getConfig(); | ||
if ($configProvider['payment'][ConfigProvider::CODE]) { | ||
$config = $configProvider['payment'][ConfigProvider::CODE]; | ||
if ($config && isset($config['script']) && isset($config['apiKeyPublic'])) { | ||
$options['script'] = $config['script']; | ||
$options['public_api_key'] = $config['apiKeyPublic']; | ||
$options['sessionId'] = ($this->getCustomerSessionId())? $this->getCustomerSessionId() : ''; | ||
} | ||
} | ||
return json_encode($options); | ||
} | ||
|
||
public function getCustomerSessionId() | ||
{ | ||
$orderIds = $this->getOrderIds(); | ||
if (empty($orderIds) || !is_array($orderIds)) { | ||
return; | ||
} | ||
$collection = $this->_salesOrderCollection->create(); | ||
$collection->addFieldToFilter('entity_id', ['in' => $orderIds]); | ||
|
||
foreach ($collection as $order) { | ||
$customerId = ($order->getCustomerId()) ? $order->getCustomerId() : $guestId = "CUSTOMER-" . $this->affirmPixelHelper->getDateMicrotime(); | ||
} | ||
return $customerId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.