Output attribute value and text alongside price in Magento
HI
I am new to Magento and still new to the whole css, php thing. And I have been searching for over a month to find this answer (I am sure it is here some place, but I cannot seem to find it)
I am building a b2b site for a clothing company. Since they are a wholesaler, they do not sell single items, but rather, they sell开发者_StackOverflow them in a pack. Depending on the items , some will come in a pack of 2-Small; 2-Medium; 2-Large, other will come in a pack of 1-Small; 2-Medium; 1-Large, and so on.
So far, I set up an attribute called “Package Set”, which describes the kind of pack the customer will be getting when ordering the item, but it only appears in the Additional Information tab, which is not good, because we want that information to stand out. Putting it in the Short Description is an option, but we want to emphasize it more.
So we want to 1. add a text “per pack” right behind the price. 2. add the value of the attribute “Package Set”, right underneath the price, so people will see it clearly, both in the category and product page. It would look some thing like,
“$60 per pack
Package Set: 2-Small; 2-Medium; 2-Large.”
I am using the modern theme running 1.4.1.1
Thank you
Copy the file "app/code/design/frontend/base/default/template/catalog/product/view/price_clone.phtml" to the directory "app/code/design/frontend/default/modern/template/catalog/product/view/". This is so you are not overwriting the original file.
Open the file for editing. After where you see this:
<?php echo $this->getPriceHtml($_product, false, '_clone') ?>
Add the following:
<?php echo $this->__('per pack') ?>
By using the function $this->__()
you are making the text available to be translated easily. It is good practice to do this always.
For the second part now add this bit on the line after:
<p><?php echo $this->__('Package Set %s', $_product->getPackageSet()) ?></p>
Again it is potentially being translated but this time your extra attribute is being inserted where it says %s
. The reason for doing this is to make it clearer when using inline translation. The line has been wrapped in a <p>
paragraph tag for yet more clarity and to ensure it appears on it's own line, not following on the end of the previous.
I have assumed your attribute has the code "product_set" - which in Magento becomes 'camel case', or getProductSet
.
Finally you might want to remove the attribute from Additional Information tab. This is quite simple, go back to the Manage Attributes page in admin, edit your attribute and change "Visible on Product View Page on Front-end" to "No".
精彩评论