...

View Full Version : Array Help



moos3
11-28-2007, 09:55 PM
I need some help with a foreach base off a part of a array



/* heres the array

array(18) {
["qty"]=>
int(1)
["name"]=>
string(12) "Moose Shirts"
["model"]=>
string(1) "1"
["tax"]=>
int(0)
["tax_description"]=>
string(21) "TEXT_UNKNOWN_TAX_RATE"
["price"]=>
string(7) "12.0000"
["final_price"]=>
float(12)
["onetime_charges"]=>
int(0)
["weight"]=>
float(0.5)
["products_priced_by_attribute"]=>
string(1) "0"
["product_is_free"]=>
string(1) "0"
["products_discount_type"]=>
string(1) "0"
["products_discount_type_from"]=>
string(1) "0"
["id"]=>
string(34) "4:7aa97a9e77b22b7cf0d48fadb290d408"
["manufacturers_id"]=>
string(2) "19"
["rowClass"]=>
string(7) "rowEven"
["attributes"]=>
array(2) {
[0]=>
array(6) {
["option"]=>
string(5) "Color"
["value"]=>
string(5) "black"
["option_id"]=>
int(4)
["value_id"]=>
string(2) "14"
["prefix"]=>
string(0) ""
["price"]=>
string(6) "0.0000"
}
[1]=>
array(6) {
["option"]=>
string(4) "Size"
["value"]=>
string(1) "l"
["option_id"]=>
int(5)
["value_id"]=>
string(2) "17"
["prefix"]=>
string(0) ""
["price"]=>
string(6) "0.0000"
}
}
["stock_reduce"]=>
int(1)
}
array(18) {
["qty"]=>
int(1)
["name"]=>
string(29) "Trisexual - I'll Try Anything"
["model"]=>
string(9) "TRISEXUAL"
["tax"]=>
int(0)
["tax_description"]=>
string(21) "TEXT_UNKNOWN_TAX_RATE"
["price"]=>
string(7) "20.0000"
["final_price"]=>
float(20)
["onetime_charges"]=>
int(0)
["weight"]=>
int(0)
["products_priced_by_attribute"]=>
string(1) "0"
["product_is_free"]=>
string(1) "0"
["products_discount_type"]=>
string(1) "0"
["products_discount_type_from"]=>
string(1) "0"
["id"]=>
string(34) "3:03fec284da22221a8500fcfe45b07ea7"
["manufacturers_id"]=>
string(1) "2"
["rowClass"]=>
string(6) "rowOdd"
["attributes"]=>
array(1) {
[0]=>
array(6) {
["option"]=>
string(4) "Size"
["value"]=>
string(11) "Extra Large"
["option_id"]=>
int(5)
["value_id"]=>
string(1) "8"
["prefix"]=>
string(0) ""
["price"]=>
string(6) "0.0000"
}
}
["stock_reduce"]=>
int(1)
}
array(18) {
["qty"]=>
int(1)
["name"]=>
string(17) "Frederick Douglas"
["model"]=>
string(6) "300-FD"
["tax"]=>
int(0)
["tax_description"]=>
string(21) "TEXT_UNKNOWN_TAX_RATE"
["price"]=>
string(7) "12.0000"
["final_price"]=>
float(12)
["onetime_charges"]=>
int(0)
["weight"]=>
int(0)
["products_priced_by_attribute"]=>
string(1) "0"
["product_is_free"]=>
string(1) "0"
["products_discount_type"]=>
string(1) "0"
["products_discount_type_from"]=>
string(1) "0"
["id"]=>
string(34) "1:fa52fb1cf1979242d150173f1be3ff61"
["manufacturers_id"]=>
string(1) "1"
["rowClass"]=>
string(7) "rowEven"
["attributes"]=>
array(2) {
[0]=>
array(6) {
["option"]=>
string(5) "Color"
["value"]=>
string(4) "Blue"
["option_id"]=>
int(4)
["value_id"]=>
string(2) "11"
["prefix"]=>
string(1) "+"
["price"]=>
string(6) "0.0000"
}
[1]=>
array(6) {
["option"]=>
string(4) "Size"
["value"]=>
string(11) "Extra Large"
["option_id"]=>
int(5)
["value_id"]=>
string(1) "8"
["prefix"]=>
string(0) ""
["price"]=>
string(6) "0.0000"
}
}
["stock_reduce"]=>
int(1)
}
*/
foreach($this->products as $man_id=>$manufacturers_id){
$manufacturers_id;
}
foreach($manufacturers_id['manufacturers_id'] as $key=>$man_id){
echo $man_id;
}
break;

Is this Right? Because its not working and I can't figure out how or why?

