Jump to content

How Is Javascript Calculating The Combination Id For Shopping Cart?


Recommended Posts

Hello,

 

I'm trying to get the shopping cart to work without javascript, but still supporting product combinations. I notice that when I pick between different combinations of products, that javascript is changing the hidden idCombination field that is used by the cart to select which product combination to add to the cart.

 

However, I'm having a tough time figuring out how the JavaScript is coming up with the different combination id's. Does anyone have any ideas?

 

If I can get the cart to work properly with combinations and without javascript, I will be sharing it here.

 

Cheers,

Justin

Link to comment
Share on other sites

you can't, it has to use Javascript to find the right combination that contains the attribute value from each attribute group.

 

Those are stored in a JS array, the the findCombinations() function searches that array using all the selected attributes.

 

If you only used 1 attribute group, you could hack the code to use the combination ID instead of the attribute ID, but that would only work for 1 attribute group per product.

Link to comment
Share on other sites

But when the form is submitted (javascript disabled), the POST array has the group ID's and also the Attribute ID's for the attribute group you selected. So the data about what attributes were selected is available. No?

 

Or am I missing something here?

 

Here is an example of the POST array when adding something to the cart with JS disabled:

 

Array
(
   [token] => 57250782e68ffd5b7ad835b05bef1d23
   [id_product] => 10
   [add] => 1
   [id_product_attribute] =>
   [submit] => Add to cart
   [group_5] => 35
   [group_2] => 28
   [qty] => 10
)

 

My thought is that we can use the group_5 and group_2 values to figure out the id_product_attribute, which is the variable we need to tell the cart class what combination is being used.

Link to comment
Share on other sites

But at least the customer will be able to add the combination they want to the cart. Right? Instead of them picking a combination, and then only the default combination shows up in the cart (this current functionality makes it look like the website is broken).

 

J

Link to comment
Share on other sites

According to browser statistics, JS is disabled on approximately 2% of all internet users. That's over 20 million people in just North America and Europe. I don't feel it is a good solution just to simply say that those people cannot shop on our website. It's a big chunk of people and I feel that something as basic as adding an item to a cart should be something that can still work regardless of JS or not. It's one of those basic functionalities and I feel it's a bit irresponsible for Prestashop to not even work if JS is disabled. I'd understand if everything didn't work as great as with JS enabled, but Prestashop is an online shopping cart solution, that is the main thing it does, and if it can't support it's primary goal without the use of JS, then I think we are missing a great opportunity for people who use Prestashop for their sites, and for the customers who shop on them.

 

ps - This isn't a rant; I want Prestashop to be as great as it can be

Link to comment
Share on other sites

pps - as an alternative if it really can't be done, I think on each product page it should have a warning that says you cannot buy products with combinations unless JS is enabled. At least this way users will understand why, when they add a product combination to their cart, that it's not working properly, and we are offering them a solution (turn on your JS!) or at the very least, an explanation.

Link to comment
Share on other sites

Lets say that 0.1% or even 0.01% of that 2% places an order. That's still 2000 - 20,000 orders. Heck even if it's 0.001% that's still 200 orders. And 200 orders can be a lot for a small shop.

 

It's mostly about accessibility and making Prestashop as good as it can be. And I believe that having a shop that still functions properly with Javascript disabled is part of making Prestashop the best open source e-commerce solution. Would you disagree?

Link to comment
Share on other sites

You could argue the same about IE6... and other things too.

 

I personally don't see it as an issue, but this is the great thing about open source, you can do what you want with it, and on this forum, you can get help and pointers (as I was doing earlier).

Link to comment
Share on other sites

  • 3 weeks later...

Agreed with Tomerg. We have worked in the .js files that run the Prestashop, and although we have to migrate changes on new versions (not for the faint of heart), because it is open source, it is relatively easy to do and OK to do.

 

Having run a very successful web store for over a decade, I can tell you that if you have .js disabled, you are probably not going to be buying a skateboard, dog collar, or wallpaper online. :)

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