Marketpress 3.0.0.3 Custom product templates not showing images for variations

Wondering if anybody else is having this issue.

I have set up mp_product.php in my theme for the custom template of a product.

Works great for products with no variations, images display as expected. However for products that have variations, the images don't show.

Is anybody else seeing this same issue occur?

  • Vinod Dalvi

    Hi Ben,

    I hope you are well today and thanks for posting on the forum.

    What @jan has described above is correct that in the latest 3.0 version of MarketPress plugin we are saving the images in the "Product Images" meta box and not as featured image so you have to change your code in your mp_product.php file to display the image from this meta box.

    Please advise.

    Kind Regards,
    Vinod Dalvi

  • Vinod Dalvi

    Hi Ben,

    The sample code is as following.

    $has_image = false;
    		if ( ! $product->has_variations() ) {
    			$values = get_post_meta( $product->ID, 'mp_product_images', true );
    			if ( $values ) {
    				$has_image = true;
    			}
    		} else {
    			foreach ( $product->get_variation_ids() as $id ) {
    				$post_thumbnail_id = get_post_thumbnail_id( $id );
    				if ( $post_thumbnail_id ) {
    					$has_image = true;
    					break;
    				}
    			}
    		}
    
    		$image_alignment = mp_get_setting( 'image_alignment_single' );
    
    		$return = '
    			<!-- MP Single Product -->
    			<section id="mp-single-product" itemscope itemtype="http://schema.org/Product">
    				<div class="mp_product mp_single_product' . ( $has_image ? ' mp_single_product-has-image mp_single_product-image-' . ( ! empty( $image_alignment ) ? $image_alignment : 'aligncenter' ) . '' : '' ) . ( $product->has_variations() ? ' mp_single_product-has-variations' : '' ) . '">';
    
    		$values = get_post_meta( $product->ID, 'mp_product_images', true );
    
    		if ( mp_get_setting( 'product_img_size' ) == 'custom' ) {
    			$size = array(
    				mp_get_setting( 'product_img_size_custom->width' ),
    				mp_get_setting( 'product_img_size_custom->height' )
    			);
    		} else {
    			$size = mp_get_setting( 'product_img_size' );
    		}
    
    		$lightbox_code = '';
    		$show_lightbox = mp_get_setting( 'show_lightbox' );
    
    		if ( $show_lightbox == 1 ) {
    			$lightbox_code = "onSliderLoad: function(el) {
    											el.lightGallery({
    												selector: '#mp-product-gallery .lslide',
    												thumbnail: true,
    												zoom: true,
    											});
    										}";
    		}
    
    		if ( $image && $has_image ) {
    			if ( ! $product->has_variations() ) {
    
    				if ( $values ) {
    
    					$return .= '<div class="mp_single_product_images">';
    
    					$return .= "<script>
    								jQuery(document).ready(function() {
    									jQuery('#mp-product-gallery').lightSlider({
    										gallery:true,
    										item:1,
    										loop:true,
    										thumbItem:5,
    										slideMargin:0,
    										enableDrag: true,
    										currentPagerPosition:'left',
    										" . $lightbox_code . "
    									});
    								});
    								</script>";
    
    					$return .= '<ul id="mp-product-gallery" class="mp_product_gallery">';
    
    					$values = explode( ',', $values );
    
    					if( $image != "single" ) {
    						foreach ( $values as $value ) {
    
    							if ( preg_match( '/http:|https:/', $value ) ) {
    								$img_url = array( esc_url( $value ) );
    							} else {
    								//$img_url = wp_get_attachment_image_src( $value, $size );
    								$original_image = wp_get_attachment_image_src( $value, 'full' );
    								$img_url        = mp_resize_image( $original_image[0], $size );
    							}
    
    							$return .= '<li data-thumb="' . $img_url[0] . '" data-src ="' . $original_image[0] . '"><img src="' . $img_url[0] . '"></li>';
    						}
    					} else {
    						if( ! empty( $values[ 0 ] ) ) {
    
    							if ( preg_match( '/http:|https:/', $values[ 0 ] ) ) {
    								$img_url = array( esc_url( $values[ 0 ] ) );
    							} else {
    								$original_image = wp_get_attachment_image_src( $values[ 0 ], 'full' );
    								$img_url        = mp_resize_image( $original_image[0], $size );
    							}
    
    							$return .= '<li data-thumb="' . $img_url[0] . '" data-src ="' . $original_image[0] . '"><img src="' . $img_url[0] . '"></li>';
    						}
    					}
    
    					$return .= '</ul><!-- end mp_product_gallery -->';
    
    					$return .= '</div><!-- end mp_single_product_images -->';
    				}
    			} else {
    
    				$return .= '<div class="mp_single_product_images">';
    				$return .= ( $variation ) ? $variation->image( false, $image, $size, $image_alignment ) : $product->image( false, $image, $size, $image_alignment );
    				$return .= '</div><!-- end mp_single_product_images -->';
    			}
    		}

    You will find this code in the following MarketPress plugin file in the mp_product function on line number 2239

    wp-content/plugins/marketpress/includes/common/template-functions.php

    Best Regards,
    Vinod Dalvi

  • Ben

    @Vinod Dalvi

    I'm not sure if we are communicating on the issue, I haven't tried your code, but clearly...its not working.

    I am making a call to the mp_product function, here's the broad strokes of my mp_product.php template.

    while (have_posts()) : the_post();
       mp_product($post->ID);
    endwhile;

    So this will show images (both for 1 image and for multi-images) and everything else properly for non-variation products, however if the product contains variations (and images are set up with the variations) the template fails to show images.

    If I do not have a custom product template set up then the variation images show properly.

    To clarify, are you telling me that I am doing something wrong and not using the mp_product function properly, or do you agree there there is a major bug that needs to be fixed.

    Thanks!

  • Ben

    ...been 3 days since I posted this. I'm pretty sure the custom template product are broken for every single site out there...isn't this kinda serious...?

    Right now to overcome the issue I have removed the custom template and have added custom css to the site to mimic the custom template as best I can.

    That said would love to have a fix or at least an acknowledgement that you have tested the issue and can see it.

    Thanks.

    Thank.

  • Vinod Dalvi

    Hi Ben,

    For me on my test the product images are displaying fine for both product with variations and with out variations so i thought there must be the issue with the custom code that you have developed.

    If you don't use the custom code then it must work for you also with the products containing variations.

    Please make sure you have added the images for every product variation on clicking the image icon as shown in the attached screenshot.

    If it also doesn't work for you after setting images for product variations then this can be due to plugin/theme conflict on your site.

    You can just try on your development site temporary using default WordPress theme like Twenty Fifteen and temporary deactivating all other plugins and activating them one by one as displayed in the following flowchart to know which theme/plugin is conflicting if any.

    https://premium.wpmudev.org/manuals/getting-support/

    Regards,
    Vinod Dalvi

  • Ben

    Can you please show me a working copy of mp_product.php template. PLEASE test to confirm it is working for products that have variation images...Thank you

    <?php
    /**
     * The Template for displaying all single posts.
     *
     * @package duena
     */
    get_header(); ?>
    	<div id="primary" class="col-md-12">
    		<div id="content" class="site-content" role="main">
    			<div class="page_wrap">
    				<?php while (have_posts()) : the_post(); ?>
    						<div class="row">
    							<div class="col-md-12">
    							<?PHP mp_product($post->ID); ?>
    							</div>
    						</div> <!-- #nd the col 8 -->
    					<?PHP endwhile; // end of the loop. ?>
    			</div> <!-- #pagewrap -->
    		</div><!-- #content -->
    	</div><!-- #primary -->
    <?php
    get_footer(); ?>
  • Rupok

    Hi Ben

    I hope you had a wonderful day.

    I just checked the current status and it seems like, our developers are still on it. Please keep in mind that our developers work round the clock and they have to deal with many critical issues. So it may take a little while before they release an update.

    And an update comes with lots of bug fixes and features update. So it takes a little time for us to release e new update. Please keep your plugins and themes updated to get all the latest update from us.

    Have a nice day. Cheers!
    Rupok

  • Kieran

    Hi Rupok,

    Appreciate you're still working on the issue but it's been 3 months now. How much longer do we have to wait to ensure we get images working in the shopping cart as worked perfectly fine in previous 2.9.X versions!?

    It's quite a critical bug in my opinion. Along with a number of other issues I have with marketpress not really talking to Appointments+ very well but I'm feeling like not much progression is being made :slight_frown:

    Kind Regards
    Kieran

  • Rupok

    Hi Kieran

    I just checked the task assigned to our developer and it seems like there is something critical behind this task. Might be lots of other things depend on this, or implementing this breaks some other things, so still there is no complete fix available on that task. And please keep in mind, they work round the clock but they has to deal with lots of other issues like this one.

    Still for confirming, I just tested this on MarketPress 3.0.0.7 and seems like the issue is still there. I do admit that's it's getting delayed so I'm contacting our developer again to give priority to this task. Thanks a lot for your patience.

    Have a nice day. Cheers!
    Rupok

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.