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

#   Impossible to overwrite checkout helper

##

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

Less More

- Posts: 31
- Thank you received: 2
-
-

5 years 9 months ago [\#328523](#328523) by [Denitz](/forum/user/42054-denitz "View Denitz's Profile")  *[Impossible to overwrite checkout helper](/forum/25-install-update/901711-impossible-to-overwrite-checkout-helper#328523 "I created the overwrite class hikashopCheckoutHelperOverride correctly and it's loaded from templates/yootheme/html/com&#95;hikashop/administrator/helpers/checkout.override.php  But the class hikashopCheckoutHelperOverride is not used because the code has direct calls to original class:  And I can't declare my own hikashopCheckoutHelper class which should extend original hikashopCheckoutHelper")* was created by *[Denitz](/forum/user/42054-denitz "View Denitz's Profile")*

I created the overwrite class **hikashopCheckoutHelperOverride** correctly and it's loaded from **templates/yootheme/html/com\_hikashop/administrator/helpers/checkout.override.php**

But the class **hikashopCheckoutHelperOverride** is not used because the code has direct calls to original class:
Code:

$checkoutHelper = hikashopCheckoutHelper::get();

And I can't declare my own hikashopCheckoutHelper class which should extend original hikashopCheckoutHelper

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzkwMTcxMS1pbXBvc3NpYmxlLXRvLW92ZXJ3cml0ZS1jaGVja291dC1oZWxwZXI/dG1wbD1tYXJrZG93bg==) 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")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86564
- Thank you received: 14311
-
-

