Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento - Products not for sale

I would like to set some products to "non-saleable", removing the "Add to cart" button and adding a link to contact form.

I'm looking for this solution for a few weeks. Searching, I found this post:

http://www.e-commercewebdesign.co.uk/blog/magento-tutorials/non-salable-products-with-attribute-sets.php

But I can't make it work. Someone could help me with more details?

like image 423
Brightweb Avatar asked Feb 21 '23 13:02

Brightweb


1 Answers

That tutorial will work, but I would do it a different way.

First of all, that tutorial forces you to use a specific attribute set ID. As with product IDs, category IDs, etc this can change if you are managing development/production server environments. I would not recommend this.

Personally (and I know there are better ways), I'd create a new product attribute, something along the lines of 'Not For Sale'. Make this attribute 'Yes/No' with a default of No (it is for sale).

Then, where you have an add to cart button, in view.phtml for example, find the chunk of code that displays the add-to-cart button, something like:

 <?php echo $this->getChildHtml('addtocart') ?>

Wrap this chunk with the following:

 <?php if(!$_product->getNotForSale()) : ?>
      <?php echo $this->getChildHtml('addtocart') ?>
 <?php endif ?>

Then for those products you don't want to be purchased, set the attribute value in product management to 'Yes'.

Additionally, you could tie an else statement in there to display an alternate button or whatever.

This method is fundamentally the same, but gives you more fine-grained control as you won't have to mess with various attribute sets and their IDs. It's also a lot easier to control your attribute names than your attribute set IDs.

--- edit --- To place content instead of the button:

<?php if(!$_product->getNotForSale()) : ?>
    <?php echo $this->getChildHtml('addtocart') ?>
<?php else : ?>
    <?php echo $this->__('Call Us to Order') ?>
    ... or whatever else you may want here ...
<?php endif ?>
like image 86
pspahn Avatar answered Feb 27 '23 19:02

pspahn