Skip to content

Commit d1150df

Browse files
Add code file tags
1 parent 2b76b22 commit d1150df

File tree

8 files changed

+265
-36
lines changed

8 files changed

+265
-36
lines changed

15/umbraco-commerce/how-to-guides/currency-switching.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ A partial view is used on the frontend to allow users to toggle between existing
3131

3232
![Currency Switcher](images/localization/country-switch.png)
3333

34-
This is done by using the following implementation:
34+
This is done by creating a `CurerrencySwitcher.cshtml` partial with the following implementation:
35+
36+
{% code title="CurerrencySwitcher.cshtml" %}
3537

3638
````csharp
3739
@using Umbraco.Commerce.Core.Api;
@@ -61,12 +63,26 @@ This is done by using the following implementation:
6163
}
6264
````
6365

66+
{% endcode %}
67+
68+
This can then be placed in your sites base template by adding the following:
69+
70+
{% code title="Layout.cshtml" %}
71+
72+
```csharp
73+
@(await Html.PartialAsync("CurerrencySwitcher"))
74+
```
75+
76+
{% endcode %}
77+
6478
## Handle Switching Currencies
6579

6680
Switching the culture is handled by a Surface controller.
6781

6882
Create a new Surface controller called `CultureSurfaceController` and add the following code:
6983

84+
{% code title="CultureSurfaceController.cs" %}
85+
7086
````csharp
7187
public class CultureSurfaceController : SurfaceController
7288
{
@@ -117,15 +133,21 @@ public class CultureSurfaceController : SurfaceController
117133
}
118134
````
119135

136+
{% endcode %}
137+
120138
The `ChangeCountryDto` class binds the country ISO code from the form.
121139

140+
{% code title="ChangeCountryDto.cs" %}
141+
122142
````csharp
123143
public class ChangeCountryDto
124144
{
125145
public string CountryIsoCode { get; set; }
126146
}
127147
````
128148

149+
{% endcode %}
150+
129151
## Result
130152

131153
With the currency switcher implemented, users can switch between countries/currencies on your website.

15/umbraco-commerce/how-to-guides/dynamically-priced-products.md

Lines changed: 58 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ To provide the correct calculations for an order, the captured data will need to
3131

3232
1. Add a new property to the `AddToCartDto` class to capture the length.
3333

34+
{% code title="AddToCartDto.cs" %}
35+
3436
```csharp
3537
public class AddToCartDto
3638
{
@@ -39,7 +41,11 @@ public class AddToCartDto
3941
}
4042
```
4143

42-
2. Update the `AddToCart` method to store the length against the order line as a [property](../key-concepts/umbraco-properties.md).
44+
{% endcode %}
45+
46+
2. Update the `AddToCart` method of the `CartSurfaceController` to store the length against the order line as a [property](../key-concepts/umbraco-properties.md).
47+
48+
{% code title="CartSurfaceController.cs" %}
4349

4450
```csharp
4551
[HttpPost]
@@ -69,12 +75,16 @@ public async Task<IActionResult> AddToCart(AddToCartDto postModel)
6975
}
7076
```
7177

78+
{% endcode %}
79+
7280
## Calculating the Order Line Price
7381

7482
We will calculate the price/tax rate of a given order line by multiplying the specified length by the unit price. This is done using a custom order line calculator.
7583

7684
1. Create a new class that implements the `IOrderLineCalculator` interface.
7785

86+
{% code title="SwiftOrderLineCalculator.cs" %}
87+
7888
```csharp
7989
public class SwiftOrderLineCalculator : IOrderLineCalculator
8090
{
@@ -128,55 +138,71 @@ public class SwiftOrderLineCalculator : IOrderLineCalculator
128138
}
129139
```
130140

141+
{% endcode %}
142+
131143
2. Register the custom calculator in the `Startup.cs` file or in an `IComposer`.
132144

145+
{% code title="SwiftShopComposer.cs" %}
146+
133147
```csharp
134-
builder.Services.AddUnique<IOrderLineCalculator, SwiftOrderLineCalculator>();
148+
internal class SwiftShopComposer : IComposer
149+
{
150+
public void Compose(IUmbracoBuilder builder)
151+
{
152+
builder.Services.AddUnique<IOrderLineCalculator, SwiftOrderLineCalculator>();
153+
}
154+
}
135155
```
136156

157+
{% endcode %}
158+
137159
## Backoffice UI
138160

139161
A useful extra step is to expose the captured data in the order's details in the Backoffice.
140162

