diff --git a/lib/Entities/DynamicSegmentFilterData.php b/lib/Entities/DynamicSegmentFilterData.php index 7b4306bfb0..2005326792 100644 --- a/lib/Entities/DynamicSegmentFilterData.php +++ b/lib/Entities/DynamicSegmentFilterData.php @@ -3,6 +3,7 @@ namespace MailPoet\Entities; use MailPoet\Segments\DynamicSegments\Filters\UserRole; +use MailPoet\Segments\DynamicSegments\Filters\WooCommerceProduct; use MailPoetVendor\Doctrine\ORM\Mapping as ORM; /** @@ -17,9 +18,9 @@ class DynamicSegmentFilterData { public const CONNECT_TYPE_AND = 'and'; public const CONNECT_TYPE_OR = 'or'; - const OPERATOR_ANY = 'any'; - const OPERATOR_ALL = 'all'; - const OPERATOR_NONE = 'none'; + public const OPERATOR_ALL = 'all'; + public const OPERATOR_ANY = 'any'; + public const OPERATOR_NONE = 'none'; /** * @ORM\Column(type="serialized_array") @@ -79,4 +80,20 @@ class DynamicSegmentFilterData { } return $this->filterData['action'] ?? null; } + + public function getOperator(): ?string { + $operator = $this->filterData['operator'] ?? null; + if (!$operator) { + return $this->getDefaultOperator(); + } + + return $operator; + } + + private function getDefaultOperator(): ?string { + if ($this->getFilterType() === self::TYPE_WOOCOMMERCE && $this->getAction() === WooCommerceProduct::ACTION_PRODUCT) { + return self::OPERATOR_ANY; + } + return null; + } }