src/Services/SegmentTrackingHelperService.php line 69

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PEL
  13.  */
  14. namespace App\Services;
  15. use App\Ecommerce\IndexService\SegmentGetter;
  16. use App\Model\Product\AbstractProduct;
  17. use App\Model\Product\Category;
  18. use CustomerManagementFrameworkBundle\SegmentManager\SegmentManagerInterface;
  19. use CustomerManagementFrameworkBundle\Targeting\SegmentTracker;
  20. use Pimcore\Targeting\VisitorInfoStorage;
  21. class SegmentTrackingHelperService
  22. {
  23.     /**
  24.      * @var VisitorInfoStorage
  25.      */
  26.     protected $visitorInfoStorage;
  27.     /**
  28.      * @var SegmentTracker
  29.      */
  30.     protected $segmentTracker;
  31.     /**
  32.      * @var SegmentGetter
  33.      */
  34.     protected $segmentGetter;
  35.     /**
  36.      * @var SegmentManagerInterface
  37.      */
  38.     protected $segmentManager;
  39.     /**
  40.      * SegmentTrackingHelperService constructor.
  41.      *
  42.      * @param VisitorInfoStorage $visitorInfoStorage
  43.      * @param SegmentTracker $segmentTracker
  44.      * @param SegmentGetter $segmentGetter
  45.      * @param SegmentManagerInterface $segmentManager
  46.      */
  47.     public function __construct(VisitorInfoStorage $visitorInfoStorageSegmentTracker $segmentTrackerSegmentGetter $segmentGetterSegmentManagerInterface $segmentManager)
  48.     {
  49.         $this->visitorInfoStorage $visitorInfoStorage;
  50.         $this->segmentTracker $segmentTracker;
  51.         $this->segmentGetter $segmentGetter;
  52.         $this->segmentManager $segmentManager;
  53.     }
  54.     /**
  55.      * @param AbstractProduct $product
  56.      */
  57.     public function trackSegmentsForProduct(AbstractProduct $product)
  58.     {
  59.         if ($this->visitorInfoStorage->hasVisitorInfo()) {
  60.             $segments $this->segmentGetter->get($product);
  61.             if ($segments) {
  62.                 $this->segmentTracker->trackSegments($this->visitorInfoStorage->getVisitorInfo(), $segments);
  63.             }
  64.         }
  65.     }
  66.     /**
  67.      * @param Category $category
  68.      */
  69.     public function trackSegmentsForCategory(Category $category)
  70.     {
  71.         if ($this->visitorInfoStorage->hasVisitorInfo()) {
  72.             $segments $this->segmentManager->getSegmentsForElement($category);
  73.             if ($segments) {
  74.                 $this->segmentTracker->trackSegments($this->visitorInfoStorage->getVisitorInfo(), $segments);
  75.             }
  76.         }
  77.     }
  78. }