141163
This is implemented as a custom [UI Extension](https://docs.umbraco.com/umbraco-commerce/key-concepts/ui-extensions/order-line-properties).
142164

143-
1. Define a new `ucOrderLineProperty` extension for the length property In a UI extension manifest.
144-
145-
```json
146-
{
147-
"type": "ucOrderLineProperty",
148-
"alias": "Uc.OrderLineProperty.ProductLength",
149-
"name": "Product Length",
150-
"weight": 400,
151-
"meta": {
152-
"propertyAlias": "productLength",
153-
"showInOrderLineSummary": true,
154-
"summaryStyle": "inline",
155-
"editorUiAlias": "Umb.PropertyEditorUi.TextBox",
156-
"labelUiAlias": "Umb.PropertyEditorUi.Label"
157-
}
158-
}
159-
```
165+
Create a new `umbraco-package.json` file in a folder in the `App_Plugins` directory in the root of your project and add the following code:
160166

161-
2. Define a `localization` entry for the new properties label and description.
167+
{% code title="umbraco-package.json" %}
162168

163169
```json
164170
{
165-
"type": "localization",
166-
"alias": "Uc.OrderLineProperty.ProductLength.EnUS",
167-
"name": "English",
168-
"meta": {
169-
"culture": "en",
170-
"localizations": {
171-
"section": {
172-
"ucProperties_productLengthLabel": "Length",
173-
"ucProperties_productLengthDescription": "Customer product ordered length"
174-
}
175-
}
176-
}
171+
"name": "SwiftShop",
172+
"extensions": [
173+
{
174+
"type": "ucOrderLineProperty",
175+
"alias": "Uc.OrderLineProperty.ProductLength",
176+
"name": "Product Length",
177+
"weight": 400,
178+
"meta": {
179+
"propertyAlias": "productLength",
180+
"showInOrderLineSummary": true,
181+
"summaryStyle": "inline",
182+
"editorUiAlias": "Umb.PropertyEditorUi.TextBox",
183+
"labelUiAlias": "Umb.PropertyEditorUi.Label"
184+
}
185+
},
186+
{
187+
"type": "localization",
188+
"alias": "Uc.OrderLineProperty.ProductLength.EnUS",
189+
"name": "English",
190+
"meta": {
191+
"culture": "en",
192+
"localizations": {
193+
"section": {
194+
"ucProperties_productLengthLabel": "Length",
195+
"ucProperties_productLengthDescription": "Customer product ordered length"
196+
}
197+
}
198+
}
199+
}
200+
]
177201
}
178202
```
179203

204+
{% endcode %}
205+
180206
The length property is now displayed in the order details in the Backoffice.
181207

182208
![Order Details](images/dynamic-price/order-editor-property.png)

15/umbraco-commerce/how-to-guides/member-based-pricing.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Next, you will create a new property editor for the member-based pricing. The in
4242

4343
With the prices defined, it's time to configure Umbraco Commerce to select the correct price based on the logged-in Member. This is done by creating a custom product adapter to override the default product adapter and select the correct price.
4444

45+
{% code title="MemberPricingProductAdapter.cs" %}
46+
4547
```csharp
4648
public class MemberPricingProductAdapter : UmbracoProductAdapter
4749
{
@@ -108,9 +110,13 @@ public class MemberPricingProductAdapter : UmbracoProductAdapter
108110
}
109111
}
110112
```
113+
{% endcode %}
114+
111115

112116
Add the following to a `Composer` file to register the custom product adapter:
113117

118+
{% code title="SwiftShopComposer.cs" %}
119+
114120
```csharp
115121
internal class SwiftShopComposer : IComposer
116122
{
@@ -121,6 +127,8 @@ internal class SwiftShopComposer : IComposer
121127
}
122128
```
123129

130+
{% endcode %}
131+
124132
## Results
125133

126134
With all this implemented, the product page will display the correct price based on the logged-in Member.

15/umbraco-commerce/how-to-guides/member-portal.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ To access the members portal, customers need to log in. Through the following st
7171
1. Open the `Login.cshtml` template file.
7272
2. Add the following code to create a login form:
7373

74+
{% code title="Login.cshtml" %}
75+
7476
```csharp
7577
@using (Html.BeginUmbracoForm<UmbLoginController>("HandleLogin", new { RedirectUrl = "/customer-portal" }))
7678
{
@@ -92,8 +94,10 @@ To access the members portal, customers need to log in. Through the following st
9294
}
9395
```
9496

97+
{% endcode %}
98+
9599
{% hint style="info" %}
96-
The `UmbLoginController` class comes pre-installed with Umbraco and handles the login process for you, so you don't need to create a custom controller.
100+
The `UmbLoginController` class comes pre-installed with Umbraco. It handles the login process, so you don't need to create a custom controller.
97101
{% endhint %}
98102

99103
On the frontend, customers can enter their username and password and click the **Login** button to access the members portal.
@@ -107,6 +111,8 @@ Now that members can log in, update the `Customer Portal` page to display the or
107111
1. Open the `CustomerPortal.cshtml` template file.
108112
2. Add the following code to display the order history:
109113

114+
{% code title="CustomerPortal.cshtml" %}
115+
110116
```csharp
111117
@inject IMemberManager memberManager
112118
@inject IUmbracoCommerceApi commerceApi
@@ -146,6 +152,8 @@ else
146152
}
147153
```
148154

155+
{% endcode %}
156+
149157
The `Customer Portal` page will now display a table of the member's order history, including the order number, date, and total price.
150158

151159
![Order History](images/member-portal/order-history.png)
@@ -164,6 +172,8 @@ writableOrder.AssignToCustomer(member.Key.ToString());
164172

165173
In your site header, add the following code to display the member login status:
166174

175+
{% code title="Header.cshtml" %}
176+
167177
```csharp
168178
@{
169179
var isLoggedIn = Context.User?.Identity?.IsAuthenticated ?? false;
@@ -182,6 +192,8 @@ In your site header, add the following code to display the member login status:
182192
}
183193
```
184194

195+
{% endcode %}
196+
185197
![Logged Out Status](images/member-portal/logged-out.png)
186198

187199
![Logged In Status](images/member-portal/logged-in.png)
@@ -193,6 +205,8 @@ To allow customers to register as members, you can create a registration form al
193205
1. Implement a registration Document Type and page in the same way as the login page.
194206
2. Open the `Register.cshtml` template file and add the following code to create a registration form:
195207

208+
{% code title="Register.cshtml" %}
209+
196210
```csharp
197211
@using (Html.BeginUmbracoForm<UmbRegisterController>("HandleRegisterMember", new { RedirectUrl = "/customer-portal", UsernameIsEmail = true }))
198212
{
@@ -226,6 +240,8 @@ To allow customers to register as members, you can create a registration form al
226240
}
227241
```
228242

243+
{% endcode %}
244+
229245
{% hint style="info" %}
230246
The `UmbRegisterController` class comes pre-installed with Umbraco. It handles the login process, so you don't need to create a custom controller.
231247
{% endhint %}

15/umbraco-commerce/how-to-guides/personalized-products.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ When the customer adds the product to the cart, the message will be saved in an
2828

2929
1. Add an `Observations` property of the `AddToCartDto` to capture the message.
3030

31+
{% code title="AddToCartDto.cs" %}
32+
3133
```csharp
3234
public class AddToCartDto
3335
{
@@ -37,9 +39,13 @@ public class AddToCartDto
3739
}
3840
```
3941

40-
2. Locate the `AddToCart` action.
42+
{% endcode %}
43+
44+
2. Locate the `AddToCart` of the `CartSurfaceController`.
4145
2. Set a property on the order line if a value has been sent with the request.
4246

47+
{% code title="CartSurfaceController.cs" %}
48+
4349
```csharp
4450
[HttpPost]
4551
public async Task<IActionResult> AddToCart(AddToCartDto postModel)
@@ -67,9 +73,15 @@ public async Task<IActionResult> AddToCart(AddToCartDto postModel)
6773
}
6874
```
6975

76+
{% endcode %}
77+
7078
## Accessing the Property in the Backoffice
7179

72-
To view the data in the Backoffice order editor, you need to register an `ucOrderProperty` extension along with the relevant label localizations as sampled below:
80+
To view the data in the Backoffice order editor, you need to register an `ucOrderProperty` extension along with the relevant label localizations as sampled below.
81+
82+
Create a new `umbraco-package.json` file in a folder in the `App_Plugins` directory in the root of your project and add the following code:
83+
84+
{% code title="umbraco-package.json" %}
7385

7486
````csharp
7587
{
@@ -105,6 +117,9 @@ To view the data in the Backoffice order editor, you need to register an `ucOrde
105117
]
106118
}
107119
````
120+
121+
{% endcode %}
122+
108123
The property is displayed in the Backoffice order editor.
109124

110125
![Backoffice Order Line Property](images/personalized-products/order-line-property.png)

0 commit comments

Comments
 (0)