11 use Magento\Catalog\Model\ProductFrontendActionFactory;
13 use Magento\Catalog\Model\ResourceModel\ProductFrontendAction\CollectionFactory;
46 private $productFrontendActionFactory;
51 private $entityManager;
56 private $collectionFactory;
61 private $frontendStorageConfigurationPool;
74 ProductFrontendActionFactory $productFrontendActionFactory,
76 CollectionFactory $collectionFactory,
80 $this->visitor = $visitor;
81 $this->productFrontendActionFactory = $productFrontendActionFactory;
82 $this->entityManager = $entityManager;
83 $this->collectionFactory = $collectionFactory;
84 $this->frontendStorageConfigurationPool = $frontendStorageConfigurationPool;
95 private function getLifeTimeByNamespace($namespace)
97 $configurationObject = $this->frontendStorageConfigurationPool->
get($namespace);
98 if ($configurationObject) {
118 private function filterNewestActions(array
$productsData, $typeId)
120 $lifetime = $this->getLifeTimeByNamespace($typeId);
123 uasort(
$productsData,
function (array $firstProduct, array $secondProduct) {
124 return $firstProduct[
'added_at'] > $secondProduct[
'added_at'];
136 private function getProductIdsByActions(array $actions)
140 foreach ($actions as $action) {
160 $visitorId = $this->visitor->getId();
173 $this->entityManager->delete(
$item);
178 $action = $this->productFrontendActionFactory->create([
181 'customer_id' => $this->session->getCustomerId(),
188 $this->entityManager->save($action);
200 $actions = $this->getAllActions();
201 $actions->addFieldToFilter(
'type_id', $typeId);
211 public function getAllActions()
216 $visitorId = $this->visitor->getId();
const ALLOW_SYNC_WITH_BACKEND_PATH
__construct(Session $session, Visitor $visitor, ProductFrontendActionFactory $productFrontendActionFactory, EntityManager $entityManager, CollectionFactory $collectionFactory, FrontendStorageConfigurationPool $frontendStorageConfigurationPool)
getActionsByType($typeId)
const TIME_TO_DO_ONE_ACTION