Fails to add to cart when using views global:random display

jptaranto - March 5, 2009 - 02:14
Project:Ubercart
Version:6.x-2.0-rc3
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Issue tags:dc2009 code sprint
Description

I first migrated my shop to the online server and had the nasty problem of the UID 0 dropping off and hence the anonymous cart failing to work.

The next problem I had, was tracked down to using views for one of my shop's pages where it was pulling 8 randomly chosen products and displaying them. Here products failed to add to cart from too. And the problem was intermittent. Sometimes they added, sometimes they didn't.

If I changed page the products added fine. Happened on beta 5 and beta 4.

#1

DigitalFrontier... - March 7, 2009 - 17:52
Status:active» postponed (maintainer needs more info)

Not sure what you mean by "changed page". Can you detail this a bit more. And maybe export your View and post it here?

#2

rszrama - March 8, 2009 - 06:17
Priority:critical» normal
Status:postponed (maintainer needs more info)» fixed

Hmm... I'm going to take a stab at this and mark it fixed... we can always reopen if necessary. Basically, this isn't a bug report with Ubercart but a limitation of randomized Views and the Forms API. When the add to cart form is clicked, it submits the POST data for the form to the same URL. The View is then rebuilt on the following pageload, but it's never normally displayed to the user. Drupal depends on having the form built in the following pageload, so it will only process the add to cart when the random products chosen include the product that was added to the cart. Drupal can then process that form and do redirect upon its completion.

#3

jptaranto - March 10, 2009 - 07:36

So basically add to cart will not work when using a random view?

#4

rszrama - March 10, 2009 - 14:15

Correct, at least without some custom module ensuring that the form you're submitting will always be present on the regenerated page.

#5

System Message - March 24, 2009 - 14:20
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

#6

com2 - June 11, 2009 - 11:09
Version:6.x-2.0-beta5» 6.x-2.0-rc3
Status:closed» active

I have a random order "special offer" block on the front page that only shows one node. The add to cart button can be included in two ways: by including the add to cart button or by including the the form field. Both have the same problem that they wont add the product to the cart. Here a dump of the form HTML:

<form action="/es" accept-charset="UTF-8" method="post" id="uc-product-add-to-cart-form-55">
<div><input name="qty" id="edit-qty" value="1" type="hidden">
<input name="op" id="edit-submit-55" value="Add to cart" class="form-submit node-add-to-cart" type="submit">
<input name="form_build_id" id="form-8d7281a887b042445ff99e0583c6c6a7" value="form-8d7281a887b042445ff99e0583c6c6a7" type="hidden">
<input name="form_token" id="edit-uc-product-add-to-cart-form-55-form-token" value="cadc335354f677502fa3f7cc1f3809a3" type="hidden">
<input name="form_id" id="edit-uc-product-add-to-cart-form-55" value="uc_product_add_to_cart_form_55" type="hidden">

</div></form>

Attached the exported view. The "ofertas" block begins at line 980. Hope someone can fix this!

AttachmentSize
random-oferta-block-with-failing-add-to-cart.txt 31.01 KB

#7

rszrama - June 11, 2009 - 16:06
Status:active» closed

Same as before, the form can't submit with a random View because Drupal's Forms API depends on the same page being loaded as is with the same form being displayed. The random View causes the HTML to change between pageloads, which means that form no longer exists. If you can somehow work it out to use a cart link, that would work.

#8

strawman - November 4, 2009 - 05:59

did anybody resolve this issue?
I'm still having the problem with Drupal 6.14, ubercart 2.0 and views 2.6

any thoughts? still need a exported View? is there another way to go about this?

#9

rszrama - November 4, 2009 - 06:49

Please review my comment in #7. The randomized View makes form submission impossible through Drupal's Forms API, because it requires the form to be present on the page after submission. Since the View is random, this isn't always the case.

 
 

Drupal is a registered trademark of Dries Buytaert.