Add to Cart, with Multiple Variants - how?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Add to Cart, with Multiple Variants - how?

Post by simonmlewis »

I may be looking after a new site that has an add to cart feature for shelving.

You enter the Depth (7-10"), and enter a length of around 10 combinations. and each alternations gives a different price.

So 7" depth by 8", might be one price, but then 9" depth by 7" would be a different price.

How do you store that data, and how do you make it make the pricing different for it all?

Do you literally have to enter every since combination in a database...? There must be some "base price".

I'm a bit stumped.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Add to Cart, with Multiple Variants - how?

Post by Celauran »

simonmlewis wrote:There must be some "base price".
How would we know? The only thing you've mentioned about pricing is that different things cost different amounts. What are we supposed to work with here?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Add to Cart, with Multiple Variants - how?

Post by simonmlewis »

Frankly I don't know either. I just wondered if there was some common method.
I'll know more later as I am seeing them tonight. I'll see their current system and go from there.
But there must be a javascript or even ajax method that queries it based on the length, width.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Add to Cart, with Multiple Variants - how?

Post by simonmlewis »

Right then I have new information.

They use a theme on Wordpress to do this.
They upload a massive CSV file. Each row has the SKU code for the range of a product, and each rows has a Depth, Length and Thickness, a unique product code, and that sizing's price.

They have over 20,000 rows of different combinations.
When this was first setup, they uploaded the CSV to the system. They cannot now see how to add or edit even a price on the site.

They are 100% behind having the whole thing redone by me. (happy days!)

I can see how they could upload that large CSV, and then I show perhaps just a DISTINCT SKU for each category or search query. But how would they edit the ONE product, photos etc. Maybe with a Primary version of each product.

But how would they then edit the various sizings. Maybe they click Edit, and below the Description, Photo(s) etc... is a set of rows for that SKU... that shows each individual prpduct code, price/sizing combination.

And when they select 2" thick, 7" depth etc... each request requests via AJAX from that massive table, for the combination for that SKU of those sizing dropdowns.

Is my thinking fairly "correct" ... ??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Add to Cart, with Multiple Variants - how?

Post by Celauran »

simonmlewis wrote:They use a theme on Wordpress to do this.
...
They are 100% behind having the whole thing redone by me.
Will the site still be done in WP, or are you really starting from scratch?
simonmlewis wrote:They upload a massive CSV file. Each row has the SKU code for the range of a product, and each rows has a Depth, Length and Thickness, a unique product code, and that sizing's price.
There's your primary key.
simonmlewis wrote:I can see how they could upload that large CSV, and then I show perhaps just a DISTINCT SKU for each category or search query. But how would they edit the ONE product, photos etc.
Look up the product by PK? Depends on how photos etc. are related to products. Have you given thought to DB schema / how you're going to organize all the data? In fact, how is it organized now?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Add to Cart, with Multiple Variants - how?

Post by simonmlewis »

Do away with WP as the main site (just as the blog bit). A whole new web site. That way, I can do whatever they want with it - as right now, I can do nothing with it!
The SKU would be the unique primary for the product.

Ignore how it's organised now. They probably do upload a CSV, but they cannot add a product. I suspect the designer has done it similar to my thinking.

When customer selects the D, H, W from the product page, it will query that table, and will only show the sizings availanble for that SKU.

When you are on a prod page, or any Thumbnail page, it will show the DISTNCT SKU, where all the other fields (desecription etc), are occupied.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Add to Cart, with Multiple Variants - how?

Post by Christopher »

simonmlewis wrote:I can see how they could upload that large CSV, and then I show perhaps just a DISTINCT SKU for each category or search query. But how would they edit the ONE product, photos etc. Maybe with a Primary version of each product.

But how would they then edit the various sizings. Maybe they click Edit, and below the Description, Photo(s) etc... is a set of rows for that SKU... that shows each individual prpduct code, price/sizing combination.

And when they select 2" thick, 7" depth etc... each request requests via AJAX from that massive table, for the combination for that SKU of those sizing dropdowns.

Is my thinking fairly "correct" ... ??
When I have done this in the past, I have had a basecode field in the product data table -- plus a field or fields for the various options. On a product page I fetch all SKUs with the same basecode and then create the page based on the customer's needs. This usually entails pulling all the options from the various SKUs and creating selection for them. The form determines the correct SKU based on the selections and submits it to the cart.
(#10850)
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Add to Cart, with Multiple Variants - how?

Post by simonmlewis »

Mmm yes. I'm really thinking my head is started to get around this one. The cart will be done via Sagepay, and I suspect they have certain Cart and Widgets for me. They must have uploaded all the Unique Codes to Sage, so that the pricing etc all gets populated. At least I hope so!

I think the Admin Product Edit page will have the core parts (desc, photo, titletag etc..), and at the foot of it, would be a table showing all the Product Stock IDs, sizings etc, each combination row by row. They can change any price via an Ajax update.
They can add a new row (if they want to add a new size for example).

That extra size then gets populated in the Depth or whatever field on the Product page for the customer.

And because the sizing fields are all in their own DB fields, the customer can filter on rustic, contemporary etc, and Depth and width... to filter right down to their perfect item.

Two hours ago my brain was stumped. But now I see things a little clearer.

I just need each SKU to have a Primary row for the "product page" Informative Stuff.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Add to Cart, with Multiple Variants - how?

Post by simonmlewis »

I am getting there now, having written a test set of products and form.
The problem is, after they have selected three options, the ajax.php page has the form in it, to use via GET to /premiercart.
But (and this might be because it's in the external .php file, when you click the Submit button, it stays within the page you are on - it doesn't go to the "action='/premiercart'" page.

Why is that?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Add to Cart, with Multiple Variants - how?

Post by Christopher »

It just sounds like Javascript is doing an Ajax call instead of submitting the form to another page.
(#10850)
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Add to Cart, with Multiple Variants - how?

Post by simonmlewis »

Here's my current problem.
I'm doing it with Ajax. So onchange, it runs ajax and pulls back data if it finds any. As each of the 2-3 <select> dropdowns and 'changed', it stores what's Posted into a session on the ajax php file.

And the problem is: if the form page is loaded and all three say "Choose", then no price is shown. but if just one of those 2-3 options are chosen, it still has the others in session so you have:

5" -Choose - Choose
Price: £30.00.

So how do you get around a problem like that?
you can't store the three options in a session on the form page, because since nothing has an onChange, the ajax hasn't been triggered so no price is shown.
Is there a way to clear the session when the page is loaded? But only to clear it if it finds something in the session, for $depth (for example) ??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Add to Cart, with Multiple Variants - how?

Post by simonmlewis »

Sorry I think I have gotten around it - if the page loaded is "premier", then it unclears the session.

But of the ajax page is loaded as nothing is assigned to "depth", it throws an error:

Code: Select all

if(isset($_GET['depth']))
{
    $depth = $_GET['depth'];
    $_SESSION['depth']=$depth;
} 
else
{
    $depth=$_SESSION['depth'];
}
How do I stop this erroring if $depth is actually NULL at the moment?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Add to Cart, with Multiple Variants - how?

Post by Celauran »

simonmlewis wrote:it throws an error
You'll need to be more specific. What doe the error say?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: Add to Cart, with Multiple Variants - how?

Post by simonmlewis »

[text]Notice: Undefined index: depth in C:\xampp\phpMyAdmin\site\ajax_premier.php on line 11[/text]

Code: Select all

<?php
session_start();

if(isset($_GET['depth']))
{
    $depth = $_GET['depth'];
    $_SESSION['depth']=$depth;
} 
else
{
    $depth=$_SESSION['depth'];
}

......
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Add to Cart, with Multiple Variants - how?

Post by Celauran »

Give $depth a default value before the if block. Alternately, you could use isset() checks.
Post Reply