shopify quantity selector increment restriction - shopify

I need to setup the quantity selector in such a way that the user cant increment after the quantity exceeds the stock.
here's the code
{% if section.settings.show_quantity_selector %}
<div class="product-form__controls-group">
<div class="product-form__item">
<label for="Quantity-{{ section.id }}">{{ 'products.product.quantity' | t }}</label>
<input type="number" id="Quantity-{{ section.id }}" name="quantity" value="1" min="1" max="current_variant.inventory_quantity == 1" class="product-form__input product-form__input--quantity" data-quantity-input>
</div>
</div>
{% endif %}

You are close, try something like this:
<input type="number" id="Quantity-{{ section.id }}" name="quantity" value="1" min="1" max="{{ current_variant.inventory_quantity }}" class="product-form__input product-form__input--quantity" data-quantity-input>

Related

Shopify: Set minimum quantity for a product using the Quantity Selector

Trying to see if there's a way on certain products in my clients Shopify store where for wholesale customers, they must order at least a quantity of 15 per item.
I'm trying a script to get the Quantity Selector to start at 15 instead of one but it's not working. Here's my code:
<quantity-input class="quantity">
<button class="quantity__button no-js-hidden" name="minus" type="button">
<span class="visually-hidden">{{ 'products.product.quantity.decrease' | t: product: product.title | escape }}</span>
{% render 'icon-minus' %}
</button>
{% assign productTags = product.tags | join: ', ' %}
{% if productTags contains 'wholesale' %}
<input class="quantity__input"
type="number"
name="quantity"
id="Quantity-{{ section.id }}"
min="15"
value="1"
form="{{ product_form_id }}"
>
{% else %}
<input class="quantity__input"
type="number"
name="quantity"
id="Quantity-{{ section.id }}"
min="1"
value="1"
form="{{ product_form_id }}"
>
{% endif %}
<button class="quantity__button no-js-hidden" name="plus" type="button">
<span class="visually-hidden">{{ 'products.product.quantity.increase' | t: product: product.title | escape }}</span>
{% render 'icon-plus' %}
</button>
</quantity-input>
Assuming all your other conditions are working regarding the wholesale Tag logic, you also need to set the Value to Min Value (in this case 15) instead of 1. So your input field code for Wholesale products would become
<input class="quantity__input" type="number" name="quantity" id="Quantity-{{ section.id }}" min="15" value="15" form="{{ product_form_id }}">

Customer Register - Identify Existing Email

I'm trying on Shopify when a user is trying to create an account, to verify if the email that the user picked already exists, the theme I'm using is Debut. So far I've had 0 success with this.
<div class="page-width">
<div class="grid">
<div class="grid__item medium-up--one-half medium-up--push-one-quarter">
<div class="input-form form-vertical">
{% form 'create_customer' %}
<h1 class="text-center">{{ 'customer.register.title' | t }}</h1>
{%- if form.errors -%}
<div class="form-message form-message--error">
{{ form.errors | default_errors }}
</div>
{%- endif -%}
<label for="FirstName">{{ 'customer.register.first_name' | t }}</label>
<input type="text" name="customer[first_name]" id="FirstName" {% if form.first_name %}value="{{ form.first_name }}"{% endif %} autofocus>
<label for="LastName">{{ 'customer.register.last_name' | t }}</label>
<input type="text" name="customer[last_name]" id="LastName" {% if form.last_name %}value="{{ form.last_name }}"{% endif %}>
<label for="Email">{{ 'customer.register.email' | t }}</label>
<input type="email" name="customer[email]" id="Email" class="{% if form.errors contains 'email' %} input--error{% endif %}" {% if form.email %} value="{{ form.email }}"{% endif %} autocorrect="off" autocapitalize="off">
<label for="CreatePassword">{{ 'customer.register.password' | t }}</label>
<input type="password" name="customer[password]" id="CreatePassword" class="{% if form.errors contains 'password' %} input--error{% endif %}">
<label for="CreatePassword2">Repeat Password</label>
<input type="password" name="customer[password]" id="CreatePassword2" class="{% if form.errors contains 'password' %} input--error{% endif %}">
<p class="text-center">
<input type="submit" value="{{ 'customer.register.submit' | t }}" class="btn">
</p>
{% endform %}
</div>
</div>
</div>
</div>
I thought that the part of
{{ form.errors | default_errors }}
Would return an error when the email is duplicate but it does nothing and the user just gets redirected to the main page. Any idea of how this can be accomplished? Thank you

how can I add products in a cart in Shopify by through a form in which only product name field is taken?

