The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

FoxyShop loading product information into an array

andersenandersen Member
in Help edited February 2013
Hi there

I'm pretty new to php so this is probably a simple request... I have a client who wants to parse a list of all products in stock as a pdf for customers to print. I have the pdf parsing down fine [fpdf generator] - I just can't get my head around how to load an array with the FoxyShop product details for all the products with inventory > 0. Can someone help me out with this?

  • fc_adamfc_adam FoxyCart Team

    Your best bet here will be @sparkweb - he built and maintains FoxyShop. He frequents the forum so I'm sure he'll be here pretty soon and will be able to point you in the right direction.
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    Hi @andersen, this is definitely do-able. What you'll want to do is to copy some of the code from foxyshop/themefiles/foxyshop-all-products.php and stick it in your printable WordPress template. This is the code that gets all the products and writes them out on the page. You'll probably want to get the code from foxyshop-product-loop.php and replace the include with the actual code on your new template page. Then you can mix and match as needed to adjust what displays. If you want to get the inventory, you'd do something like this right after the $product array gets initialized in the loop:
    $code = $product['$code']; // get the currect product code
    if (isset($product['inventory_values'][$code]['count])) { //we do have some inventory to check
    	if ($product['inventory_values'][$code]['count] > 0) continue; //move on to our next item in the big loop if the inventory is <= 0
  • andersenandersen Member
    edited February 2013
    Hi @sparkweb

    Thanks for this - it all makes sense, but when I run the file I get the page name instead of the product name in $product. Would you have a look at some code? Here's the debugging version, just asking for the product names without checking for an inventory level:
     * This file adds the Test Catalogue template to the Going Green Child Theme.
     * @author StudioPress
     * @package Generate
     * @subpackage Customizations
    Template Name: Test-Catalogue
    // Add custom body class to the head
    add_filter( 'body_class', 'goinggreen_add_body_class' );
    function goinggreen_add_body_class( $classes ) {
       $classes[] = 'goinggreen-landing';
       return $classes;
    //get_header(); //the pdf parser doesn't like html - could this contribute?
    global $product;
    class PDF extends FPDF
    // Page header
    function Header()
        // Logo
        // Arial bold 15
        // Move to the right
        // Title
        // Line break
    // Page footer
    function Footer()
        // Position at 1.5 cm from bottom
        // Arial italic 8
        // Page number
        $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
    // Instanciation of inherited class
    $pdf = new PDF();
    // *** here is the loop
    while (have_posts()) : the_post();
         global $product, $post;
         $product = foxyshop_setup_product();
         $pdf->Cell(0,25,$product['name'],0,1);  // it didn't like the apply_filters() either
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    edited February 2013
    This is just doing a loop for the current page. You want to run a special query for products like so:
    global $wp_query;
    	$paged = get_query_var('page');
    	$args = array('post_type' => 'foxyshop_product', 'post_status' => 'publish', 'posts_per_page' => -1);
    	$args = array_merge($args,foxyshop_sort_order_array());
    	echo '<ul class="foxyshop_product_list">';
    	while (have_posts()) :
    	     global $product, $post;
    	     $product = foxyshop_setup_product();
    	     $pdf->Cell(0,25,$product['name'],0,1);  // it didn't like the apply_filters() either

    EDIT: See the foxyshop-all-products.php page in the /themefiles/ for the example that I grabbed.
  • that was the piece that made it all fall into place, thanks so much :D
  • Hi again - one more question. I want to check the category of a product in the loop and include/exclude it by category. like this:
    if ($product['category'] = "category") continue;

    i understand it's the wrong direction for that type of variable, is there a way to check which category the product is in?
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    @andersen, a product could be in many different categories, so it goes like this:
  • hi again! thanks so much for your great help so far. I have a problem that when the single product displays, the Add to Cart button is disabled even though the default variation seems to be automatically selected. if the buyer wants the default variation, they have to click a different variation, and then reclick the default. Is there a way to enable the Add to Cart button straight away?
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    Could you whisper your url so I could see what's going on?
  • I'm having trouble getting the whisper to work... I'll email you directly :)
Sign In or Register to comment.