Файл cart.tpl¶
Данный файл отвечает за отображение корзины.
В базовом шаблоне он имеет следующую структуру:
1 {# Variables
2 # @var items
3 # @var deliveryMethods
4 # @var paymentMethods
5 # @var paymentMethodsArray
6 # @var ranges
7 # @var profile
8 #}
9
10 {$this->registerMeta('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">')}
11 <script type="text/javascript" src="/templates/commerce/shop/default/js/cart.js"></script>
12
13 <script type="text/javascript">
14 var deliveryMethods_prices = new Array;
15 var currencySymbol = '{$CS}';
16 var totalPrice = '{echo ShopCore::app()->SCart->totalPrice()}';
17
18 {foreach $deliveryMethods as $d}
19 {if $d->getIsPriceInPercent() == true}
20 {$delPrice = round(ShopCore::app()->SCart->totalPrice() * $d->toCurrency() / 100, 2)}
21 {else:}
22 {$delPrice = $d->toCurrency()}
23 {/if}
24 deliveryMethods_prices[{echo $d->getId()}] = '{echo $delPrice}';
25 {/foreach}
26 </script>
27
28 <h5>Корзина</h5>
29 <div class="spLine"></div>
30
31 {if !$items}
32 {echo ShopCore::t('Корзина пуста')}
33 {return}
34 {/if}
35
36 <form action="{shop_url('cart')}" method="post" name="cartForm">
37 <input type="hidden" name="recount" value="1">
38 {form_csrf()}
39 <table class="cartTable" width="100%">
40 <thead align="left">
41 <th>{echo ShopCore::t('Фото')}</th>
42 <th>{echo ShopCore::t('Название')}</th>
43 <th>{echo ShopCore::t('Цена')}</th>
44 <th>{echo ShopCore::t('Количество')}</th>
45 <th>{echo ShopCore::t('Всего')}</th>
46 <th class="admin"></th>
47 </thead>
48 <tbody>
49 {foreach $items as $key=>$item}
50 <tr>
51 <td style="width:90px;padding:2px;">
52 <div style="width:90px;height:90px;overflow:hidden;">
53 {if $item.model->getMainImage()}
54 <img src="{productImageUrl($item.model->getId() . '_main.jpg')}" border="0" alt="image" width="90" />
55 {/if}
56 </div>
57 </td>
58 <td>
59 <a href="{shop_url('product/' . $item.model->getUrl())}">{echo ShopCore::encode($item.model->getName())}</a> {$item.variantName}
60 </td>
61 <td>{echo ShopCore::app()->SCurrencyHelper->convert($item.price)} {$CS}</td>
62 <td>
63 <!-- {form_dropdown("products[$key]",$ranges, $item.quantity, 'onChange="document.cartForm.submit();"')} -->
64 <input type="text" name="products[{$key}]" value="{$item.quantity}" style="width:24px;">
65 </td>
66 <td>{echo ShopCore::app()->SCurrencyHelper->convert($item.totalAmount)} {$CS}</td>
67 <td><a href="{shop_url('cart/delete/' . $key)}" rel="nofollow" class="delete">X</a></td>
68 </tr>
69 {/foreach}
70 </tbody>
71 <tfoot>
72 <td></td>
73 <td></td>
74 <td></td>
75 <td></td>
76 <td></td>
77 <td></td>
78 </tfoot>
79 </table>
80
81 <div id="buttons">
82 <a href="#" id="checkout" onClick="document.cartForm.submit();">Пересчитать</a>
83 </div>
84
85 </form>
86
87 <div class="sp"></div>
88 <h5>Способ доставки</h5>
89 <div class="spLine"></div>
90
91 {if sizeof($deliveryMethods) > 0}
92 <ul class="deliveryMethods">
93 {$n=0}
94 {foreach $deliveryMethods as $deliveryMethod}
95 {if $deliveryMethod->getIsPriceInPercent() == true}
96 {$delPrice = round(ShopCore::app()->SCart->totalPrice() * $deliveryMethod->getPrice() / 100, 2)}
97 {else:}
98 {$delPrice = $deliveryMethod->toCurrency()}
99 {/if}
100 {if $n==0}
101 {$checked = "checked"}
102 {$activeDeliveryMethod = $deliveryMethod->getId()}
103 {else:}
104 {$checked = ''}
105 {/if}
106 {$n++}
107 {if $deliveryMethod->getFreeFrom() == 0 && $deliveryMethod->getPrice() > 0}
108 {$priceStr = "$delPrice".' '.$CS}
109 {$free = false}
110 {elseif(ShopCore::app()->SCart->totalPrice(false) >= $deliveryMethod->getFreeFrom()):}
111 {$priceStr = "бесплатно"}
112 {$free = true}
113 {elseif($deliveryMethod->getFreeFrom() > 0 && $deliveryMethod->getPrice() > 0):}
114 {$priceStr = "$delPrice".' '.$CS}
115 {$free = false}
116 {/if}
117
118 <li>
119 <h3>
120 <label>
121 {if $free==true}
122 <input type="radio" onclick="changeDeliveryMethod(this.value,true);" {$checked} name="deliveryMethod" value="{echo $deliveryMethod->getId()}" />
123 {else:}
124 <input type="radio" onclick="changeDeliveryMethod(this.value);" {$checked} name="deliveryMethod" value="{echo $deliveryMethod->getId()}" />
125 {/if}
126
127 {echo ShopCore::encode($deliveryMethod->getName())} ({$priceStr})
128 </label>
129 </h3>
130 <div class="desc">{echo $deliveryMethod->getDescription()}</div>
131 </li>
132 {if $n==1}
133 {if $free==true}
134 {$srciptText = "changeDeliveryMethod($activeDeliveryMethod, true);\r\n"}
135 {else:}
136 {$srciptText = "changeDeliveryMethod($activeDeliveryMethod);\r\n"}
137 {/if}
138 {/if}
139 {/foreach}
140 </ul>
141 {/if}
142 <div id="paymentMethods">
143 {if sizeof($paymentMethods) > 0}
144 <div class="sp"></div>
145 <h5>Способ оплаты</h5>
146 <div class="spLine"></div>
147
148 <ul class="deliveryMethods">
149 {$n=0}
150 {foreach $paymentMethods as $paymentMethod}
151
152 {if $n==0}
153 {$checked = "checked"}
154 {$activePaymentMethod = $paymentMethod->getId()}
155 {$n++}
156 {else:}
157 {$checked = ''}
158 {/if}
159 <li>
160 <h3>
161 <label>
162 <input type="radio" onclick="changePaymentMethod(this.value);" {$checked} name="paymentMethod" value="{echo $paymentMethod->getId()}" />
163
164 {echo ShopCore::encode($paymentMethod->getName())}
165 </label>
166 </h3>
167 <div class="desc">{echo $paymentMethod->getDescription()}</div>
168 </li>
169 {/foreach}
170 </ul>
171 {/if}
172 </div>
173
174 <div id="total">
175 <span class="value" id="totalPriceText">
176 {echo ShopCore::app()->SCart->totalPrice()} {$CS}
177 </span>
178 <span class="label">
179 {echo ShopCore::t('Итог')}
180 </span>
181 </div>
182
183 <div class="sp"></div>
184 <h5>Адрес получателя</h5>
185
186 {if $errors}
187 <div class="spLine"></div>
188 <div class="errors">
189 {$errors}
190 </div>
191 {/if}
192
193 <div class="spLine"></div><br/>
194 <div style="margin-left:20px;">
195 <form action="{shop_url('cart')}" method="post" name="orderForm">
196 <input type="hidden" name="deliveryMethodId" id="deliveryMethodId" value="0">
197 <input type="hidden" name="paymentMethodId" id="paymentMethodId" value="0">
198 <input type="hidden" name="makeOrder" value="1">
199 <div class="fieldName">Имя, фамилия:</div>
200 <div class="field">
201 <input type="text" class="input" name="userInfo[fullName]" value="{$profile.name}">
202 </div>
203 <div class="clear"></div>
204
205 <div class="fieldName">Email:</div>
206 <div class="field">
207 <input type="text" class="input" name="userInfo[email]" value="{$profile.email}">
208 </div>
209 <div class="clear"></div>
210
211 <div class="fieldName">Телефон:</div>
212 <div class="field">
213 <input type="text" class="input" name="userInfo[phone]" value="{$profile.phone}">
214 </div>
215 <div class="clear"></div>
216
217 <div class="fieldName">Адрес доставки:</div>
218 <div class="field">
219 <input type="text" class="input" name="userInfo[deliverTo]" value="{echo $profile.address}">
220 </div>
221 <div class="clear"></div>
222
223 <div class="fieldName">Комментарий к заказу:</div>
224 <div class="field">
225 <textarea name="userInfo[commentText]" class="input" rows="6"></textarea>
226 </div>
227 <div class="clear"></div>
228
229 <div id="buttons">
230 <a href="#" id="checkout" onClick="document.orderForm.submit();">{echo ShopCore::t('Оформить Заказ')}</a>
231 </div>
232 {form_csrf()}
233 </form>
234 </div>
235
236 <script type="text/javascript">
237 {$srciptText}
238 changePaymentMethod({echo $activePaymentMethod});
239 </script>
Главные участки файла cart.tpl¶
Проверка на наличие добавленных продуктов в корзину¶
1
2 {if !$items}
3 {echo ShopCore::t('Корзина пуста')}
4 {return}
5 {/if}
Отображение списка добавленных в корзину продуктов¶
1
2 <table class="cartTable" width="100%">
3 <thead align="left">
4 <th>{echo ShopCore::t('Фото')}</th>
5 <th>{echo ShopCore::t('Название')}</th>
6 <th>{echo ShopCore::t('Цена')}</th>
7 <th>{echo ShopCore::t('Количество')}</th>
8 <th>{echo ShopCore::t('Всего')}</th>
9 <th class="admin"></th>
10 </thead>
11 <tbody>
12 {foreach $items as $key=>$item}
13 <tr>
14 <td style="width:90px;padding:2px;">
15 <div style="width:90px;height:90px;overflow:hidden;">
16 {if $item.model->getMainImage()}
17 <img src="{productImageUrl($item.model->getId() . '_main.jpg')}" border="0" alt="image" width="90" />
18 {/if}
19 </div>
20 </td>
21 <td>
22 <a href="{shop_url('product/' . $item.model->getUrl())}">{echo ShopCore::encode($item.model->getName())}</a> {$item.variantName}
23 </td>
24 <td>{echo ShopCore::app()->SCurrencyHelper->convert($item.price)} {$CS}</td>
25 <td>
26 <!-- {form_dropdown("products[$key]",$ranges, $item.quantity, 'onChange="document.cartForm.submit();"')} -->
27 <input type="text" name="products[{$key}]" value="{$item.quantity}" style="width:24px;">
28 </td>
29 <td>{echo ShopCore::app()->SCurrencyHelper->convert($item.totalAmount)} {$CS}</td>
30 <td><a href="{shop_url('cart/delete/' . $key)}" rel="nofollow" class="delete">X</a></td>
31 </tr>
32 {/foreach}
33 </tbody>
34 <tfoot>
35 <td></td>
36 <td></td>
37 <td></td>
38 <td></td>
39 <td></td>
40 <td></td>
41 </tfoot>
42 </table>
Отображение возможных вариантов доставки¶
1
2 <h5>Способ доставки</h5>
3 <div class="spLine"></div>
4
5 {if sizeof($deliveryMethods) > 0}
6 <ul class="deliveryMethods">
7 {$n=0}
8 {foreach $deliveryMethods as $deliveryMethod}
9 {if $deliveryMethod->getIsPriceInPercent() == true}
10 {$delPrice = round(ShopCore::app()->SCart->totalPrice() * $deliveryMethod->getPrice() / 100, 2)}
11 {else:}
12 {$delPrice = $deliveryMethod->toCurrency()}
13 {/if}
14 {if $n==0}
15 {$checked = "checked"}
16 {$activeDeliveryMethod = $deliveryMethod->getId()}
17 {else:}
18 {$checked = ''}
19 {/if}
20 {$n++}
21 {if $deliveryMethod->getFreeFrom() == 0 && $deliveryMethod->getPrice() > 0}
22 {$priceStr = "$delPrice".' '.$CS}
23 {$free = false}
24 {elseif(ShopCore::app()->SCart->totalPrice(false) >= $deliveryMethod->getFreeFrom()):}
25 {$priceStr = "бесплатно"}
26 {$free = true}
27 {elseif($deliveryMethod->getFreeFrom() > 0 && $deliveryMethod->getPrice() > 0):}
28 {$priceStr = "$delPrice".' '.$CS}
29 {$free = false}
30 {/if}
31
32 <li>
33 <h3>
34 <label>
35 {if $free==true}
36 <input type="radio" onclick="changeDeliveryMethod(this.value,true);" {$checked} name="deliveryMethod" value="{echo $deliveryMethod->getId()}" />
37 {else:}
38 <input type="radio" onclick="changeDeliveryMethod(this.value);" {$checked} name="deliveryMethod" value="{echo $deliveryMethod->getId()}" />
39 {/if}
40
41 {echo ShopCore::encode($deliveryMethod->getName())} ({$priceStr})
42 </label>
43 </h3>
44 <div class="desc">{echo $deliveryMethod->getDescription()}</div>
45 </li>
46 {if $n==1}
47 {if $free==true}
48 {$srciptText = "changeDeliveryMethod($activeDeliveryMethod, true);\r\n"}
49 {else:}
50 {$srciptText = "changeDeliveryMethod($activeDeliveryMethod);\r\n"}
51 {/if}
52 {/if}
53 {/foreach}
54 </ul>
55 {/if}
Отображение общей суммы заказа¶
1
2 <div id="total">
3 <span class="value" id="totalPriceText">
4 {echo ShopCore::app()->SCart->totalPrice()} {$CS}
5 </span>
6 <span class="label">
7 {echo ShopCore::t('Итог')}
8 </span>
9 </div>
Отображение ошибок при заполнении формы с контактными данными¶
1
2 {if $errors}
3 <div class="spLine"></div>
4 <div class="errors">
5 {$errors}
6 </div>
7 {/if}
Отображение формы с контактными данными¶
1
2 <form action="{shop_url('cart')}" method="post" name="orderForm">
3 <input type="hidden" name="deliveryMethodId" id="deliveryMethodId" value="0">
4 <input type="hidden" name="makeOrder" value="1">
5 <div class="fieldName">Имя, фамилия:</div>
6 <div class="field">
7 <input type="text" class="input" name="userInfo[fullName]">
8 </div>
9 <div class="clear"></div>
10
11 <div class="fieldName">Email:</div>
12 <div class="field">
13 <input type="text" class="input" name="userInfo[email]">
14 </div>
15 <div class="clear"></div>
16
17 <div class="fieldName">Телефон:</div>
18 <div class="field">
19 <input type="text" class="input" name="userInfo[phone]">
20 </div>
21 <div class="clear"></div>
22
23 <div class="fieldName">Адрес доставки:</div>
24 <div class="field">
25 <input type="text" class="input" name="userInfo[deliverTo]">
26 </div>
27 <div class="clear"></div>
28
29 <div class="fieldName">Комментарий к заказу:</div>
30 <div class="field">
31 <textarea name="userInfo[commentText]" class="input" rows="6"></textarea>
32 </div>
33 <div class="clear"></div>
34
35 <div id="buttons">
36 <a href="#" id="checkout" onClick="document.orderForm.submit();">{echo ShopCore::t('Оформить Заказ')}</a>
37 </div>
38 {form_csrf()}
39 </form>