Extending 3rd Party Mod

Cupara

Well-known member
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.
 
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.
 
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.
 
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';
        }
    }
}
 
OK...

And what does the xfPoints_ControllerPublic_Shop class look like now you made the previous change?
 
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;
    }
}
 
I can't see anything obviously wrong.

Try this just before the return line:

PHP:
Zend_Debug::dump($totalPoints);
 
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?
 
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.
 
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.
 
I think the class name of IceShop is wrong so fix that first.

Not sure why the arcade one isn't working though.
 
Top Bottom