Am unsure what I am doing wrong here. I am trying to do a php if statement that if the field equals zero it will print. I have tried the following multiple different ways and nothing seems to be working. Def appreciate some guidance/direction on what i am doing wrong. I define the uc_sell_price in my template file preprocess.

        <?php if ($uc_sell_price = '0.00000'): ?>
        <div class="servicecontact">
  		<a href = "http://localhost/techsupport/contact">Contact for Price</a>
    	</div>	
    	<?php else: ?>
		<?php endif; ?>

many thanks!

Comments

nevets’s picture

Have you tried 0.0 (vs '0.00000')?

calebm12’s picture

yes, just tried it. if i leave the apostrophe it shows up regardless. if i remove apostrophe it doesnt show up regardless.

nevets’s picture

Missed you had a single '=', try $uc_sell_price == 0.0

calebm12’s picture

Still not working.
I just tried

        <?php if ($uc_sell_price == 0.0): ?>
        <div class="servicecontact">
  	<a href = "http://localhost/techsupport/contact">Contact for Price</a>
    	</div>	
    	<?php else: ?>
	<?php endif; ?>

I went and looked at the phpmyadmin and the sell_price field is 0.00000 for one record and 45.00000 for another. For both of these records they both end up printing the link.

nevets’s picture

Is the field type a string? If yes, you will need '0.00000'

calebm12’s picture

Still no go. I am wondering if ubercart is playing a role in this not working. In my template.php file i am declaring the following:

function mystique_theme_preprocess_node(&$vars) {
  if ($vars['template_files'][0] == 'node-product') {
    $node = node_build_content(node_load($vars['nid']));
    $vars['uc_sell_price'] = drupal_render($node->content['sell_price']);
  }
}

If i just print the uc_sell_price, for one record it is printing $45.00 and for the other record its not printing anything. However if i go to phpadmin and look at the uc_products table the values related to these records are 45.00000 and 0.00000 for sell_price. this is a different table then the content_type_product.
Really perplexed as to what i can do from here.

nevets’s picture

I am confused on what you are doing, $node ($vars['node']) is is already available in hook_preprocess_node() so why are you calling node_load() and node_build_content()?

As for the problem, you just want $node->content['sell_price'] (which is available in node.tpl.php), rendering it adds html so none of the tests I suggested would work.

calebm12’s picture

Appreciate your patience on this. I apologize for my very very weak php background.....learning as i go.

In regards to the first question. I took that code directly from an ubercart theme (fusion core i believe).

I have tried printing directly the sell price

<?php print $node->content['sell_price']['#value'];?>

Once again it looks like it renders. As i get the following for one record "Price: $45.00" and nothing prints on the second record (the zero one).

If i do a print r to see all the fields i do see the sell_price and its not in the database table rendered.

nevets’s picture

A quick test shows that if ( $node->sell_price == 0.00 ) should work

jason.hao’s picture

If the type of $uc_sell_price is string try this:
if ($uc_sell_price === '0.00000'):

If the type of $uc_sell_price is int or float try this:
if ($uc_sell_price === 0):
or
if ($uc_sell_price === 0.0):

More detail: PHP Comparison Operators

calebm12’s picture

This
<?php if ($node->sell_price == 0.00 ): ?>
did it!
Thanks for hanging with me!!!