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 .= '