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

#   Overriding Hikashop classes for custom features

##

- **[brainforge](/forum/user/423-brainforge "View brainforge's Profile")**
- [![brainforge's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar423.jpg)](/forum/user/423-brainforge "View brainforge's Profile") Topic Author
- [ Offline](/forum/user/423-brainforge)

Less More

- Posts: 298
- Thank you received: 5
-
-
-
- [](https://brainforge.co.uk)
-

15 years 1 week ago [\#28425](#28425) by [brainforge](/forum/user/423-brainforge "View brainforge's Profile")  *[Overriding Hikashop classes for custom features](/forum/2-general-talk-about-hikashop/28425-overriding-hikashop-classes-for-custom-features#28425 "In helper.php line 760 would it be possible to check for the existance of a class file in either the site or admin template locations? The purpose would be to reduce the risk of any class customisations a developer may have made getting accidently overridden during a Hikashop upgrade. I.E. change code to something like this: This idea came about while thinking of possible solutions to the following topics:  Another idea was for a couple of new functions which could be called by a plug-in:  onBeforeVoucherAdded onAfterVoucherAdded These would be invoked in loadAndCheck function of discount.php something like this:  Any other ideas if how this moght be achieved?")* was created by *[brainforge](/forum/user/423-brainforge "View brainforge's Profile")*

In *helper.php* line 760 would it be possible to check for the existance of a class file in either the site or admin template locations?
The purpose would be to reduce the risk of any class customisations a developer may have made getting accidently overridden during a Hikashop upgrade.
I.E. change code Code:

if(!class_exists($className)) include_once(constant(strtoupper('HIKASHOP_'.$group)).$class.'.php');

to something like this: Code:

if(!class_exists($className)) { $app = JFactory::getApplication(); $classfile= JPATH_SITE . DS . 'templates'.DS.$app-&gt;getTemplate().DS.'classes'.DS.'com_hikashop'.DS.$class.'.php' if (file_exists($classfile)) { // Add some way of checking if custom class is compatible with installed Hikashop version // If not then produce an error include_once($classfile); } else { $classfile= JPATH_ADMINISTRATOR . DS . 'templates'.DS.$app-&gt;getTemplate().DS.'classes'.DS.'com_hikashop'.DS.$class.'.php' if (file_exists($classfile)) { // Add some way of checking if custom class is compatible with installed Hikashop version // If not then produce an error include_once($classfile); } } if(!class_exists($className)) include_once(constant(strtoupper('HIKASHOP_'.$group)).$class.'.php');

This idea came about while thinking of possible solutions to the following topics:
[ 11199-coupons-and-discounts](http://www.hikashop.com/en/support/forum/2-general-talk-about-hikashop/11199-coupons-and-discounts.html)
[ 27448-coupons-for-specific-products](http://www.hikashop.com/en/support/forum/2-general-talk-about-hikashop/27448-coupons-for-specific-products.html)

Another idea was for a couple of new functions which could be called by a plug-in:
*onBeforeVoucherAdded
onAfterVoucherAdded*
These would be invoked in *loadAndCheck* function of *discount.php* something like this: Code:

function loadAndCheck($coupon_code,&amp;$total,$zones,&amp;$products,$display_error=true){ $coupon = $this-&gt;load($coupon_code); if (...onBeforeVoucherAdded... exists) { $beforeResult = ...-&gt;onBeforeVoucherAdded($coupon,$total,$zones,$products,$display_error); if ($beforeResult === FALSE) return null; if (is_object($beforeResult)) return $beforeResult; } $result = $this-&gt;check($coupon,$total,$zones,$products,$display_error); if (...onAfterVoucherAdded... exists) { $afterResult = ...-&gt;onAfterVoucherAdded($result,$coupon,$total,$zones,$products,$display_error); if ($afterResult === FALSE) return null; if (is_object($afterResult)) return $afterResult; } return $result; }

Any other ideas if how this moght be achieved?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzItZ2VuZXJhbC10YWxrLWFib3V0LWhpa2FzaG9wLzI4NDI1LW92ZXJyaWRpbmctaGlrYXNob3AtY2xhc3Nlcy1mb3ItY3VzdG9tLWZlYXR1cmVzP3RtcGw9bWFya2Rvd24=) or [Create an account](/register) 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")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86322
- Thank you received: 14281
-
-

15 years 1 week ago [\#28444](#28444) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Overriding Hikashop classes for custom features](/forum/2-general-talk-about-hikashop/28425-overriding-hikashop-classes-for-custom-features#28444 "In helper.php line 760 would it be possible to check for the existance of a class file in either the site or admin template locations? The purpose would be to reduce the risk of any class customisations a developer may have made getting accidently overridden during a Hikashop upgrade. I.E. change code to something like this: This idea came about while thinking of possible solutions to the following topics:  Another idea was for a couple of new functions which could be called by a plug-in:  onBeforeVoucherAdded onAfterVoucherAdded These would be invoked in loadAndCheck function of discount.php something like this:  Any other ideas if how this moght be achieved?")*

The current code already allow you to override all the classes in HikaShop.
You can just create a joomla system plugin and implement the class in the plugin file. Since the code checks that the class does not already exists before loading the file in HikaShop and since the system plugins are always loaded first, you will be able to achieve just what you're looking for.
So I don't feel like that code is needed actually.

Regarding the addition of events on the coupon checking code, that's a nice idea even though I doubt that it will be used a lot. We'll implement something for that (not like that).

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzItZ2VuZXJhbC10YWxrLWFib3V0LWhpa2FzaG9wLzI4NDI1LW92ZXJyaWRpbmctaGlrYXNob3AtY2xhc3Nlcy1mb3ItY3VzdG9tLWZlYXR1cmVzP3RtcGw9bWFya2Rvd24=) or [Create an account](/register) to join the conversation.

- **[brainforge](/forum/user/423-brainforge "View brainforge's Profile")**
- [![brainforge's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar423.jpg)](/forum/user/423-brainforge "View brainforge's Profile") Topic Author
- [ Offline](/forum/user/423-brainforge)

Less More

- Posts: 298
- Thank you received: 5
-
-
-
- [](https://brainforge.co.uk)
-

15 years 6 days ago [\#28492](#28492) by [brainforge](/forum/user/423-brainforge "View brainforge's Profile")  Replied by *[brainforge](/forum/user/423-brainforge "View brainforge's Profile")* on topic *[Re: Overriding Hikashop classes for custom features](/forum/2-general-talk-about-hikashop/28425-overriding-hikashop-classes-for-custom-features#28492 "In helper.php line 760 would it be possible to check for the existance of a class file in either the site or admin template locations? The purpose would be to reduce the risk of any class customisations a developer may have made getting accidently overridden during a Hikashop upgrade. I.E. change code to something like this: This idea came about while thinking of possible solutions to the following topics:  Another idea was for a couple of new functions which could be called by a plug-in:  onBeforeVoucherAdded onAfterVoucherAdded These would be invoked in loadAndCheck function of discount.php something like this:  Any other ideas if how this moght be achieved?")*

Looks like a system plug-in along the following lines will do the job:
Code:

class plgSystemMyclasses extends JPlugin { public function onAfterRoute() { if (JRequest::getVar('option') == 'com_hikashop') { if (!class_exists('hikashop')) { include(JPATH_ADMINISTRATOR . DS . 'components/com_hikashop/helpers/helper.php'); } include(__DIR__ . DS . '/class/myclasses.php'); } } }

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzItZ2VuZXJhbC10YWxrLWFib3V0LWhpa2FzaG9wLzI4NDI1LW92ZXJyaWRpbmctaGlrYXNob3AtY2xhc3Nlcy1mb3ItY3VzdG9tLWZlYXR1cmVzP3RtcGw9bWFya2Rvd24=) or [Create an account](/register) 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")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86322
- Thank you received: 14281
-
-

15 years 6 days ago [\#28501](#28501) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Overriding Hikashop classes for custom features](/forum/2-general-talk-about-hikashop/28425-overriding-hikashop-classes-for-custom-features#28501 "In helper.php line 760 would it be possible to check for the existance of a class file in either the site or admin template locations? The purpose would be to reduce the risk of any class customisations a developer may have made getting accidently overridden during a Hikashop upgrade. I.E. change code to something like this: This idea came about while thinking of possible solutions to the following topics:  Another idea was for a couple of new functions which could be called by a plug-in:  onBeforeVoucherAdded onAfterVoucherAdded These would be invoked in loadAndCheck function of discount.php something like this:  Any other ideas if how this moght be achieved?")*

Yes. You could even do simpler:

Do not have that code in your plugin file and directly have your classes there.
When joomla starts loading, it will include your plugin file and your classes will be instantiated automatically and since it won't find your plugin class it won't try to call it but your classes will already be there for HikaShop to use.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzItZ2VuZXJhbC10YWxrLWFib3V0LWhpa2FzaG9wLzI4NDI1LW92ZXJyaWRpbmctaGlrYXNob3AtY2xhc3Nlcy1mb3ItY3VzdG9tLWZlYXR1cmVzP3RtcGw9bWFya2Rvd24=) or [Create an account](/register) 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.083 seconds

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