Skip to content

Commit

Permalink
Fix logic in equals() method
Browse files Browse the repository at this point in the history
  • Loading branch information
shochdoerfer committed Jun 20, 2023
1 parent a4c9897 commit 09f95f9
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/Traits/OrderItemCustomerOptionCapableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,32 @@ public function equals(SyliusOrderItemInterface $item): bool
return false;
}

$product = $item instanceof self ? $item->getProduct() : null;
if (!$item instanceof self) {
return false;
}

/** @var OrderItemOptionInterface[] $itemCustomerConfiguration */
$itemCustomerConfiguration = $item->getCustomerOptionConfiguration(true);
$curItemCustomerConfiguration = $this->getCustomerOptionConfiguration(true);

// configuration array size needs to be identical
if (count($itemCustomerConfiguration) !== count($curItemCustomerConfiguration)) {
return false;
}

// configuration array keys need to match
$diff = array_diff_key($itemCustomerConfiguration, $curItemCustomerConfiguration);
if (count($diff) !== 0) {
return false;
}

// iterate over all options and compare their values
foreach ($itemCustomerConfiguration as $code => $value) {
if ($curItemCustomerConfiguration[$code]->getOptionValue() !== $value->getOptionValue()) {
return false;
}
}

return ($product instanceof ProductInterface) ? !$product->hasCustomerOptions() : true;
return true;
}
}

0 comments on commit 09f95f9

Please sign in to comment.