moos3
11-28-2007, 10:37 PM
here is what I have come up with so far, I also included the code to be exceuted


function send_man_order_email($zf_insert_id, $zf_mode) {
global $currencies, $order_totals;
foreach($this->products as $k=>$v){
$man_id = $v['manufacturers_id'];
// Get Manufacturers Email
$sql = "SELECT c.seller_fulfillment_email,c.seller_fulfillment_email_text,m.manufacturers_name FROM seller_profiles AS c,manufacturers AS m WHERE m.manufacturers_id = c.seller_manufacturers_id AND c.seller_manufacturers_id = '$man_id'";
$sql_res = mysql_query($sql);
$man_rows = mysql_fetch_assoc($sql_res);
$man_email = $man_rows['seller_fulfillment_email'];
$man_name = $man_rows['manufacturers_name'];
$full_text = $man_rows['seller_fulfillment_email_text'];
// print_r($this);
// die();
if ($this->email_low_stock != '' and SEND_LOWSTOCK_EMAIL=='1') {
// send an email
$email_low_stock = SEND_EXTRA_LOW_STOCK_EMAIL_TITLE . "\n\n" . $this->email_low_stock;
zen_mail('', SEND_EXTRA_LOW_STOCK_EMAILS_TO, EMAIL_TEXT_SUBJECT_LOWSTOCK, $email_low_stock, STORE_OWNER, EMAIL_FROM, array('EMAIL_MESSAGE_HTML' => nl2br($email_low_stock)),'low_stock');
}

// lets start with the email confirmation
// make an array to store the html version
$html_msg=array();

//intro area
$email_order = EMAIL_TEXT_HEADER . EMAIL_TEXT_FROM . $man_name . "\n\n" .
$this->customer['firstname'] . ' ' . $this->customer['lastname'] . "\n\n" .
EMAIL_THANKS_FOR_SHOPPING . "\n" . EMAIL_DETAILS_FOLLOW . "\n" .
EMAIL_SEPARATOR . "\n" .
EMAIL_TEXT_ORDER_NUMBER . ' ' . $zf_insert_id . "\n" .
EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n" .
EMAIL_TEXT_INVOICE_URL . ' ' . zen_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $zf_insert_id, 'SSL', false) . "\n\n";
$html_msg['EMAIL_TEXT_HEADER'] = EMAIL_TEXT_HEADER;
$html_msg['EMAIL_TEXT_FROM'] = EMAIL_TEXT_FROM;
$html_msg['INTRO_STORE_NAME'] = $man_name;
$html_msg['EMAIL_THANKS_FOR_SHOPPING'] = EMAIL_THANKS_FOR_SHOPPING;
$html_msg['EMAIL_DETAILS_FOLLOW'] = EMAIL_DETAILS_FOLLOW;
$html_msg['INTRO_ORDER_NUM_TITLE'] = EMAIL_TEXT_ORDER_NUMBER;
$html_msg['INTRO_ORDER_NUMBER'] = $zf_insert_id;
$html_msg['INTRO_DATE_TITLE'] = EMAIL_TEXT_DATE_ORDERED;
$html_msg['INTRO_DATE_ORDERED'] = strftime(DATE_FORMAT_LONG);
$html_msg['INTRO_URL_TEXT'] = EMAIL_TEXT_INVOICE_URL_CLICK;
$html_msg['INTRO_URL_VALUE'] = zen_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $zf_insert_id, 'SSL', false);

//comments area
if ($this->info['comments']) {
$email_order .= zen_db_output($this->info['comments']) . "\n\n";
$html_msg['ORDER_COMMENTS'] = nl2br(zen_db_output($this->info['comments']));
} else {
$html_msg['ORDER_COMMENTS'] = '';
}

//products area
$email_order .= EMAIL_TEXT_PRODUCTS . "\n" .
EMAIL_SEPARATOR . "\n" .
$this->products_ordered[$man_id] .
EMAIL_SEPARATOR . "\n";
$html_msg['PRODUCTS_TITLE'] = EMAIL_TEXT_PRODUCTS;
$html_msg['PRODUCTS_DETAIL']='<table class="product-details" border="0" width="100%" cellspacing="0" cellpadding="2">' . $seller_product_html . '</table>';

