1
votes

This example shows how to add a field to let customers to choose their own price. But the button in that example is for fast checkout. I am trying to add the customer-chosen price to cart? How do I do this?

The code that I have (google app engine - python) adds the item to the cart but not the price; the price is always zero. This is the code I am using:

self.response.out.write("""

$ <input type="text" name="item_price_1"/>

<div class="product">
<input type="hidden" class="product-title" value="%s">

<input type="hidden" class="product-attr-id" value="id#%s">

<div class="googlecart-add-button" tabindex="0" role="button" title="Add to cart">
</div></div>

And this is the sandbox script:

#sandbox script 
self.response.out.write("""<script  id='googlecart-script' type='text/javascript' src='https://checkout.google.com/seller/gsc/v2_2/cart.js?mid=1234567890' integration='jscart-wizard' post-cart-to-sandbox='true' currency='USD' productWeightUnits='LB'></script> """) 
1

1 Answers

0
votes

I solved the problem:

According to documentation, javascript to add the items to cart only processes

elements that appear within a tag that uses the CSS product class. For example, in the HTML snippet above, if the price (and the product-price class) appeared outside of the element, the shopping cart JavaScript would not identify a price for the item.

So added $ <input type="text" name="item_price_1"/> inside the <div class="product"> as class="product-price":

<div class="product">
<input type="hidden" class="product-title" value="%s">
$ <input type="text" class="product-price" name="item_price_1"/>
<input type="hidden" class="product-attr-id" value="id#%s">

<div class="googlecart-add-button" tabindex="0" role="button" title="Add to cart">
</div></div>