Add product to cart using a plugin
10 years 2 months ago #245011
by Rixters
Add product to cart using a plugin was created by Rixters
-- HikaShop version -- : 2.6.3
-- Joomla version -- : 3.5.1
-- PHP version -- : 7.0.9
-- Browser(s) name and version -- : FF
Because Hikashop doesn't provide a functionality to add a product for free when a certain cart amount is met, I'm trying to build a plugin who does that for me. Could you provide a code sample how to add a product to the cart when a plugin event is fired? can I also then reset the the price to 0?
Hope you can get me started...
-- Joomla version -- : 3.5.1
-- PHP version -- : 7.0.9
-- Browser(s) name and version -- : FF
Because Hikashop doesn't provide a functionality to add a product for free when a certain cart amount is met, I'm trying to build a plugin who does that for me. Could you provide a code sample how to add a product to the cart when a plugin event is fired? can I also then reset the the price to 0?
Hope you can get me started...
Please Log in or Create an account to join the conversation.
10 years 2 months ago #245020
by nicolas
Replied by nicolas on topic Add product to cart using a plugin
Hi,
On this thread, we talk about adding a product to the cart with either a redirect, a form submit, or code:
www.hikashop.com/forum/2-general-talk-ab...-product-fields.html
But it's actually quite easy to do:
$class = hikashop::get('class.cart');
$class->update($product_id, $quantity);
On this thread, we talk about adding a product to the cart with either a redirect, a form submit, or code:
www.hikashop.com/forum/2-general-talk-ab...-product-fields.html
But it's actually quite easy to do:
$class = hikashop::get('class.cart');
$class->update($product_id, $quantity);
Please Log in or Create an account to join the conversation.
10 years 2 months ago #245107
by Rixters
Replied by Rixters on topic Add product to cart using a plugin
Great! That worked!
Just to be complete. Can I also remove a product from the cart or change the price using this class?
Thanks for the help!
Just to be complete. Can I also remove a product from the cart or change the price using this class?
Thanks for the help!
Please Log in or Create an account to join the conversation.
10 years 2 months ago #245109
by nicolas
Replied by nicolas on topic Add product to cart using a plugin
Hi,
Yes, and it's really easy. It's the same function with the quantity being 0 :
$class = hikashop::get('class.cart');
$class->update($product_id, 0);
Also note that the quantity is not added by default, it replaces the quantity of the product in the cart.
If you want to add a quantity of 2 to the quantity already in the cart, you need to do like that:
$class = hikashop::get('class.cart');
$class->update($product_id, 2, true);
Yes, and it's really easy. It's the same function with the quantity being 0 :
$class = hikashop::get('class.cart');
$class->update($product_id, 0);
Also note that the quantity is not added by default, it replaces the quantity of the product in the cart.
If you want to add a quantity of 2 to the quantity already in the cart, you need to do like that:
$class = hikashop::get('class.cart');
$class->update($product_id, 2, true);
The following user(s) said Thank You: Rixters
Please Log in or Create an account to join the conversation.
10 years 2 months ago #245183
by Rixters
Replied by Rixters on topic Add product to cart using a plugin
Hi Nicolas,
With your help I created a plugin that add a free product to the cart depending on the total cart price. github.com/RickR2H/hikashop-free-product
Thanks for the help and regards!
With your help I created a plugin that add a free product to the cart depending on the total cart price. github.com/RickR2H/hikashop-free-product
Thanks for the help and regards!
Please Log in or Create an account to join the conversation.
10 years 2 months ago #245185
by kyratn
Replied by kyratn on topic Add product to cart using a plugin
Hi,
Thanks for the share. It can be very useful...
Regards
Thanks for the share. It can be very useful...
Regards
Please Log in or Create an account to join the conversation.
10 years 1 month ago #246528
by Siberio87
Replied by Siberio87 on topic Add product to cart using a plugin
thank you sir for the plugin!
Please Log in or Create an account to join the conversation.
6 years 5 months ago #317785
by ynnadje
Replied by ynnadje on topic Add product to cart using a plugin
Thank you Nicholas,
This is a very usefull plugin. Could I add multiple products depending on the cart-total.
example
If you buy for 30€, you receive free product B
If you buy voor 100€ you receive product A + B
When buying for 500€, you receive products A + B + C
...
This is a very usefull plugin. Could I add multiple products depending on the cart-total.
example
If you buy for 30€, you receive free product B
If you buy voor 100€ you receive product A + B
When buying for 500€, you receive products A + B + C
...
Please Log in or Create an account to join the conversation.
6 years 5 months ago #317792
by nicolas
Replied by nicolas on topic Add product to cart using a plugin
Hi,
With the plugin on our marketplace ( www.hikashop.com/marketplace/product/118...on-free-product.html ) you can do:
If you buy for 30€, you receive free product B
If you buy for 100€ you receive product A
When buying for 500€, you receive products C
But you can't have it add several products at once. That would require some development in the plugin to support it.
With the plugin on our marketplace ( www.hikashop.com/marketplace/product/118...on-free-product.html ) you can do:
If you buy for 30€, you receive free product B
If you buy for 100€ you receive product A
When buying for 500€, you receive products C
But you can't have it add several products at once. That would require some development in the plugin to support it.
Please Log in or Create an account to join the conversation.
3 years 10 months ago #346503
by bansi
Replied by bansi on topic Add product to cart using a plugin
how to fetch the product id for all different products?
Please Log in or Create an account to join the conversation.
3 years 10 months ago #346549
by nicolas
Replied by nicolas on topic Add product to cart using a plugin
Hi,
Where do you want to do that ? What information of the products you have at hand ?
Where do you want to do that ? What information of the products you have at hand ?
Please Log in or Create an account to join the conversation.
Time to create page: 0.283 seconds