forked from trafilea/nx-shopify
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(theme): adds the cart template and its corresponding files when …
…a theme gets generated ISSUES CLOSED: trafilea#53
- Loading branch information
jibinycricket
committed
May 31, 2021
1 parent
10294d3
commit 1f66126
Showing
5 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
packages/nx-shopify/src/generators/theme/files/src/theme/templates/cart/cart.liquid.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{% if cart.item_count > 0 %} | ||
<h1>My Cart</h1> | ||
<form action="/cart" method="post" novalidate> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Product</th> | ||
<th>Price</th> | ||
<th>Quantity</th> | ||
<th>Total Price</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for item in cart.items %} | ||
<tr class="responsive-table-row"> | ||
<td> | ||
{% if item.image != blank %} | ||
<a href="{{ item.url | within: collections.all }}"> | ||
{{ item | img_url: '240x240' | img_tag: item.title }} | ||
</a> | ||
{% endif %} | ||
</td> | ||
<td> | ||
<a href="{{ item.url }}">{{ item.product.title }}</a> | ||
{% unless item.product.has_only_default_variant %} | ||
<p>{{ item.variant.title }}</p> | ||
{% endunless %} | ||
<a href="/cart/change?line={{ forloop.index }}&quantity=0"> | ||
<small>Remove</small> | ||
</a> | ||
</td> | ||
<td> | ||
{% if item.original_line_price != item.line_price %} | ||
{{ item.price | money }} | ||
<s>{{ item.original_price | money }}</s> | ||
{% else %} | ||
{{ item.price | money }} | ||
{% endif %} | ||
</td> | ||
<td> | ||
<input type="number" | ||
name="updates[]" | ||
id="updates_{{ item.key }}" | ||
value="{{ item.quantity }}" | ||
min="0"> | ||
</td> | ||
<td> | ||
{{ item.line_price | money }} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
|
||
<p>Subtotal</p> | ||
<p>{{ cart.total_price | money }}</p> | ||
|
||
<input type="submit" name="update" value="Update"> | ||
<input type="submit" name="checkout" class="button" value="Checkout"> | ||
</form> | ||
{% else %} | ||
<h1>My Cart</h1> | ||
{% endif %} |
17 changes: 17 additions & 0 deletions
17
...x-shopify/src/generators/theme/files/src/theme/templates/cart/cart.template.scss.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { | ||
ThemeModule, | ||
ThemeContext, | ||
ThemeOnReady, | ||
} from '<%= importPath %>/core'; | ||
|
||
import './cart.template.scss'; | ||
|
||
export class CartTemplate extends ThemeModule implements ThemeOnReady { | ||
constructor(context: ThemeContext) { | ||
super(context); | ||
} | ||
|
||
onReady() { | ||
console.log('Cart Template: onReady() called'); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...hopify/src/generators/theme/files/src/theme/templates/cart/cart.template.spec.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { CartTemplate } from './cart.template'; | ||
|
||
describe('CartTemplate', () => { | ||
const mockThemeContext = { themeName: 'TestName' }; | ||
|
||
let cartTemplate: CartTemplate; | ||
|
||
beforeEach(() => { | ||
cartTemplate = new CartTemplate(mockThemeContext); | ||
}); | ||
|
||
it('should initiate successfully', () => { | ||
expect(cartTemplate).toBeTruthy(); | ||
}); | ||
|
||
it('should not mutate the context', () => { | ||
expect(cartTemplate.context).toMatchObject(mockThemeContext); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
.../nx-shopify/src/generators/theme/files/src/theme/templates/cart/cart.template.ts.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { | ||
ThemeModule, | ||
ThemeContext, | ||
ThemeOnReady, | ||
} from '<%= importPath %>/core'; | ||
|
||
import './cart.template.scss'; | ||
|
||
export class CartTemplate extends ThemeModule implements ThemeOnReady { | ||
constructor(context: ThemeContext) { | ||
super(context); | ||
} | ||
|
||
onReady() { | ||
console.log('Cart Template: onReady() called'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters