0

I created my payment module. During module's instalation i'm creating new table ps_mymodule_card with id, customer_id and card_number fields.

In register page I added new text input (card_nubmer) in account register page using hookCreateAccountForm() in module. It displays proper but how to get customer id in function hookCreateAccount($params) inside my payment module? I want to add own post data to database during (or just after) user register .

1 Answer 1

0

modules/mypaymentmodule/mypaymentmodule.php

public function hookCreateAccountForm()
    {
        return '<!--new field in form-->'
        . '<div class="form-group">'
            . '<label for="card_number">'
                . 'Card number:'
            . '</label>'
            . '<input class="form-control" id="card_number" type="text" name="card_number">'
            . '</div>'
            . '<!--new field in form-->';
    }

    public function hookCreateAccount($params)
    {
            [here put some validation of data]

            $cadrNumber = $params['_POST']['card_number'];
            $customer = $params['newCustomer'];

            $db = Db::getInstance();
            $query = 'INSERT INTO `'._DB_PREFIX_.'mymodule_card`
                    (`customer_id`, `card_number`)
                    VALUES
                    ("'.intval($customer->id).'", "'.  intval($cadrNumber).'")';
            $db->Execute($query);
    }

function below is calling of course during module instalation!

private function _createMymoduleCardTbl()
    {
        $db = Db::getInstance();
        $query = "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."mymodule_card` (
                                `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
                                `customer_id` INT NOT NULL ,
                                `card_number` TEXT NOT NULL
                                ) ENGINE = MYISAM ";

        $db->Execute($query);

        return TRUE;
    }

do not forget about hooks registering in install method!!

$this->registerHook('createAccountForm')
$this->registerHook('createAccount')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.