how to retrieve additional fields on the edit product page?

Discussion in 'aMember Pro v.4' started by customcodegeek, Feb 11, 2012.

  1. customcodegeek

    customcodegeek Member

    Joined:
    Feb 10, 2012
    Messages:
    40
    I have added an additional field to the admin edit product page with this code in my custom plugin

    Code:
    // this method will be called in the product edit page
        function onProductForm(Am_Event $event){
            $form = $event->getForm();
    
            $form->addElement('text', 'ab_return_url', array('size' => 60, 'class'=>'translate'))
                    ->setLabel(___("Paypal Return URL\n" .
                    "This is the url the thanks page will redirect to after payment\n" .
                    "You can use this for one time offers"));
    
        }
    and it adds it to the 'Additional' field set but the value is not saving.

    would you tell me what code I would need to use to add the field and it keeps its value when saved and also what code I can use to retrieve that value on the onThanksPage event?
  2. customcodegeek

    customcodegeek Member

    Joined:
    Feb 10, 2012
    Messages:
    40
    [update]

    Ok I realized that it's not saving because there isn't a field available on the am_billing_plans table where everything else gets saved.

    I am instead going to use a custom brick so I can add the redirect url to the signup form for a product.
    the brick is added and it can be configured ok and the data gets saved.

    I am using this code

    Code:
    class Am_Form_Brick_redirectUrl extends Am_Form_Brick
    {
        protected $hideIfLoggedInPossible = self::HIDE_DONT;
    
        public function __construct($id = null, $config = null)
        {
            $this->name = ___('Thanks Redirect URL (Hidden)');
            parent::__construct($id, $config);
        }
        public function initConfigForm(Am_Form $form)
        {
            $form->addText('redirect_url')->setLabel(___('Redirect URL'));
        }
    
        public function insertBrick(HTML_QuickForm2_Container $form)
        {
            $form->addHidden('redirect_url')->setValue($this->getConfig('redirect_url'));
        }
    
    }
    Will this data be available in the onThanksPage event?

    ie. Can the signup form that was used for the purchase be retrieved so I can setRedirect to use the URL that was saved to the custom brick?
    eg;

    Code:
    // this method will be called before rendering "thanks" page
        function onThanksPage(Am_Event $event)
        {
            $controller = $event->getController(); // ThanksController instance
            $invoice = $event->getInvoice(); // Invoice instance OR NULL (!)
            if (!$invoice) return;
    
             // get signup form here
             // get value saved in redirect_url
             $savedredirecturl = (how to get it?)
             $controller->getResponse()->setRedirect($savedredirecturl);
    
        }
  3. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    No it will not be available.
    Here is what you need to do:
    1. Set handlers for both Am_Event::SIGNUP_USER_UPDATED and Am_Event::SIGNUP_USER_ADDED events.
    Both will receive three parameters: $vars, $user, $form
    2. get redirect url from form and store it in session.
    3. on tahnks page extract it from session and use as you need.
  4. customcodegeek

    customcodegeek Member

    Joined:
    Feb 10, 2012
    Messages:
    40
    ah of course I can use the $_SESSION global to store that because both the form and the payment would always be in the same session. I was over thinking it. thanks Alexander
  5. customcodegeek

    customcodegeek Member

    Joined:
    Feb 10, 2012
    Messages:
    40
    sorry Alexander but I'm having trouble with getting the parameters . I keep getting a 'cannot access protected property' with this code in my custom amember plugin
    Code:
    
    function onSignupUserUpdated (Am_Event $event){
            $vars = $event->vars;
    }
    
    
    can you give me the code to access the $vars ?
  6. customcodegeek

    customcodegeek Member

    Joined:
    Feb 10, 2012
    Messages:
    40
    sorry Alexander, I found it.

    Code:
    $vars = $event->getvars();
    I'm just getting used to the new classes but I'm getting there!

Share This Page