//-->@mod Apr 9, 2018 added Buy It Again carousel to homepage
include_once('conn.php');
include_once('includes.php');
//-->@Buy it again Query
//-->@Read from session var
$buyia_mbr_id=intval($_SESSION['mbr_id']);
$cur_buyia_mbr_id=intval($_COOKIE['buyia_mbr_id']);
//-->@if no session var then check cookie
if($buyia_mbr_id == 0) {
//-->use cookie value
$buyia_mbr_id=intval($cur_buyia_mbr_id);
} else {
//-->@use session value
if($cur_buyia_mbr_id != $buyia_mbr_id) {
//-->@update cookie to session value if cookie doesn't match and save for 365 days (1 year)
setcookie_days('buyia_mbr_id',$buyia_mbr_id,365);
} // end if, save cookie if zero
} // end if, check session var
$buyia_q="SELECT DISTINCT oc.ItemID FROM dd_orders_content oc, dd_orders_info oi, dd_catalog ctlg WHERE (oi.mbr_id='{$buyia_mbr_id}')
AND (oc.OrderID=oi.OrderID)
AND (oi.order_paid ='y')
AND (ctlg.ItemID=oc.ItemID)
AND (ctlg.product_in_stock =1)
AND (ctlg.product_inv_qty >0) ORDER BY ItemID DESC";
//----
//-->@sql cache query, 90secs (1min 30secs, save CSV query results
$buyia_carousel_csv_ids=''; // default null CSV list
$buyia_sep=''; // default null CSV separater
$buyia_results_arr=cart_sqlcache('csv_buyia_'.$buyia_mbr_id, 90, $buyia_q);
if( is_array($buyia_results_arr) ) {
foreach($buyia_results_arr as $a_buyia) {
$x_item_id=intval($a_buyia['ItemID']);
//-->@if ItemID is greater than zero then append to CSV list
if($x_item_id >0) {
$buyia_carousel_csv_ids.=$buyia_sep.$x_item_id;
$buyia_sep=','; // set delimitar to comma
} // end if, ItemID is greater than zero
} // // end foreach
} // if csv results for this member's previous orders
//-->@carousel display
//-->@Carousel for Buy It Again
$carousel_display='';
if($buyia_carousel_csv_ids !='') {
$q_prod_crsl="SELECT * FROM dd_catalog WHERE (ItemID IN($buyia_carousel_csv_ids)) AND (product_in_stock =1) AND (product_inv_qty >0) ORDER BY RAND()";
//-->@sql cache query, 90secs (1min 30secs)
$carousel_results_arr=cart_sqlcache('carousel_buyia_'.$buyia_mbr_id, 90, $q_prod_crsl);
if( is_array($carousel_results_arr) ) {
$carousel_display='
Buy Again
';
foreach($carousel_results_arr as $a_prod_crsl) {
//while($a_prod_crsl=mysql_fetch_assoc($r_prod_crsl)) {
$x_crsl_id=intval($a_prod_crsl['ItemID']);
$x_crsl_name=getExcerpt($a_prod_crsl['ItemName'],0,56);
$x_crsl_prod_link=seo_product_url($x_crsl_id);
$x_crsl_img_url=$a_prod_crsl['ItemImageURL'];
//-->@no image available
if($x_crsl_img_url == '') $x_crsl_img_url=$site_url.'/images/no_image.gif';
$x_crsl_img_tag=fixedHeightImage($x_crsl_img_url,144,'als-img');
$x_crsl_details=get_price_struct_table($a_prod_crsl,false,true,10); //don't exclude price, show low inventory notice,fixed font size 10
$x_crsl_add_to_cart_btn=<<
';
} // end foreach, end while, fetch carousel product info
$carousel_display.='
';
//-->@add display to buy it again table
$buy_again_carousel='
'
.$carousel_display.'
';
} // end if, query
} // end if, buyia_carousel_csv_ids is not null
//--> get product id
// and if present and non-zero then
// forward to product page
$product_id=intval($_GET[productid]);
if($product_id)
{
$q_prod="select ItemID from dd_catalog WHERE (ItemID='$product_id') LIMIT 1";
$r_prod=mysql_query($q_prod);
if(($r_prod) && mysql_num_rows($r_prod))
{
//--> product exists, forward to seo product url
$seo_prod_url=seo_product_url($product_id);
//--> redirect
header("Location: $seo_prod_url");
} // end if
} // end if, check product redirect
$q1 = "select * from dd_catalog, dd_categories where dd_catalog.ItemCategory = dd_categories.CategoryID order by rand() limit 0,1";
$r1 = mysql_query($q1) or die(mysql_error());
include_once('templates/HeaderTemplate.php');
include_once('templates/IndexTemplate.php');
include_once('templates/FooterTemplate.php');
?>