Unhandled Error!

Invalid argument supplied for foreach()

Document /modules/prp/classes/prp_util.php
Document type PHP document
Line 145
Exception class Phpr_PhpException

Code Highlight

    public static function getCategoryHierarchyText($category_list, $name) {
        $root_cat = self::getCategoryHierarchy($category_list, $name);
        $children = $root_cat->children;
        $o        = array();
        $o      []= $root_cat->name;
 
        foreach ( $children as $child )
        {
            $o []= $child->name;
            foreach ( $child->children as $sub_cat )
            {
                $o []= $sub_cat->name;
                break;//Only display one category
# Call Stack Code Document Line
19 Prp_Util::getCategoryHierarchyText(object(Db_DataCollection), 'Books') /modules/cms/classes/cms_controller.php(383) : eval()'d code 218
18 eval(()) /modules/cms/classes/cms_controller.php 383
17 Cms_Controller->evalWithException('?><?php $prp_string = new Prp_String(); $hr = '<hr class="product_list_hr">'; if (isset($paginate) && $paginate) { $page_index = isset($page_index) ? $page_index-1 : 0; $records_per_page = isset($records_per_page) ? $records_per_page : 10; $pagination = $products->paginate($page_index, $records_per_page); } else { $pagination = null; } if ($pagination) { $this->render_partial('prp_pagination', array('pagination'=>$pagination, 'base_url'=>$pagination_base_url, 'class'=>'pagination pagination_top')); } ?> <div class="product_list"> <? $products = $products instanceof Db_ActiveRecord ? $products->find_all() : $products; $total_products = sizeof($products); $i = 0; /* $product_ids = array(); foreach ($products as $product) { $product_ids []= $product->x_prp_book_id; } $author_sql = "SELECT pap.author_id,pap.book_id,pa.first_name,pa.last_name FROM "; $author_sql .= "prp_authors_products pap LEFT JOIN prp_authors pa ON (pap.author_id = pa.author_id ) "; $author_sql .= "WHERE pap.book_id IN ( ". implode(',', $product_ids) ." )"; $authors = array(); if ( sizeof($product_ids) ) { $authors = Db_DbHelper::objectArray( $author_sql ); } */ foreach ($products as $product): $is_discounted = $product->is_discounted(); $i++; $last_product = ($total_products - $i) == 0 ? true : false; /* $author_names = array(); foreach( $authors as $a ) { if ( $a->book_id == $product->x_prp_book_id ) { $name = h( $a->first_name.' '.$a->last_name ); $link = '/author/'.$prp_string->urlify( $name ); $author_names []= "<a href='$link'>$name</a>"; } } */ $authors = Prp_Util::getContributorArray( $product->category_list, "Authors", $product->x_prp_contributor_order ); $v_editors = Prp_Util::getContributorArray( $product->category_list, "Volume Editors", $product->x_prp_contributor_order ); $contributors = Prp_Util::getContributorArray( $product->category_list, "Contributors", $product->x_prp_contributor_order ); $bargain_class = ''; $bargain_text = ''; if( Prp_Util::hasCategory( $product->category_list, "Bargain Books" ) ) { $bargain_class = 'bargain'; $bargain_text = 'Bargain'; } elseif (Prp_Util::hasCategory( $product->category_list, "Super Bargain Books" )) { //append super bargain to add yellow bg $bargain_class = 'bargain super-bargain'; $bargain_text = 'Super<br/>Bargain'; } ?> <div class="product_list_box"> <? //$image_url = $product->image_url(0, 130, 130); $isbn = Prp_String::removeDashes( $product->x_prp_isbn ); /* $image_url = 'http://prpbooks.com/image/w/80/inventory/hi-res/'.$isbn.'.jpg'; $image_url = 'holder.js/80x120'; //$image_url = 'https://s3.amazonaws.com/com.prpbooks/images/covers/sm/'.$isbn.'.jpg'; */ $blank_image = Prp_Util::getFileUrl('images/misc/placeholder/tmp_book_bg.png'); $image_url = preg_match('/\d+/', $isbn ) ? Prp_Util::getCoverUrl( $isbn, 'sm' ) : $blank_image; if ($image_url): ?> <div class="float_left"> <a href="<?= $product->page_url('/book') ?>"> <img class="product_image" src="<?= $blank_image ?>" data-src="<?= $image_url ?>" alt="<?= h($product->name) ?>"/> </a> <? if ($bargain_class !== ''): ?> <div class="<?= $bargain_class ?>"><?= $bargain_text ?></div> <? endif ?> </div> <? endif ?> <div class="info_box info float_left"> <h4> <a href="<?= $product->page_url('/book') ?>"> <?= h($product->name) ?> <? if ( $product->x_prp_subtitle != '' ): ?> <span class="product_list_subtitle"><?= h($product->x_prp_subtitle) ?></span> <? endif ?> </a> </h4> <?php if ( sizeof($authors) ) { $author_links = array(); foreach ($authors as $author) { $author_links []= $author['link']; } echo '<div class="product_contributors">'. implode(", ", $author_links).'</div>'; } if ( sizeof($v_editors) ) { $editor_links = array(); foreach ($v_editors as $editor) { $editor_links []= $editor['link']; } echo '<div class="product_contributors"><i>edited by</i> '. implode(", ", $editor_links).'</div>'; } if ( sizeof($contributors) ) { $contributor_links = array(); foreach ($contributors as $contributor) { $contributor_links []= $contributor['link']; } $cols = 3; if (sizeof($contributor_links) < $cols) { echo '<div class="product_contributors"><i>contributions from</i> '. implode(", ", $contributor_links).'</div>'; } else { echo '<div class="product_contributors"><i>contributions from</i></div>'; $this->render_partial('prp_contributor_rows', array('contributor_links' => $contributor_links)); } } ?> <p> <?= $prp_string->shortenString( preg_replace('/<br \/>/', ' ', strip_tags( $product->description, '<br>' ) ), 190 ) ?> </p> <? $final_price = $product->price; $price_type = ''; $p_class = ''; $price_details = Prp_Util::getProductPriceDetails($product); if ($price_details['is_discounted']) { $price_type = $price_details['is_direct'] ? 'Direct ' : $price_details['bargain_type'].' '; $p_class = 'class="strike"'; } ?> <div class="float_left"> <table class="product_details"> <tr> <th>Format</th> <? $formats = Prp_Util::getFormats( $product ); $formats = implode(', ', $formats); $ebook_only = $formats == 'eBook'; ?> <td><?= $formats ?></td> </tr> <tr> <th>ISBN</th> <td><?= h($isbn) ?></td> </tr> <? if (!$ebook_only && $product->track_inventory) { ?> <tr> <th>Availability:</th> <td> <? if ($product->in_stock > 0) { ?> <strong><?= $product->in_stock ?></strong> in stock <? } else { ?> Out of stock <? } ?> </td> </tr> <? } ?> <tr> <th><?= $price_type ?>Price</th> <td> <span <?= $p_class ?>> <?= format_currency($product->price) ?> </span> <? if ($price_details['is_discounted']): ?> <? $final_price = $price_details['price'] ?> <span class='sale'> <span class='<?= $price_details['is_direct'] ? '' : 'red' ?>'> <?= format_currency($price_details['price']) ?> </span> </span> <? endif ?> </td> </tr> <? if ( $url_parent == 'coming-soon' ): ?> <tr> <th>Release Date</th> <td><?= $product->x_prp_release_date->format('%m/%d/%y') ?></td> </tr> <? endif ?> </table> </div> <div class="float_right"> <? if (!$product->is_out_of_stock() && Prp_Util::isProductReleased($product) && $url_parent != 'ebooks' && !Prp_Util::isBible($product) ): ?> <?= open_form( array('action'=>$product->page_url('/book') ) ) ?> <?/* <!-- <input onclick="return $(this).getForm().sendRequest('shop:on_addToCart', {update: {'mini_cart': 'shop:mini_cart', 'product_page': 'product_partial'}})" type="image" name="add_to_cart" class="add_to_cart" src="<?= root_url('/themes/default/resources/images/add-to-cart.png') ?>" alt="Add to cart"/> --> */?> <br/> <? $this->render_partial('prp_add_to_cart', array('name' => h($product->name), 'category' => h(Prp_Util::getCategoryHierarchyText($product->category_list, "Books")), 'pid' => $product->id, 'price' => $final_price )); ?> </form> <? endif ?> <div class="ebook-links float_left"> <? if ( $product->x_prp_kindle_url ): ?> <a href="<?= $product->x_prp_kindle_url ?>"> <div class="kindle_color rounded"> Kindle </div> </a> <? endif ?> <? if ( $product->x_prp_itunes_url ): ?> <a href="<?= $product->x_prp_itunes_url ?>"> <div class="itunes_color rounded"> iTunes/ePub </div> </a> <? endif ?> </div> <div class="clear"></div> </div> <div class="clear"></div> </div> <div class="clear"></div> </div> <?= $last_product ? '' : $hr ?> <? endforeach ?> </div> <? if ($pagination) { $this->render_partial('prp_pagination', array('pagination'=>$pagination, 'base_url'=>$pagination_base_url)); } ?> <script type="text/javascript"> $(document).ready(function() { var isMobDevice = (/iphone|ipad|Android|webOS|iPod|BlackBerry|Windows Phone|ZuneWP7/gi).test(navigator.appVersion); if(!isMobDevice){ $('.product_list img').show().lately(); }else{ $('.product_list img').each(function(){ $(this).attr('src',$(this).data('src')); }); } <? $this->render_partial('facebook_pixel_addtocart'); ?> }); </script> ', 'CMS partial', 'prp_product_list', array(5) [products => object(Shop_Product), records_per_page => '10', paginate => '1', pagination_base_url => '/books/counseling/counseling-books', page_index => 'counseling-books']) /modules/cms/classes/cms_controller.php 1020
16 Cms_Controller->render_partial('prp_product_list', array(5) [products => object(Shop_Product), records_per_page => '10', paginate => '1', pagination_base_url => '/books/counseling/counseling-books', page_index => 'counseling-books']) /modules/cms/classes/cms_controller.php(383) : eval()'d code 176
15 eval(()) /modules/cms/classes/cms_controller.php 383
14 Cms_Controller->evalWithException('?><? //Save the category product sorting mode if it has been changed. if (post('sorting')) { //Cms_VisitorPreferences::set('cat_sorting_'.$category->id, post('sorting')); Cms_VisitorPreferences::set('cat_sorting', post('sorting')); } //Load the product sorting mode. The default mode is 'name'. //$sorting_preferences = Cms_VisitorPreferences::get('cat_sorting_'.$category->id, array('name')); $sorting_preferences = Cms_VisitorPreferences::get('cat_sorting', array('url_name')); $selected_option = $sorting_preferences[0]; //$sorting_preferences = array('name'); $products = null; $extra = ''; //Display by letter if ( preg_match('/^[a-zA-Z]{1}$/',$url_parent) ) { $products = $category->list_products(array( 'sorting'=>$sorting_preferences )); //Search url_name so "it's not fair" and "Right Reason" show up. //The issue is that the quote gets in the way and there is no quote in the url_name $products->where( "url_name LIKE ?", $url_parent."%" ); $extra = '/'.$url_parent; } elseif ( $url_parent == '0-9' ) { $sql = array(); for( $i=0; $i <= 9; $i++ ) { $sql []= "shop_products.name like '$i%'"; } $products = $category->list_products(array( 'sorting'=>$sorting_preferences )); $products->where( implode( ' OR ', $sql ) ); $extra = '/'.$url_parent; } //This is coming from /category/extra/new-releases not /books/new-releases elseif ( $url_parent == 'new-releases' ) { $products = Prp_Util::getNewReleases(); $extra = '/'.$url_parent; } elseif ( $url_parent == 'coming-soon' ) { $products = Prp_Util::getComingSoon(); $extra = '/'.$url_parent; } elseif ( $url_parent == 'bargain-books' ) { /* $category = Shop_Category::create()->find_by_code('bargain-books'); if ($category) { $products = $category->list_products(array( 'sorting'=>$sorting_preferences )); } */ $products = $category->list_products(array( 'sorting'=>$sorting_preferences )); } elseif ( $url_parent == 'super-bargain-books' ) { /* $category = Shop_Category::create()->find_by_code('super-bargain-books'); if ($category) { $products = $category->list_products(array( 'sorting'=>$sorting_preferences )); } */ $products = $category->list_products(array( 'sorting'=>$sorting_preferences )); $this->render_partial('prp_mailchimp_superbargain_form'); } elseif ( $url_parent == 'ebooks' ) { $products = Prp_Util::getDigitalBooks(); $extra = '/'.$url_parent; } elseif ( $url_root == 'authors' ) { //Remove the unique number from a category //These are added because people can exist in multiple categories //r-c-sproul-1 -> r-c-sproul $url_name = preg_replace('/-\d+$/', '', $url_parent).'%'; $obj = new Shop_Product(); $obj->join('shop_products_categories', 'shop_products.id = shop_products_categories.shop_product_id'); $obj->join('shop_categories', 'shop_categories.id = shop_products_categories.shop_category_id'); $products = $obj->where('shop_categories.url_name LIKE ?', $url_name); //$products = $obj->where('shop_categories.url_name != ?', 'super-bargain-books'); } //Default if ($products == null) { $products = $category->list_products(array( 'sorting'=>$sorting_preferences )); $products->where('shop_products.url_name NOT LIKE ?', '%_b'); $products->Where('shop_products.url_name NOT LIKE ?', '%_sb'); /* $cat_url_name = $url_root; $cat_url_name = $url_parent ? $url_parent : $cat_url_name; $cat_url_name = $url_name ? $url_name : $cat_url_name; $products = new Shop_Product(); $products->join('shop_products_categories', 'shop_products.id = shop_products_categories.shop_product_id'); $products->join('shop_categories', 'shop_categories.id = shop_products_categories.shop_category_id'); $products->where('shop_categories.url_name = ?', $cat_url_name); $products->where('shop_products.url_name NOT LIKE ?', '%_b'); $products->orWhere('shop_products.url_name NOT LIKE ?', '%_sb'); //$products->where('shop_categories.url_name <> ?', 'bargain-books'); //$products->where('shop_categories.url_name <> ?', 'super-bargain-books'); $products->order($selected_option); foreach ($sorting_preferences as $key => $value) { traceLog("key: $key value: $value"); } traceLog("url_root: ($url_root)"); traceLog("url_parent: ($url_parent)"); traceLog("url_name: ($url_name)"); */ } $page_index = $this->request_param(-1, 0); //echo 'Page index: '. $page_index; ?> <?= open_form() ?> <p class="float_right"> <? //Save the category product sorting mode if it has been changed. if (post('sorting')) { //Cms_VisitorPreferences::set('cat_sorting_'.$category->id, post('sorting')); Cms_VisitorPreferences::set('cat_sorting', post('sorting')); } //Load the product sorting mode. The default mode is 'name'. //$sorting_preferences = Cms_VisitorPreferences::get('cat_sorting_'.$category->id, array('name')); $sorting_preferences = Cms_VisitorPreferences::get('cat_sorting', array('url_name')); $selected_option = $sorting_preferences[0]; ?> <select onchange="$(this).getForm().sendRequest('on_action', {update: {'category_products': 'shop:category'}})" name="sorting[]"> <option <?= option_state('url_name', $selected_option) ?> value="url_name">A&ndash;Z Title</option> <option <?= option_state('url_name desc', $selected_option) ?> value="url_name desc">Z&ndash;A Title</option> <? /* <option <?= option_state('price desc', $selected_option) ?> value="price desc">Price: High to Low</option> <option <?= option_state('price', $selected_option) ?> value="price">Price: Low to High</option> */ ?> </select> </p> <div class="clear"></div> </form> <? $this->render_partial('prp_product_list', array( 'products'=>$products, 'records_per_page'=>10, 'paginate'=>true, 'pagination_base_url'=>$category->page_url('').$extra, //'pagination_base_url'=>'/'.$category->url_name, 'page_index'=>$page_index )); ?>', 'CMS partial', 'shop:category', array(0)) /modules/cms/classes/cms_controller.php 1020
13 Cms_Controller->render_partial('shop:category', array(0), array(3) [cache => '1', cache_vary_by => array(1), cache_versions => array(1)]) /modules/cms/classes/cms_controller.php(383) : eval()'d code 78
12 eval(()) /modules/cms/classes/cms_controller.php 383
11 Cms_Controller->evalWithException('?><div class="side_by_side_products_off"> <? if (!$category): ?> <h2>We are sorry, the specified category not found.</h2> <? else: //echo Phpr::$session->get( 'continue_shopping_page', 'not set' ); $parent_category = $category->parent; $name = '<a href="/'.$category->url_name.'">'.$category->name.'</a>'; if ($category->name != 'Books') { if (is_a($parent_category, 'Shop_Category') && $parent_category->name != 'Books' && $parent_category->name != 'Series' && $parent_category->name !== null) { $p_url = '<a href="/books/'.$parent_category->url_name.'">'.$parent_category->name.'</a>'; if ($parent_category->name == 'Authors') { $p_url = '<a href="/'.$parent_category->url_name.'">'.$parent_category->name.'</a>'; } //$name = '<a href="/'. $parent_category->url_name .'/'.$category->url_name.'">'.$category->name.'</a>'; $name = $category->name; $name = $p_url . ' &raquo; ' . $name; } } else { $name = 'Books'; } if ( preg_match('/^[a-zA-Z]{1}$/',$url_parent) ) { $name = 'Titles beginning with "'.strtoupper($url_parent).'"'; } elseif ( $url_parent == '0-9' ) { $name = 'Titles beginning with "0-9"'; } elseif ($url_parent == 'new-releases') { $name = 'New Releases'; } elseif ($url_parent == 'coming-soon') { $name = 'Coming Soon'; } elseif ($url_parent == 'bargain-books') { $name = 'Bargain Books'; } elseif ($url_parent == 'super-bargain-books') { $name = 'Super Bargain Books'; } elseif ($url_parent == 'ebooks') { $name = 'eBooks'; } $author_page = $url_root == 'authors'; $author_style = $author_page ? ' style="width:415px"' : ''; ?> <div class="float_left" <?= $author_style ?>> <h1><?= $name ?></h1> <? if ( $category->description ): ?> <div class="description"><?= $category->description ?></div> <? endif ?> </div> <? if ($author_page): ?> <div class='float_right author_page'> <img class='contributor' alt='<?= $name ?>' src='<?= Prp_Util::getAuthorImgUrl($name) ?>' /> </div> <script type="text/javascript" src="/themes/default/resources/javascript/contributor.js"></script> <? endif ?> <div class='clear'></div> <div id="category_products"> <?php $this->render_partial('shop:category', array(), array( 'cache'=>true,// Enable caching 'cache_vary_by'=>array('url'), // We are going to reuse this partial on different pages, but its content can be different for different pages so we want to create different partial cache versions for different pages 'cache_versions'=>array('catalog') ) ); ?> </div> <? endif ?> </div>', 'CMS page', 'Category') /modules/cms/classes/cms_controller.php 608
10 Cms_Controller->eval_page_content(()) /modules/cms/classes/cms_controller.php 198
9 Cms_Controller->open(object(Cms_Page), array(3) [0 => 'books', 1 => 'counseling', 2 => 'counseling-books']) /controllers/application.php 72
8 Application->On404(())
7 call_user_func_array(array(2) [0 => object(Application), 1 => 'On404'], array(0)) /phproad/modules/phpr/classes/phpr_controller.php 170
6 Phpr_Controller->executeAction('On404', array(0)) /phproad/modules/phpr/classes/phpr_controller.php 84
5 Phpr_Controller->_run('On404', array(0)) /phproad/modules/phpr/classes/phpr_response.php 64
4 Phpr_Response->open404(()) /phproad/modules/phpr/classes/phpr_response.php 37
3 Phpr_Response->open('/category/books/counseling/counseling-books') /phproad/system/phproad.php 31
2 include('/usr/share/nginx/www/phproad/system/phproad.php') /boot.php 114
1 require_once('/usr/share/nginx/www/boot.php') /index.php 3