Im new to Magento
Just installed this plugin http://shop.bubblecode.net/magento-attribute-image.html
All is going well, so on my product view page I run the following code to get my attribute ids
$ids = $_product->getData('headset_features');
Now the above plugin states it comes with this helper http://shop.bubblecode.net/attachment/download/link/id/11/
The function in this class I need to use is
public function getAttributeOptionImage($optionId)
{
$images = $this->getAttributeOptionImages();
$image = array_key_exists($optionId, $images) ? $images[$optionId] : '';
if ($image && (strpos($image, 'http') !== 0)) {
$image = Mage::getDesign()->getSkinUrl($image);
}
return $image;
}
I am really struggling to make use of this function.
I noticed in the helper class Bubble_AttributeOptionPro_Helper_Data extends Mage_Core_Helper_Abstract
So here is what I thought should work
echo Mage::helper('core')->Bubble_AttributeOptionPro_Helper_Data->getAttributeOptionImage($ids[0]);
But its not working for me, it kills the page, can someone please tell me how to access the function.
Thanks in advance.
UPDATE:
Just tried $helper = Mage::helper('AttributeOptionPro'); which also kills the page
Based on the helper classgroup for this module (bubble_aop, defined in the config), you can instantiate the helper class as follows:
$helper = Mage::helper('bubble_aop');
However I do not see anything in the class definition which gets it to pull data from the product entity.
You need to look into the module's etc folder and in config.xml you should have a node called helpers under config > global. The first child of that node (so that is before class node) is the name you should use to instantiate your helper and call your method so you would have something like Mage::helper('child_node_name')->getAttributeOptionImage($optionId);
Most of the helper classes extend Mage_Core_Helper_Abstrat which is abstract (can't be instantiated). If you run get_class(Mage::helper('core')) you will get Mage_Core_Helper_Data, because actually the default helper class in a module is Namespace/Module/Hepler/Data.php
Related
I am modularizing laravel. I have decided to move all the default routes, controllers, resources, etc.. to /app/Modules/Pub. For the most part this has worked well. However I would like to change the default resources path of the application. Unfortunately this doesn't seem to be (easily) configurable.
So... using grep I was able to track down the resource_path() function to /var/www/sigma/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php
I think it's possible to override this function somewhere but this seems like a subpar hack as this function consists simply of:
app()->resourcePath($path)
Again using grep I found out that this function is to be found in /var/www/sigma/vendor/laravel/framework/src/Illuminate/Foundation/Application.php
This seems to be the thing to change since it does not reference any configuration value, rather the value is hard coded:
return $this->basePath.DIRECTORY_SEPARATOR.'resources'.($path ? DIRECTORY_SEPARATOR.$path : $path);
But I think it's safe to assume it's pretty foolish to change anything under the vendor folder manually. Obviously I need to override this function somewhere. I am unclear where and how to do this
Create a new Application class which extends the \Illuminate\Foundation\Application:
<?php
namespace <YOUR NAMESPACE HERE>;
class ApplicationCustom extends \Illuminate\Foundation\Application
{
public function __construct()
{
parent::__construct();
}
/**
* Get the path to the resources directory.
*
* #param string $path
* #return string
*/
public function resourcePath($path = '')
{
// Implement the custom method
}
}
Now, just change your bootstrap/app.php file to use the custom class:
$app = new YOUR_NAMESPACE\ApplicationCustom(
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);
Hope it helps.
You could create a class somewhere in your project and extend the default \Illuminate\Foundation\Application class. Then override the methods you need and switch the class instantiated in bootstrap/app.php with your custom one.
I have created interceptor for catalog product controller's save action
<type name="Magento\Catalog\Controller\Adminhtml\Product\Save">
<plugin name="ricky_catalog_save_product"
type="Ricky\Catalog\Plugin\Product\Save" sortOrder="10"
/>
</type>
My plugin class is below
namespace Ricky\Catalog\Plugin\Product;
class Save {
public function afterExecute(
\Magento\Catalog\Controller\Adminhtml\Product\Save $subject,
$result)
{
$productId = $subject->productId; // This is not working
/** $productId is provided in excute method in Save class
in Magento\Catalog\Controller\Adminhtml\Product\Save **/
}
}
For some reasons I have to use Plugin (Interceptor Design Pattern), I know I can get newly created prouduct id by using observer for catalog_product_save_after event. But please provide solution for plugins.
Thanks for help :)
If you are accessing the property $subject->productId, that means it should be defined in the class
\Magento\Catalog\Controller\Adminhtml\Product\Save.
There is no class variable defined with name productId.
You can override the controller and define one more public class variable
public $productId;
and assign product id somewhere in the execute() method:-
$this->productId = $productId;
Now in your plugin use it as:-
$subject->productId
Tested and working..!!
You can get the product Id in this way
$productId = $subject->getRequest()->getParam('id');
Hope this helps !! Happy Coding
Okay, so i have pages controller and user_authenticator controller.
pages controller is like a terminal to my views whilst the user_authenticator controller does the functions that relates to users like registration/logging in.
Whenever i'm done with a function in user_authenticator say for example logging in, how do i load the views via pages controller?
Login->user_auth(controller)->acc_model(model)->user_auth(controller)->view.
to
Login->user_auth->acc_model->pages(controller)->view.
It would be a boon for me if you guys can tell me if what i'm doing is impractical and a better way to do things. Or maybe i should just stick to loading views on the controller i used previously.
EDIT: so i may have forgotten the purpose of my pages controller but i remembered due to a moment of clarity from my foggy and tired mind.
I made a pages controller solely to load views, i guess in a sense, pages won't be loading ALL view but atleast most of the views, for example, if i had links in my views to other views, i would link them via the pages.
For specific functions that need specific controllers i guess i can let them handle loading some views.
Then again, if someone could tell me what i'm doing is a waste of time and should just delete pages controller please tell me so, i'd like to know why.
also if you have any suggestions for further uses of my pages controller thatd be great!
Also regarding session. I have a base controller.
<?php
class MY_Controller extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function is_logged_in($data){
$session = $this->session->userdata();
if($session['isloggedin']['username'] == ''){
return isset($session);
}else{
return FALSE;}
}
}
?>
How do i make it so that it automatically runs and checks for every controller i load if there are any session set?
Do i have to put it into a constructor? or do i have to call the base controller method from all controllers?
Here is the best solution for you.
You can use Hooks
Step1:
application/config/config.php
$config['enable_hooks'] = TRUE;//enable hook
Step2:
application/config/hooks.php
$is_logged_in= array();
$is_logged_in['class'] = '';
$is_logged_in['function'] = 'is_logged_in';//which function will be executed
$is_logged_in['filename'] = 'is_logged_in.php';//hook file name
$is_logged_in['filepath'] = 'hooks';//path.. default
$is_logged_in['params'] = array();
$hook['post_controller_constructor'][] = $is_logged_in;//here we decare a hook .
//the hook will be executed after CI_Controller construct.
//(also u can execute it at other time , see the CI document)
Step3:
application/hooks/is_logged_in.php //what u decared
<?php
//this function will be called after CI controller construct!
function is_logged_in(){
$ci =& get_instance();//here we get the CI super object
$session = $ci->session->userdata();//get session
if($session['isloggedin']){ //if is logged in = true
$ci->username = 'mike';//do what you want just like in controller.
//but use $ci instead of $this**
}else{
//if not loggedin .do anything you want
redirect('login');//go to login page.
}
}
Step4:application/controller/pages.php
<?php
class pages extends CI_Controller{
function construct ........
function index(){
echo $this->username;//it will output 'Mike', what u declared in hook
}
}
Hope it will help u.
I'm using Magento with Typo3 (Shopfusion). I've an extension for uploading order images it works in "pure" Magento but in Magento through Shopfusion.
I already debugged Magento as far as I could. In shopfusion the following Singleton leads into an empty array. I checked the getOrderAttachments from "RedPandaPlus_OrderAttachments_Block_Attachments" and found out that it isn't called
Singleton call:
$orderAttachments = Mage::getSingleton('redpandaplus_orderattachments/session')->getOrderAttachments();
Code of method:
class RedPandaPlus_OrderAttachments_Block_Attachments extends Mage_Core_Block_Template
{
,...
public function getOrderAttachments($orderId)
{
$collection = Mage::getModel('redpandaplus_orderattachments/orderattachment')->getCollection()
->addFieldToFilter('order_id', $orderId);
return $collection->toArray();
}
,...
}
As I can see from your code, you are missing the $orderId argument in your call:
$orderAttachments = Mage::getSingleton('redpandaplus_orderattachments/session')->getOrderAttachments();
To help you get the orderId I need to know where you are calling this method.
I am using CodeIgniter. I want to use my own class to pass as an argument inside controller functions.
Normally, I can put this class in a folder and include it to MY_Controller with its path. But I want to learn if there is a way to do this in CodeIgniter. I can't put it in libraries folder and can't use loader class because it tries to create an instance of an object, but I want to create instance whenever I want. Loader class gives an error if my own class need constructor parameters.
What is the best way to do that?
Which is the best folder to put in it?
This is very easy. Consider this example
<?php
Class Home extends CI_Controller{
public $arg1 = 1;
public $arg2 = 2;
function index($this->$arg1 , $this->$arg2){ //or function index()
//Then inside function
//$vara = $this->$arg1 , $varb = $this->$arg2;
}
}