Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions src/EventListener/AddToCartListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,29 @@ public function getCustomerOptionsFromRequest(Request $request): array
return [];
}

$customerOptions = $addToCart['customer_options'];

// Date options need a little extra attention
// We transform the date fields into a single date string
foreach ($addToCart['customer_options'] as $code => $value) {
$customerOption = $this->customerOptionRepository->findOneByCode($code);
Assert::notNull($customerOption);

switch ($customerOption->getType()) {
case CustomerOptionTypeEnum::TEXT:
// remove empty entries like " "
if (trim($value) == "") {
unset($customerOptions[$code]);
} else {
$customerOptions[$code] = trim($value);
}

break;
case CustomerOptionTypeEnum::DATE:
$day = $value['day'];
$month = $value['month'];
$year = $value['year'];
$addToCart['customer_options'][$code] = sprintf('%d-%d-%d', $year, $month, $day);
$day = $value['day'];
$month = $value['month'];
$year = $value['year'];
$customerOptions[$code] = sprintf('%d-%d-%d', $year, $month, $day);

break;
case CustomerOptionTypeEnum::DATETIME:
Expand All @@ -146,12 +157,12 @@ public function getCustomerOptionsFromRequest(Request $request): array
$hour = $time['hour'] ?? 0;
$minute = $time['minute'] ?? 0;

$addToCart['customer_options'][$code] = sprintf('%d-%d-%d %d:%d', $year, $month, $day, $hour, $minute);
$customerOptions[$code] = sprintf('%d-%d-%d %d:%d', $year, $month, $day, $hour, $minute);

break;
}
}

return $addToCart['customer_options'];
return $customerOptions;
}
}