Can you get the price of the currently selected product option? - bigcartel

I'm implementing a Paypal Pay in 4 message and can't figure out how to update the message with the price of the currently selected product option. Is this functionality available?
I'm currently using product.default_price, but for products with a variable price I have to display the default paypal message where I would prefer to use the price of the currently selected option as reflected in the "Add to Cart" button. The html for the theme I am using doesn't reveal how that data is obtained.
Paypal message:
<div
data-pp-message
data-pp-style-layout="text"
data-pp-style-logo-type="primary"
data-pp-style-text-color="black"
data-pp-amount="{{ product.default_price }}">
</div>
Thanks for any suggestions.

Related

POST the data from a modal form of bootstrap: What am I missing?

Ask Question
No.1 for booking in our surroundings
No hidden costs
Attractive offers with price advantage
Name
Email address
Question
</footer>

amp-form session based backend and 3rd party cookies

Trying to grok this e-commerce scenario...
I build an amp product page in amp that has the new amp-form
The add to cart button is an XHR to my backend (that is session based, using
cookies by default)
User searches for product and results take them
to my amp product page, but they've never been to my site
They submit the add to cart form
the CORS preflight makes it's way to my backend, and i set all the correct allows as per https://github.com/ampproject/amphtml/blob/master/spec/amp-cors-requests.md
Now the actual request is made... backend initializes a session,
returns session identifier as a cookie, but since user never went to
my site...just the google amp cache it's treated as a 3rd party
cookie and browser discards it (cause user disables 3rd party cookies)
users session is lost, as is their add to cart action
So the question is, how do i keep the session around and the item in the cart?
Am i missing something? is there a trick i'm not seeing?
appreciate any insights.
Associating the shopping cart with the CLIENT_ID would be the best way to solve this problem. Unfortunately, transferring the CLIENT_ID via forms is not yet supported in AMP. It's currently being implemented, you can watch this issue for the current status.
Here is an approach that works right now: the idea is to encode the shopping cart content into a string that is returned in the form result. This way we can generate "View Cart" and "Checkout" links including the shopping cart content. Once the user clicks on one of those links, you can create the actual shopping cart in your backend and store the user id in a cookie.
For example:
<form action-xhr="/add-to-cart" method="POST">
<input type="hidden" name="itemId" value="headphones-123">
<!-- Hide after form submit success -->
<input type="submit" name="add" value="Add to Cart">
<div submit-success>
<template type="amp-mustache">
<!-- shopping cart contents, e.g headphones-123 -->
{#shoppingCartContent}
View In Cart
Checkout
{/shoppingCartContent}
</template>
</div>
<div submit-error>
<template type="amp-mustache">
{{message}} <!-- e.g. Only 2 Headphones are left. -->
</template>
</div>
</form>
The disadvantage of this approach is that the shopping cart will be lost when the user leaves the page without viewing the cart first. This will be solved once the CLIENT_ID can be passed via amp-form.
I also know very limited info about AMP pages but I suggest that you please read through the use of User identification and try using an AMP-generated client ID. As mentioned in the documentation:
By default, AMP will manage the provision of a client ID whether the page is accessed from the publisher's original website or through a cache.
Likewise, learn more about client ID substitution, including how to add an optional user notification ID, in Variables supported in AMP analytics.
Hope that helps!

Getting dropdown value from template django

I am facing an issue working with django ( using shopcart ). I want to add a select options field to change dynamically an item suscription in the cart, but I am not getting the value selected from the template.
In my template where I display the cart I have :
<form action="" method="GET">{%csrf_token%}
<select name="suscr" title="suscr">
<option value="" selected>Suscribe</option>
<option value="1" name="suscr" >Weekly</option>
<option value="2" name="suscr">Monthly</option>
</select>
</form>
I want to select an option and then, if I press 'Checkout' to have the cart updated.
Appart from that, I believe its missing a method modifying the item in cart.py.
Any ideas would help.
Thanks
The above form is inside a loop
{% for item in cart %}
What i propose you to do is not python-oriented but all javascript for the most part as, from the description, we assume that what you are dealing with is going all at the client-side.
As you are dealing with a shopping cart, what i'd do is storing what the user is checking in a sessionStorage so that the information would persist while the user navigates through your website even with multiple tabs. As the user might just be "walking around" you shopping website, there's no need to push things to the database without even knowing if the user wants that. Just remove the form and keep with the select, then you get what the user selected appending an attribute to select: <select onchange=my_function(this.value)>...</select> and then, inside my_functionin a script change whatever you want to the page.
When the user enters the shopping cart page you show him what he selected so far getting the items from the sessionStorageand then, if he/she confirms that wants to buy, then submit a form to the server-side, update the database and proccess that as your workflow states.
tl;dr: store the options in sessionStorage, just post to the server at the end.
For help on the server-side update your question with more info about the cart.py

How can I replace a select box in django with buttons using bootstrap?

I am working on a ticketing system and a create new ticket form which requires you to enter the status (working, open, closed etc.), the severity (low, high, normal, asap etc.) and several other parameters. The select boxes seem to be old-school and time-consuming so I want to replace them with a series of buttons.
model
status = models.CharField(max_length=100, choices=STATUS_CHOICES)
severity = models.CharField(max_length=100, choices=SEVERITY_CHOICES)
template:
<div class="form-group">
{{ form.status.errors }}
<label for="id_status" >Status:</label>
{{ form.status }}
</div>
<div class="form-group">
{{ form.severity.errors }}
<label for="id_severity" >Severity:</label>
{{ form.severity }}
</div>
How can this be achieved?
I'm assuming you meant radio buttons here, in which case you need to change the form widget for the field:
SEVERITY_CHOICES=[('critical','Critical'),
('blocking','Blocking),
('normal','Normal)]]
severity = forms.ChoiceField(choices=SEVERITY_CHOICES, widget=forms.RadioSelect())
If that's not what you're after then you'll have to write your own custom widget.
Button is not meant for that, man.
I commented your question and what i meant was - HOW - in the sense of HTML, can BUTTON be used for storing selected value? Button is not meant for that. Button is meant for clickin and doing something upon click.
Yes - you can make button click open drop-down list of elements. And yes- twitter bootstrap supports that (http://getbootstrap.com/components/#btn-dropdowns).
But what does not work is:
Button does not store the selected value. You would have to write all that js by yourself - change button inner text to indicate selected value.
Even worse - BUTTON is not an html element with value attribute - and it does not get posted on form post. You would have to come up with some means of inserting that value into list of values that get posted on form submit. All possible if you know your javascript.
There is no support in django for presenting field with many values as button. You would have to create your own widget for that. Again - it is all possible with django.
BUT... Why go through all that work, when, with some CSS you could just make your select LOOK like the button styles that Twitter bootstrap offers....

sqllite read/write queue concern with django

I'm building a website where college students can order delivery food. One special attribute about our site is that customers have to choose a preset delivery time. For example we have a drop at 7pm, 10pm, and at midnight.
All the information about the food is static (ie price, description, name), except the quantity remaining for that specific drop time.
Obviously i didn't want to hardcode the HTML for all the food items on my menu page, so i wrote a forloop in the html template. So i need to store the quantity remaining for the specific time somewhere in my model. the only problem is that I'm scared that if i use the same variable to transport the quantity remaining number to my template, i'll give out wrong information if alot of people are accessing the menu page at the same time.
For example, lets say the 7pm drop has 10 burritos remaining. And the 10pm drop has 40 burritos. Is there a chance that if someone has faster internet than the other customer, the wrong quantity remaining will display?
how would you guys go around to solve this problem?
i basically need a way to tell my template the quantity remaining for that specific time. and using the solution i have now, doesn't make me feel at ease. Esp if many people are going to be accessing the site at the same time.
view.py
orders = OrderItem.objects.filter(date__range=[now - timedelta(hours=20), now]).filter(time=hour)
steak_and_egg = 0
queso = 0
for food in orders:
if food.product.name == "Steak and Egg Burrito":
steak_and_egg = steak_and_egg + food.quantity
elif food.product.name == "Queso Burrito":
queso = queso + food.quantity
#if burritos are sold out, then tell template not to display "buy" link
quantity_steak_and_egg = max_cotixan_steak_and_egg - steak_and_egg
quantity_queso = max_cotixan_queso - queso
#psuedocode
steakandegg.quantity_remaining = quantity_steak_and_egg
queso.quantity_remaining = quantity_queso
HTML:
{% for item in food %}
<div id="food_set">
<img src="{{item.photo_menu.url}}" alt="" id="thumbnail photo" />
<div style='overflow:hidden'>
<p id="food_name">{{item.name}}</p>
<p id="price">${{item.price}}</p>
</div>
<p id="food_restaurant">By {{item.restaurant}}</p>
<div id="food_footer">
<img src="{{MEDIA_URL}}/images/order_dots.png" alt="" id="order_dots" />
<a id ="order_button" href="{{item.slug}}"></a>
<p id="quantity_remaining">{{item.quantity_remaining}} left</p>
</div><!-- end food_footer-->
</div><!-- end food_set-->
I don't understand what "faster Internet" or "using the same variable" have to do with anything here (or, indeed, what it has to do with sqlite particularly).
This question is about a fundamental property of web apps: that they are request/response based. That is, the client makes a request, and the server replies with a response, which represents the status of the data at that time. There's simply no getting around that: you can make it more dynamic, by using Ajax to update the page after the initial load, which is what StackOverflow does to show update messages while you're on the page. But even then, there's still a delay.
(I should note that there are ways of doing real-time updates, but they're complicated, and almost certainly overkill for a college food-ordering website.)
Now the issue is, why does this matter? It shouldn't. The user sees a page saying there is 1 burrito left - perhaps with a red warning saying "order quickly! almost gone!" - and they press the order button. On submission of that order, your code presumably checks for the actual status at that time. And, guess what, in the meantime you've processed another order and the burrito has already gone. So what? You simply show a message to the user, "sorry, it's gone, try something else". Anyone with any experience ordering things on the web - say, concert tickets - will understand what's happened.