Skip to main content

Disable cart or cart memory

More
11 years 7 months ago #191516 by FilipHradil
-- 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.

More
11 years 7 months ago #191587 by nicolas
Replied by nicolas on topic Disable cart or cart memory
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.

More
11 years 7 months ago #191592 by FilipHradil
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.

More
11 years 7 months ago #191595 by nicolas
Replied by nicolas on topic Disable cart or cart memory
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.

More
11 years 7 months ago - 11 years 7 months ago #191723 by FilipHradil
Hello, I made plugin with following code but it does not work -absolutely nothing happens
I did plugin exacly by developers documentation.
Code:
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: 11 years 7 months ago by FilipHradil.

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

More
11 years 7 months ago #191743 by Mohamed Thelji
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.

More
11 years 7 months ago #192004 by FilipHradil
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.

More
11 years 7 months ago #192005 by nicolas
Replied by nicolas on topic Disable cart or cart memory
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.

More
11 years 7 months ago #192072 by FilipHradil
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.

More
11 years 7 months ago #192282 by FilipHradil
Hello,

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


This attachment is hidden for guests.
Please log in or register to see it.

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

More
11 years 7 months ago #192305 by nicolas
Replied by nicolas on topic Disable cart or cart memory
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.

More
11 years 7 months ago #192327 by FilipHradil
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.

More
11 years 7 months ago #192328 by Xavier
Replied by Xavier on topic Disable cart or cart memory
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.

More
11 years 7 months ago - 11 years 7 months ago #192456 by FilipHradil
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: 11 years 7 months ago by FilipHradil.

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

More
11 years 7 months ago #192474 by nicolas
Replied by nicolas on topic Disable cart or cart memory
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.

More
11 years 7 months ago #192498 by FilipHradil
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.

More
11 years 7 months ago - 11 years 7 months ago #192539 by nicolas
Replied by nicolas on topic Disable cart or cart memory
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: 11 years 7 months ago by nicolas.

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

More
11 years 7 months ago #192568 by FilipHradil
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.

More
11 years 7 months ago #192577 by nicolas
Replied by nicolas on topic Disable cart or cart memory
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.

More
11 years 7 months ago #192650 by FilipHradil
Hello,

thank you!!!
There was just little problem but if condition made it :)
Code:
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.307 seconds
Powered by Kunena Forum