<?php

get_header();

$product_id = types_render_field("product-id", array("output"=>"raw"));

?>
<div class="product-landing">
	<div class="container">
		<section id="content" role="main">
			<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
			<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
				<section class="entry-content">
					<div id="page-title" class="page-title"></div>
					<?php the_content(); ?>
					<div id="products" class="products" data-product-id="<?= $product_id ?>"></div>
					<?php
					$child_posts = types_child_posts('product-component');
						$child_posts_sorted = usort($child_posts, function ($a, $b) {
							$a_viewOrder = intval($a->fields['product-component-view-order']);
							$b_viewOrder = intval($b->fields['product-component-view-order']);
							if ($a_viewOrder == $b_viewOrder) { return 0; }
							return ($a_viewOrder < $b_viewOrder) ? -1 : 1;
						});

						
						

						foreach ($child_posts as $key=>$post) :
							$product_component_image		= types_render_field("product-component-image", array("raw"=>"true"));
							$product_component_name 		= types_render_field("product-component-name", array("raw"=>"true"));
							$product_component_description 	= types_render_field("product-component-description", array("raw"=>"true"));
					?>
					<div class="product-component">
						<img src="<?= $product_component_image ?>" alt="" />
						<div class="product-component-details">
							<div class="name"><?= $product_component_name ?></div>
							<div class="description"><?= $product_component_description ?></div>
						</div>
					</div>
					<?php endforeach; ?>
				</section>
			</article>		
			<?php endwhile; endif; ?>
		</section>
	</div>
</div>
<?php get_footer(); ?>
