Skip to content

Commit c43ea11

Browse files
MercuryKojobrusch
authored andcommitted
Pimcore X provides TargetGroup Object in Action Array (#299)
* Pimcore X provides TargetGroup Object in Action Array Pimcore X now provides TargetGroup Object in Action Array instead of id also some isset checks for php8.1 * Update src/Targeting/ActionHandler/AssignTargetGroupAndSegment.php Co-authored-by: Bernhard Rusch <[email protected]>
1 parent 8d7d86b commit c43ea11

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Targeting/ActionHandler/AssignTargetGroupAndSegment.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,14 @@ public function apply(VisitorInfo $visitorInfo, array $action, Rule $rule = null
101101
}
102102

103103
$targetGroupId = $action['targetGroup'] ?? null;
104-
$targetGroup = TargetGroup::getById($targetGroupId);
104+
if ($targetGroupId instanceof TargetGroup) {
105+
$targetGroup = $targetGroupId;
106+
$targetGroupId = $targetGroup->getId();
107+
} else {
108+
$targetGroup = TargetGroup::getById($targetGroupId);
109+
}
105110

106-
if ($action['trackActivity'] && $targetGroup) {
111+
if (isset($action['trackActivity']) && $action['trackActivity'] && $targetGroup) {
107112
$totalWeight = $action['weight'];
108113
if ($visitorInfo->hasTargetGroupAssignment($targetGroup)) {
109114
$assignedTargetGroup = $visitorInfo->getTargetGroupAssignment($targetGroup);
@@ -113,7 +118,7 @@ public function apply(VisitorInfo $visitorInfo, array $action, Rule $rule = null
113118
$this->activityManager->trackActivity(new TargetGroupAssignActivity($customer, $targetGroup, $action['weight'], $totalWeight));
114119
}
115120

116-
if ($action['assignSegment'] === 'assign_only' || $action['assignSegment'] === 'assign_consider_weight') {
121+
if (isset($action['assignSegment']) && ($action['assignSegment'] === 'assign_only' || $action['assignSegment'] === 'assign_consider_weight')) {
117122
//get segment based on target group
118123
$segments = $this->segmentManager->getSegments();
119124
$segments->setCondition('targetGroup = ?', $targetGroupId);

0 commit comments

Comments
 (0)