//order totals area
$html_ot .= '<td class="order-totals-text" align="right" width="100%">' . '&nbsp;' . '</td> ' . "\n" . '<td class="order-totals-num" align="right" nowrap="nowrap">' . '---------' .'</td> </tr>' . "\n" . '<tr>';
for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
$email_order .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n";
$html_ot .= '<td class="order-totals-text" align="right" width="100%">' . $order_totals[$i]['title'] . '</td> ' . "\n" . '<td class="order-totals-num" align="right" nowrap="nowrap">' .($order_totals[$i]['text']) .'</td> </tr>' . "\n" . '<tr>';
}
$html_msg['ORDER_TOTALS'] = '<table border="0" width="100%" cellspacing="0" cellpadding="2">' . $html_ot . '</table>';

//addresses area: Delivery
$html_msg['HEADING_ADDRESS_INFORMATION']= HEADING_ADDRESS_INFORMATION;
$html_msg['ADDRESS_DELIVERY_TITLE'] = EMAIL_TEXT_DELIVERY_ADDRESS;
$html_msg['ADDRESS_DELIVERY_DETAIL'] = ($this->content_type != 'virtual') ? zen_address_label($_SESSION['customer_id'], $_SESSION['sendto'], true, '', "<br />") : 'n/a';
$html_msg['SHIPPING_METHOD_TITLE'] = HEADING_SHIPPING_METHOD;
$html_msg['SHIPPING_METHOD_DETAIL'] = (zen_not_null($this->info['shipping_method'])) ? $this->info['shipping_method'] : 'n/a';

if ($this->content_type != 'virtual') {
$email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" .
EMAIL_SEPARATOR . "\n" .
zen_address_label($_SESSION['customer_id'], $_SESSION['sendto'], 0, '', "\n") . "\n";
}

//addresses area: Billing
$email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" .
EMAIL_SEPARATOR . "\n" .
zen_address_label($_SESSION['customer_id'], $_SESSION['billto'], 0, '', "\n") . "\n\n";
$html_msg['ADDRESS_BILLING_TITLE'] = EMAIL_TEXT_BILLING_ADDRESS;
$html_msg['ADDRESS_BILLING_DETAIL'] = zen_address_label($_SESSION['customer_id'], $_SESSION['billto'], true, '', "<br />");

if (is_object($GLOBALS[$_SESSION['payment']])) {
$email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" .
EMAIL_SEPARATOR . "\n";
$payment_class = $_SESSION['payment'];
$email_order .= $GLOBALS[$payment_class]->title . "\n\n";
$email_order .= (isset($this->info['cc_type']) && $this->info['cc_type'] != '') ? $this->info['cc_type'] . "\n\n" : '';
$email_order .= ($GLOBALS[$payment_class]->email_footer) ? $GLOBALS[$payment_class]->email_footer . "\n\n" : '';
} else {
$email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" .
EMAIL_SEPARATOR . "\n";
$email_order .= PAYMENT_METHOD_GV . "\n\n";
}
$html_msg['PAYMENT_METHOD_TITLE'] = EMAIL_TEXT_PAYMENT_METHOD;
$html_msg['PAYMENT_METHOD_DETAIL'] = (is_object($GLOBALS[$_SESSION['payment']]) ? $GLOBALS[$payment_class]->title : PAYMENT_METHOD_GV );
$html_msg['PAYMENT_METHOD_FOOTER'] = (is_object($GLOBALS[$_SESSION['payment']]) && $GLOBALS[$payment_class]->email_footer != '') ? nl2br($GLOBALS[$payment_class]->email_footer) : $this->info['cc_type'];

// include disclaimer
$email_order .= "\n-----\n" . sprintf(EMAIL_DISCLAIMER, STORE_OWNER_EMAIL_ADDRESS) . "\n\n";
// include copyright
$email_order .= "\n-----\n" . EMAIL_FOOTER_COPYRIGHT . "\n\n";

while (strstr($email_order, '&nbsp;')) $email_order = str_replace('&nbsp;', ' ', $email_order);

$html_msg['EMAIL_FIRST_NAME'] = $this->customer['firstname'];
$html_msg['EMAIL_LAST_NAME'] = $this->customer['lastname'];
// $html_msg['EMAIL_TEXT_HEADER'] = EMAIL_TEXT_HEADER;
$html_msg['EXTRA_INFO'] = '';
zen_mail($man_name . ' ' . '', $man_email, EMAIL_TEXT_SUBJECT . EMAIL_ORDER_NUMBER_SUBJECT . $zf_insert_id, $email_order, STORE_NAME, $this->customer['email_address'], $html_msg, 'checkout');

// send additional emails
if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
$extra_info=email_collect_extra_info('','', $man_name . ' ' . '', $man_email,'');
$html_msg['EXTRA_INFO'] = $extra_info['HTML'];

