Custom product field - adding it as a column inside the admin area?

Discussion in 'Customization & add-ons' started by stevenjohn, Sep 13, 2012.

  1. stevenjohn

    stevenjohn Member

    Joined:
    Nov 9, 2006
    Messages:
    40
    Hi there,

    I have added a new product field using the code:

    Am_Di::getInstance()->productTable->customFields()->add(new Am_CustomFieldSelect('product_grouping', "Parent category for product", 'This enables us to provide overall credits for product sets', '', array('options' => array(1=>'Group1', 2=>'Group2'))));

    and as you expect it all works perfectly.

    However, I'd like to see the value of this field to be displayed as a custom column on the admin product listing page, i.e. /amember/admin-products page, preferrably with a sort feature.

    Can anyone point me in the right direction?

    Many thanks, Steve
  2. bfritton

    bfritton Certified aMember Developer

    Joined:
    Oct 26, 2009
    Messages:
    54
    Steve, did you ever figure this out? Thanks.
  3. bfritton

    bfritton Certified aMember Developer

    Joined:
    Oct 26, 2009
    Messages:
    54
    Found a good example. Add this into your bootstrap.

    PHP:
    function onGridProductInitForm(Am_Event_Grid $event)
        {
            
    $event->getGrid()->getForm()->addInteger('apicredit_count')
                ->
    setLabel___("API Credit Count\n".
                        
    "(keep as 0 to give no credits)"));
            
    $options = array('' => '-- ' ___('Please select') . ' --');
            foreach (
    $this->getDi()->db->selectCol("SELECT product_id AS ARRAY_KEY, title FROM ?_product") as $k => $v)
                
    $options[$k] = $v;
            
    $event->getGrid()->getForm()->addSelect('apicreds_product_id')
                ->
    setLabel(___("API Credits Product\n".
                
    "(keep empty for non-API credits product)"))
                ->
    loadOptions($options);
        }
    alex likes this.

Share This Page