<?php


?>

<div id="storeprima-latest-container" class="storeprima-latest-one-container">

	<div class="storeprima-latest-one-heading">
	
		<h3><?php echo esc_html(get_theme_mod('store_prima_latest_heading', __('Latest Products', "store-prima"))); ?></h3>
		<p><?php echo esc_html(get_theme_mod('store_prima_latest_text', __('Some Of Our Products', "store-prima"))); ?></p>
		
	</div>
	
	<div class="storeprima-latest-one-content">
	
		<?php

			$store_prima_products_products = array();
		
			if( class_exists( 'WooCommerce' ) ):
		
					$store_prima_products_args = array(
						'return' => 'ids',
						'limit'	=> get_theme_mod('store_prima_latest_item_num', '9'),
					);
					$store_prima_products_products = wc_get_products( $store_prima_products_args );

					if( !empty($store_prima_products_products) ):
					foreach( $store_prima_products_products as $i ) : 
					$store_prima_products_product = wc_get_product( $i );

					$store_prima_products_product_id = $i;
					$store_prima_products_product_orig_price = "";
					$store_prima_products_product_sale_price = "";
					$store_prima_products_product_on_sale = false;
					$store_prima_products_product_currency = "";
					$store_prima_products_product_type = "";
					$store_prima_products_product_name = "";
					$store_prima_products_product_desc = "";
					$store_prima_products_product_sale_amount = (int)0;
					$store_prima_products_product_variations = "";
					$store_prima_products_product_variation_name = "";
					$store_prima_products_product_variation_value = array();
					$store_prima_products_product_has_variations = "no";
					$store_prima_products_product_variation_array = array();

					$store_prima_products_product_orig_price = $store_prima_products_product->get_regular_price();
					$store_prima_products_product_sale_price = $store_prima_products_product->get_sale_price();
					$store_prima_products_product_on_sale = $store_prima_products_product->is_on_sale();
					$store_prima_products_product_currency = get_woocommerce_currency_symbol();
					$store_prima_products_product_type = $store_prima_products_product->get_type();
					$store_prima_products_product_image = wp_get_attachment_image_src( $store_prima_products_product->get_image_id(), 'full' );
					$store_prima_products_product_name = $store_prima_products_product->get_name();
					$store_prima_products_product_desc = $store_prima_products_product->get_short_description();
				
					if( $store_prima_products_product->is_type( 'variable' ) ){
						
						$store_prima_products_product_has_variations = "yes";
						
						$store_prima_products_product_variations = $store_prima_products_product->get_available_variations();
						
						foreach( $store_prima_products_product_variations as $i ){

							$store_prima_products_product_variation_array[$i["variation_id"]] = array();
							
							foreach( $i["attributes"] as $key => $value){
								$store_prima_products_product_variation_name = str_replace('attribute_','',$key);
								$store_prima_products_product_variation_value[] = $value;
								$store_prima_products_product_variation_array[$i["variation_id"]]['value'] = $value;
							}
							
							//$store_prima_products_product_variation_id[] = $i["variation_id"];
							$store_prima_products_product_variation_array[$i["variation_id"]]["display_price"] = $i["display_price"];
							$store_prima_products_product_variation_array[$i["variation_id"]]["display_regular_price"] = $i["display_regular_price"];

						}						
						
					}
				
					
				
					if( "" != $store_prima_products_product_sale_price ){
						
						$store_prima_products_product_sale_amount = ( ( floor($store_prima_products_product_orig_price * 100) - floor($store_prima_products_product_sale_price * 100) ) / 100 );
						
					}

		?>		
		<div class="storeprima-latest-one-content-item">
		
			<div class="storeprima-latest-one-content-item-image">
				<img src="<?php echo esc_url($store_prima_products_product_image[0]); ?>" />
			</div>
			<div class="storeprima-latest-one-content-item-content">
				
				<h3><a href="<?php echo esc_url($store_prima_products_product->get_permalink()); ?>"><?php echo esc_html($store_prima_products_product_name); ?></a></h3>
				<p><?php echo esc_html($store_prima_products_product_desc); ?></p>
				<p>

					<?php if( "variable" == $store_prima_products_product_type ): ?>

						<span class="storeprima-latest-one-item-price-sale"><?php echo esc_html($store_prima_products_product->get_price_html()); ?></span>

					<?php else : ?>

						<?php if( "" != $store_prima_products_product_sale_price ): ?>

							<span class="storeprima-latest-one-item-price-orig"><s><?php echo esc_html($store_prima_products_product_currency) .'' . esc_html($store_prima_products_product_orig_price); ?></s></span>
							<span class="storeprima-latest-one-item-price-sale"><?php echo esc_html($store_prima_products_product_currency) .'' . esc_html($store_prima_products_product_sale_price); ?></span>

						<?php else : ?>

							<span class="storeprima-latest-one-item-price-sale"><?php echo esc_html($store_prima_products_product_currency ).'' . esc_html($store_prima_products_product_orig_price); ?></span>

						<?php endif; ?>						

					<?php endif; ?>						
				</p>
				<p class="storeprima-latest-one-content-item-content-add-to-cart"><a href="<?php echo esc_url($store_prima_products_product->get_permalink()); ?>"><?php esc_html_e( "Details", "store-prima" ); ?></a></p>
				
			</div>			
			
		</div>
		<?php endforeach; endif; endif; ?>
		
		<?php if( !class_exists( 'WooCommerce' ) || empty($store_prima_products_products) ): ?>
		<div class="storeprima-latest-one-content-item">
		
			<div class="storeprima-latest-one-content-item-image">
				<img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/product.png" />
			</div>
			<div class="storeprima-latest-one-content-item-content">
				
				<h3><a href="#"><?php esc_html_e( "Test Product", "store-prima" ) ?></a></h3>
				<p><?php esc_html_e( "Test Product description comes here. Add some products, put some products on sale.", "store-prima" ) ?></p>
				<p>
					<span class="storeprima-latest-one-item-price-sale"><?php esc_html_e( "$20", "store-prima" ) ?></span>							
				</p>
				<p class="storeprima-latest-one-content-item-content-add-to-cart"><a href="#"><?php esc_html_e( "Details", "store-prima" ) ?></a></p>
				
			</div>			
			
		</div>
				
		<div class="storeprima-latest-one-content-item">
		
			<div class="storeprima-latest-one-content-item-image">
				<img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/product.png" />
			</div>
			<div class="storeprima-latest-one-content-item-content">
				
				<h3><a href="#"><?php esc_html_e( "Test Product", "store-prima" ) ?></a></h3>
				<p><?php esc_html_e( "Test Product description comes here. Add some products, put some products on sale.", "store-prima" ) ?></p>
				<p>
					<span class="storeprima-latest-one-item-price-sale"><?php esc_html_e( "$20", "store-prima" ) ?></span>							
				</p>
				<p class="storeprima-latest-one-content-item-content-add-to-cart"><a href="#"><?php esc_html_e( "Details", "store-prima" ) ?></a></p>
				
			</div>			
			
		</div>
				
		<div class="storeprima-latest-one-content-item">
		
			<div class="storeprima-latest-one-content-item-image">
				<img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/product.png" />
			</div>
			<div class="storeprima-latest-one-content-item-content">
				
				<h3><a href="#"><?php esc_html_e( "Test Product", "store-prima" ) ?></a></h3>
				<p><?php esc_html_e( "Test Product description comes here. Add some products, put some products on sale.", "store-prima" ) ?></p>
				<p>
					<span class="storeprima-latest-one-item-price-sale"><?php esc_html_e( "$20", "store-prima" ) ?></span>							
				</p>
				<p class="storeprima-latest-one-content-item-content-add-to-cart"><a href="#"><?php esc_html_e( "Details", "store-prima" ) ?></a></p>
				
			</div>			
			
		</div>
				
		<div class="storeprima-latest-one-content-item">
		
			<div class="storeprima-latest-one-content-item-image">
				<img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/product.png" />
			</div>
			<div class="storeprima-latest-one-content-item-content">
				
				<h3><a href="#"><?php esc_html_e( "Test Product", "store-prima" ) ?></a></h3>
				<p><?php esc_html_e( "Test Product description comes here. Add some products, put some products on sale.", "store-prima" ) ?></p>
				<p>
					<span class="storeprima-latest-one-item-price-sale"><?php esc_html_e( "$20", "store-prima" ) ?></span>							
				</p>
				<p class="storeprima-latest-one-content-item-content-add-to-cart"><a href="#"><?php esc_html_e( "Details", "store-prima" ) ?></a></p>
				
			</div>			
			
		</div>
				
		<div class="storeprima-latest-one-content-item">
		
			<div class="storeprima-latest-one-content-item-image">
				<img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/product.png" />
			</div>
			<div class="storeprima-latest-one-content-item-content">
				
				<h3><a href="#"><?php esc_html_e( "Test Product", "store-prima" ) ?></a></h3>
				<p><?php esc_html_e( "Test Product description comes here. Add some products, put some products on sale.", "store-prima" ) ?></p>
				<p>
					<span class="storeprima-latest-one-item-price-sale"><?php esc_html_e( "$20", "store-prima" ) ?></span>							
				</p>
				<p class="storeprima-latest-one-content-item-content-add-to-cart"><a href="#"><?php esc_html_e( "Details", "store-prima" ) ?></a></p>
				
			</div>			
			
		</div>
				
		<div class="storeprima-latest-one-content-item">
		
			<div class="storeprima-latest-one-content-item-image">
				<img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/product.png" />
			</div>
			<div class="storeprima-latest-one-content-item-content">
				
				<h3><a href="#"><?php esc_html_e( "Test Product", "store-prima" ) ?></a></h3>
				<p><?php esc_html_e( "Test Product description comes here. Add some products, put some products on sale.", "store-prima" ) ?></p>
				<p>
					<span class="storeprima-latest-one-item-price-sale"><?php esc_html_e( "$20", "store-prima" ) ?></span>							
				</p>
				<p class="storeprima-latest-one-content-item-content-add-to-cart"><a href="#"><?php esc_html_e( "Details", "store-prima" ) ?></a></p>
				
			</div>			
			
		</div>
				
		<div class="storeprima-latest-one-content-item">
		
			<div class="storeprima-latest-one-content-item-image">
				<img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/product.png" />
			</div>
			<div class="storeprima-latest-one-content-item-content">
				
				<h3><a href="#"><?php esc_html_e( "Test Product", "store-prima" ) ?></a></h3>
				<p><?php esc_html_e( "Test Product description comes here. Add some products, put some products on sale.", "store-prima" ) ?></p>
				<p>
					<span class="storeprima-latest-one-item-price-sale"><?php esc_html_e( "$20", "store-prima" ) ?></span>							
				</p>
				<p class="storeprima-latest-one-content-item-content-add-to-cart"><a href="#"><?php esc_html_e( "Details", "store-prima" ) ?></a></p>
				
			</div>			
			
		</div>
				
		<div class="storeprima-latest-one-content-item">
		
			<div class="storeprima-latest-one-content-item-image">
				<img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/product.png" />
			</div>
			<div class="storeprima-latest-one-content-item-content">
				
				<h3><a href="#"><?php esc_html_e( "Test Product", "store-prima" ) ?></a></h3>
				<p><?php esc_html_e( "Test Product description comes here. Add some products, put some products on sale.", "store-prima" ) ?></p>
				<p>
					<span class="storeprima-latest-one-item-price-sale"><?php esc_html_e( "$20", "store-prima" ) ?></span>							
				</p>
				<p class="storeprima-latest-one-content-item-content-add-to-cart"><a href="#"><?php esc_html_e( "Details", "store-prima" ) ?></a></p>
				
			</div>			
			
		</div>
				
		<div class="storeprima-latest-one-content-item">
		
			<div class="storeprima-latest-one-content-item-image">
				<img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/product.png" />
			</div>
			<div class="storeprima-latest-one-content-item-content">
				
				<h3><a href="#"><?php esc_html_e( "Test Product", "store-prima" ) ?></a></h3>
				<p><?php esc_html_e( "Test Product description comes here. Add some products, put some products on sale.", "store-prima" ) ?></p>
				<p>
					<span class="storeprima-latest-one-item-price-sale"><?php esc_html_e( "$20", "store-prima" ) ?></span>							
				</p>
				<p class="storeprima-latest-one-content-item-content-add-to-cart"><a href="#"><?php esc_html_e( "Details", "store-prima" ) ?></a></p>
				
			</div>			
			
		</div>
				
		<div class="storeprima-latest-one-content-item">
		
			<div class="storeprima-latest-one-content-item-image">
				<img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/product.png" />
			</div>
			<div class="storeprima-latest-one-content-item-content">
				
				<h3><a href="#"><?php esc_html_e( "Test Product", "store-prima" ) ?></a></h3>
				<p><?php esc_html_e( "Test Product description comes here. Add some products, put some products on sale.", "store-prima" ) ?></p>
				<p>
					<span class="storeprima-latest-one-item-price-sale"><?php esc_html_e( "$20", "store-prima" ) ?></span>							
				</p>
				<p class="storeprima-latest-one-content-item-content-add-to-cart"><a href="#"><?php esc_html_e( "Details", "store-prima" ) ?></a></p>
				
			</div>			
			
		</div>
				
		<div class="storeprima-latest-one-content-item">
		
			<div class="storeprima-latest-one-content-item-image">
				<img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/product.png" />
			</div>
			<div class="storeprima-latest-one-content-item-content">
				
				<h3><a href="#"><?php esc_html_e( "Test Product", "store-prima" ) ?></a></h3>
				<p><?php esc_html_e( "Test Product description comes here. Add some products, put some products on sale.", "store-prima" ) ?></p>
				<p>
					<span class="storeprima-latest-one-item-price-sale"><?php esc_html_e( "$20", "store-prima" ) ?></span>							
				</p>
				<p class="storeprima-latest-one-content-item-content-add-to-cart"><a href="#"><?php esc_html_e( "Details", "store-prima" ) ?></a></p>
				
			</div>			
			
		</div>
				
		<div class="storeprima-latest-one-content-item">
		
			<div class="storeprima-latest-one-content-item-image">
				<img src="<?php echo esc_url(get_template_directory_uri()); ?>/assets/images/product.png" />
			</div>
			<div class="storeprima-latest-one-content-item-content">
				
				<h3><a href="#"><?php esc_html_e( "Test Product", "store-prima" ) ?></a></h3>
				<p><?php esc_html_e( "Test Product description comes here. Add some products, put some products on sale.", "store-prima" ) ?></p>
				<p>
					<span class="storeprima-latest-one-item-price-sale"><?php esc_html_e( "$20", "store-prima" ) ?></span>							
				</p>
				<p class="storeprima-latest-one-content-item-content-add-to-cart"><a href="#"><?php esc_html_e( "Details", "store-prima" ) ?></a></p>
				
			</div>			
			
		</div>		
		
		<?php endif; ?>
		
	</div>	

</div>