Jump to content

Adding product to shopping cart from a custom module page


senso321

Recommended Posts

Dear all,

 

i got a very interesting question for you all. How am I able to add a product from a custom moduel page to shopping cart?

All my products info comes from a database where they are linked with ID-s. Im able to get all the information regarding the product with simple database and php calls, but how am i able to pass the product info into shopping cart so my client can make a purasche ?

 

There is no information available regarding this question. Also i have checked classes/cart.php and controllers/front/cartcontroller.php for such functions, but there seems to be nothing like that to achieve my goal.

 

Help me please :)

 

BR's

Edited by senso321 (see edit history)
Link to comment
Share on other sites

This is almost like a habit with my topics.

 

Here is the solution :)

 

		$Cart = $this->context->cart;
		$Cart->updateQty($quantity, $id_product, $id_product_attribute = null, $id_customization = false, $operator = 'up', $id_address_delivery = 0, $shop = null, $auto_add_cart_rule = true);

BR's

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

This is almost like a habit with my topics.

 

Here is the solution :)

 

 

		$Cart = $this->context->cart;
		$Cart->updateQty($quantity, $id_product, $id_product_attribute = null, $id_customization = false, $operator = 'up', $id_address_delivery = 0, $shop = null, $auto_add_cart_rule = true);

BR's

 

Hi,

 

I'm trying to do the same thing and came across your post.  Can you elaborate more on how to do this?  is the above code what's needed to grab the product information and throw it in the cart?  Can you show a more full example please?

Thanks!

Link to comment
Share on other sites

What do you want to know.

$Cart = $this->context->cart;

This line get's the cart context from cookies ( all the info relevant to cart - it's id and so on )
And the 2nd line

$Cart->updateQty($quantity, $id_product, $id_product_attribute = null, $id_customization = false, $operator = 'up', $id_address_delivery = 0, $shop = null, $auto_add_cart_rule = true);

Uses updateQty function located in classes/cart.php . As we are developing by OOP then we can use it to simply pass the product info to cart. You have to provide quantity - $quantity, product id - $id_product and attribute combinaion ( if you are using combinations ) - $id_product_attribute.

Im personally using it within a ajax file within a foreach loop to pass all the related products ( when certain conditions are met ) to the cart.

BR's

Link to comment
Share on other sites

  • 2 months later...
  • 3 years later...
On 1/30/2014 at 6:12 PM, senso321 said:

This is almost like a habit with my topics.

 

Here is the solution :)

 


		$Cart = $this->context->cart;
		$Cart->updateQty($quantity, $id_product, $id_product_attribute = null, $id_customization = false, $operator = 'up', $id_address_delivery = 0, $shop = null, $auto_add_cart_rule = true);

BR's

How are you handling the product sizes? like there can be a small, medium or large product. Where are you giving those ids?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...