Disable cart or cart memory

  • Posts: 217
  • Thank you received: 4
10 years 3 months ago #191516

-- HikaShop version -- : 2.3.5

Hello,

I am starting eshop with wedding dresses. So I assume that customer won't buy more than 1 product.
I have hidden cart and after adding item to cart customer is redirected to checkout.

But when customer quit his checkout and buy item again he have to pay for both two items.

I need to disable cart, or its memory in order to pay just for one item (last added to cart).

Thank you
Filip

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

  • Posts: 83832
  • Thank you received: 13572
  • MODERATOR
10 years 3 months ago #191587

Hi,

Click on the "limit" button of the products listing in your backend. There, create a new limit. In it, set the "period" to "cart", the "type" to "quantity" and the "value" to "1" and that will only allow one item in the cart.
When the user will try to add a second product in the cart, it will display an error message to the user.

That's the closest you can get to what you need without any coding.

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

  • Posts: 217
  • Thank you received: 4
10 years 3 months ago #191592

Yes that is what I allready did. But I need to hide this error message and I need to delete old item in cart and add recent.

I hope you understand me.
Thank you in advance
F

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

  • Posts: 83832
  • Thank you received: 13572
  • MODERATOR
10 years 3 months ago #191595

Hi,

In that case, you should not use a limit and develop a HikaShop plugin implementing in it the onBeforeCartUpdate trigger where you would call $cartClass->resetCart in order to reset the cart whenever a user would add a product to the cart.

As I said in my previous message, the limit configuration is the closest to what you want without coding anything.

The following user(s) said Thank You: FilipHradil

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

  • Posts: 217
  • Thank you received: 4
10 years 3 months ago #191723

Hello, I made plugin with following code but it does not work -absolutely nothing happens
I did plugin exacly by developers documentation.

function onBeforeCartUpdate(&$cartClass,&$cart,$product_id,$quantity,$add,$type,$resetCartWhenUpdate,$force,&$do)
  {         
	  $cartClass = hikashop_get('class.cart');
		$cartClass->resetCart();
		$app = JFactory::getApplication();
		$app->redirect( $this->redirect_url );    
  }

Thank you

Last edit: 10 years 3 months ago by FilipHradil.

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

  • Posts: 12953
  • Thank you received: 1778
10 years 3 months ago #191743

Hello,
Are you sure that you have correctly published your plugin ? if yes, you should probably add some debug code on your plugin to see if it's really called.

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

  • Posts: 217
  • Thank you received: 4
10 years 2 months ago #192004

Hello,

yes plugin is really published.
Could you send me example of debug?

Many thanks
FILIP

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

  • Posts: 83832
  • Thank you received: 13572
  • MODERATOR
10 years 2 months ago #192005

Hi,

You should remove the line:
$cartClass = hikashop_get('class.cart');
as $cartClass is already given to you.

And you don't want the redirect either or the product wouldn't be added to the cart at all.

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

  • Posts: 217
  • Thank you received: 4
10 years 2 months ago #192072

Hello,

Thank you very much I will try it as soon as I get home.

I need on current procedure to remove existing items to cart,
add new item and go to checkout.

Thank you

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

  • Posts: 217
  • Thank you received: 4
10 years 2 months ago #192282

Hello,

I think the trigger isn't called or plugin isn't loaded.
Could you check it please? I am helpless :/


File Attachment:

File Name: deleteCart.zip
File Size:1 KB

Attachments:

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

  • Posts: 83832
  • Thank you received: 13572
  • MODERATOR
10 years 2 months ago #192305

I've installed the plugin on my end and added an exit after the echo "it works" code and I get the message:
take.ms/TcZxf
So the trigger is called just fine.
Note that if you turned on the "Use AJAX when possible for add to cart buttons" option of the HikaShop configuration, the add to cart will be done in ajax and thus you won't see your debug text and even without that, the message won't display on the page if you do a redirect just after that.

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

  • Posts: 217
  • Thank you received: 4
10 years 2 months ago #192327

Hello Nicolas,

thank you.
I have display Use AJAX..... in hikashop configuration.
I don't know if I code the plugin correctly, its my first plugin.

I installed it in joomla extension manager, allowed it and after I checked that is allowed in hikashop plugins.

Have I forgotten something?

Thank you
Filip

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

  • Posts: 13201
  • Thank you received: 2322
10 years 2 months ago #192328

Hi,

You have done all the needed steps to use the plugin.
As Nicolas said, to check if the plugin is called, you have to disable the AJax option in HikaShop and add an "exit;" after the "it works!" text to see the result.

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

  • Posts: 217
  • Thank you received: 4
10 years 2 months ago #192456

Hello, I don't know what I did but it almost works now.

But cart will be reseted and clicked item wasn't added. Even if the code is in onBeforeCartUpdate procedure.

Can somebody advise me method which remove oldest product in cart?


Thank you

Last edit: 10 years 2 months ago by FilipHradil.

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

  • Posts: 83832
  • Thank you received: 13572
  • MODERATOR
10 years 2 months ago #192474

It's normal that the clicked item won't be added since you added a redirect in your onBeforeCartUpdate which will stop the cart update procedure before it had the time to add the new product into the cart.

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

  • Posts: 217
  • Thank you received: 4
10 years 2 months ago #192498

I removed whole code except reseCart method but the problem is still there.
Is there any method which removes only 1 item from cart (first added)?

Thank you

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

  • Posts: 83832
  • Thank you received: 13572
  • MODERATOR
10 years 2 months ago #192539

It's not about removing one item. It's about reseting the cart before adding the new one.
I'm guessing that some other variables should be reset in the cartClass variable.

Maybe a simpler solution would be to do the add to cart yourself after the reset like that:
$cartClass = hikashop_get('class.cart');
$cartClass->resetCart();
$cartContent = $cartClass->get();
$cartClass->updateEntry($quantity,$cartContent,(int)$product_id,1,false,$type,$force);

Last edit: 10 years 2 months ago by nicolas.

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

  • Posts: 217
  • Thank you received: 4
10 years 2 months ago #192568

Hello,

I place your code in onBeforeCartUpdate procedure but after clicking button "add to cart"
the blank page with this url was open (........product/updatecart)

Maybe some redirect to cart needed?


Thank you

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

  • Posts: 83832
  • Thank you received: 13572
  • MODERATOR
10 years 2 months ago #192577

Hi,

There was a typo in my code. I've edited my post to fix it. That should avoid the blank page.

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

  • Posts: 217
  • Thank you received: 4
10 years 2 months ago #192650

Hello,

thank you!!!
There was just little problem but if condition made it :)

if(!empty($cartContent)){
                  $cartClass = hikashop_get('class.cart'); 
                  $cartClass->resetCart();  
                  $cartContent = $cartClass->get();
                  //$cartClass->updateEntry($quantity,$cartContent,(int)$product_id,1,false,$type,$force);
 }

Please, last little query, how can I logout user (just logout - without redirecting)

Thank you!

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

Time to create page: 0.078 seconds
Powered by Kunena Forum