HOWTO: Price on Application

Last modified by Discovery on Fri, June 25, 2010 09:46
Source|Old Revisions  

This is an old revision of the document!


Introduction: adding 'Price on Application'

With some suppliers it is not possible to put their prices online, instead a ‘Price on Application’ button has to show. Furthermore the ‘add to cart’ button has to be rendered inoperable. By default this functionality is not built into Magento (1.1.7), with this ‘hack’ you can get around this and have as many different messages as you like, e.g. ‘Call for Price’, ‘Coming Soon!’ or ‘Call for Availability’.

As ever, backup files that get modified.

1) Add a new attribute, 'poa'.

Go to Admin→Catalog→Attributes→Manage Attributes and add a new attribute. Call it ‘poa’, set it to type ‘Dropdown’, ‘Global Scope’, Default Value of ‘No’, Values Required ‘No’, ‘Apply to All Product Types’ and set ‘No’ to all Frontend Properties. Under Label Options give it the name ‘POA’ and then add in entries for what you want to show, e.g. ‘POA’, ‘Coming Soon’ and so on. If you want to have an attribute that hotlinks to your contact us page then in the ‘English’ column put some links, so the Default goes to ‘Call for Price’ and the English value is ‘<a href=”contacts”>Call for Price</a>’

Save the attribute and now go into Admin→Catalog→Attributes→Attribute Sets.

Open your attribute sets for products that are likely to be ‘Price on Application’ (or whatever). Drag and drop the new ‘poa’ attribute in the ‘prices’ folder from the unassigned attributes. Save the attribute set(s).

Now open a test product that uses one of the modified attribute sets, go to the prices page and look for the new POA drop down. The attribute values that you setup earlier will show. Choose one of them and save the product.

2) Set the attribute to be usable on list pages.

Create a file app/etc/modules/category_product_attributes.xml with the following:

<?xml version="1.0"?>
<config>
  <frontend>
    <product>
      <collection>
        <attributes>
         <poa/>
        </attributes>
      </collection>
    </product>
  </frontend>
</config> 

3) Now open the template file that shows prices: /app/design/frontend/default/[theme]/template/catalog/product/price.phtml

After the line:

<?php $_product = $this->getProduct() ?>

Add this line:

<?php if ($_product->getAttributeText('poa')==NULL): ?>

Now go to the end of the file and add:

<?php else: ?>
<span class="regular-price"><?php echo $_product->getAttributeText('poa') ?></span>
<?php endif; ?>

Save the file.

4) Fix product pages

Now remove the add to cart buttons from the product pages when a poa attribute is set, open: /app/design/frontend/default/default/template/catalog/product/view/addtocart.phtml

After the line:

<?php $_product = $this->getProduct() ?>

Add this line:

<?php if ($_product->getAttributeText('poa')==NULL): ?>

At the end (just before <fieldset class=”add-to-cart-box”>)add:

<?php endif; ?>

Save the file.

5. Fix listing pages

Remove add to cart buttons from listing pages, open: /app/design/frontend/default/default/template/catalog/product/list.phtml

There are two instances of this line, one for grid and one for list:

                <button class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart') ?></span></button>

Add an if around them so that that they look like:

                <?php if ($_product->getAttributeText('poa')==NULL): ?>
                <button class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart') ?></span></button>
                <?php endif; ?>

6. Fix 'Compare Products'

Now repeat the same ‘add to cart’ switch in the template for ‘compare products’. Open: /app/design/frontend/default/[theme]/template/catalog/product/compare/list.phtml

Change:

                    <button class="button" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToCartUrl($_item) ?>', true)"><span><?php echo $this->__('Add to Cart') ?></span></button>

To:

                    <?php if ($_item->getAttributeText('poa')==NULL): ?>
                    <button class="button" onclick="setPLocation('<?php echo $this->helper('catalog/product_compare')->getAddToCartUrl($_item) ?>', true)"><span><?php echo $this->__('Add to Cart') ?></span></button>
                    <?php endif; ?>

7. Hide 'tier' prices.

You can setup ‘tier’ prices and keep them hidden with a final modification. Open: /app/design/frontend/default/[theme]/template/catalog/product/view/tierprices.phtml

Again, an ‘if’ is used to see if anything is set in the ‘poa’ attribute, if it is then a message to call for tier prices can be given. Change the code to:

<?php
/**
 * @see Mage_Catalog_Block_Product_View
 */
$_product = $this->getProduct();
$_tierPrices = $this->getTierPrices();
?>
<?php if (count($_tierPrices) > 0): ?>
    <ul class="tier-prices">
    <?php if ($_product->getAttributeText('poa')!=NULL): ?>
    <li>Quantity discounts available, call for prices!</li>'
    <?php else: ?>
    <?php foreach ($_tierPrices as $_price): ?>
        <?php if ($this->helper('tax')->displayBothPrices() && $_price['formated_price'] != $_price['formated_price_incl_tax']): ?>
            <li><?php echo $this->__('Buy %1$s for %2$s (%3$s incl. tax) each', $_price['price_qty'], $_price['formated_price'], $_price['formated_price_incl_tax']) ?>
        <?php else: ?>
            <li><?php echo $this->__('Buy %1$s for %2$s each', $_price['price_qty'], $_price['formated_price']) ?>
        <?php endif; ?>
        <?php if(($_product->getPrice() == $_product->getFinalPrice() && $_product->getPrice() > $_price['price'])
        || ($_product->getPrice() != $_product->getFinalPrice() &&  $_product->getFinalPrice() > $_price['price'])): ?>
            <?php echo $this->__('and') ?> <strong class="benefit"><?php echo $this->__('save')?> <?php echo $_price['savePercent']?>%
        <?php endif ?></strong>
        </li>
    <?php endforeach ?>
    <?php endif; ?>
    </ul>
<?php endif;?>

8. Test.

Now it should not be possible to see the price of a product marked up as ‘price on application’, or add a ‘poa’ product to the cart. The only clue to a product’s price is in the filtered navigation. That can be left in so that the customer that pays attention can get a clue as to the price ;-) The product should show ‘correctly’ in the search, but if you have any custom blocks for showing new products in a different way then the price could be given away, and those blocks too may need to be modified as per the above template files.




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs