Preorder Buttons: Part II
Hi,
[Magento Version 1.4.1.1]
In the last post we discussed how we can control the caption of the Add To Cart button to reflect our BackOrdering settings from the admin. What we want to do next is to offer the Magento admin more fine-grained control over the PreOredering setting. The idea is to add an “Allow Preorder” option on each product so we can individually select the preoredering option for each product.
Step A: The Admin
Login in the Magento Admin and browse to Manage Attributes from the Catalog Menu. Add a new preorder attribute with the following settings:
- Catalog Input Type for Store Owner: Yes/No
- Values Required: Yes
- Used in Product Listing: Yes
We’ll then need to add our new attribute to the General Attribute Set from the Manage Attribute Sets menu.
Step B: The Code
All we need now is to retrieve the Preorder attribute in both addtocart.phtml and list.phtml, for the former we’ll add:
<?php $rpreorder = $_product->getData('preorder'); ?>
and the latter:
<?php $rpreorder = $_product->getPreorder(); ?>
The getPreorder function didn’t work for some reason in the addtocart.html so we settle with the getData function for now.
It was mentioned in severeal forums that we also need to add this line to the catalog.xml layout file:
<action method="addAttribute"><attribute>Preorder</attribute></action>
But this wasn’t necessary in my case and Magento picked it up automatically, maybe this was needed in older Magento version.