[Skip to main content](#vessel-content)

#   Problem with custom plugin in product show view

##

- **[deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")**
- [![deuce4884's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/38332-deuce4884 "View deuce4884's Profile") Topic Author
- [ Offline](/forum/user/38332-deuce4884)

Less More

- Posts: 128
- Thank you received: 3
-
-

10 years 7 months ago -  10 years 7 months ago [\#233683](#233683) by [deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")  *[Problem with custom plugin in product show view](/forum/31-development/883187-problem-with-custom-plugin-in-product-show-view#233683 "-- 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&#95;default view. I have attached the component and plugin.  The code I have at the beginning of my show&#95;default view to work with the plugin is:  $this-&gt;element-&gt;grains, $this-&gt;element-&gt;gun&#95;type, and $this-&gt;element-&gt;bullet&#95;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.")* was created by *[deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")*

-- 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.

*This attachment is hidden for guests.
Please log in or register to see it.*

*This attachment is hidden for guests.
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-&gt;row-&gt;unit_type == "pallets"){ if($this-&gt;row-&gt;package_count == "50000"){ $ballistic_sku = rtrim($this-&gt;element-&gt;product_code,"50KP"); }elseif($this-&gt;row-&gt;package_count == "100000"){ $ballistic_sku = rtrim($this-&gt;element-&gt;product_code,"100KP"); } }elseif($this-&gt;row-&gt;unit_type == "cases"){ $ballistic_sku = rtrim($this-&gt;element-&gt;product_code,"L"); }else{ $ballistic_sku = $this-&gt;element-&gt;product_code; } $dispatcher = JDispatcher::getInstance(); $ballistics = $dispatcher-&gt;trigger('onProductballistics', array($ballistic_sku, $this-&gt;element-&gt;grains, $this-&gt;element-&gt;gun_type, $this-&gt;element-&gt;bullet_type)); }

$this-&gt;element-&gt;grains, $this-&gt;element-&gt;gun_type, and $this-&gt;element-&gt;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 7 months ago by [deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg4MzE4Ny1wcm9ibGVtLXdpdGgtY3VzdG9tLXBsdWdpbi1pbi1wcm9kdWN0LXNob3ctdmlldz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

10 years 7 months ago [\#233711](#233711) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Problem with custom plugin in product show view](/forum/31-development/883187-problem-with-custom-plugin-in-product-show-view#233711 "-- 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&#95;default view. I have attached the component and plugin.  The code I have at the beginning of my show&#95;default view to work with the plugin is:  $this-&gt;element-&gt;grains, $this-&gt;element-&gt;gun&#95;type, and $this-&gt;element-&gt;bullet&#95;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.")*

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.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg4MzE4Ny1wcm9ibGVtLXdpdGgtY3VzdG9tLXBsdWdpbi1pbi1wcm9kdWN0LXNob3ctdmlldz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")**
- [![deuce4884's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/38332-deuce4884 "View deuce4884's Profile") Topic Author
- [ Offline](/forum/user/38332-deuce4884)

Less More

- Posts: 128
- Thank you received: 3
-
-

10 years 7 months ago [\#234102](#234102) by [deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")  Replied by *[deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")* on topic *[Problem with custom plugin in product show view](/forum/31-development/883187-problem-with-custom-plugin-in-product-show-view#234102 "-- 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&#95;default view. I have attached the component and plugin.  The code I have at the beginning of my show&#95;default view to work with the plugin is:  $this-&gt;element-&gt;grains, $this-&gt;element-&gt;gun&#95;type, and $this-&gt;element-&gt;bullet&#95;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.")*

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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg4MzE4Ny1wcm9ibGVtLXdpdGgtY3VzdG9tLXBsdWdpbi1pbi1wcm9kdWN0LXNob3ctdmlldz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

10 years 7 months ago [\#234104](#234104) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Problem with custom plugin in product show view](/forum/31-development/883187-problem-with-custom-plugin-in-product-show-view#234104 "-- 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&#95;default view. I have attached the component and plugin.  The code I have at the beginning of my show&#95;default view to work with the plugin is:  $this-&gt;element-&gt;grains, $this-&gt;element-&gt;gun&#95;type, and $this-&gt;element-&gt;bullet&#95;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.")*

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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg4MzE4Ny1wcm9ibGVtLXdpdGgtY3VzdG9tLXBsdWdpbi1pbi1wcm9kdWN0LXNob3ctdmlldz90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.057 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
