Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 2
Write a Category If Statement
 
buffalokill
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2007-12-12
Coeur d'Alene, Idaho
 

Hi Guys,

I’m messing around with trying to create a if statement in Magento. The root of the problem is that I don’t have the option to set a product to “Call for Price”.

I’m still pretty green with Magento, so please correct me if I’m way off. I opened up

app/design/frontend/default/default/template/review/product/detailed.phtml

I want to create an IF STATEMENT on whether or not this product belongs to a specific category. If it is in the category “phone-voicemail-systems”, then I don’t want an Add To Cart button.

So my plan is to replace the <div class="product-shop"> on line 47 of detailed.phtml with some basic html that states they need to call for price.

So, basically I want to make it something like this

if (’phone-voicemail-systems’) {

<div class="product-shop"> ... </div>

} else {

Call For Price

}

I’ve searched around the forums for an If Statement such as that, and have had no luck. Anyone have any pointers or links that could help me tackle this? Much appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
buffalokill
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2007-12-12
Coeur d'Alene, Idaho
 

I still have yet to figure out the proper call. These are all the ones I’ve tried with no love.

<?php if($this->getCurrentCategory('phone-voicemail-systems')): ?>
<h1>Only Show On Phone Voicemail Category</h1>
<?php endif; ?>

And the rest....

<?php if($this->IsTopCategory('phone-voicemail-systems')): ?>

<?php 
if($this->IsCategory('phone-voicemail-systems')): ?>

<?php 
if($this->getCurrentCategory()->getName('phone-voicemail-systems')): ?>

<?php 
if($this->getCurrentCategory('phone-voicemail-systems')): ?>

Anyone have any pointers on where I’m going wrong with this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
buffalokill
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2007-12-12
Coeur d'Alene, Idaho
 

FOUND IT! W00t!

Took alot longer than anticipated. Here is how I handled it. I modified the templates, so that anything with a price of 0.00, will automagically show a “Please Call for Price”.

Product Page
Just below the product title in template/catalog/product/view.phtml

<?php $_callforprice $_product->getPrice(); 
                 if (
$_callforprice '0.00'): ?>

                
<div class="product-call-price">
                <
strong>Please Call for Price</strong>
                </
div>

                
<?php else: ?>

Add to cart button 
and stuff....

<?php endif; ?>

Category Page
Just below the product description in template/catalog/product/list.phtml

** You have to do this twice in this file. Once for Grid View, and once for List View. (around line 57 and line 140 )

<?php $_callforprice $_product->getPrice();  
                 if (
$_callforprice '0.00'): ?>

                
<div class="product-call-price">
                <
strong>Please Call for Price</strong>
                </
div>

<?php else: ?>

Add to cart button 
and stuff....

<?php endif; ?>

There might be a couple more template files that need this treatement. I’ll find out in a bit.

 
Magento Community Magento Community
Magento Community
Magento Community
 
kalqlate
Jr. Member
 
Total Posts:  26
Joined:  2008-06-17
 

Thanks, buffalokill!

Not implementing this currently, but I have a suspicion that I’ll need it.

Is there a code repository for tips like this? If not, there should be.

Cheers!
David

 
Magento Community Magento Community
Magento Community
Magento Community
 
Kerry Hatcher
Sr. Member
 
Avatar
Total Posts:  96
Joined:  2008-07-15
Macon, GA
 

@Chris,

When you added the code, did it show up on all the pages, just the product pages, and/or the cat pages?

(yes Chris is across the hall but I figured we would converse here for everyone Else’s benefit!)

 
Magento Community Magento Community
Magento Community
Magento Community
 
Kerry Hatcher
Sr. Member
 
Avatar
Total Posts:  96
Joined:  2008-07-15
Macon, GA
 

Ok I’ll put it back in piece by piece, see if I can see what is going on. I’ll post back my findings.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Kerry Hatcher
Sr. Member
 
Avatar
Total Posts:  96
Joined:  2008-07-15
Macon, GA
 

http://screencast.com/t/TJxXEA88yKb

In php if->then statements var=something test if you can set the var to something and will return true every time. you must use == to test if the var equals something. See my noted code in the link above. Here is my completed source snippet from list.phtml

I’m gonna work up a more detailed answer later.

<?php if($_product->getRatingSummary()): ?>
            <?php 
