Example #1
0
 /**
  * @param bool $isActive
  * @param string $returnConfigValue
  * @param bool $returnValue
  * @dataProvider dataProviderForTestIsActive
  */
 public function testIsGoogleAdwordsActive($isActive, $returnConfigValue, $returnValue)
 {
     $this->_scopeConfigMock->expects($this->any())->method('isSetFlag')->with(\Magento\GoogleAdwords\Helper\Data::XML_PATH_ACTIVE)->will($this->returnValue($isActive));
     $this->_scopeConfigMock->expects($this->any())->method('getValue')->with($this->isType('string'))->will($this->returnCallback(function () use($returnConfigValue) {
         return $returnConfigValue;
     }));
     $this->assertEquals($returnValue, $this->_helper->isGoogleAdwordsActive());
 }
 /**
  * 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;
     /** @var $order \Magento\Sales\Model\Order */
     foreach ($this->_collection as $order) {
         $conversionValue += $order->getBaseGrandTotal();
     }
     $this->_registry->register(\Magento\GoogleAdwords\Helper\Data::CONVERSION_VALUE_REGISTRY_NAME, $conversionValue);
     return $this;
 }
Example #3
0
 /**
  * Render block html if Google AdWords is active
  *
  * @return string
  */
 protected function _toHtml()
 {
     return $this->_googleAdwordsData->isGoogleAdwordsActive() ? parent::_toHtml() : '';
 }