Jump to content

How to add product to the cart using php?


vocabo

Recommended Posts

Hello,

I would like to add a custom page to my template. I need my page to be able to add products to the cart that are not present in the database. These products will be personalized by the user and in general will differ from the products in the database. How can I do this?

Thanks in advance!

Link to comment
Share on other sites

You cannot add to the cart products that are not in the database.

You probably should try to find a different approach, either way, it sounds like quite a complex problem, not something that will be solved by a few lines of code.

Link to comment
Share on other sites

Thank you for your fast reply!

Before looking for other solution I will give it another try. I will appreciate any suggestions. I have a module which enables the users to add prints and text to the product and then eventually to purchase it. Let's say that I will use a product from the database. How to access its views images and to replace them with the user generated design of the product? Then possibly I have to add the personalized product to the database in order to add it to the cart after that.

www.zazzle.com is a good example of what I am trying to achieve.

Basically I need four functions to be used from my php page:

$product = get_product($product_id);
edit_product($product, $new_data);
add_product_to_database($product);
add_product_to_cart($product_id)



Thanks!

Link to comment
Share on other sites

It's not as simple as 4 php commands.

you should look into the product class (/classes/Product.php), and see how's it's being used/ updated.

You can do the first 3 functions you want using it.

To add to the cart, you can look into / controllers/CartController.php

Link to comment
Share on other sites

The customer will be able to add prints and lines of text and to specify where. After that a new image for the product will be generated with the user design and information about the text, font, color, size and rotation of the user design. I need to add the personalized product to the cart, but it seems this is not an easy task. PrestaShop doesn't support virtual products to be added to the cart and there is not an API documentation, explaining the basic tasks. It is a bit of misleading to classify PrestaShop as an open source system. In my understanding this term means documentation and flexibility for extensions.

Best regards!

Link to comment
Share on other sites

  • 11 months later...

I also wanted to add my php files and want to add custom product to cart.

 

Actually i m working on a canvas printing site. Customer upload image select product size, crop picture and select some effects then add to cart. So i need function/class reference to add product (picture, size, effect, rate, etc) and continue with prestashop checkout/cart system ???

 

Addition: Also want to know how to link external php files to prestashop?

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...