/** * @return void */ public function testMergeVisitorProductIndex() { $mainTable = 'mainTable'; $data = ['dataKey' => 'dataValue']; $matchFields = ['matchField']; $this->connectionMock->expects($this->once())->method('insertOnDuplicate')->with($mainTable, $data, array_keys($data)); $this->helper->mergeVisitorProductIndex($mainTable, $data, $matchFields); }
/** * Add information about product ids to visitor/customer * * @param \Magento\Framework\DataObject|\Magento\Reports\Model\Product\Index\AbstractIndex $object * @param int[] $productIds * @return $this */ public function registerIds(\Magento\Framework\DataObject $object, $productIds) { $row = [ 'visitor_id' => $object->getVisitorId(), 'customer_id' => $object->getCustomerId(), 'store_id' => $object->getStoreId(), ]; $addedAt = (new \DateTime())->getTimestamp(); $data = []; foreach ($productIds as $productId) { $productId = (int)$productId; if ($productId) { $row['product_id'] = $productId; $row['added_at'] = $this->dateTime->formatDate($addedAt); $data[] = $row; } $addedAt -= $addedAt > 0 ? 1 : 0; } $matchFields = ['product_id', 'store_id']; foreach ($data as $row) { $this->_resourceHelper->mergeVisitorProductIndex($this->getMainTable(), $row, $matchFields); } return $this; }
/** * Add information about product ids to visitor/customer * * @param \Magento\Framework\DataObject|\Magento\Reports\Model\Product\Index\AbstractIndex $object * @param int[] $productIds * @return $this */ public function registerIds(\Magento\Framework\DataObject $object, $productIds) { $row = ['visitor_id' => $object->getVisitorId(), 'customer_id' => $object->getCustomerId(), 'store_id' => $object->getStoreId()]; $data = []; foreach ($productIds as $productId) { $productId = (int) $productId; if ($productId) { $row['product_id'] = $productId; $data[] = $row; } } $matchFields = ['product_id', 'store_id']; foreach ($data as $row) { $this->_resourceHelper->mergeVisitorProductIndex($this->getMainTable(), $row, $matchFields); } return $this; }