I have made a form page in Shopify in which following fields I have taken:-
<form action="/cart" method="post">
{% comment %}
Successful message
{% endcomment %}
{% if form.posted_successfully? %}
<p class="note form-success">
{{ 'contact.form.post_success' | t }}
</p>
{% endif %}
<div class="selection-wrapper">
{{ form.errors | default_errors }}
</div>
<div class="selection-wrapper">
<div class="grid">
<label for="Name" class="hidden-label">Name*</label>
<div class="grid__item medium-up--one-half">
<input type="text" style="width:100%;" name="first_name" id="FirstName" {% if form.first_name %}value="{{ form.first_name }}"{% endif %} required>
<label for="FirstName">{{ 'customer.register.first_name' | t }}</label>
</div>
<div class="grid__item medium-up--one-half">
<input type="text" style="width:100%;" name="last_name" id="LastName" {% if form.last_name %}value="{{ form.last_name }}"{% endif %}>
<label for="LastName">{{ 'customer.register.last_name' | t }}</label>
</div>
</div>
<br/>
<div class="grid">
<label for="Email" class="hidden-label">Email Address *</label>
<input type="email" style="width:100%;" id="Email" name="email" autocapitalize="off" value="{% if form.email %}{{ form.email }}{% elsif customer %}{{ customer.email }}{% endif %}">
</div>
<br/>
<div class="grid">
<label for="ContactFormPhone" class="hidden-label">Key Code Card Number*</label>
<input type="text" id="key_cord_card_no" style="width:100%;" name="keyCordCardNo" value="{{ form.keyCordCardNo }}" required>
</div>
<br/>
<div class="grid">
<label for="Product Name" class="hidden-label">Product Name*</label>
<input type="text" id="productName" style="width:100%;" name="product_name" value="{{ form.product_name }}" required>
the </div>
<div class="grid">
<p class="submit">
<input type="submit" class="button solid" value="submit">
</p>
</div>
</div>
</form>
I have to add product to cart by its name how can i do it?
How can I add products in a cart in Shopify by through a form in which only product name field is taken?
The short answer is - you can't add a product only by his name.
A product MUST have a variant ID in order for you to submit it to the cart.
The long answer is:
The only way to add a product by it's name is if you make an AJAX request to the product page and get the variant ID from there and submit that.
You always buy a variant in Shopify, even if a product doesn't have any variants it always have a defaut variant which is bought.
So if you plan to allow the customer to enter the product name in a text field you will need to make an AJAX request to the search page ( since I assume the customer won't be able to enter the exact name of the product in order for you to make a direct AJAX request ) and get the first result ( it will be best if you add the variant ID in the result item as a data attribute for example or some other way so that you don't need to make a second AJAX call to the product page itself ) and submit that to the cart.
Since the information given is so little I can't provide you any code or further instructions how to proceed.

the pk=request i have some errors in it. i cant seems to link my reserve to another page because of this error

def reserve(request):
if request.method=="POST":
user=User.objects.get(pk=request.POST['user'])
**book = Book.objects.get(pk=request.POST['book'])**
book.isAvailable=True
book.save()
reservation=Reserve(dateLoaned=datetime.now(),book=book, user=user)
reservation.save()
reservations=Reserve.objects.all()
return redirect('/library/reservations/')
else:
user=User.objects.all()
book=Book.objects.all()
return render(request, 'reserve.html',{"users":user, "book":book})
There is some error in my book = Book.objects.get(pk=request.post[book'])
Im doing a project that needs to be submitted on Monday. PLS HELP!
reserve.html
{% extends 'base.html' %}
{% load static %}
{% block title %}
Reserve
{% endblock %}
{% block maincontent %}
<form action="../reserve/" method="post">
{% csrf_token %}
<br>
<div class="table">
<input value="{{ book.title }}" class="form-control"
id="exampleFormControlInput1" enabled>
</div>
<div class="form-group">
<td>
<img src = "{{ book.cover }}" height="150" width="100"/>
</td>
</div>
<div class="form-group">
<br>
<label for="FormControlSelect1">Select Users</label>
<select class="form-control" id="FormControlSelect1" required
name="user">
{% for user in users %}
<option value="{{ user.pk }}">{{ user }}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<button type="submit" class="btn btn-success btn-block">Reserve</button><br>
</div>
<input type="hidden" value="{{ book.pk }}" name="book" />
</form>
{% endblock %}
My reserve html might have some error. it should link my reserve to another page. but it didnt.
Error in the above image MultiValueDictKeyError. You have to replace the below code
reservation = Reserve.objects.get(pk=request.POST['reservation'])
to
reservation = Reserve.objects.get(pk=request.POST.get('reservation'))

FOSUserBundle override Login logic

I have override my Login form, so I want login by mobileNumber, not by username and password.
This is the template:
{% if error %}
<div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}
<form action="{{ path("fos_user_security_check") }}" method="post">
{% if csrf_token %}
<input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />
{% endif %}
<div class="main-text">Войти</div>
<div class="text-description-mobile-phone">Мобильный телефон</div>
<input type="text" name="mobileNumber" placeholder="+7(999) 123-45-67" class="info-input" required="required" />
<div class="text-description-password">Код из СМС</div>
<input type="text" name="code" placeholder="9876" class="info-input" required="required" />
<div class="line"></div>
<input type="submit" id="_submit" name="_submit" value="{{ 'Войти'|trans }}" class="enter-button"/>
</form>
Where does the login logic take place?
Where can I add checking of my own field?
How can I override user identification?
Can you provide an example?
I found the answer in the Internet. If someone will face the same problem, you can find solution there: https://ourcodeworld.com/articles/read/459/how-to-authenticate-login-manually-an-user-in-a-controller-with-or-without-fosuserbundle-on-symfony-3
Or in russian : http://fkn.ktu10.com/?q=node/9574