1
我有一个工作函数,我在我的osCommerce页面中创建,该页面对产品进行排序并将其交付给相应的拖放托运人。它工作的很好,但不是在第一页加载。事实上,它就好像该函数从未被调用,直到页面在第一次加载后刷新为止。我真的需要在首次加载时执行此功能,以确保这些产品通过电子邮件发送给正确的公司。我在checkout_success.php中调用函数。我有以下的不仅仅是文件内的标签上面:功能将不会在页面加载时触发
send_dropships_mail($dropship_array, $products_array, $order_id, $deliveryaddress_array);
我的功能:
function send_dropships_mail($dropship_array, $products_array, $order_id, $deliveryaddress_array) {
// Create new dropships array indexed by dsid
$newDropships = array();
foreach ($dropship_array as $dropship) {
$newDropships[$dropship['id']] = $dropship;
}
// Perform grouping of products by dsid
// Array of 'dsid' => array of product indices
$dstToProduct = array();
foreach ($products_array as $i => $product) {
if (!isset($dstToProduct[$product['dsid']])) {
$dstToProduct[$product['dsid']] = array();
}
$dstToProduct[$product['dsid']][] = $i;
}
$orders_products_id_query = tep_db_query("select orders_products_id from orders_products where orders_id = " . $order_id);
while ($ipidq = tep_db_fetch_array($orders_products_id_query)) {
$orders_products_id_array[] = array('orders_products_id' => $ipidq['orders_products_id']);
}
$orders_products_id_attributes_query = tep_db_query("select orders_products_id, products_options, products_options_values from orders_products_attributes where orders_id = " . $order_id);
while ($opidq = tep_db_fetch_array($orders_products_id_attributes_query)) {
$orders_products_id_attributes_array[] = array('orders_products_id' => $opidq['orders_products_id'],
'p_o' => $opidq['products_options'],
'p_o_v' => $opidq['products_options_values']);
}
$p_attribute = "";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: [email protected] \r\n" .
"Reply-To: [email protected] \r\n" .
"X-Mailer: PHP/" . phpversion();
// Now we are ready to send emails
foreach ($dstToProduct as $dsid => $productIndices) {
$email = $newDropships[$dsid]['email'];
$subject = "A new order has been placed";
// Build message text
$date = date('m/d/Y');
$text = '<span style="color: #513311; font-size: 14px;"><table cellpadding="3" style="margin-top: 20px;"><tr style="background-color: #6d7d59; color: #ffffff; font-weight: bold; font-size: 12px;"><td style="width: 240px; vertical-align:text-top;">Product Name</td><td style="width: 120px; vertical-align:text-top;">Model Number</td><td style="width: 80px; vertical-align:text-top;">Quantity</td><td style="width: 80px; vertical-align:text-top;">Price</td></tr>';
foreach ($productIndices as $productIndex) {
$p_attribute = "";
if (count($orders_products_id_attributes_array) > 0) {
foreach ($orders_products_id_attributes_array as $opidaa) {
if ($products_array[$productIndex]['orders_products_id'] == $opidaa['orders_products_id']) {
$p_attribute .= "<i> - " . $opidaa['p_o'] . " " . $opidaa['p_o_v'] . "</i><br>";
} else {
$p_attribute = "";
}
}
}
if ($p_attribute == "") {
$text .= '<tr style="background-color: #f0f0f0; color: #513311; font-size: 12px;"><td style="vertical-align:text-top;">' . $products_array[$productIndex]["text"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["model"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["qty"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["price"] . '</td></tr>';
} else {
$text .= '<tr style="background-color: #f0f0f0; color: #513311; font-size: 12px;"><td>' . $products_array[$productIndex]["text"] . '<br>' . $p_attribute . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["model"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["qty"] . '</td><td style="vertical-align:text-top;">' . $products_array[$productIndex]["price"] . '</td></tr>';
}
}
$text .= '</table>';
$text .= '<table cellpadding="3" style="margin-top: 20px;"><tr style="background-color: #6d7d59; color: #ffffff; font-weight: bold; font-size: 12px;"><td style="width: 200px;">Delivery Address</td></tr><tr style="background-color: #f0f0f0; color: #513311; font-size: 12px;"><td>' . $deliveryaddress_array[0]['name'] . '<br>' . $deliveryaddress_array[0]['address'] . '<br>' . $deliveryaddress_array[0]['city'] . ', ' . $deliveryaddress_array[0]['state'] . ' ' . $deliveryaddress_array[0]['zip'] . '</td></tr></table>';
if (!mail($email, $subject, $text, $headers)) {
mail('[email protected]', 'Error sending product', 'The follow order was not sent to the drop shippers: ' . $order_id);
}
}
}
是有时间限制,多数民众赞成设置成自从什么?虽然这仍然无法解释为什么页面需要刷新才能使函数正常工作。任何帮助表示赞赏!
它是有道理的,但问题是这些数组中的一些直到checkout_success.php文件中的标记之前才被定义。我应该将所有数组移动到header.php文件中,然后使用: if(stripos($ _ SERVER ['REQUEST_URI'],'checkout_success.php')) 确保函数不在任何checkout_success.php以外的其他页面? –