Jump to content

Enquiry basket


opalepatrick
 Share

Recommended Posts

Hi, I am trying to work out the best way to make something like a shopping basket without all the financial stuff. Basically, choose products/items, add to 'basket', view basket, send enquiry. Pre-processwire I did this with sessions etc. Thinking as I have already constructed the catalogue and individual product pages, I should be able to move on from there. Can't get it straight in my head so any guidance would be appreciated.

Link to comment
Share on other sites

Hello @opalepatrick,

I am not sure what you mean with "without the finicial stuff", but if you have set-up your ProcessWire installation with the structure of a shop and just want a cart, you could checkout Snipcart. They even have a tutorial for combining Snipcart with ProcessWire. I have not very much experience with this service, but it seems like a simple and developer centered solution. ?

Regards, Andreas

Link to comment
Share on other sites

Sounds like you just need a form. OK, even a 'financial stuff shop' is just forms. 

I am assuming you are not taking payment with the orders (hence the without the financial stuff).

On the frontend, at its simplest, depending on the number of products you have, you create a dropdown list (like an asm select) of products. The label is the product name/title, the value is the product (page) ID. A user selects a product, and it is added to a list or table below the dropdown using JavaScript (like jQuery). To get a bit fancy, you then disable that item in the dropdown list. Assuming you were using a table, each row is a unique product, The table can have several columns, one for title, one for a product description, one with an input for quantity, and one with a delete button/x plus a hidden input for product ID, etc. If an item is removed from the table (JavaScript), you delete the row and re-enable its selection in the dropdown. 

I am assuming you will at least be collecting the customer's email, so create an input for that. Create a submit button as well.

When the submit button is pressed, we use JavaScript (simple using jQuery), to process the form. If there are no products selected, just return an error. If there are products, at the very least we want to send the product ID, its matching quantity and the customer's email. We use JavaScript to serialise these and submit the form.

Server-side, you validate and sanitize the data. Product ID and quantities are just integers. You then do what you need to do....thank yous, create a record of the order, redirect, etc. 

  • Like 1
Link to comment
Share on other sites

Thank you both. Yes 'financial stuff' wasn't very eloquent or illuminating but you got the gist of it ? - Essentially it would be the structure of a shop without billing or prices, just the ability to choose items and then dump them in a basket and add quantities or delete items then email back the info and confirm to the client.  Thank you very much kongondo for your detailed explanation. Much appreciated.

Link to comment
Share on other sites

Quote

Pre-processwire I did this with sessions etc.

You don't necessarily have to change that approach with ProcessWire ?

I've done a few projects with a similar setup, and the easiest method (in my opinion) is to use either sessions (if you're happy to involve PHP in this) or cookies (for a JavaScript only solution) to keep track of the products that were added to cart:

  • When "Add to cart" (or whatever you call it) button is clicked, use JavaScript to add product info to cookie or submit an AJAX request to a PHP based processor in which you sanitise and store product details in PHP session.
    • Note: if you use a PHP processor, you might want to consider making that button a form submit with product ID / details as a hidden text field. This way even if the user doesn't have JavaScript available/enabled, you'll still be able to process the request.
  • When the user reaches the order form, autofill a hidden field (textarea) with contents of the cart. I've handled this part with FormBuilder forms, but obviously you can use a custom form as well.

As long as you're essentially just sending a list of selected product names, sanitising data is a simple task, and even if someone does figure out the "hidden form field" trick and goes on to modify the data manually, there's no real harm in that. Or you can just leave that field visible , if it's fine that the client adds more details before sending the enquiry – or perhaps even replace it with a neater UI.

Hope this helps a bit.

  • Like 3
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...