2013-11-25 8 views
1

osCommerce 페이지에서 작성한 작동 기능이 있습니다. osCommerce 페이지는 제품을 정렬 한 후 그에 따라 배송 업체에 전달합니다. 그것은 잘 작동하지만 첫 번째 페이지로드에서는 작동하지 않습니다. 실제로 함수가 마치 처음으로로드 된 후 페이지가 새로 고쳐질 때까지 함수가 호출되지 않는 것처럼 보입니다. 이 제품이 올바른 회사에 이메일로 전송되도록 첫 페이지로드시이 기능을 실행해야합니다. checkout_success.php에서 함수를 호출하려고합니다. 나는 단지 파일 내의 태그를 다음 있습니다 :페이지로드시 기능이 실행되지 않습니다.

send_dropships_mail($dropship_array, $products_array, $order_id, $deliveryaddress_array); 

내 기능 : osCommerce에 또는 무언가로 설정 이잖아 시간 제한

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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;" . $opidaa['p_o'] . "&nbsp;" . $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'] . '&nbsp;&nbsp;' . $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:&nbsp;' . $order_id); 
    } 

} 
} 

있습니까? 여전히 기능이 작동하려면 페이지를 새로 고쳐야하는 이유가 설명되지는 않습니다. 어떤 도움을 주셔서 감사합니다!

답변

1

다른 논리를 초기화하기 전에 맨 위의 header.php에이 행과이 행과 관련된 모든 논리를 배치해야합니다.

send_dropships_mail($dropship_array, $products_array, $order_id, $deliveryaddress_array); 

문제는이 기능이 매우 늦게 실행이 이미 지난 부하에 무슨 일이 있었 있기 때문에 당신이 당신의 페이지를 새로 고침 할 때 왜 모든 이전 값이 당신의 렌더링 된 HTML에 표시되어있다 코드에서 호출되고 있다는 점이다 새로운 데이터가 보입니다.

희망이 있습니다. :)

+0

문제는 이러한 배열 중 일부는 checkout_success.php 파일의 태그 이전까지 정의되어 있지 않습니다. 모든 배열을 header.php 파일로 이동해야합니까? if (stripos ($ _ SERVER [ 'REQUEST_URI'], 'checkout_success.php')) 함수가 checkout_success.php가 아닌 다른 페이지? –

관련 문제