if ($GLOBALS[$_SESSION['payment']]->auth_code || $GLOBALS[$_SESSION['payment']]->transaction_id) {
$pmt_details = 'AuthCode: ' . $GLOBALS[$_SESSION['payment']]->auth_code . ' TransID: ' . $GLOBALS[$_SESSION['payment']]->transaction_id . "\n\n";
$email_order = $pmt_details . $email_order;
$html_msg['EMAIL_TEXT_HEADER'] = nl2br($pmt_details) . $html_msg['EMAIL_TEXT_HEADER'];
}

zen_mail('', SEND_EXTRA_ORDER_EMAILS_TO, SEND_EXTRA_NEW_ORDERS_EMAILS_TO_SUBJECT . ' ' . EMAIL_TEXT_SUBJECT . EMAIL_ORDER_NUMBER_SUBJECT . $zf_insert_id,
$email_order . $extra_info['TEXT'], STORE_NAME, EMAIL_FROM, $html_msg, 'checkout_extra');
}
}
}

moos3
11-29-2007, 03:41 AM
bump anyone?

Fumigator
11-29-2007, 04:59 AM
I won't even attempt to untangle the mess you posted.


Because its not working and I can't figure out how or why?

A programmer's skillz needs to include the ability to debug code. What kinds of things have you tried in your efforts to debug this? We need some useful information.

Sometimes it's just easier (and better in the long run) to trash what you've done and start from the beginning-- and the beginning is the design of your project.

moos3
11-29-2007, 08:52 PM
Yeah, I would but then I would have trash the whole email system that is part of zen-cart. I have the following code that is currently working:


foreach($this->products as $k=>$v){
//email code here
}

How can I make it so it only email one per id, like I have man id 1,2,1. I only need it wo email once per id so like 1,2 but not the thrid 1. Ideas and suggestions.

