Home > blog posting, e-commerce, magento, technical notes > Magento Notes — Magento for B-2-B Web site

Magento Notes — Magento for B-2-B Web site

March 27th, 2009

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

I have recently been approached to work on a couple catalog-driven web sites for wholesalers and manufacturers, and what I have been presenting to them is simply a customized Magento installation in which 1) the pricing gets stripped out and/or
2) the pricing and the “add to cart” button gets stripped

Some of them also require that site operators approve customers before they can attempt to login; there’s a plugin for this here.

Below is a how-to on how to hide the “add-to-cart” button to non-logged in users.  Users would need to login in order to have a functional shopping cart:

Step 1 - To hide price: open the template file that shows prices: /app/design/frontend/default/[theme]/template/catalog/product/price.phtml and go to line line 30 (below: <?php $_id = $_product->getId() ?>) and add:

<?php if(Mage::getSingleton(’customer/session’)->isLoggedIn()): ?>

and at the very end, add:

<?php endif; /* if ($this->isCustomerLoggedIn()): */ ?>

Step 2 - go to /app/design/frontend/default/default/template/catalog/product/view/addtocart.phtml and add:

<?php if(Mage::getSingleton(’customer/session’)->isLoggedIn()): ?>

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

and then add:

<?php endif; ?>

before <fieldset class=”add-to-cart-box”>

Step 3 - Remove add to cart buttons from /app/design/frontend/default/default/template/catalog/product/list.phtml

add the same if and endif statement around the following line of code:

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

so that it looks like:

<?php if(Mage::getSingleton(’customer/session’)->isLoggedIn()): ?>
<button class=”button” onclick=”setLocation(’<?php echo $this->getAddToCartUrl($_product) ?>’)”><span><?php echo $this->__(’Add to Cart’) ?></span></button>
<?php endif; ?>

read through the code and you will see 2 instances of the above (one for grid and one for list view)

Step 4 - Do the same as step 3 to file: /app/design/frontend/default/[theme]/template/catalog/product/compare/list.phtml

As I finished this, I found a more detailed wiki post on Magento: http://www.magentocommerce.com/wiki/price_on_application, it’s actually quite a bit more extensive and details on how to add attributes for variations to showing price.

Bookmark and Share


blog posting, e-commerce, magento, technical notes , ,

  1. No comments yet.
  1. No trackbacks yet.