Custom actions

14 posts in this topic

Posted

Hi,
Wasn't sure where to put this.
I'm very confused about how the custom actions works.
I looked at this tutorial: http://community.invisionpower.com/resources/documentation/index.html/_/developer-resources/ipnexus/ipnexus-custom-actions-r496
But it's not of much help really..
I tried with this very basic function:



public function onPaid( $member, $package, $invoice )

        {

            $this->DB->update( "ccs_custom_database_3", array( 'field_34' => 1 ), 'primary_id_field=1' );

        }


Well, no errors was displayed when trying to purchase my item, however that query didn't get executed, or it didn't change anything. No PHP errors at all, nothing to debug with.
Also, i would like to use the custom fields for my product, how can I do this?

Share this post


Link to post
Share on other sites

Posted

Remember that IPB is using own driver..

Example from one of my actions..


public function onPaid($member, $package, $invoice) {

	 $db = $this->connect();


	 foreach ($invoice->items as $key => $item) {

		 continue;

	 }


	 (...)


	 sqlsrv_query($db, $sql, $params);


	 $db = ipsRegistry::DB();


	 $db->query("SHOW TABLE STATUS LIKE 'igzxccn_nexus_purchases'");

	 while ($row = $db->fetch()) {

		 $statusTable = $row;

	 }


	 $data = array(

		 'lkey_key' => $hash,


			 (...)

	 );


	 $db->insert('nexus_licensekeys', $data);

}



Also, onPaid will get executed only after the payment will be confirmed. So purchase made, and payment received where onPurchase gonna run after the invoice will be generated as I remember.

p.s. before I determined how this all exactly works like I had to create ~6-8 tickets to get spec info :tongue:

Mikkel-T likes this

Share this post


Link to post
Share on other sites

Posted

Your lucky they would answer your tickets, they wouldn't support me :P
Tried this:



public function onPaid( $member, $package, $invoice )

        {

            $db = $this->connect();

            $db = ipsRegistry::DB();

            $db->update( "ccs_custom_database_3", array( 'field_34' => 1 ), 'primary_id_field=1' );

        }


Wouldn't work either.. :(

Share this post


Link to post
Share on other sites

Posted

Your class isn't extending anything, and you haven't set $this->DB, so you're calling a property that doesn't exist :)

You want:

public function onPaid( $member, $package, $invoice ) { ipsRegistry::DB()->update( "ccs_custom_database_3", array( 'field_34' => 1 ), 'primary_id_field=1' ); }






Share this post


Link to post
Share on other sites

Posted

Hi Mark,
I thought I achieved that by using this:

$db = ipsRegistry::DB();
$db->update( "ccs_custom_database_3", array( 'field_34' => 1 ), 'primary_id_field=1' );
Anyway, I tried yours without luck.

Then I tried this:



private $registry;

    private $DB;

    private $settings;

    private $request;

    private $lang;

    private $member;

    private $memberData;

    private $cache;

    private $caches;


    function __construct($registry){

            $this->registry   =  $registry;

            $this->DB         =  $this->registry->DB();

            $this->settings   =& $this->registry->fetchSettings();

            $this->request    =& $this->registry->fetchRequest();

            $this->lang       =  $this->registry->getClass('class_localization');

            $this->member     =  $this->registry->member();

            $this->memberData =& $this->registry->member()->fetchMemberData();

            $this->cache      =  $this->registry->cache();

            $this->caches     =& $this->registry->cache()->fetchCaches();

    }

        /**

         * Item Purchased (run before onPurchaseGenerated)

         *

         * @param       array   The member purchasing

         * @param       array   Package data (combined array with row from nexus_packages and nexus_packages_*, depending on the package type)

         * @param       invoice Invoice Model

         * @return      void

         */

        public function onPaid( $member, $package, $invoice )

        {

            $this->DB->update( "ccs_custom_database_3", array( 'field_34' => 1 ), 'primary_id_field=1' );

        }


And it didn't appear to be working either..
Is the registry sent when this class is created?

Share this post


Link to post
Share on other sites

Posted

Nexus doesn't send the registry instance to the constructor.

What is the entire file you're using? You're probably naming the class wrong.

Share this post


Link to post
Share on other sites

Posted

Does the UPDATE struct is fine? Make sure the first value should be a table name without the prefix, the TABLE should be located in forum database as using the above what @Mark stated you connect to forum db, not external.

Share this post


Link to post
Share on other sites

Posted

This is my class:



<?php


class custom_actions_WowJob //extends ipsCommand

{


    private $registry;

    private $DB;

    private $settings;

    private $request;

    private $lang;

    private $member;

    private $memberData;

    private $cache;

    private $caches;


    function __construct($registry){

            $this->registry   =  $registry;

            $this->DB         =  $this->registry->DB();

            $this->settings   =& $this->registry->fetchSettings();

            $this->request    =& $this->registry->fetchRequest();

            $this->lang       =  $this->registry->getClass('class_localization');

            $this->member     =  $this->registry->member();

            $this->memberData =& $this->registry->member()->fetchMemberData();

            $this->cache      =  $this->registry->cache();

            $this->caches     =& $this->registry->cache()->fetchCaches();

    }

