onAfterCartUpdate infinite loop

  • Posts: 18
  • Thank you received: 2
10 years 2 months ago #202335

-- HikaShop version -- : 2.3.4
-- Joomla version -- : 3.4.1
-- PHP version -- : 5.5.x

Hello,

this is probably very easy for you developers of Hikashop, but I'am stuck.

We've written a very simple Plugin to automaticaly add a product on after the cart gets updated, that creates an infinite loop :(

public function onAfterCartUpdate(&$cartClass,&$cart,$product_id,$quantity,$add,$type,$resetCartWhenUpdate,$force){
		//die(print_r($product_id));
		
		//if( $product_id != '17962' ){ Does not work because $product_id is an Array, and the id is either the "real" product id, or the id from the table "hikashop_cart_product", which I do not know
			
			$c = $cartClass->loadFullCart();
			if( count($c->products) ){

				$sum = 0;			
				foreach($c->products as $i => $product){
					if( !empty($product->length) ){ // if product has custom field "length"
						$sum += $product->cart_product_quantity - 1; // that "- 1" is willed...
					}
				}
				
				$cartClass->update('17962', $sum); // infinite loop
				
			}
		//}
	}


EDIT: Sorry for not setting the right forum category.

Last edit: 10 years 2 months ago by Head.

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

  • Posts: 26264
  • Thank you received: 4043
  • MODERATOR
10 years 2 months ago #202345

Hi,

It will be better to use the "onBeforeCareUpdate" in order to be able to modify the quantity dynamically before the cart is updated in the database.

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.

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

Time to create page: 0.092 seconds
Powered by Kunena Forum