echo $this->getReviewsSummaryHtml($_product'short'?>
            <?php 
endif; ?>
                
               
// Begin added code for call for price 
                
<?php $_callforprice $_product->getPrice(); 
                 if (
$_callforprice <= '0.00'): ?>

                
<div class="product-call-price">
                <
strong>Please Call for Price</strong>
                </
div>

                
<?php else: ?>
                
// End added code for call for price (except the end if noted below)
                
            
<?php echo $this->getPriceHtml($_producttrue?>
            <?php 
if($_product->isSaleable()): ?>
            
<button class="form-button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart'?></span></button>
            
<?php else: ?>
            
<div class="out-of-stock"><?php echo $this->__('Out of stock'?></div>
            
<?php endif; ?>
            <?php 
endif; ?> // Added this endif 
            
<div class="clear"></div>
            <
class="add-to">
             
                
<?php if ($this->helper('wishlist')->isAllow()) : ?>
                
<a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-cart"><?php echo $this->__('Add to Wishlist'?></a>
                
<?php endif; ?>
                <?php 
if($_compareUrl=$this->getAddToCompareUrl($_product)): ?><br/>
                <
a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Add to Compare'?></a>
                
<?php endif; ?>
                
                
                
            
</p>
Image Attachments
code.png
File Attachments
view.phtml  (File Size: 6KB - Downloads: 286)
list.phtml  (File Size: 7KB - Downloads: 166)
 
Magento Community Magento Community
Magento Community
Magento Community
 
wellington_br
Member
 
Total Posts:  53
Joined:  2008-09-25
 

Hello
On my site, here http://www.hnbrindes.com.br/loja/br/index.php/canecas-e-copos/plastico product price does not work without the cart and it remains the written consultation, the details of the product and still have cart.
Tanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Kerry Hatcher
Sr. Member
 
Avatar
Total Posts:  96
Joined:  2008-07-15
Macon, GA
 

Man I’m glad I documented this so well, just upgraded and it broke the call for price. Then I couldn’t remember how to do it wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
Wilson Sheldon
Member
 
Total Posts:  47
Joined:  2008-06-07
 

Thanks guys!  This was really useful.

Does anyone know if there’s a way to roll this into a ‘private’ packaged extension?  I’m just curious if you could install it, so it never has to be monitored during upgrades.

Wilson
Atlanta, GA

 
Magento Community Magento Community
Magento Community
Magento Community
 
bernatalsina
Jr. Member
 
Total Posts:  1
Joined:  2008-12-17
 

Hi,
nice Job Kerry Hatcher, but there’s a bug, if you switch to “list” view, the price appers 0,0$, no the message,

any solution?
thks

Bernat Alsina

[ad] estudio de diseño

 
Magento Community Magento Community
Magento Community
Magento Community
 
dalbeck
Jr. Member
 
Total Posts:  18
Joined:  2009-04-09
 

I am also getting the same problem when you switch it to list view.  I also noticed it is not showing the price for me when you go to the product details page only for the list of products, any suggestions?

 
Magento Community Magento Community
Magento Community
Magento Community
 
q23media
Member
 
Avatar
Total Posts:  72
Joined:  2009-04-29
 

Hi guys! I have the same problem with the list view concerning the “call for price” message...maybe someone could post a solution for that? would be great, cause i just have the list view as default and I need this “call for price” function…

Thanks & Bye
Jakob

 
Magento Community Magento Community
Magento Community
Magento Community
 
GreenLEEP
Jr. Member
 
Avatar
Total Posts:  21
Joined:  2008-10-23
Montreal, QC, Canada
 

Any idea if this applies to the newer releases of magento (1.3 on) the code in the files referenced isnt the same and my background in phtml isnt the best?
Many thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
q23media
Member
 
Avatar
Total Posts:  72
Joined:  2009-04-29
 

http://www.magentocommerce.com/wiki/price_on_application

this helped me...thanx so much snake

Edit: very easy if you follow the instructions step by step

 
Magento Community Magento Community
Magento Community
Magento Community
 
modulesformagento
Jr. Member
 
Avatar
Total Posts:  19
Joined:  2009-11-24
Los Angeles, CA
 

Hello Everyone, we have actually just completed our “call for price” module, it removes the price and add to cart button and replaces the price with text. By default the text reads “please call for price” but it can be easily changed on each piece. Also the price filter will exclude all products that are active with this module so you won’t have multiple products from $0.00 -$1.00 in the filter.  I know you already solved the issue but our module is extremely easy to work with and maybe a better alternative than the solution above. I would love some feedback and hopefully this helps for all of your requests.

http://www.modulesformagento.com

Image Attachments
Call-for-Price_menu.jpgCall-for-Price_function.jpgm4mbox3.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2