Fumigator
11-29-2007, 09:52 PM
array_unique() (http://us3.php.net/manual/en/function.array-unique.php)

moos3
11-29-2007, 11:40 PM
That removes them from what I read.

Fumigator
11-29-2007, 11:44 PM
You don't apply the results of array_unique() to your original array, you assign the results to a new array and use it for whatever needs you have for a unique set of values from your original array.

moos3
11-29-2007, 11:57 PM
so if i understand this correctly


$man_products = array_unquie($this-products['manufacturers_id']);
foreach($man_products as $k=>$v){
//email code here
}

That will remove only repeated manufacturers?

So the following array


array(18) {
["qty"]=>
int(1)
["name"]=>
string(12) "Moose Shirts"
["model"]=>
string(1) "1"
["tax"]=>
int(0)
["tax_description"]=>
string(21) "TEXT_UNKNOWN_TAX_RATE"
["price"]=>
string(7) "12.0000"
["final_price"]=>
float(12)
["onetime_charges"]=>
int(0)
["weight"]=>
float(0.5)
["products_priced_by_attribute"]=>
string(1) "0"
["product_is_free"]=>
string(1) "0"
["products_discount_type"]=>
string(1) "0"
["products_discount_type_from"]=>
string(1) "0"
["id"]=>
string(34) "4:7aa97a9e77b22b7cf0d48fadb290d408"
["manufacturers_id"]=>
string(2) "1"
["rowClass"]=>
string(7) "rowEven"
["attributes"]=>
array(2) {
[0]=>
array(6) {
["option"]=>
string(5) "Color"
["value"]=>
string(5) "black"
["option_id"]=>
int(4)
["value_id"]=>
string(2) "14"
["prefix"]=>
string(0) ""
["price"]=>
string(6) "0.0000"
}
[1]=>
array(6) {
["option"]=>
string(4) "Size"
["value"]=>
string(1) "l"
["option_id"]=>
int(5)
["value_id"]=>
string(2) "17"
["prefix"]=>
string(0) ""
["price"]=>
string(6) "0.0000"
}
}
["stock_reduce"]=>
int(1)
}
array(18) {
["qty"]=>
int(1)
["name"]=>
string(29) "Trisexual - I'll Try Anything"
["model"]=>
string(9) "TRISEXUAL"
["tax"]=>
int(0)
["tax_description"]=>
string(21) "TEXT_UNKNOWN_TAX_RATE"
["price"]=>
string(7) "20.0000"
["final_price"]=>
float(20)
["onetime_charges"]=>
int(0)
["weight"]=>
int(0)
["products_priced_by_attribute"]=>
string(1) "0"
["product_is_free"]=>
string(1) "0"
["products_discount_type"]=>
string(1) "0"
["products_discount_type_from"]=>
string(1) "0"
["id"]=>
string(34) "3:03fec284da22221a8500fcfe45b07ea7"
["manufacturers_id"]=>
string(1) "2"
["rowClass"]=>
string(6) "rowOdd"
["attributes"]=>
array(1) {
[0]=>
array(6) {
["option"]=>
string(4) "Size"
["value"]=>
string(11) "Extra Large"
["option_id"]=>
int(5)
["value_id"]=>
string(1) "8"
["prefix"]=>
string(0) ""
["price"]=>
string(6) "0.0000"
}
}
["stock_reduce"]=>
int(1)
}
array(18) {
["qty"]=>
int(1)
["name"]=>
string(17) "Frederick Douglas"
["model"]=>
string(6) "300-FD"
["tax"]=>
int(0)
["tax_description"]=>
string(21) "TEXT_UNKNOWN_TAX_RATE"
["price"]=>
string(7) "12.0000"
["final_price"]=>
float(12)
["onetime_charges"]=>
int(0)
["weight"]=>
int(0)
["products_priced_by_attribute"]=>
string(1) "0"
["product_is_free"]=>
string(1) "0"
["products_discount_type"]=>
string(1) "0"
["products_discount_type_from"]=>
string(1) "0"
["id"]=>
string(34) "1:fa52fb1cf1979242d150173f1be3ff61"
["manufacturers_id"]=>
string(1) "1"
["rowClass"]=>
string(7) "rowEven"
["attributes"]=>
array(2) {
[0]=>
array(6) {
["option"]=>
string(5) "Color"
["value"]=>
string(4) "Blue"
["option_id"]=>
int(4)
["value_id"]=>
string(2) "11"
["prefix"]=>
string(1) "+"
["price"]=>
string(6) "0.0000"
}
[1]=>
array(6) {
["option"]=>
string(4) "Size"
["value"]=>
string(11) "Extra Large"
["option_id"]=>
int(5)
["value_id"]=>
string(1) "8"
["prefix"]=>
string(0) ""
["price"]=>
string(6) "0.0000"
}
}
["stock_reduce"]=>
int(1)
}

would become


array(18) {
["qty"]=>
int(1)
["name"]=>
string(12) "Moose Shirts"
["model"]=>
string(1) "1"
["tax"]=>
int(0)
["tax_description"]=>
string(21) "TEXT_UNKNOWN_TAX_RATE"
["price"]=>
string(7) "12.0000"
["final_price"]=>
float(12)
["onetime_charges"]=>
int(0)
["weight"]=>
float(0.5)
["products_priced_by_attribute"]=>
string(1) "0"
["product_is_free"]=>
string(1) "0"
["products_discount_type"]=>
string(1) "0"
["products_discount_type_from"]=>
string(1) "0"
["id"]=>
string(34) "4:7aa97a9e77b22b7cf0d48fadb290d408"
["manufacturers_id"]=>
string(2) "19"
["rowClass"]=>
string(7) "rowEven"
["attributes"]=>
array(2) {
[0]=>
array(6) {
["option"]=>
string(5) "Color"
["value"]=>
string(5) "black"
["option_id"]=>
int(4)
["value_id"]=>
string(2) "14"
["prefix"]=>
string(0) ""
["price"]=>
string(6) "0.0000"
}
[1]=>
array(6) {
["option"]=>
string(4) "Size"
["value"]=>
string(1) "l"
["option_id"]=>
int(5)
["value_id"]=>
string(2) "17"
["prefix"]=>
string(0) ""
["price"]=>
string(6) "0.0000"
}
}
["stock_reduce"]=>
int(1)
}
array(18) {
["qty"]=>
int(1)
["name"]=>
string(29) "Trisexual - I'll Try Anything"
["model"]=>
string(9) "TRISEXUAL"
["tax"]=>
int(0)
["tax_description"]=>
string(21) "TEXT_UNKNOWN_TAX_RATE"
["price"]=>
string(7) "20.0000"
["final_price"]=>
float(20)
["onetime_charges"]=>
int(0)
["weight"]=>
int(0)
["products_priced_by_attribute"]=>
string(1) "0"
["product_is_free"]=>
string(1) "0"
["products_discount_type"]=>
string(1) "0"
["products_discount_type_from"]=>
string(1) "0"
["id"]=>
string(34) "3:03fec284da22221a8500fcfe45b07ea7"
["manufacturers_id"]=>
string(1) "2"
["rowClass"]=>
string(6) "rowOdd"
["attributes"]=>
array(1) {
[0]=>
array(6) {
["option"]=>
string(4) "Size"
["value"]=>
string(11) "Extra Large"
["option_id"]=>
int(5)
["value_id"]=>
string(1) "8"
["prefix"]=>
string(0) ""
["price"]=>
string(6) "0.0000"
}
}
["stock_reduce"]=>
int(1)
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum