コード例 #1
0
 /**
  * Push trackEcommerceCartUpdate to tracker on cart view page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return \Henhed\Piwik\Observer\CartViewObserver
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if ($this->_dataHelper->isTrackingEnabled()) {
         $this->_trackerHelper->addQuote($this->_checkoutSession->getQuote(), $this->_piwikTracker);
     }
     return $this;
 }
コード例 #2
0
 /**
  * Add `trackEcommerceCartUpdate' checkout cart customer data
  *
  * @param \Magento\Checkout\CustomerData\Cart $subject
  * @param array $result
  * @return array
  */
 public function afterGetSectionData(\Magento\Checkout\CustomerData\Cart $subject, $result)
 {
     if ($this->_dataHelper->isTrackingEnabled()) {
         $quote = $this->_checkoutSession->getQuote();
         if ($quote->getId()) {
             $tracker = $this->_trackerFactory->create();
             $this->_trackerHelper->addQuote($quote, $tracker);
             $result['piwikActions'] = $tracker->toArray();
         }
     }
     return $result;
 }
コード例 #3
0
 /**
  * Test for \Henhed\Piwik\Helper\Tracker::addQuote
  *
  * Also covers `addQuoteItem' and `addQuoteTotal'
  *
  * @param array $items
  * @param float $total
  * @dataProvider addQuoteDataProvider
  */
 public function testAddQuote($items, $total)
 {
     // Build expected tracker result from $items and $total
     $expectedResult = [];
     foreach ($items as $item) {
         list($sku, $name, $price, $qty) = $item;
         $expectedResult[] = ['addEcommerceItem', $sku, $name, false, (double) $price, (double) $qty];
     }
     $expectedResult[] = ['trackEcommerceCartUpdate', (double) $total];
     // Test `addQuote' with mock quote created from $items and $total
     $this->_helper->addQuote($this->_getQuoteMock($items, $total), $this->_tracker);
     $this->assertSame($expectedResult, $this->_tracker->toArray());
 }