Marketpress Upgrade to 3.0 -> Issues in custom mp_product.php template file

Hey there,

I am having an issue with a custom template for mp_product.php. Since upgrading the installation to the latest today, my code in the custom template file:

<?php mp_buy_button(true, 'single'); ?>

No longer has the desired effect of adding the product to the cart for the user.

Can you advise what has replaced this insertion code for the buy now button so I can add it into my template file?

  • Adam Czajczyk

    Hello tomtranmer,

    I hope you're well today and thank you for your question!

    According to in-file documentation the "mp_buy_button()" function is still there and should work:

    /**
    	 * Display the buy or add to cart button
    	 *
    	 * param bool $echo Optional, whether to echo
    	 * param string $context Options are list or single
    	 * param int $post_id The post_id for the product. Optional if in the loop.
    	 */
    	function mp_buy_button( $echo = true, $context = 'list', $product_id = null )

    I think however that you may want to double check whether the function is used inside the loop or not. If it's outside the loop the "$product_id" parameter is obligatory because otherwise it will not be able to determine which product it should use.

    Would you please double-check that and let me know? It would also be great if you could share an entire code of your mp_product.php template file with me. To do this, you could either post it in your replay here and mark as a "code" or create a pastebin and share a link to it with me.

    Best regards,
    Adam

  • tomtranmer

    Thanks for your response.

    Attached is the mp_product file. I did try to explicitly specify the Product ID (which appears to be returning the correct ID).

    Things work fine when adding to the cart from the basic template, so it myst be something wrong in mine. Any help you can provide in fixing it up would be swell.

    mp_product template file follows:

    <?php get_header(); ?>
    
    			<div id="content" class="clearfix row">
    
    				<div id="main" class="col-sm-12 clearfix" role="main">
    
    					<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    					<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting">
    						<?php
    						// check if the post has a Post Thumbnail assigned to it.
    						if ( has_post_thumbnail() ) {
    							the_post_thumbnail('full', array('class' => 'page_header'));
    						}
    						?>
    						<header>
    
    							<div class="page-header" style="border-bottom: none; margin: 20px 0 10px;">
    								<div class="row">
    									<div class="col-sm-6 col-sm-offset-6">
    										<h1 class="page-title" style="float:left; text-transform: uppercase;l font-size: 26px" itemprop="headline"><?php the_title(); ?></h1>
    										<div style="clear:both"></div>
    										<?php mp_buy_button(true, 'single'); ?>
    
    										<!-- <button class="mp_button mp_button-buynow" type="submit" name="buynow"><?php _e( 'Buy Now', 'mp' ); ?></button> -->
    									</div>
    								</div>
    							</div>
    
    							<div style="clear:both"></div>
    
    						</header> <!-- end article header -->
    
    						<section class="post_content clearfix" itemprop="articleBody">
    							<?php 
    
    							the_content(); 
    
    							echo '<div style="clear:both"></div>';
    
    							// mp_product_price(true);
    							// mp_buy_button(true, 'single');
    							/* echo mp_category_list($post->ID, '
    								<div class="mp_product_categories">' . __( 'Categorized in ', 'mp' ), ', ', '</div>
    							'); */
    
    							?>
    
    						</section> <!-- end article section -->
    
    						<div class="disclaimer" style="margin-top: 10px">
    							<p><strong>Disclaimer:</strong> All information contained, written, portrayed or visualized on this website should not be taken as a form of diagnosis, treatment or prescription. It is strongly advised that you seek the assistance of a competent wellness professional before embarking on any changes to your personal well being. No claims are made for promissory reason and any information contained on this site is for educational purposes only. Any statements made have not been evaluated by the FDA or CHB and should never take the place of or be considered a substitution for the advice of your qualified health care provider.</p>
    						</div>
    
    <!-- 						<div class="row">
    							<div class="col-xs-10 col-xs-offset-1">
    								<h3>You might also be interested in...</h3>
    								<?php mp_list_products(true, true, 0, 3, 'sales', 'DESC'); ?>
    							</div>
    						</div> -->
    
    						<footer>
    
    							<?php the_tags('<p class="tags"><span class="tags-title">' . __("Tags","wpbootstrap") . ':</span> ', ', ', '</p>'); ?>
    
    						</footer> <!-- end article footer -->
    
    					</article> <!-- end article -->
    
    					<?php // comments_template('',true); ?>
    
    					<?php endwhile; ?>		
    
    					<?php else : ?>
    
    					<article id="post-not-found">
    					    <header>
    					    	<h1><?php _e("Not Found", "wpbootstrap"); ?></h1>
    					    </header>
    					    <section class="post_content">
    					    	<p><?php _e("Sorry, but the requested resource was not found on this site.", "wpbootstrap"); ?></p>
    					    </section>
    					    <footer>
    					    </footer>
    					</article>
    
    					<?php endif; ?>
    
    				</div> <!-- end #main -->
    
    				<?php // get_sidebar(); // sidebar 1 ?>
    
    			</div> <!-- end #content -->
    
    <?php get_footer(); ?>
  • Adam Czajczyk

    Hello tomtramner!

    I tested your template on my own setup and I can confirm the issue. I've noticed however that the button doesn't trigger AJAX call the same way as the "regular" buy button does. I've tested some other variants including using recommended "mp_*" functions instead of "the_content()" in template but with no luck so far.

    That said, I'm calling our second line support team for help here and hopefully they'll be able to give us some helping hand here. Please not however that their response time may be a bit longer than mine here on support forum as they deal with a lot of complex issues on daily basis.

    Please keep an eye on this thread fur further information.

    Best regards,
    Adam

  • George

    Hi tomtranmer,

    I hope you’re having a good day. :slight_smile:

    Please check below code to make your custom mp_product.php template compatible with MarketPress 3.0.0.7.

    <?php get_header(); ?>
    
    			<div id="content" class="clearfix row">
    
    				<div id="main" class="col-sm-12 clearfix" role="main">
    
    					<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    					<article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting">
    						<?php
    						// check if the post has a Post Thumbnail assigned to it.
    						if ( has_post_thumbnail() ) {
    							the_post_thumbnail('full', array('class' => 'page_header'));
    						}
    						?>
    						<header>
    
    							<div class="page-header" style="border-bottom: none; margin: 20px 0 10px;">
    								<div class="row">
    									<div class="col-sm-6 col-sm-offset-6">
    										<h1 class="page-title" style="float:left; text-transform: uppercase;l font-size: 26px" itemprop="headline"><?php the_title(); ?></h1>
    										<div style="clear:both"></div>
    										<?php mp_buy_button(true, 'single'); ?>
    
    										<!-- <button class="mp_button mp_button-buynow" type="submit" name="buynow"><?php _e( 'Buy Now', 'mp' ); ?></button> -->
    									</div>
    								</div>
    							</div>
    
    							<div style="clear:both"></div>
    
    						</header> <!-- end article header -->
    
    						<section id="mp-single-product" class="post_content clearfix" itemprop="articleBody">
    							<?php 
    
    							the_content(); 
    
    							echo '<div style="clear:both"></div>';
    
    							 mp_product_price(true);
    
    							 $product = new MP_Product( $product_id );
    						 	if ( $product->exists() ) {
    								$button = $product->buy_button( true, $context, array(), false, false );
    							}
    
    							 echo mp_category_list($post->ID, '
    								<div class="mp_product_categories">' . __( 'Categorized in ', 'mp' ), ', ', '</div>
    							'); 
    
    							?>
    
    						</section> <!-- end article section -->
    
    						<div class="disclaimer" style="margin-top: 10px">
    							<p><strong>Disclaimer:</strong> All information contained, written, portrayed or visualized on this website should not be taken as a form of diagnosis, treatment or prescription. It is strongly advised that you seek the assistance of a competent wellness professional before embarking on any changes to your personal well being. No claims are made for promissory reason and any information contained on this site is for educational purposes only. Any statements made have not been evaluated by the FDA or CHB and should never take the place of or be considered a substitution for the advice of your qualified health care provider.</p>
    						</div>
    
    <!-- 						<div class="row">
    							<div class="col-xs-10 col-xs-offset-1">
    								<h3>You might also be interested in...</h3>
    								<?php mp_list_products(true, true, 0, 3, 'sales', 'DESC'); ?>
    							</div>
    						</div> -->
    
    						<footer>
    
    							<?php the_tags('<p class="tags"><span class="tags-title">' . __("Tags","wpbootstrap") . ':</span> ', ', ', '</p>'); ?>
    
    						</footer> <!-- end article footer -->
    
    					</article> <!-- end article -->
    
    					<?php // comments_template('',true); ?>
    
    					<?php endwhile; ?>		
    
    					<?php else : ?>
    
    					<article id="post-not-found">
    					    <header>
    					    	<h1><?php _e("Not Found", "wpbootstrap"); ?></h1>
    					    </header>
    					    <section class="post_content">
    					    	<p><?php _e("Sorry, but the requested resource was not found on this site.", "wpbootstrap"); ?></p>
    					    </section>
    					    <footer>
    					    </footer>
    					</article>
    
    					<?php endif; ?>
    
    				</div> <!-- end #main -->
    
    				<?php // get_sidebar(); // sidebar 1 ?>
    
    			</div> <!-- end #content -->
    
    <?php get_footer(); ?>

    Let us know if you need any assistance or face any other issue. :slight_smile:

    Cheers,
    George

  • tomtranmer

    Thanks George,

    Just a heads up to anyone else experiencing this issue.

    The old mp_buy button code does not appear to function correctly. The new code works to display the buy button, but only in the custom page.mp-single-product context.

    <?php 
    
    	$product = new MP_Product( $product_id );
    	if ( $product->exists() ) {
    		$button = $product->buy_button( true, $context, array(), false, false );
    	}
    ?>

    If the code is moved out if that div context, it appears to have the same failure as with the earlier mp_buy button.

    I was able to restructure my products to accommodate the new template requirements.

  • Milan

    Hello Gareth

    Hope you are well today. :slight_smile:

    Its always better to ask on separate thread than this one for your this issue though its seems similar. This way we would be able to help you further and in depth very quickly. So if you are still not happy with alternative solution which you derived with mp_list_products function, please do open new thread at our support forum and we will assist you further. :slight_smile:

    Thanks for being with us. :slight_smile:
    Cheers,
    Milan

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.