_helper = $helper; $this->_collection = $collection; $this->_registry = $registry; } /** * Set base grand total of order to registry * * @param \Magento\Framework\Event\Observer $observer * @return \Magento\GoogleAdwords\Observer\SetConversionValueObserver */ public function execute(\Magento\Framework\Event\Observer $observer) { if (!($this->_helper->isGoogleAdwordsActive() && $this->_helper->isDynamicConversionValue())) { return $this; } $orderIds = $observer->getEvent()->getOrderIds(); if (!$orderIds || !is_array($orderIds)) { return $this; } $this->_collection->addFieldToFilter('entity_id', ['in' => $orderIds]); $conversionValue = 0; $conversionCurrency = false; $sendOrderCurrency = $this->_helper->hasSendConversionValueCurrency(); foreach ($this->_collection as $order) { /** @var $order \Magento\Sales\Api\Data\OrderInterface */ $conversionValue += $sendOrderCurrency ? $order->getGrandTotal() : $order->getBaseGrandTotal(); $conversionCurrency = $sendOrderCurrency ? $order->getOrderCurrencyCode() : false; } $this->_registry->register( \Magento\GoogleAdwords\Helper\Data::CONVERSION_VALUE_CURRENCY_REGISTRY_NAME, $conversionCurrency ); $this->_registry->register( \Magento\GoogleAdwords\Helper\Data::CONVERSION_VALUE_REGISTRY_NAME, $conversionValue ); return $this; } }