- Posts: 128
- Thank you received: 3
Problem with custom plugin in product show view
10 years 6 months ago - 10 years 6 months ago #233683
by deuce4884
Problem with custom plugin in product show view was created by deuce4884
-- HikaShop version -- : 2.5.0
-- Joomla version -- : 3.4.1
-- PHP version -- : 5.3.24
I have created a custom component to enter information for our products. I'm kinda new to working with creating plugins. I've created a plugin to work with this information in the product show_default view. I have attached the component and plugin.
The code I have at the beginning of my show_default view to work with the plugin is:
$this->element->grains, $this->element->gun_type, and $this->element->bullet_type are all custom fields I've created for the products and they are not empty. The code I have further down in the view to display the results of working with the plugin is:
I'm not getting anything to display and I know the data is there for the products I've tried this with. I'm sure it's something simple that is going on with this, but I'm just not sure what it is. Thanks for any help.
-- Joomla version -- : 3.4.1
-- PHP version -- : 5.3.24
I have created a custom component to enter information for our products. I'm kinda new to working with creating plugins. I've created a plugin to work with this information in the product show_default view. I have attached the component and plugin.
This attachment is hidden for guests.
Please log in or register to see it.
Please log in or register to see it.
This attachment is hidden for guests.
Please log in or register to see it.
Please log in or register to see it.
The code I have at the beginning of my show_default view to work with the plugin is:
Code:
// Get plugin 'productballistics' of plugin type 'ballistics'
$plugin = JPluginHelper::getPlugin('ballistics', 'productballistics');
// Check if plugin is enabled
if($plugin){
//fetch variables to run through productballistics plugin
if($this->row->unit_type == "pallets"){
if($this->row->package_count == "50000"){
$ballistic_sku = rtrim($this->element->product_code,"50KP");
}elseif($this->row->package_count == "100000"){
$ballistic_sku = rtrim($this->element->product_code,"100KP");
}
}elseif($this->row->unit_type == "cases"){
$ballistic_sku = rtrim($this->element->product_code,"L");
}else{
$ballistic_sku = $this->element->product_code;
}
$dispatcher = JDispatcher::getInstance();
$ballistics = $dispatcher->trigger('onProductballistics', array($ballistic_sku, $this->element->grains, $this->element->gun_type, $this->element->bullet_type));
}
$this->element->grains, $this->element->gun_type, and $this->element->bullet_type are all custom fields I've created for the products and they are not empty. The code I have further down in the view to display the results of working with the plugin is:
Code:
foreach($ballistics as $ballistic){
echo $ballistic;
}
I'm not getting anything to display and I know the data is there for the products I've tried this with. I'm sure it's something simple that is going on with this, but I'm just not sure what it is. Thanks for any help.
Last edit: 10 years 6 months ago by deuce4884.
Please Log in or Create an account to join the conversation.
10 years 6 months ago #233711
by nicolas
Replied by nicolas on topic Problem with custom plugin in product show view
Hi,
I've had a quick look at the code but I didn't find it to be wrong.
But then, I would recommend a simpler version of your solution.
Instead of customizing the show_default view to add a trigger to call a custom plugin, it's better to either directly put your custom code in the show_default view, or to use a trigger we already have in HikaShop (onHikashopBeforeDisplayView) in your custom plugin and fill in your HTML in the extraData array that is displayed automatically by the view and so you avoid having a view override.
In either case, you reduce the number of locations where you have your code, so you reduce the possibilities of making a mistake, and it's also easier to maintain in the future.
I've had a quick look at the code but I didn't find it to be wrong.
But then, I would recommend a simpler version of your solution.
Instead of customizing the show_default view to add a trigger to call a custom plugin, it's better to either directly put your custom code in the show_default view, or to use a trigger we already have in HikaShop (onHikashopBeforeDisplayView) in your custom plugin and fill in your HTML in the extraData array that is displayed automatically by the view and so you avoid having a view override.
In either case, you reduce the number of locations where you have your code, so you reduce the possibilities of making a mistake, and it's also easier to maintain in the future.
Please Log in or Create an account to join the conversation.
10 years 6 months ago #234102
by deuce4884
Replied by deuce4884 on topic Problem with custom plugin in product show view
Well I first had the code directly in the view, but I wasn't sure if it would be wise to have database connections and queries directly in the view.
Please Log in or Create an account to join the conversation.
10 years 6 months ago #234104
by nicolas
Replied by nicolas on topic Problem with custom plugin in product show view
Well, it's indeed bad practice when you're developing a whole application in MVC. But for a custom development I don't see a problem. Having your code easy to maintain by reducing the locations where you add your custom code, and simplifying it in the process is more important from my point of view in that case.
Please Log in or Create an account to join the conversation.
Time to create page: 0.185 seconds