Problem with $cartclass->loadFullCart() & coupons

  • Posts: 40
  • Thank you received: 2
9 years 2 months ago #213915

-- HikaShop version -- : 2.4.0
-- Joomla version -- : 3.4.3
-- PHP version -- : 5.6.13
-- Browser(s) name and version -- : Any
-- Error-message(debug-mod must be tuned on) -- : 9 0.2051 6934888 JDocumentRendererModule->render( ) .../modules.php:25
10 0.2052 6936448 JModuleHelper::renderModule( ) .../module.php:103
11 0.2053 6957672 include( '/var/www/clients/client1/web12/web/modules/mod_hikashop_cart/mod_hikashop_cart.php' ) .../helper.php:190
12 0.2061 6963864 hikashop_getLayout( ) .../mod_hikashop_cart.php:44
13 0.2065 7022936 ProductViewProduct->display( ) .../helper.php:735
14 0.2065 7023816 ProductViewProduct->cart( ) .../view.html.php:37
15 0.2088 7151920 hikashopCartClass->loadFullCart( ) .../view.html.php:1909
16 0.2163 7879136 hikashopDiscountClass->loadAndCheck( ) .../cart.php:1425
17 0.2164 7881192 hikashopDiscountClass->check( ) .../discount.php:152
18 0.2165 7886000 hikashopCartClass->update( ) .../discount.php:347
19 0.2175 7921840 JEventDispatcher->trigger( ) .../cart.php:314
20 0.2175 7923816 JEvent->update( ) .../dispatcher.php:160
21 0.2175 7925240 call_user_func_array:{/var/www/clients/client1/web12/web/libraries/joomla/event/event.php:69} ( ) .../event.php:69
22 0.2175 7925744 plgHikashopFmjDocs->onBeforeCartUpdate( ) .../event.php:69
23 0.2175 7925896 hikashopCartClass->loadFullCart( ) .../fmjdocs.php:112
24 0.2197 7971496 hikashopDiscountClass->loadAndCheck( ) .../cart.php:1425
25 0.2198 7971568 hikashopDiscountClass->check( ) .../discount.php:152
26 0.2199 7975608 hikashopCartClass->update( ) .../discount.php:347
27 0.2204 7994112 JEventDispatcher->trigger( ) .../cart.php:314
28 0.2204 7996328 JEvent->update( ) .../dispatcher.php:160
29 0.2204 7997752 call_user_func_array:{/var/www/clients/client1/web12/web/libraries/joomla/event/event.php:69} ( ) .../event.php:69
30 0.2204 7998128 plgHikashopFmjDocs->onBeforeCartUpdate( ) .../event.php:69
31 0.2204 7998272 hikashopCartClass->loadFullCart( ) .../fmjdocs.php:112
32 0.2226 8039632 hikashopDiscountClass->loadAndCheck( ) .../cart.php:1425
33 0.2227 8039704 hikashopDiscountClass->check( ) .../discount.php:152
34 0.2229 8043744 hikashopCartClass->update( ) .../discount.php:347
35 0.2235 8062248 JEventDispatcher->trigger( ) .../cart.php:314
36 0.2235 8064464 JEvent->update( ) .../dispatcher.php:160
37 0.2235 8065888 call_user_func_array:{/var/www/clients/client1/web12/web/libraries/joomla/event/event.php:69} ( ) .../event.php:69

Hello,
I have a custom plugin, where in "onBeforeCartUpdate", I call:

/** @var $cartClass hikashopCartClass */
$fullCart = $cartClass->loadFullCart(true, true);

If a user has entered an expired or inactive coupon. or the coupon in the cart is "remembered" from his/her session, all pages which display the cart module and this plugin is processed, are broken. It has nothing to do with any further lines of the plugin, as the script always loops until that command and then again through the coupon part, which at some point calls "onBeforeCartUpdate", essentially creating the loop.

When xdebug is installed, the attached xdebug list is shown (repeatedly until the nested function limit is reached).

Any ideas?

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
9 years 2 months ago #213921

Hi,

The issue is that the cart data is already loaded in a special way before the call to onBeforeCartUpdate and when you call loadFullCart from that trigger in a plugin, it overwrite some pieces of that loading and thus it doesn't work properly.
What are you trying to load ? Most of the information on the cart should already be available in the variables given to the trigger.
Otherwise, it's possible to reinitialize the cart loading after that by using the same code as before the call to that trigger.

Please Log in or Create an account to join the conversation.

  • Posts: 40
  • Thank you received: 2
9 years 2 months ago #214010

Thanks for the quick reply Nicolas,
I see.
Unfortunately I need access to data which is not passed, like the products that are already in the cart and some other stuff.
I am interested though, in your alternative solution. What do you mean exactly by
"Otherwise, it's possible to reinitialize the cart loading after that by using the same code as before the call to that trigger." ?

The problem is, that the script never gets to "after that", because of an endless loop, which is triggered by the discount class in the check() function in line 347 (Version 2.4.0)
There
$class->update('',0,0,'coupon');
is called, which results in the trigger "onBeforeCartUpdate" from the cart class, which results in an endless loop between the two.

What do you propose me to change to avoid this?

BTW, why not make the whole cart (with all the loadfullcart-data) available through the trigger in the first place? That way, it wouldn't be necessary for us to call it again?

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 2 months ago #214016

Hi,

If you need the cart content, you can use the "get" function instead.
You can also perform some sql queries. But you can't call a loadfullcart in that context because the trigger itself is coming from the loadfullcart.
With the cart system refactoring (for hikashop 3) it should be better but for the moment, I can just recommend you something else that retrieve your required data directly in the database without the hikashop processing and triggers.. Or to place some kind or static variable to avoid the loop in your plugin (so when you call the loadfullcart you do not process it in your plugin ...)

Regards


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: thesilentman

Please Log in or Create an account to join the conversation.

  • Posts: 40
  • Thank you received: 2
9 years 2 months ago #214405

HI Jerome,

thanks, I used the get() function and rewrote my plugin. It's working now.

Thanks.

Please Log in or Create an account to join the conversation.

Time to create page: 0.060 seconds
Powered by Kunena Forum