Forum Moderators: coopster

Message Too Old, No Replies

Printing array values - how?

does my wishlist code contain an array?

         

marcus76

10:37 pm on May 5, 2009 (gmt 0)

10+ Year Member



hi,

Can someone please give me some pointers on how i can list out the product_id's of the products stored in the wishlist?

Is there an array defined below? if not how would i go about adding it into the code so i could reference it later.

My Wishlist file below:

Thanks

Marcus

<?php
/*
$Id: wishlist.php,v 3.0 2005/04/20 Dennis Blake
osCommerce, Open Source E-Commerce Solutions

Released under the GNU General Public License
*/

/*******************************************************************
****** QUERY THE DATABASE FOR THE CUSTOMERS WISHLIST PRODUCTS ******
*******************************************************************/
require_once(DIR_WS_LANGUAGES . $language . '/' . FILENAME_WISHLIST);

?>
<!-- wishlist //-->

<?php
$info_box_contents = array();
$info_box_contents[] = array('align' => 'left',
'text' => BOX_HEADING_CUSTOMER_WISHLIST
);
new infoBoxHeadingCSS($info_box_contents, false, false, tep_href_link(FILENAME_WISHLIST, '','NONSSL'));

$info_box_contents = array();

if (is_array($wishList->wishID) && !empty($wishList->wishID)) {
reset($wishList->wishID);

if (count($wishList->wishID) < MAX_DISPLAY_WISHLIST_BOX) {

$wishlist_box = '';
$counter = 1;

/*******************************************************************
*** LOOP THROUGH EACH PRODUCT ID TO DISPLAY IN THE WISHLIST BOX ****
*******************************************************************/

while (list($wishlist_id, ) = each($wishList->wishID)) {
$wishlist_id = tep_get_prid($wishlist_id);

$products_query = tep_db_query("SELECT pd.products_id, pd.products_name, pd.products_description, p.products_image, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) AS specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) AS final_price from (" . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd) LEFT JOIN " . TABLE_SPECIALS . " s ON (p.products_id = s.products_id) WHERE pd.products_id = '" . $wishlist_id . "' AND p.products_id = pd.products_id AND pd.language_id = '" . $languages_id . "' order by products_name");
$products = tep_db_fetch_array($products_query);

$wishlist_box .= '0' . $counter . '. ';
$wishlist_box .= '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products['products_id'], 'NONSSL') . '">' . $products['products_name'] . '</a><br/>';

$counter++;
}

$wishlist_box .= '';

} else {

$wishlist_box = '<div class="ShoppingCartBoxContents">' . sprintf(TEXT_WISHLIST_COUNT, count($wishList->wishID)) . '</div>';

}

} else {

$wishlist_box = '<div class="ShoppingCartBoxContents">' . BOX_WISHLIST_EMPTY . '</div>';

}

$info_box_contents[] = array('align' => '',
'text' => $wishlist_box);

new infoBoxCSS($info_box_contents);
?>


<!-- wishlist_eof //-->

dreamcatcher

6:05 am on May 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The product id var is being parsed via $products['products_id'].

So, assign a new array:

$info_box_contents = array();
$product_ids = array();

Then after $counter++; add:

$product_ids[] = $products['products_id'];

To get all the ids, implode the array:

if (!empty($product_ids)) {
implode(',',$product_ids);
}

Looks like oscommerce/zen cart code.

dc

enigma1

9:22 am on May 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



there should be a db table called customers_wishlist. But the ids are mixed with the attributes in it they aren't straight integers. So you need to retrieve the product identifiers:

You could do

<?php
$storage_array = array();
$wl_query = tep_db_query("select products_id from " . TABLE_WISHLIST . "");
while( $wl_array = tep_db_fetch_array($wl_query);
// Discard the attributes
$storage_array[] = (int)$wl_array['products_id'];
}

// Make them unique
$storage_array = array_values(array_flip($storage_array));

// Get the products info
for($i=0, $j=count($storage_array); $i<$j; $i++) {
echo tep_get_products_name($storage_array[$i]) . '<br />';
}
?>