diff --git a/Block/Promotion/Banners.php b/Block/Promotion/Banners.php index 6a3a54c3..484170fd 100644 --- a/Block/Promotion/Banners.php +++ b/Block/Promotion/Banners.php @@ -1,21 +1,39 @@ 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'; + } + } } diff --git a/Block/Promotion/CartPage/Aslowas.php b/Block/Promotion/CartPage/Aslowas.php index 3335eabf..a67dc841 100644 --- a/Block/Promotion/CartPage/Aslowas.php +++ b/Block/Promotion/CartPage/Aslowas.php @@ -114,4 +114,8 @@ public function getMFPValue() { return $this->asLowAsHelper->getFinancingProgramValue(); } + + public function getLearnMoreValue(){ + return $this->asLowAsHelper->isVisibleLearnmore() ? 'true' :'false'; + } } diff --git a/Block/Promotion/Pixel/Confirm.php b/Block/Promotion/Pixel/Confirm.php new file mode 100644 index 00000000..4b93db39 --- /dev/null +++ b/Block/Promotion/Pixel/Confirm.php @@ -0,0 +1,172 @@ +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; + } +} diff --git a/Block/Promotion/ProductPage/Aslowas.php b/Block/Promotion/ProductPage/Aslowas.php index e93e9e7d..4dab4ebf 100644 --- a/Block/Promotion/ProductPage/Aslowas.php +++ b/Block/Promotion/ProductPage/Aslowas.php @@ -105,4 +105,8 @@ public function getProductId() { return $this->affirmPaymentHelper->getProduct()->getId(); } + + public function getLearnMoreValue(){ + return $this->asLowAsHelper->isVisibleLearnmore() ? 'true' :'false'; + } } diff --git a/Helper/AsLowAs.php b/Helper/AsLowAs.php index f85b48c0..cf38bd0b 100644 --- a/Helper/AsLowAs.php +++ b/Helper/AsLowAs.php @@ -97,4 +97,14 @@ public function getFinancingProgramValueALS(Product\Collection $productCollectio return $this->getFinancingProgramDefault(); } } + + /** + * Is visible Learn more for ALA + * + * @return boolean + */ + public function isVisibleLearnmore() + { + return $this->affirmPaymentConfig->getAsLowAsValue('learn_more'); + } } diff --git a/Helper/Payment/Data.php b/Helper/Payment/Data.php index b4a409c9..bc54108f 100755 --- a/Helper/Payment/Data.php +++ b/Helper/Payment/Data.php @@ -1,4 +1,37 @@ scopeConfig = $scopeConfig; + $this->affirmPaymentConfig = $configAffirm; + } + + /** + * Get pixel active status for confirm page + * + * @return string + */ + public function isAffirmAnalyticsAvailable() + { + return $this->affirmPaymentConfig->getPixelValue('active_confirm'); + } + + public function getDateMicrotime() + { + $microtime = explode(' ', microtime()); + $msec = $microtime[0]; + $msecArray = explode('.', $msec); + $date = date('Y-m-d-H-i-s') . '-' . $msecArray[1]; + return $date; + } +} diff --git a/Model/Config.php b/Model/Config.php index 6fbbeca0..6f3763d5 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -1,19 +1,36 @@ scopeConfig->getValue( + 'affirm/' . self::KEY_PIXEL . '/' . $key, ScopeInterface::SCOPE_WEBSITE + ); + } + /** * Returns payment configuration value * diff --git a/Model/Observer/SetAffirmAnalyticsOnOrderSuccessPageView.php b/Model/Observer/SetAffirmAnalyticsOnOrderSuccessPageView.php new file mode 100644 index 00000000..90143ac7 --- /dev/null +++ b/Model/Observer/SetAffirmAnalyticsOnOrderSuccessPageView.php @@ -0,0 +1,76 @@ +_layout = $layout; + $this->_storeManager = $storeManager; + } + + /** + * Add order information into Affirm block to render on checkout success pages + * + * @param EventObserver $observer + * @return void + */ + public function execute(Observer $observer) + { + $orderIds = $observer->getEvent()->getOrderIds(); + if (empty($orderIds) || !is_array($orderIds)) { + return; + } + $block = $this->_layout->getBlock('affirm_pixel_javascript'); + if ($block) { + $block->setOrderIds($orderIds); + } + } +} diff --git a/Model/Plugin/Checkout/CustomerData/Cart.php b/Model/Plugin/Checkout/CustomerData/Cart.php index 9529c55d..74b2c0de 100644 --- a/Model/Plugin/Checkout/CustomerData/Cart.php +++ b/Model/Plugin/Checkout/CustomerData/Cart.php @@ -1,19 +1,36 @@ getQuote()->getTotals(); $subtotal = isset($totals['subtotal']) ? $totals['subtotal']->getValue() : 0; if($subtotal > (float)$this->affirmPaymentConfig->getAsLowAsMinMpp()) { $result['mfpValue'] = $this->asLowAsHelper->getFinancingProgramValue(); } - + $result['learnMore'] = $this->asLowAsHelper->isVisibleLearnmore() ? 'true' :'false'; $result['allow_affirm_quote_aslowas'] = $this->affirmPaymentHelper->isAffirmAvailable(); return $result; } -} +} \ No newline at end of file diff --git a/Model/Plugin/Product/ListProduct.php b/Model/Plugin/Product/ListProduct.php index 820dd9de..37bff59e 100755 --- a/Model/Plugin/Product/ListProduct.php +++ b/Model/Plugin/Product/ListProduct.php @@ -1,4 +1,38 @@ addAttributeToFilter('entity_id', $product->getId()); $mfpValue = $this->asLowAsHelper->getFinancingProgramValueALS($productCollection); - $priceHtml .= '
getDataAffirmColor() . ' ' . (!empty($mfpValue) ? 'data-promo-id="' . $mfpValue . '"' : '') . ' data-amount="0">
'; + $learnMore = $this->asLowAsHelper->isVisibleLearnmore() ? 'true' :'false'; + $priceHtml .= '
getDataAffirmColor() . ' ' . (!empty($mfpValue) ? 'data-promo-id="' . $mfpValue . '"' : '') . ' data-amount="0" data-learnmore-show="'.$learnMore.'">
'; } return $priceHtml; diff --git a/composer.json b/composer.json index 69147cea..4cf51916 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "affirm/magento2", "description": "Affirm's extension for the Magento 2 https://www.affirm.com/", "type": "magento2-module", - "version": "2.0.8", + "version": "2.0.9", "license": [ "BSD-3-Clause" ], diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 7fd07bcf..77f8e71c 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -235,6 +235,10 @@ validate-number + + + Magento\Config\Model\Config\Source\Yesno + @@ -281,7 +285,13 @@ - + + + + + Magento\Config\Model\Config\Source\Yesno + + diff --git a/etc/config.xml b/etc/config.xml index 6fadf5ef..15a667da 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -85,6 +85,7 @@ 0 0.10 12 + 1 diff --git a/etc/frontend/events.xml b/etc/frontend/events.xml index b695bd7f..159d8113 100644 --- a/etc/frontend/events.xml +++ b/etc/frontend/events.xml @@ -16,4 +16,10 @@ + + + + + + diff --git a/etc/module.xml b/etc/module.xml index 9238599a..7d14e222 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -10,7 +10,7 @@ */ --> - + diff --git a/view/frontend/layout/checkout_onepage_success.xml b/view/frontend/layout/checkout_onepage_success.xml new file mode 100644 index 00000000..fdfaeed0 --- /dev/null +++ b/view/frontend/layout/checkout_onepage_success.xml @@ -0,0 +1,41 @@ + + + + + + + + + diff --git a/view/frontend/requirejs-config.js b/view/frontend/requirejs-config.js index e52779c1..59fb81e4 100644 --- a/view/frontend/requirejs-config.js +++ b/view/frontend/requirejs-config.js @@ -23,7 +23,8 @@ var config = { 'aslowasPDP': 'Astound_Affirm/js/aslowasPDP', 'aslowasPLP': 'Astound_Affirm/js/aslowasPLP', 'aslowasCC': 'Astound_Affirm/js/aslowasCC', - 'aslowasMC': 'Astound_Affirm/js/aslowasMC' + 'aslowasMC': 'Astound_Affirm/js/aslowasMC', + 'affirmPixel': 'Astound_Affirm/js/affirmPixel' } } }; diff --git a/view/frontend/templates/pixel/confirm.phtml b/view/frontend/templates/pixel/confirm.phtml new file mode 100644 index 00000000..e2a0f703 --- /dev/null +++ b/view/frontend/templates/pixel/confirm.phtml @@ -0,0 +1,57 @@ + +getOptions(); +?> + + + + + + diff --git a/view/frontend/templates/promotion/aslowasCart.phtml b/view/frontend/templates/promotion/aslowasCart.phtml index f6852223..14013718 100644 --- a/view/frontend/templates/promotion/aslowasCart.phtml +++ b/view/frontend/templates/promotion/aslowasCart.phtml @@ -1,25 +1,43 @@ getMFPValue(); +$learnMore = $block->getLearnMoreValue(); ?> - getDataAffirmColor() . '>'; ?> + getDataAffirmColor() . ' data-learnmore-show="'.$learnMore.'">'; ?> \ No newline at end of file diff --git a/view/frontend/templates/promotion/aslowasPDP.phtml b/view/frontend/templates/promotion/aslowasPDP.phtml index 3aac593c..990c2529 100644 --- a/view/frontend/templates/promotion/aslowasPDP.phtml +++ b/view/frontend/templates/promotion/aslowasPDP.phtml @@ -1,29 +1,47 @@ getMFPValue(); $productId = $block->getProductId(); +$learnMore = $block->getLearnMoreValue(); ?> - getDataAffirmColor() . '>'; ?> + getDataAffirmColor() . ' data-learnmore-show="'.$learnMore.'">'; ?>