get_row("select i.* ,d.* from " . $wpdb->prefix . "posts as i left join " . $wpdb->prefix . "foxypress_inventory_downloadables as d on i.ID = d.inventory_id and d.status = 1 where i.ID = '" . mysql_escape_string($inventory_id) . "'"); if(!empty($item)) { $product = array(); //base info $product['id'] = $inventory_id; $product['code'] = get_post_meta($item->ID,'_code',TRUE); $product['name'] = $item->post_title; $product['description'] = $item->post_content; $product['url'] = foxypress_get_product_url($inventory_id); $product['weight'] = get_post_meta($item->ID,'_weight',TRUE); $product['weight2'] = get_post_meta($item->ID,'_weight2',TRUE); $product['quantity'] = get_post_meta($item->ID,'_quantity',TRUE); $product['quantity_max'] = get_post_meta($item->ID,'_quantity_max',TRUE); $product['quantity_min'] = get_post_meta($item->ID,'quantity_min',TRUE); $product['price'] = get_post_meta($item->ID,'_price',TRUE); $featuredImageID = (has_post_thumbnail($item->ID)) ? get_post_thumbnail_id($item->ID) : 0; if($featuredImageID != 0) { $featuredSrc = wp_get_attachment_image_src($featuredImageID, 'full'); $product['featured_image'] = array("id" => $featuredImageID, "name" => $featuredSrc[0]); } else { $product['featured_image'] = ""; } $product['sale_price'] = get_post_meta($item->ID,'_saleprice',TRUE); $product['sale_start'] = get_post_meta($item->ID,'_salestartdate',TRUE); $product['sale_end'] = get_post_meta($item->ID,'_saleenddate',TRUE); $product['discount_quantity_amount'] = get_post_meta($item->ID,'_discount_quantity_amount',TRUE); $product['discount_quantity_percentage'] = get_post_meta($item->ID,'_discount_quantity_percentage',TRUE); $product['discount_price_amount'] = get_post_meta($item->ID,'_discount_price_amount',TRUE); $product['discount_price_percentage'] = get_post_meta($item->ID,'_discount_price_percentage',TRUE); $product['start_date'] = get_post_meta($item->ID,'_item_start_date',TRUE); $product['end_date'] = get_post_meta($item->ID,'_item_end_date',TRUE); $product['active'] = get_post_meta($item->ID,'_item_active',TRUE); $product['sub_frequency'] = get_post_meta($item->ID,'_sub_frequency',TRUE); $product['sub_startdate'] = get_post_meta($item->ID,'_sub_startdate',TRUE); $product['sub_enddate'] = get_post_meta($item->ID,'_sub_enddate',TRUE); $product['downloadable'] = ($item->downloadable_id != "") ? array("id" => $item->downloadable_id ,"filename" => INVENTORY_DOWNLOADABLE_DIR . "/" . $item->filename ,"maxdownloads" => $item->maxdownloads) : null; //categories $categories = array(); $cats = $wpdb->get_results("select itc.category_id , c.category_name , c.category_image from " . $wpdb->prefix . "foxypress_inventory_to_category as itc inner join " . $wpdb->prefix . "foxypress_inventory_categories as c on itc.category_id = c.category_id where itc.inventory_id = '" . $inventory_id . "'"); if(!empty($cats)) { foreach($cats as $cat) { $categories[] = array("id" => $cat->category_id, "name" => $cat->category_name, "image" => INVENTORY_IMAGE_DIR . "/" . $cat->category_image); } } $product['categories'] = $categories; //images $images = array(); $current_images = get_posts(array('numberposts' => -1, 'post_type' => 'attachment','post_status' => null,'post_parent' => $inventory_id, 'order' => 'ASC','orderby' => 'menu_order', 'post_mime_type' => 'image')); foreach ($current_images as $img) { $src = wp_get_attachment_image_src($img->ID, 'full'); $images[] = array("id" => $img->ID, "name" => $src[0], "order" => $img->menu_order); } $product['images'] = $images; //options $options = array(); $opts = $wpdb->get_results("select o.*, og.option_group_name from " . $wpdb->prefix . "foxypress_inventory_options as o inner join " . $wpdb->prefix . "foxypress_inventory_option_group as og on o.option_group_id = og.option_group_id where o.inventory_id = '" . $inventory_id . "' order by o.option_order"); if(!empty($opts)) { foreach($opts as $opt) { $options[] = array("id" => $opt->option_id ,"group_id" => $opt->option_group_id ,"group_name" => $opt->option_group_name ,"text" => $opt->option_text ,"value" => $opt->option_value ,"extra_price" => $opt->option_extra_price ,"extra_weight" => $opt->option_extra_weight ,"code" => $opt->option_code ,"quantity" => $opt->option_quantity ,"active" => $opt->option_active ,"order" => $opt->option_order); } } $product['options'] = $options; //attributes $attributes = array(); $atts = $wpdb->get_results("select * from " . $wpdb->prefix . "foxypress_inventory_attributes where inventory_id = '" . $inventory_id . "' order by attribute_id"); if(!empty($atts)) { foreach($atts as $att) { $attributes[] = array("id" => $att->attribute_id, "text" => $att->attribute_text, "value" => $att->attribute_value); } } $product['attributes'] = $attributes; return $product; } return null; } function foxypress_GetProductQuantitySold($inventory_id) { global $wpdb, $post; $code = get_post_meta($inventory_id,'_code',TRUE); $quantitySold = 0; $foxyStoreURL = get_option('foxycart_storeurl'); $foxyAPIKey = get_option('foxycart_apikey'); $foxyAPIURL = "https://" . $foxyStoreURL . ".foxycart.com/api"; $foxyData = array(); $foxyData["api_token"] = $foxyAPIKey; $foxyData["api_action"] = "transaction_list"; $foxyData["transaction_date_filter_begin"] = $StartDate; $foxyData["transaction_date_filter_end"] = $EndDate; $foxyData["hide_transaction_filter"] = ""; $foxyData["is_test_filter"] = ""; $foxyData["product_code_filter"] = $code; //$foxyData["pagination_start"] = $PageStart; $SearchResults = foxypress_curlPostRequest($foxyAPIURL, $foxyData); $foxyXMLResponse = simplexml_load_string($SearchResults, NULL, LIBXML_NOCDATA); $Orders = array(); if($foxyXMLResponse->result == "SUCCESS") { foreach($foxyXMLResponse->transactions->transaction as $t) { foreach($t->transaction_details->transaction_detail as $td) { if($code == $td->product_code) { $quantitySold = $quantitySold + (int)$td->product_quantity; } } } } return $quantitySold; } function foxypress_GetProductsByCategory($category_id, $items_per_page = 999999, $page_number = 1) { global $wpdb; $start = ($page_number != "" && $page_number != "0") ? ($page_number - 1) * $items_per_page : 0; $drRows = $wpdb->get_row("SELECT count(i.ID) as RowCount FROM " . $wpdb->prefix . "posts as i INNER JOIN " . $wpdb->prefix . "foxypress_inventory_to_category as ic ON i.ID=ic.inventory_id and ic.category_id = '" . $category_id . "' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_active on i.ID = pm_active.post_ID and pm_active.meta_key = '_item_active' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_start_date on i.ID = pm_start_date.post_ID and pm_start_date.meta_key = '_item_start_date' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_end_date on i.ID = pm_end_date.post_ID and pm_end_date.meta_key = '_item_end_date' WHERE i.post_type = '" . FOXYPRESS_CUSTOM_POST_TYPE. "' AND i.post_status = 'publish' AND pm_active.meta_value = '1' AND (coalesce(pm_start_date.meta_value, now()) <= now() AND coalesce(pm_end_date.meta_value, now()) >= now()) ORDER BY ic.sort_order, i.ID DESC"); $total_pages = ceil($drRows->RowCount/$items_per_page); $items = $wpdb->get_results("SELECT i.ID FROM " . $wpdb->prefix . "posts as i INNER JOIN " . $wpdb->prefix . "foxypress_inventory_to_category as ic ON i.ID=ic.inventory_id and ic.category_id = '" . $category_id . "' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_active on i.ID = pm_active.post_ID and pm_active.meta_key = '_item_active' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_start_date on i.ID = pm_start_date.post_ID and pm_start_date.meta_key = '_item_start_date' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_end_date on i.ID = pm_end_date.post_ID and pm_end_date.meta_key = '_item_end_date' WHERE i.post_type = '" . FOXYPRESS_CUSTOM_POST_TYPE. "' AND i.post_status = 'publish' AND pm_active.meta_value = '1' AND (coalesce(pm_start_date.meta_value, now()) <= now() AND coalesce(pm_end_date.meta_value, now()) >= now()) ORDER BY ic.sort_order, i.ID DESC LIMIT $start, $items_per_page"); $products = array(); $paging = array("total_pages" => $total_pages, "total_items" => $drRows->RowCount, "current_page" => $page_number, "items_per_page" => $items_per_page); if(!empty($items)) { foreach($items as $item) { $product = foxypress_GetProduct($item->ID); if(!empty($product) && $product != null) { $products[] = $product; } } return array("products" => $products, "pagination" => $paging); } return null; } function foxypress_GetProducts($items_per_page = 999999, $page_number = 1, $include_history="1") { global $wpdb; if ( $include_history == "1" ){ $historySQL="AND (coalesce(pm_start_date.meta_value, now()) <= now() AND coalesce(pm_end_date.meta_value, now()) >= now())"; } $start = ($page_number != "" && $page_number != "0") ? ($page_number - 1) * $items_per_page : 0; $drRows = $wpdb->get_row("SELECT count(i.ID) as RowCount FROM " . $wpdb->prefix . "posts as i LEFT JOIN " . $wpdb->prefix . "postmeta as pm_active on i.ID = pm_active.post_ID and pm_active.meta_key = '_item_active' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_start_date on i.ID = pm_start_date.post_ID and pm_start_date.meta_key = '_item_start_date' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_end_date on i.ID = pm_end_date.post_ID and pm_end_date.meta_key = '_item_end_date' WHERE i.post_type = '" . FOXYPRESS_CUSTOM_POST_TYPE . "' AND i.post_status = 'publish' AND pm_active.meta_value = '1' " . $historySQL . " ORDER BY i.ID DESC"); $total_pages = ceil($drRows->RowCount/$items_per_page); $items = $wpdb->get_results("SELECT i.ID FROM " . $wpdb->prefix . "posts as i LEFT JOIN " . $wpdb->prefix . "postmeta as pm_active on i.ID = pm_active.post_ID and pm_active.meta_key = '_item_active' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_start_date on i.ID = pm_start_date.post_ID and pm_start_date.meta_key = '_item_start_date' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_end_date on i.ID = pm_end_date.post_ID and pm_end_date.meta_key = '_item_end_date' WHERE i.post_type = '" . FOXYPRESS_CUSTOM_POST_TYPE . "' AND i.post_status = 'publish' AND pm_active.meta_value = '1' " . $historySQL . " ORDER BY i.ID DESC LIMIT $start, $items_per_page"); $products = array(); $paging = array("total_pages" => $total_pages, "total_items" => $drRows->RowCount, "current_page" => $page_number, "" => $items_per_page); if(!empty($items)) { foreach($items as $item) { $product = foxypress_GetProduct($item->ID); if(!empty($product) && $product != null) { $products[] = $product; } } return array("products" => $products, "pagination" => $paging); } return null; } function foxypress_SearchProducts($search_term, $items_per_page = 999999, $page_number = 1) { global $wpdb; $start = ($page_number != "" && $page_number != "0") ? ($page_number - 1) * $items_per_page : 0; $drRows = $wpdb->get_row("SELECT SUM(SubRowCount) as RowCount FROM ( SELECT count(i.ID) as SubRowCount FROM " . $wpdb->prefix ."posts as i LEFT JOIN " . $wpdb->prefix . "postmeta as pm_active on i.ID = pm_active.post_ID and pm_active.meta_key = '_item_active' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_start_date on i.ID = pm_start_date.post_ID and pm_start_date.meta_key = '_item_start_date' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_end_date on i.ID = pm_end_date.post_ID and pm_end_date.meta_key = '_item_end_date' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_code on i.ID = pm_code.post_ID and pm_code.meta_key = '_code' WHERE i.post_type = '" . FOXYPRESS_CUSTOM_POST_TYPE . "' AND i.post_status = 'publish' AND pm_active.meta_value = '1' AND (coalesce(pm_start_date.meta_value, now()) <= now() AND coalesce(pm_end_date.meta_value, now()) >= now()) AND ( pm_code.meta_value = '" . mysql_escape_string($search_term) . "' or i.post_title = '" . mysql_escape_string($search_term) . "' or i.post_content = '" . mysql_escape_string($search_term) . "' ) UNION SELECT count(i.ID) as SubRowCount FROM " . $wpdb->prefix ."posts as i LEFT JOIN " . $wpdb->prefix . "postmeta as pm_active on i.ID = pm_active.post_ID and pm_active.meta_key = '_item_active' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_start_date on i.ID = pm_start_date.post_ID and pm_start_date.meta_key = '_item_start_date' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_end_date on i.ID = pm_end_date.post_ID and pm_end_date.meta_key = '_item_end_date' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_code on i.ID = pm_code.post_ID and pm_code.meta_key = '_code' WHERE i.post_type = '" . FOXYPRESS_CUSTOM_POST_TYPE . "' AND i.post_status = 'publish' AND pm_active.meta_value = '1' AND (coalesce(pm_start_date.meta_value, now()) <= now() AND coalesce(pm_end_date.meta_value, now()) >= now()) AND ( pm_code.meta_value LIKE '%" . mysql_escape_string($search_term) . "%' or i.post_title LIKE '%" . mysql_escape_string($search_term) . "%' or i.post_content LIKE '%" . mysql_escape_string($search_term) . "%' ) ) as Counts"); $total_pages = ceil($drRows->RowCount/$items_per_page); $searchSQL = "(SELECT i.* FROM " . $wpdb->prefix ."posts as i LEFT JOIN " . $wpdb->prefix . "postmeta as pm_active on i.ID = pm_active.post_ID and pm_active.meta_key = '_item_active' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_start_date on i.ID = pm_start_date.post_ID and pm_start_date.meta_key = '_item_start_date' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_end_date on i.ID = pm_end_date.post_ID and pm_end_date.meta_key = '_item_end_date' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_code on i.ID = pm_code.post_ID and pm_code.meta_key = '_code' WHERE i.post_type = '" . FOXYPRESS_CUSTOM_POST_TYPE . "' AND i.post_status = 'publish' AND pm_active.meta_value = '1' AND (coalesce(pm_start_date.meta_value, now()) <= now() AND coalesce(pm_end_date.meta_value, now()) >= now()) AND ( pm_code.meta_value = '" . mysql_escape_string($search_term) . "' or i.post_title = '" . mysql_escape_string($search_term) . "' or i.post_content = '" . mysql_escape_string($search_term) . "' ) ORDER BY i.ID ) UNION (SELECT i.* FROM " . $wpdb->prefix ."posts as i LEFT JOIN " . $wpdb->prefix . "postmeta as pm_active on i.ID = pm_active.post_ID and pm_active.meta_key = '_item_active' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_start_date on i.ID = pm_start_date.post_ID and pm_start_date.meta_key = '_item_start_date' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_end_date on i.ID = pm_end_date.post_ID and pm_end_date.meta_key = '_item_end_date' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_code on i.ID = pm_code.post_ID and pm_code.meta_key = '_code' WHERE i.post_type = '" . FOXYPRESS_CUSTOM_POST_TYPE . "' AND i.post_status = 'publish' AND pm_active.meta_value = '1' AND (coalesce(pm_start_date.meta_value, now()) <= now() AND coalesce(pm_end_date.meta_value, now()) >= now()) AND ( pm_code.meta_value LIKE '%" . mysql_escape_string($search_term) . "%' or i.post_title LIKE '%" . mysql_escape_string($search_term) . "%' or i.post_content LIKE '%" . mysql_escape_string($search_term) . "%' ) ORDER BY i.ID ) LIMIT $start, $items_per_page"; $items = $wpdb->get_results($searchSQL); $products = array(); $paging = array("total_pages" => $total_pages, "total_items" => $drRows->RowCount, "current_page" => $page_number, "items_per_page" => $items_per_page); if(!empty($items)) { foreach($items as $item) { $product = foxypress_GetProduct($item->ID); if(!empty($product) && $product != null) { $products[] = $product; } } return array("products" => $products, "pagination" => $paging); } return null; } function foxypress_GetProductFormEnd() { return ""; } function foxypress_GetProductFormStart($inventory_id, $form_id = "foxypress_form", $include_quantity_field = true) { global $wpdb, $post; $form = ""; $item = $wpdb->get_row("SELECT i.* ,c.category_name ,d.downloadable_id FROM " . $wpdb->prefix . "posts as i INNER JOIN (SELECT min( itc_id ) AS itc_id, inventory_id, category_id FROM " . $wpdb->prefix . "foxypress_inventory_to_category GROUP BY inventory_id) as ic on i.ID = ic.inventory_id INNER JOIN " . $wpdb->prefix . "foxypress_inventory_categories as c ON ic.category_id = c.category_id LEFT JOIN " . $wpdb->prefix . "foxypress_inventory_downloadables as d on i.ID = d.inventory_id and d.status = 1 LEFT JOIN " . $wpdb->prefix . "postmeta as pm_active on i.ID = pm_active.post_ID and pm_active.meta_key = '_item_active' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_start_date on i.ID = pm_start_date.post_ID and pm_start_date.meta_key = '_item_start_date' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_end_date on i.ID = pm_end_date.post_ID and pm_end_date.meta_key = '_item_end_date' WHERE (i.ID = '" . mysql_escape_string($inventory_id) . "') AND i.post_type = '" . FOXYPRESS_CUSTOM_POST_TYPE . "' AND i.post_status = 'publish' AND pm_active.meta_value = '1' AND (coalesce(pm_start_date.meta_value, now()) <= now() AND coalesce(pm_end_date.meta_value, now()) >= now()) "); if(empty($item)){ return ""; } $_code = get_post_meta($item->ID,'_code',TRUE); $_name = $item->post_title; $_description = $item->post_content; $_weight = get_post_meta($item->ID,'_weight',TRUE); $_weight2 = get_post_meta($item->ID,'_weight2',TRUE); $_quantity = get_post_meta($item->ID,'_quantity',TRUE); $_quantity_min = get_post_meta($item->ID,'_quantity_min',TRUE); $_quantity_max = get_post_meta($item->ID,'_quantity_max',TRUE); $_price = get_post_meta($item->ID,'_price',TRUE); $_sale_price = get_post_meta($item->ID,'_saleprice',TRUE); $_sale_start = get_post_meta($item->ID,'_salestartdate',TRUE); $_sale_end = get_post_meta($item->ID,'_saleenddate',TRUE); $_discount_quantity_amount = get_post_meta($item->ID,'_discount_quantity_amount',TRUE); $_discount_quantity_percentage = get_post_meta($item->ID,'_discount_quantity_percentage',TRUE); $_discount_price_amount = get_post_meta($item->ID,'_discount_price_amount',TRUE); $_discount_price_percentage = get_post_meta($item->ID,'_discount_price_percentage',TRUE); $_start_date = get_post_meta($item->ID,'_item_start_date',TRUE); $_end_date = get_post_meta($item->ID,'_item_end_date',TRUE); $_active = get_post_meta($item->ID,'_item_active',TRUE); $_sub_frequency = get_post_meta($item->ID,'_sub_frequency',TRUE); $_sub_startdate = get_post_meta($item->ID,'_sub_startdate',TRUE); $_sub_enddate = get_post_meta($item->ID,'_sub_enddate',TRUE); $ActualPrice = foxypress_GetActualPrice($_price, $_sale_price, $_sale_start, $_sale_end); $main_inventory_image = foxypress_GetMainInventoryImage($item->ID); $form = "
" . ( ($include_quantity_field) ? "" : "" ) . "post_title) . "\" /> category_name) . "\" /> ID . "\" /> blogid . "\" /> " . ( (get_option('foxypress_include_memberid') == "1") ? "" : "" ) . foxypress_GetMinMaxFormFields($item->downloadable_id, $_quantity_min, $_quantity_max, $_quantity) . ( ($_discount_quantity_amount != "") ? "" : "" ) . ( ($_discount_quantity_percentage != "") ? "" : "" ) . ( ($_discount_price_amount != "") ? "" : "" ) . ( ($_discount_price_percentage != "") ? "" : "" ) . ( ($_sub_frequency != "") ? "" : "" ) . ( ($_sub_startdate != "") ? "" : "" ) . ( ($_sub_enddate != "") ? "" : "" ) . foxypress_BuildAttributeForm($inventory_id); return $form; } function foxypress_GetCategories() { global $wpdb; $categories = array(); $cats = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "foxypress_inventory_categories ORDER BY category_id"); if(!empty($cats)) { foreach($cats as $cat) { $categories[] = array("id" => $cat->category_id, "name" => $cat->category_name, "image" => INVENTORY_IMAGE_DIR . "/" . $cat->category_image); } return $categories; } return null; } function foxypress_GetCategoryCount($category_id) { global $wpdb; $item = $wpdb->get_row("SELECT count(i.ID) as ItemCount FROM " . $wpdb->prefix . "posts as i INNER JOIN " . $wpdb->prefix . "foxypress_inventory_to_category as ic ON i.ID=ic.inventory_id INNER JOIN " . $wpdb->prefix . "foxypress_inventory_categories as c ON ic.category_id = c.category_id LEFT JOIN " . $wpdb->prefix . "postmeta as pm_active on i.ID = pm_active.post_ID and pm_active.meta_key = '_item_active' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_start_date on i.ID = pm_start_date.post_ID and pm_start_date.meta_key = '_item_start_date' LEFT JOIN " . $wpdb->prefix . "postmeta as pm_end_date on i.ID = pm_end_date.post_ID and pm_end_date.meta_key = '_item_end_date' WHERE c.category_id='" . $category_id . "' AND i.post_type = '" . FOXYPRESS_CUSTOM_POST_TYPE. "' AND i.post_status = 'publish' AND pm_active.meta_value = '1' AND (coalesce(pm_start_date.meta_value, now()) <= now() AND coalesce(pm_end_date.meta_value, now()) >= now()) "); if(!empty($item)) { return $item->ItemCount; } return "0"; } function foxypress_GetTrackingModule() { $url = plugins_url() . "/foxypress/ajax.php"; $trackingform = "
Enter your order number
Enter your last name
"; return $trackingform; } function foxypress_GetMiniCartWidget($dropdowndisplay, $hideonzero) { if ( $dropdowndisplay == "" ) { if ( $hideonzero == "1" ) { ?>
0 items.
0.00 View Cart
Your Cart
your cart

Your Cart

item qty price
Check Out