        /**

         * Item Purchased (run before onPurchaseGenerated)

         *

         * @param       array   The member purchasing

         * @param       array   Package data (combined array with row from nexus_packages and nexus_packages_*, depending on the package type)

         * @param       invoice Invoice Model

         * @return      void

         */

        public function onPaid( $member, $package, $invoice )

        {

            $this->DB->update( "ccs_custom_database_3", array( 'field_34' => 1 ), 'primary_id_field=1' );

            ipsRegistry::DB()->update( "ccs_custom_database_3", array( 'field_34' => 1 ), 'primary_id_field=1' );

        }


        /**

         * Purchase record generated (run after onPaid)

         *

         * @param       array   The member purchasing

         * @param       array   Package data (combined array with row from nexus_packages and nexus_packages_*, depending on the package type)

         * @param       invoice Invoice Model

         * @param       array   Row from nexus_purchases [since Nexus 1.5]

         * @return      void

         */

        public function onPurchaseGenerated( $member, $package, $invoice, $purchase )

        {

            $db = $this->connect();

            $db = ipsRegistry::DB();

            $db->update( "ccs_custom_database_3", array( 'field_34' => 1 ), 'primary_id_field=1' );

        }


        /**

         * Purchase Renewed, but was still active anyway

         *

         * @param       array   The member renewing

         * @param       array   Package data (combined array with row from nexus_packages and nexus_packages_*, depending on the package type)

         * @param       invoice Invoice Model

         * @param       array   The row from nexus_purchases [since Nexus 1.5]

         * @return      void

         */

        public function onRenew( $member, $package, $invoice, $purchase )

        {


        }        


        /**

         * Purchase Renewed after had expired

         *

         * @param       array                   The member renewing

         * @param       array                   Package data (combined array with row from nexus_packages and nexus_packages_*, depending on the package type)

         * @param       invoice|null    Invoice Model [May not be set if manually reactivating]

         * @param       array                   The row from nexus_purchases [since Nexus 1.5]

         * @return      void

         */

        public function onReactivate( $member, $package, $invoice, $purchase )

        {


        }


        /**

         * Purchase Expired

         *

         * @param       array                   The member the purchase belongs to

         * @param       array                   Package data (combined array with row from nexus_packages and nexus_packages_*, depending on the package type)

         * @param       invoice|null    Will usually be null. If the purchase is expiring because the invoice which previously renewed it is now being marked unpaid, the invoice object will be passed.

         * @param       array                   The row from nexus_purchases [since Nexus 1.5]

         * @return      void

         */

        public function onExpire( $member, $package, $invoice, $purchase )

        {


        }


        /**

         * Purchase Cancelled or Deleted

         *

         * @param       array                   The member the purchase belongs to

         * @param       array                   Package data (combined array with row from nexus_packages and nexus_packages_*, depending on the package type)

         * @param       invoice|null    Will usually be null. If the purchase is being cancelled because the invoice which was used to purchase it it is now being marked unpaid, the invoice object will be passed.

         * @param       array                   The row from nexus_purchases [since Nexus 1.5]

         * @return      void

         */

        public function onCancel( $member, $package, $invoice, $purchase )

        {


        }


        /**

         * Purchase is transferred to another member

         *

         * @param       array           Old owner

         * @param       array           Package data (combined array with row from nexus_packages and nexus_packages_*, depending on the package type)

         * @param       array           The row from nexus_purchases

         * @param       customer        New owner

         * @return      void

         */

        public function onTransfer( $oldOwner, $package, $purchase, $newOwner )

        {


        }


        /**

         * Purchase is upgraded/downgraded

         *

         * @param       array           The member the purchase belongs to

         * @param       array           Old package data (combined array with row from nexus_packages and nexus_packages_*, depending on the package type)

         * @param       array           The row from nexus_purchases

         * @param       package         New package object

         * @return      void

         */

        public function onchange( $member, $oldPackage, $purchase, $newPackage )

        {


        }


        /**

         * Purchases' parent purchase is changed

         *

         * @param       array                   The member the purchase belongs to

         * @param       array                   Package data (combined array with row from nexus_packages and nexus_packages_*, depending on the package type)

         * @param       array                   The row from nexus_purchases

         * @param       array|null        The previous parent (may be null if had no parent previously)

         * @param       array|null        The new parent (may be null if was previously associated and now not)

         * @return      void

         */

        public function onAssociate( $member, $package, $purchase, $oldParent, $newParent )

        {


        }


}

Share this post


Link to post
Share on other sites

Posted

First of all


$db = $this->connect();

$db = ipsRegistry::DB();



you overwrite first $db with second $db.

Share this post


Link to post
Share on other sites

Posted

Yea, I don't use onPurchaseGenerated just onpaid, which is the one not working.

Share this post


Link to post
Share on other sites

Posted

1. You're specifying a constructor and assuming the registry is passed to it, which it isn't.
2. You're calling $this->connect() which doesn't exist.

Share this post


Link to post
Share on other sites

Posted

Okay, if the registry is not passed how would I do then :)
Should I extend a specific class, and how would I eventually get on from there?

Share this post


Link to post
Share on other sites

Posted

Instead of $this->DB-> use ipsRegistry::DB()->
It's a Singleton.

Share this post


Link to post
Share on other sites

Posted

Okay, but for some reason that doesn't work either.
Also if i want to use custom fields how can I do that? :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Who's Browsing   0 members

    No registered users viewing this page.