New Product Fields

Discussion in 'Customization & add-ons' started by celina, Jan 15, 2009.

  1. celina

    celina Member

    Joined:
    Sep 9, 2008
    Messages:
    86
    Okay, I've read about how to add fields when soliciting information from customers, but what I need is the ability to add additional fields for specific products. I am selling subscriptions to a print and digital magazine. Customers can choose to order the digital magazine only, or subscribe to the print and digital magazine at the same time. When they subscribe to the digital magazine, I don't need to know the mailing address, but if they are subscribing to the print and digital together, I do need that info. Also, all orders will be emailed to our subscription house, and I need to be able to include a product id in that email, so i need both the ability to add an additional product field (in this case, ID or SKU) that would be hidden from signup page but included in email, as well as the ability to send out more than one admin email (one goes to me, one goes to my fulfillment house.)

    Any ideas?
  2. jimjwright

    jimjwright New Member

    Joined:
    Sep 12, 2007
    Messages:
    162
    Hello,

    I believe the "Add Fields" mechanism in Admin CP is used for adding custom fields into the member or user record. You can pre-populate a custom field by invoking signup.php as follows:

    signup.php?field_name=value

    Like I said I'm not sure if this is what you want. This is adding a field to the user's record.

    If you had two products setup in aMember (i..e. 1. Digital 2. Digital/Print) then you could just assign them different PRICE GROUP ID's. Then customize signup.php/signup.html so that products in a particular group do not display mailing address fields. You would be using the PRICE GROUP ID as a filtering mechanism.

    The user would select URL that looks something like the following:

    signup.php?price_group=#

    Not sure if that is what your after. You mention ID/SKU but when you setup the product aMember assigns a Product ID to the product. Can you not use that ID or does it have to be a user assigned SKU that matches fulfillment house. If that is case you might have to modifiy product.inc.php and call add_product_field() directly. I think if you do it this way it will show up in Admin CP when configuring product. You could probably write a plugin to do the same thing. Typically plugins add additional product fields to the product record. Plugins are better approach since you don't have to worry about custom code on upgrade but you already have custom code :).

    As far as email I'm sure it can probably be done but I haven't messed with email enough to help out.

    Jimmy
  3. matgetch

    matgetch New Member

    Joined:
    Sep 5, 2007
    Messages:
    5
    Is there another way to do this? I would also like to be able to add custom fields that only display for certain products/price groups.
  4. ashpeters

    ashpeters New Member

    Joined:
    Feb 23, 2009
    Messages:
    8
    I too am trying to find a solution to this question.

    Any assistance would be awesome.

    Ash
  5. instapro

    instapro New Member

    Joined:
    Apr 24, 2009
    Messages:
    13
    ya... Even I need this!!

    But, temporarily, I have altered the products table and added a field...

    Any other proper method??
  6. th0m3k

    th0m3k New Member

    Joined:
    May 8, 2009
    Messages:
    9
    If I understand well you have similar problem like me.

    I want to add a new field in the admin cp, add new product.
    I altered also the db but I dont know what code like is needed to insert and where.

    The admin/products.php function add_product is very difficult, I dont understand how it works...

    Do you have result already? :)
  7. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    543
    You cannot do it easily out of the box.

    But I am sure someone around here could create a custom field function of some sort to add custom fields to products themselves too... shouldn't be too hard.
  8. fojaha

    fojaha New Member

    Joined:
    May 28, 2009
    Messages:
    1
    I need a custom product field. I'd like to add "domain name" to a hosting subscription, but so far it seems that adding a custom field is for the user's profile, not a specific product. Please help me to do this.
  9. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    543
    Speaking of which, I went ahead myself (as I needed it for a client) and created a plugin which can be customized and expanded to support really anything you might need in terms of custom fields in product settings.

    Right out of the box, it adds a custom input/text field to your Product setting page, but it can be customized to include any other type of input field or any number of fields (I just have to do it manually, I guess, as I haven't figured out a fancy way with ajax or something to create those on the fly).

    If you need it, let me know... I'll offer it for dirt cheap as it is, and we can talk about any customizations on top of that if you need them done.
  10. richie

    richie New Member

    Joined:
    Aug 22, 2006
    Messages:
    12
    There is quite an easy solution to this problem. Simply create a file called 'site.inc.php' in the amember directory with the following information:

    PHP:
    <?php
    add_product_field
    ('field_name''Field Name''text'"Field Description to appear on product page");
    ?>
    Hope this helps!
    leelbog1 likes this.
  11. alphadog99

    alphadog99 Guest

    I think the common need is a way to add fields to the signup.php page that only display when a certain product is selected.

    Does anyone have a solution for this? Here is an example.

    I have 4 products. They are auto related. If someone chooses the product for 3 vehicles then I need the year, make and model from 3 vehicles.
    If they choose the 1 vehicle option, then I only need vehicle info for one vehicle.

    Currently if I add fields the traditional way, then they are all displayed upon signup.
    I need a solution that will allow the fields to change upon selecting different products.

    Thanks,
  12. davidm1

    davidm1 aMember User & Partner

    Joined:
    May 16, 2006
    Messages:
    4,437
    Sounds like you should use some sort of javascript that shows the extra fields when a product is selected, but hides them if another is.

    Sorry, i dont have code for this- you should be able to find someone cheap who can do it at rentacoder or guru etc..

    David
  13. erwinvdb

    erwinvdb aMember Pro Customer

    Joined:
    Aug 30, 2007
    Messages:
    264
    Three easy steps for free - you don't have to pay anyone for it, we're a community here ;)

    1) Add this at the top of the signup.html page (which can be found in templates directory) (I've done that just after {include file="header.html"} )
    Code:
    <script type="text/javascript">
    <!--
    function show_additional_field(id){
    	obj = document.getElementById('myfield_id');
    	if (id == 'product[COLOR="red"]id#[/COLOR]'){
    		obj.style.display = 'block';
    	} else {
    		obj.style.display = 'none';
    	}
    }
     -->
    </script>
    and replace id# with the ID number of the product that has to be selected. For example:
    Code:
    <script type="text/javascript">
    <!--
    function show_additional_field(id){
    	obj = document.getElementById('field_id');
    	if (id == 'product[COLOR="red"]1[/COLOR]'){
    		obj.style.display = 'block';
    	} else {
    		obj.style.display = 'none';
    	}
    }
     -->
    </script>
    2) Then add this piece to the html INPUT tags of the product fields:
    Code:
    onclick="show_additional_field(this.id)"
    So this:
    Code:
        {if $config.select_multiple_products}
        <input class="required" type="checkbox" id="product{$p.product_id}" name="product_id[]" value="{$p.product_id|escape}"
            {if in_array($p.product_id, (array)$smarty.request.product_id)}checked="checked"{/if}
            />
        {else}
        <input class="required"  type="radio" id="product{$p.product_id}" name="product_id" value="{$p.product_id|escape}"
            {if $p.product_id == $smarty.request.product_id }checked="checked"{/if}
            />
        {/if}{* end if $config.select_multiple_products *}
        {else}
        <input type="hidden" id="product{$p.product_id}" name="product_id" value="{$p.product_id}" />
        {/if} 
    ...becomes this:
    Code:
        {if $config.select_multiple_products}
        <input class="required" type="checkbox" id="product{$p.product_id}" name="product_id[]" value="{$p.product_id|escape}"
            {if in_array($p.product_id, (array)$smarty.request.product_id)}checked="checked"{/if}
            onclick="show_additional_field(this.id)"/>
        {else}
        <input class="required"  type="radio" id="product{$p.product_id}" name="product_id" value="{$p.product_id|escape}"
            {if $p.product_id == $smarty.request.product_id }checked="checked"{/if}
            onclick="show_additional_field(this.id)"/>
        {/if}{* end if $config.select_multiple_products *}
        {else}
        <input type="hidden" id="product{$p.product_id}" name="product_id" value="{$p.product_id}" onclick="show_additional_field(this.id)"/>
        {/if} 
    3) And finally put this div html tag
    Code:
    <div id="field_id" style="display:none;"> </div>
    around the field that would like to have appeared/hide when productid# is selected. As an example I show you how to hide/show the coupon field.
    Change this:
    Code:
    <input type="text" name="coupon" id="f_coupon"
        class="{ldelim} remoteCoupon: 'ajax.php'{rdelim}" 
        value="{$smarty.request.coupon|escape}" size="15" />
    ...to:
    Code:
    <div id="myfield_id" style="display:none;"><input type="text" name="coupon" id="f_coupon"
        class="{ldelim} remoteCoupon: 'ajax.php'{rdelim}" 
        value="{$smarty.request.coupon|escape}" size="15" /></div>
    Now you should have a coupon field that only shows up when product1 is selected.

    And to give credit where credit is due: Andrey Seredkin of aMember helped me solve a similar situation with this solution ;)

    Note however that I found that display:none doesn't work for DIV if that DIV is not inside a TD.
    So I added a table around it. But then I got double borders... I fixed that by removing padding (that's CSS) on the outside and adding padding on the inside, and removing borders on both.
  14. vacc_webmaster

    vacc_webmaster Member

    Joined:
    Jan 24, 2007
    Messages:
    51
    hide/show fields on click

    How would this be accomplished for fieldsother than products?

    I have the following field:
    <td>
    <input type=hidden name="supervision[]" value="" />
    <label><input type="checkbox" name="supervision[]" value="3" />No</label><br />
    <label><input type="checkbox" name="supervision[]" value="4" />Yes</label><br />

    When YES is selected 10 additional fields should show. The fields are from drop down lists, radio buttons, text areas, and check lists.

    If there is any other way to do it, any suggestion would be great but it seems that Javascript would need to be used.

    Just hate having members seeing so many fields when they shouldn't be displaying if not intrested.

    From there, I would use the concept in the profile page.

    Send me a PM or any suggestions or examples of this if its been done before.
  15. erwinvdb

    erwinvdb aMember Pro Customer

    Joined:
    Aug 30, 2007
    Messages:
    264
    Sample principle: put extra fields/data/info inside a DIV tag that's by default display:none and use an onclick event for the checkbox.
  16. toniclodge

    toniclodge New Member

    Joined:
    Sep 20, 2009
    Messages:
    12
    Thanks for the tip erwinvdb! But from what I see your solution only works if there are multiple products on a page and the user then selects one. The way I have it set up now is that I only show the user one product (using the Signup Page Wizard) but need to show/hide an additional field based on the product # selected.

    So I never use radio buttons, as there is only 1 product per page. Any advice on how to modify your approach to fit this scenario?

    Thanks!
  17. erwinvdb

    erwinvdb aMember Pro Customer

    Joined:
    Aug 30, 2007
    Messages:
    264
    Yes you've to add code where you check if there's one or more products on the page.

Share This Page