cancel
Showing results for 
Search instead for 
Did you mean: 

Add custom dynamic field to product page

Add custom dynamic field to product page

How would I go about making a custom dynamic field on a product page?

 

Like this (red box):

Screen Shot 2016-06-23 at 13.08.04.png

 

I know I have to change the file addtocart.phtml but don't know how to code it.

 

It looks rather simple but I haven't figured it out yet.

 

Any help would be appreciated!

5 REPLIES

Re: Add custom dynamic field to product page

Hello hotdog9,

Before changing the code, you may consider adding required attribute using Magento standard functionality.

 

In order to perform this go to: Admin Panel -> Catalog -> Attributes -> Manage Attributes -> Button "Add New Attribute".

Here you can create attribute (field) of required type and set it up. In order this attribute to be visible on product page -  set "Yes" for "Visible on Product View Page on Front-end" in attribute settings.

After this you need to set which product groups this field should be assigned to. It can be set up  here: Admin Panel -> Catalog -> Attributes -> Manage Attribute Sets

 

For example, go to Attribute Set "Default" and drag new attribute from right column to left, to the General section. After this in an appropriate section on the Product Edit Page this filed will appear. 

 

Do not forget to make system re-index  (System -> Index Management) and clear cache (System -> Cache Management).

 

Best Regards, 
Plumrocket Team

 

Re: Add custom dynamic field to product page

Thanks for the reply!

I've already done that.

What I'm looking for in my case is to show the user how much they're purchasing.

For example say you want to buy bananas and they come in packages. 1 package = 0.3 kg.

I want that "= 0.3 kg" next to quantity, but just for products that require it (all products that use 'fruits' attribute set).

Do you know of any solution that would give me this?

Thanks in advance Smiley Happy

Re: Add custom dynamic field to product page

Hey hotdog9,

 

In this case, you can go to: 

app/design/frontend/base/default/template/catalog/product/view/addtocart.phtml

 

and add the following code:

 

<?php if ($product->getAttributeSetId() == ATTRIBUTE_SET_ID): ?>
    <?php echo $product->getAttributeText('YOUR_ATTRIBUTE_CODE'); ?>
<?php endif; ?>

ATTRIBUTE_SET_ID - change to ID of   "fruits" attribute set. If it is more comfortable for you to check by name,  and not by ID you can make the following:

 

<?php if (Mage::getModel('eav/entity_attribute_set')->load($product->getAttributeSetId())->getAttributeSetName() == 'fruits'): ?>

Best Regards,
Plumrocket Team

Re: Add custom dynamic field to product page

I will try it out and come back to you if I have any issues!

Thank you so much for your assistance Smiley Happy

Re: Add custom dynamic field to product page

Hi again,

So I notice this problem. Whenever I edit something in that .phtml file, the stuff below it goes missing.

Say I add your code above the code for the button, and the button goes missing and everything else beneath it.

Any thoughts? I’ve tried editing a bit before on this page and stumbled upon this same problem.

Cache is disabled if it makes any difference.