5 years 9 months ago [\#328528](#328528) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Impossible to overwrite checkout helper](/forum/25-install-update/901711-impossible-to-overwrite-checkout-helper#328528 "I created the overwrite class hikashopCheckoutHelperOverride correctly and it's loaded from templates/yootheme/html/com&#95;hikashop/administrator/helpers/checkout.override.php  But the class hikashopCheckoutHelperOverride is not used because the code has direct calls to original class:  And I can't declare my own hikashopCheckoutHelper class which should extend original hikashopCheckoutHelper")*

Hi,

Indeed if you want to extend from the original helper it's problematic. This class is called directly for some reasons on our end.
An easy solution would be to not extend from the original class and copy its code, but then, you might have issues in the future when updating.
Another solution could be to load the the content of the checkout.php helper file with file_get_contents, do a str_replace on the class name and then use exec on the string. That way, you dynamically rename the class name without directly modifying the core file.
Here are a page with different solutions to that problematic:
[ stackoverflow.com/questions/2658906/is-t...-class-safely-in-php](https://stackoverflow.com/questions/2658906/is-there-any-way-to-redeclare-a-class-safely-in-php)
Using namespaces would be the cleanest solution I believe but I don't think it would be applicable in this situation.
Using runkit is interesting but it requires a special extension added to your PHP, so if your hosting doesn't have it, or you want to migrate to another hosting in the future where the extension is not available, it would be problematic.

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

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

Less More

- Posts: 31
- Thank you received: 2
-
-

5 years 9 months ago -  5 years 9 months ago [\#328555](#328555) by [Denitz](/forum/user/42054-denitz "View Denitz's Profile")  Replied by *[Denitz](/forum/user/42054-denitz "View Denitz's Profile")* on topic *[Impossible to overwrite checkout helper](/forum/25-install-update/901711-impossible-to-overwrite-checkout-helper#328555 "I created the overwrite class hikashopCheckoutHelperOverride correctly and it's loaded from templates/yootheme/html/com&#95;hikashop/administrator/helpers/checkout.override.php  But the class hikashopCheckoutHelperOverride is not used because the code has direct calls to original class:  And I can't declare my own hikashopCheckoutHelper class which should extend original hikashopCheckoutHelper")*

Just modify the get() method to load override:
Code:

public static function get($cart_id = null) { if(self::$instance === null) { $classname = class_exists('hikashopCheckoutHelperOverride') ? 'hikashopCheckoutHelperOverride' : 'hikashopCheckoutHelper'; self::$instance = new $classname($cart_id); self::$instance-&gt;config = hikashop_config(); self::$instance-&gt;loadWorkflow(); } return self::$instance; }

Last edit: 5 years 9 months ago by [Denitz](/forum/user/42054-denitz "View Denitz's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzkwMTcxMS1pbXBvc3NpYmxlLXRvLW92ZXJ3cml0ZS1jaGVja291dC1oZWxwZXI/dG1wbD1tYXJrZG93bg==) 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")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86564
- Thank you received: 14311
-
-

5 years 9 months ago [\#328559](#328559) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Impossible to overwrite checkout helper](/forum/25-install-update/901711-impossible-to-overwrite-checkout-helper#328559 "I created the overwrite class hikashopCheckoutHelperOverride correctly and it's loaded from templates/yootheme/html/com&#95;hikashop/administrator/helpers/checkout.override.php  But the class hikashopCheckoutHelperOverride is not used because the code has direct calls to original class:  And I can't declare my own hikashopCheckoutHelper class which should extend original hikashopCheckoutHelper")*

Hi,

That's a good proposition. We sure can add that for the next version of HikaShop.

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

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

Less More

- Posts: 31
- Thank you received: 2
-
-

5 years 9 months ago [\#328646](#328646) by [Denitz](/forum/user/42054-denitz "View Denitz's Profile")  Replied by *[Denitz](/forum/user/42054-denitz "View Denitz's Profile")* on topic *[Impossible to overwrite checkout helper](/forum/25-install-update/901711-impossible-to-overwrite-checkout-helper#328646 "I created the overwrite class hikashopCheckoutHelperOverride correctly and it's loaded from templates/yootheme/html/com&#95;hikashop/administrator/helpers/checkout.override.php  But the class hikashopCheckoutHelperOverride is not used because the code has direct calls to original class:  And I can't declare my own hikashopCheckoutHelper class which should extend original hikashopCheckoutHelper")*

Thanks, but note that this method is not good: it caches instance created with or without $cart_id.
First call without $cart_id will cache instance without $cart_id, next call with $cart_id will return this cached instance without $cart_id.

It's unrelated to my proposition, just the current code is illogical.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzkwMTcxMS1pbXBvc3NpYmxlLXRvLW92ZXJ3cml0ZS1jaGVja291dC1oZWxwZXI/dG1wbD1tYXJrZG93bg==) 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")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86564
- Thank you received: 14311
-
-

5 years 9 months ago [\#328651](#328651) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Impossible to overwrite checkout helper](/forum/25-install-update/901711-impossible-to-overwrite-checkout-helper#328651 "I created the overwrite class hikashopCheckoutHelperOverride correctly and it's loaded from templates/yootheme/html/com&#95;hikashop/administrator/helpers/checkout.override.php  But the class hikashopCheckoutHelperOverride is not used because the code has direct calls to original class:  And I can't declare my own hikashopCheckoutHelper class which should extend original hikashopCheckoutHelper")*

Hi,

No worries. First, normally you only have one cart, the current cart. And thus no need to pass the cart_id.
It's only used for rare cases, like custom plugins, or HikaAuction to override the current cart to handle with another one.
And in that case, it's the same cart for the whole processing of the page since you only have one checkout interface per page.
So the cart that the initial instance is cached and provided regardless of what you supply the constructor is actually done on purpose so that once the checkout instance is initialized with the correct cart, regardless of whether other pieces of code have the correct cart_id, they will base themselves on the correct cart that the current page is handling.
Thank you for your concern.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI1LWluc3RhbGwtdXBkYXRlLzkwMTcxMS1pbXBvc3NpYmxlLXRvLW92ZXJ3cml0ZS1jaGVja291dC1oZWxwZXI/dG1wbD1tYXJrZG93bg==) 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.066 seconds

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