Skip to content
This repository has been archived by the owner on Aug 30, 2018. It is now read-only.

[Timber] add cart discounts #522

Merged
merged 1 commit into from
Mar 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions assets/ajax-cart.js.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,11 @@ var ajaxCart = (function(module, $) {
itemMinus: cartItem.quantity - 1,
itemQty: cartItem.quantity,
price: Shopify.formatMoney(cartItem.price, settings.moneyFormat),
vendor: cartItem.vendor
vendor: cartItem.vendor,
linePrice: Shopify.formatMoney(cartItem.line_price, settings.moneyFormat),
originalPrice: Shopify.formatMoney((cartItem.line_price + cartItem.total_discount), settings.moneyFormat),
Copy link
Contributor

@NathanPJF NathanPJF Jun 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is talking about cartItem.line_price, this can be:

originalLinePrice: Shopify.formatMoney(cartItem.original_line_price, settings.moneyFormat)

discounts: cartItem.discounts,
discountsApplied: cartItem.line_price === (cartItem.line_price - cartItem.total_discount) ? false : true
Copy link
Contributor

@NathanPJF NathanPJF Jun 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be:

discountsApplied: cartItem.line_price === cartItem.original_line_price ? false : true

};

items.push(item);
Expand All @@ -309,7 +313,9 @@ var ajaxCart = (function(module, $) {
data = {
items: items,
note: cart.note,
totalPrice: Shopify.formatMoney(cart.total_price, settings.moneyFormat)
totalPrice: Shopify.formatMoney(cart.total_price, settings.moneyFormat),
totalCartDiscount: cart.total_discount === 0 ? 0 : {{ 'cart.general.savings_html' | t: price: '[savings]' | json }}.replace('[savings]', Shopify.formatMoney(cart.total_discount, settings.moneyFormat)),
totalCartDiscountApplied: cart.total_discount === 0 ? false : true
}

$cartContainer.append(template(data));
Expand Down
4 changes: 4 additions & 0 deletions assets/timber.scss.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -2539,4 +2539,8 @@ label.error {
border-color: $colorDrawerBorder;
}

.ajaxcart-item__price-strikethrough {
float: right;
}

{% endif %} // settings.ajax_cart_method
3 changes: 2 additions & 1 deletion locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"checkout": "Zur Kasse",
"empty": "Ihr Einkaufswagen ist im Moment leer.",
"continue_browsing_html": "Mit der Suche <a href=\"/collections/all\">hier</a> fortfahren.",
"close_cart": "Einkaufswagen schließen"
"close_cart": "Einkaufswagen schließen",
"savings_html": "Sie sparen {{ price }}"
},
"label": {
"product": "Artikel",
Expand Down
3 changes: 2 additions & 1 deletion locales/en.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"checkout": "Check Out",
"empty": "Your cart is currently empty.",
"continue_browsing_html": "Continue browsing <a href=\"/collections/all\">here</a>.",
"close_cart": "Close Cart"
"close_cart": "Close Cart",
"savings_html": "You're saving {{ price }}"
},
"label": {
"product": "Product",
Expand Down
3 changes: 2 additions & 1 deletion locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"checkout": "Finalizar pedido",
"empty": "Su carrito actualmente está vacío.",
"continue_browsing_html": "Continúe explorando <a href=\"/collections/all\">aquí</a>.",
"close_cart": "Cerrar carrito"
"close_cart": "Cerrar carrito",
"savings_html": "Está ahorrando {{ price }}"
},
"label": {
"product": "Producto",
Expand Down
3 changes: 2 additions & 1 deletion locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"checkout": "Procéder au paiement",
"empty": "Votre panier est vide.",
"continue_browsing_html": "<a href=\"/collections/all\">Retourner au magasinage</a>.",
"close_cart": "Fermer le panier"
"close_cart": "Fermer le panier",
"savings_html": "Vous économisez {{ price }}"
},
"label": {
"product": "Produit",
Expand Down
3 changes: 2 additions & 1 deletion locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"checkout": "Fechar pedido",
"empty": "Seu carrinho está vazio no momento.",
"continue_browsing_html": "Continue navegando <a href=\"/collections/all\">aqui</a>.",
"close_cart": "Fechar carrinho"
"close_cart": "Fechar carrinho",
"savings_html": "Você está economizando {{ price }}"
},
"label": {
"product": "Produto",
Expand Down
3 changes: 2 additions & 1 deletion locales/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"checkout": "Check-Out",
"empty": "O seu carrinho de compras está neste momento vazio.",
"continue_browsing_html": "Continue a ver <a href=\"/collections/all\">aqui</a>.",
"close_cart": "Fechar Carrinho de Compras"
"close_cart": "Fechar Carrinho de Compras",
"savings_html": "Está a poupar {{ price }}"
},
"label": {
"product": "Produto",
Expand Down
21 changes: 20 additions & 1 deletion snippets/ajax-cart-template.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,23 @@
</div>
</div>
<div class="grid__item display-table-cell one-half text-right">
{{{price}}}
{{#if discountsApplied}}
<small class="ajaxcart-item__price-strikethrough"><s>{{{originalPrice}}}</s></small>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on my comments above, this can be :

<small class="ajaxcart-item__price-strikethrough"><s>{{{originalLinePrice}}}</s></small>

<br><span>{{{linePrice}}}</span>
{{else}}
<span>{{{linePrice}}}</span>
{{/if}}
</div>
</div>
{{#if discountsApplied}}
<div class="grid--full display-table">
<div class="grid__item text-right">
{{#each discounts}}
<small class="ajaxcart-item__discount">{{ this.title }}</small><br>
{{/each}}
</div>
</div>
{{/if}}
</div>
</div>
</div>
Expand All @@ -74,6 +90,9 @@
<div class="grid__item one-third text-right">
<p>{{{totalPrice}}}</p>
</div>
{{#if totalCartDiscount}}
<p class="ajaxcart__savings text-center"><em>{{{totalCartDiscount}}}</em></p>
{{/if}}
</div>
<p class="text-center">{% endraw %}{{ 'cart.general.shipping_at_checkout' | t }}{% raw %}</p>
<button type="submit" class="btn--secondary btn--full cart__checkout" name="checkout">
Expand Down
12 changes: 12 additions & 0 deletions templates/cart.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,15 @@
<input type="number" name="updates[]" id="updates_{{ item.id }}" value="{{ item.quantity }}" min="0">
</td>
<td data-label="{{ 'cart.label.total' | t }}" class="text-right">
{% if item.original_line_price != item.line_price %}
<span class="cart-item__original-price"><s>{{ item.original_line_price | money }}</s></span>
{% endif %}
<span class="h3">
{{ item.line_price | money }}
</span>
{% for discount in item.discounts %}
<span class="cart-item__discount">{{ discount.title }}</span>
{% endfor %}
</td>
</tr>
{% endfor %}
Expand All @@ -102,6 +108,12 @@
<span class="cart__subtotal-title">{{ 'cart.general.subtotal' | t }}</span>
<span class="h3 cart__subtotal">{{ cart.total_price | money }}</span>
</p>
{% if cart.total_discounts > 0 %}
{% assign savings = cart.total_discounts | money %}
<p>
<span class="cart-subtotal__savings"><em>{{ 'cart.general.savings_html' | t: price: savings }}</em></span>
</p>
{% endif %}
<p><em>{{ 'cart.general.shipping_at_checkout' | t }}</em></p>
<input type="submit" name="update" class="btn--secondary update-cart" value="{{ 'cart.general.update' | t }}">
<input type="submit" name="checkout" class="btn" value="{{ 'cart.general.checkout' | t }}">
Expand Down