I am writing code to add review emails to the queue based on the channels like Amazon, Walmart and so on. The way I am doing it is as follows. I would like to know if the code can be optimized in some other way such as using a Switch or something so that I don't have to use multiple if-else statments.
if ($my_order->pay_method == AMAZONSTORE) {
$emailQueue = new Luxe_EmailQueue();
// $emailQueue->replace_or_add(EMAIL_REVIEW_MAIL1, $customerData->email, $subject, $body, $send_date_php, $my_order->id);
// Temporary adding bcc
$emailQueue->replace_or_add(EMAIL_REVIEW_MAIL1, $customerData->email, $subject, $body, $send_date_php, $my_order->id, null, "", "[email protected]");
$emailQueue->save();
unset($emailQueue);
// Add second (reminder) email also, for 7 days after the first email.
$emailQueue = new Luxe_EmailQueue();
// $emailQueue->replace_or_add(EMAIL_REVIEW_MAIL2, $customerData->email, $subject,
// $smarty->fetch('amazon_store_review_email2.tpl'), $email_dispatch_dates['second_review_email_date_php'], $my_order->id);
// Temporary adding bcc
$emailQueue->replace_or_add(EMAIL_REVIEW_MAIL2, $customerData->email, $subject,
$smarty->fetch('amazon_store_review_email2.tpl'), $email_dispatch_dates['second_review_email_date_php'], $my_order->id, null, "", "[email protected]");
$emailQueue->save();
unset($emailQueue);
} elseif ($my_order->pay_method == PMM) {
# code...
} elseif ($my_order->pay_method == RP) {
# code...
} elseif ($my_order->pay_method == WALMART) {
# code...
} elseif ($my_order->pay_method == EBAY) {
# code...
} else {
// NO payment Method matched.
}
Try This way
switch ($my_order->pay_method) {
case "AMAZONSTORE":
# code...
break;
case "PMM":
# code...
break;
case "RP":
# code...
break;
case "WALMART":
# code...
break;
case "WALMART":
# code...
break;
default:
// NO payment Method matched.
}