• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Extending 3rd Party Mod

Mythotical

Well-known member
#1
I'm trying to extend 3rd party mods so that my xfPoints mod can tie into them. The problem I'm having is extending to the point that my variables are accessible within the templates.

Take for instance a Ice Shop, trying to tie into the public view where I can give a total of points accumulated before they purchase items. Once they purchase an item the points are deducted instead of using real currency. Don't know how Ice Shop works but using it as an example.

I have this so far:
Code:
class xfPoints_ControllerPublic_Shop extends XFCP_xfPoints_ControllerPublic_Shop
{
    public function actionIndex()
    {
    	$response = parent::actionIndex();

	    	$user_id = XenForo_Visitor::getUserId();

	    	$pointsModel = $this->getModelFromCache('xfPoints_Model_Currency');
	    	$totalPoints = $pointsModel->getUserPointsId($user_id);
	    	$totalPoints = $totalPoints['xfpoints_currency'];

	    	$response = array(
	    		'totalPoints' => $totalPoints,
	    		);

	    return $response;
    }
}
So if anyone can give me some guidance here it would be much appreciated.
 

Chris D

XenForo developer
Staff member
#2
I can see what you're trying to achieve... but unfortunately you're not executing it properly.

You're starting right...

PHP:
$response = parent::actionIndex();
That's correct. You're calling the parent function and storing it in a variable.

Then you're getting your data.

Where it's going wrong is where you're overwriting your parent variable with an array.

PHP:
$response = array('totalPoints' => $totalPoints);
So now you've done that, when you do:

PHP:
return $response;
You're not returning the parent.

What you need to do is add your array of data into the existing parent function. Not overwrite the parent function with your data.
 

Mythotical

Well-known member
#6
LOL Thanks for trying Kim, I'm sure it is the right idea but my variable still doesn't work so I'm assuming your method was off in some area or something. I have no idea.
 

Mythotical

Well-known member
#8
LoadControllerPublic.php
Code:
class xfPoints_Listener_LoadControllerPublic
{

    public static function loadControllerPublic($class, &$extend)
    {
        if ($class == 'XenForo_ControllerPublic_Register') {
            $extend[] = 'xfPoints_ControllerPublic_Register';
        }
        if ($class == 'XenForo_ControllerPublic_Member') {
            $extend[] = 'xfPoints_ControllerPublic_Member';
        }
        if ($class == 'XenForo_ControllerPublic_Account') {
        	$extend[] = 'xfPoints_ControllerPublic_Account';
        }
        if ($class == 'IceShop_ControllerPublic_Index') {
	        $extend[] = 'xfPoints_ControllerPublic_Shop';
        }
    }
}
 

Chris D

XenForo developer
Staff member
#9
OK...

And what does the xfPoints_ControllerPublic_Shop class look like now you made the previous change?
 

Mythotical

Well-known member
#10
Code:
class xfPoints_ControllerPublic_Shop extends XFCP_xfPoints_ControllerPublic_Shop
{
    public function actionIndex()
    {
    	$response = parent::actionIndex();

	    	$user_id = XenForo_Visitor::getUserId();

	    	$pointsModel = $this->getModelFromCache('xfPoints_Model_Currency');
	    	$totalPoints = $pointsModel->getUserPointsId($user_id);
	    	$totalPoints = $totalPoints['xfpoints_currency'];

	    	$response->params['totalPoints'] = $totalPoints;

	    return $response;
    }
}
 

Chris D

XenForo developer
Staff member
#11
I can't see anything obviously wrong.

Try this just before the return line:

PHP:
Zend_Debug::dump($totalPoints);
 

Chris D

XenForo developer
Staff member
#13
Nothing at all?

Not even a blank string?

What if you just type something that would cause a deliberate exception or make a deliberate typo. Does it cause a error to be displayed?
 

Mythotical

Well-known member
#15
If it helps I had the same issue trying to tie into XFArcade

Code:
class xfPoints_ControllerPublic_Arcade extends XFCP_xfPoints_ControllerPublic_Arcade
{
    public function actionPlay()
    {
    	$response = parent::actionPlay();

	    	$user_id = XenForo_Visitor::getUserId();

	    	$pointsModel = $this->getModelFromCache('xfPoints_Model_Currency');
	    	$totalPoints = $pointsModel->getUserPointsId($user_id);
	    	$totalPoints = $totalPoints['xfpoints_currency'];
	    	//echo $totalPoints;

	    	 $response->params['totalPoints'] = $totalPoints['xfpoints_currency'];

	    return $response;
    }
}
Code:
class xfPoints_Listener_LoadControllerPublic
{

    public static function loadControllerPublic($class, &$extend)
    {
        if ($class == 'XenForo_ControllerPublic_Register') {
            $extend[] = 'xfPoints_ControllerPublic_Register';
        }
        if ($class == 'XenForo_ControllerPublic_Member') {
            $extend[] = 'xfPoints_ControllerPublic_Member';
        }
        if ($class == 'XenForo_ControllerPublic_Account') {
        	$extend[] = 'xfPoints_ControllerPublic_Account';
        }
        if ($class == 'Arcade_ControllerPublic_Arcade') {
	        $extend[] = 'xfPoints_ControllerPublic_Arcade';
        }
    }
}
I added edits from above and added to the Arcade with same results.
 

Chris D

XenForo developer
Staff member
#16
Yeah so your extended code isn't firing at all.

Double/triple check you're extending the right Ice Shop class and then accessing it correctly.