How to use do parameter of onBeforeCartUpdate ?

  • Posts: 64
  • Thank you received: 0
11 years 4 months ago #112361

I am using onBeforeCartUpdate to check that if product meets some condition than max quantity should be one.So now I am doing this.

function onBeforeCartUpdate($class, &$cart, $product_id, $quantity, $add, $type,$resetCartWhenUpdate,$force,&$do){		
 $isPro = Helper::isMyProduct($product_id);		
 if($isPro){				
   if($quantity>1){
    $do = false;
   }				
 }
}

Now the problem is, if I set quantity more than one in cart module it works fine.but if quantity is set more than one from checkout page and after clicking on update(refresh) button it goes to thank you page.

Last edit: 11 years 4 months ago by irfanhanfi.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 4 months ago #112427

Hi,

the format of the data is different on the checkout as all the products are updated at the same time.
So you actually have in $product_id an array of cart_product_id=>new quantity.
Simply do a vardump of $product_id and you will see what I mean.

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

  • Posts: 64
  • Thank you received: 0
11 years 4 months ago #112435

This is what I have done.

function onBeforeCartUpdate($class, &$cart, $product_id, $quantity, $add, $type,$resetCartWhenUpdate,$force,&$do){		
		$msg= 'msg';
		$user = JFactory::getUser();
		$userId = $user->get('id');
		if($type=='product'){
			$myProduct = Helper::isMyProduct($product_id);		
			if($myProduct){				
				if($quantity>1){
					$do = false;
					JFactory::getApplication()->enqueueMessage($msg, 'error');
				}				
			}			
		}elseif($type=='item'){
			//Array([37] => Array([cart_product_quantity] => 2))//via cart module
			//Array([37] => 2)//checkout
			foreach($product_id as $carProdId=>$detail){
				$prod_id = $this->getProductId($carProdId);
				if(is_array($detail)){
					$qnty = $detail['cart_product_quantity'];
				}else{
					$qnty = $detail;
				}
				$myProduct = Helper::isMyProduct($prod_id);		
				if($myProduct){					
					if($qnty>1){
						$do = false;
						JFactory::getApplication()->enqueueMessage($msg, 'error');
					}				
				}
			}
		}		
		return true;
	}

The problem is, if quantity is changed in checkout page and if condition goes $do=false it takes to thank you page but works for cart module.
Thanks for your help.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 4 months ago #112439

Yes, if you do a $do=false in the onBeforeCartUpdate trigger, it means that you don't want the cart to be updated.
And on the checkout, when the cart is not updated on a step, it goes to the next step automatically.

Instead of the trigger onBeforeCartUpdate, I would recommend to implement onAfterProductQuantityCheck(&$product, &$wantedQuantity,&$quantity, &$cartContent, &$cart_product_id_for_product, &$displayErrors)

Instead of allowing you to cancel the cart update, it allows you to modify the $quantity variable that will be updated for one product.
You get the new quantity requested by the user in $wantedQuantity.
And the format of the variables is the same regardless if you add a product to the cart or modify the quantities in the checkout.

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

  • Posts: 64
  • Thank you received: 0
11 years 4 months ago #112444

I used onAfterProductQuantityCheck event but this did not fire.I have used it similar to onBeforeCartUpdate event.

Thanks.

Last edit: 11 years 4 months ago by irfanhanfi.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 4 months ago #112449

Then you probably have an old version of HikaShop where that event doesn't exist.
It is triggered by the line:
$dispatcher->trigger('onAfterProductQuantityCheck', array(&$product, &$wantedQuantity,&$quantity, &$cartContent, &$cart_product_id_for_product, &$displayErrors) );

in the file administrator/components/com_hikashop/classes/cart.php


If you don't have it, then it means that you don't have the latest version of HikaShop.

The following user(s) said Thank You: irfanhanfi

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

  • Posts: 64
  • Thank you received: 0
11 years 1 month ago #126095

I have some custom validation for cart.I want that user must not go to next step until he enters all the information.Is it possible to stop user from moving into the next step until all conditions are fulfilled in previous step? Is there any event that I can use for validation?

Thanks,

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 1 month ago #126117

With the latest version of Hikashop, you now have the possibility to add custom views on the checkout with the trigger onCheckoutStepList and then you can plug yourself on the controller of the checkout with the onAfterCheckoutStep trigger which will be called when the user click on the next button of the step where your view is on your checkout workflow.
There is no documentation yet for these triggers on our website as they are brand new, but it will allow you to do what you want.

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

Time to create page: 0.064 seconds
Powered by Kunena Forum