Is there any way to pass a value from an extension to a module or a plugin in ExpressionEngine?
I created this very useful extension to take advantage of the expresso store module:
<?php
use Store\Model\Order;
use Store\Model\OrderShippingMethod;
class Credit_tracker_ext
{
protected $ee;
public $name = 'Credit tracker extention';
public $settings_exist = 'n';
public $hooks = array('store_checkout_form_validation', 'store_order_shipping_methods');
public function __construct($settings = '')
{
$this->ee = ee();
$this->settings = $settings;
}
public function activate_extension()
{
foreach ($this->hooks as $hook) {
$data = array(
'class' => __CLASS__,
'method' => $hook,
'hook' => $hook,
'settings' => serialize($this->settings),
'priority' => 10,
'version' => $this->version,
'enabled' => 'y',
);
ee()->db->insert('extensions', $data);
}
}
public function disable_extension()
{
ee()->db->where('class', __CLASS__);
ee()->db->delete('extensions');
}
public function settings()
{
}
public function store_checkout_form_validation($str, $obj)
{
}
public function store_order_shipping_methods(Order $order, array $obj)
{
if (ee()->extensions->last_call !== false) {
$methods = ee()->extensions->last_call;
}
$option = [];
foreach ($order->items as $value) {
$option = new OrderShippingMethod;
$option->id = $value->entry_id;
}
$methods[$option->id] = $option;
var_dump($methods);
return $methods;
}
}
I'd like to set up the object $method as a global array, to access it from another file, in another moment.
To clarify this point, the extension in this system is called at a certain point of the code, and the function that fires the extension is called hook, like in WordPress.
So essentially, I'd like to call the variable that I returned within another file (for example mod.credit_traker.php), where I can simply call the variable $methods.
Anyone who had this problem before?