src/Ecommerce/IndexService/SegmentGetter.php line 54

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\Ecommerce\IndexService;
  15. use App\Model\Product\AccessoryPart;
  16. use App\Model\Product\Car;
  17. use CustomerManagementFrameworkBundle\SegmentManager\SegmentManagerInterface;
  18. use Pimcore\Bundle\EcommerceFrameworkBundle\IndexService\Getter\GetterInterface;
  19. class SegmentGetter implements GetterInterface
  20. {
  21.     const SEGMENT_GROUP_MANUFACTURER 'Interest Manufacturer';
  22.     const SEGMENT_GROUP_CAR_CLASS 'Interest Car Class';
  23.     const SEGMENT_GROUP_BODY_STYLE 'Interest Body Style';
  24.     /**
  25.      * @var SegmentManagerInterface
  26.      */
  27.     protected $segmentManager;
  28.     /**
  29.      * SegmentGetter constructor.
  30.      *
  31.      * @param SegmentManagerInterface $segmentManager
  32.      */
  33.     public function __construct(SegmentManagerInterface $segmentManager)
  34.     {
  35.         $this->segmentManager $segmentManager;
  36.     }
  37.     public function get($object$config null)
  38.     {
  39.         $segments = [];
  40.         if ($object instanceof Car) {
  41.             $manufacturer $object->getManufacturer();
  42.             if ($manufacturer) {
  43.                 $segments[] = $this->segmentManager->createCalculatedSegment($manufacturer->getKey(), self::SEGMENT_GROUP_MANUFACTURER);
  44.             }
  45.             $carClass $object->getCarClass();
  46.             if ($carClass) {
  47.                 $segments[] = $this->segmentManager->createCalculatedSegment($carClassself::SEGMENT_GROUP_CAR_CLASS);
  48.             }
  49.             $bodyStyle $object->getBodyStyle();
  50.             if ($bodyStyle) {
  51.                 $segments[] = $this->segmentManager->createCalculatedSegment($bodyStyle->getKey(), self::SEGMENT_GROUP_BODY_STYLE);
  52.             }
  53.         }
  54.         if ($object instanceof AccessoryPart) {
  55.             $manufacturer $object->getManufacturer();
  56.             if ($manufacturer) {
  57.                 $segments[] = $this->segmentManager->createCalculatedSegment($manufacturer->getKey(), self::SEGMENT_GROUP_MANUFACTURER);
  58.             }
  59.         }
  60.         return $segments;
  61.     }
  62. }