Я использую minicart.js для личного проекта.Здесь у меня есть значение набора полей, которое я добавляю как элемент корзины:
<fieldset>
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="add" value="1" />
<input type="hidden" name="business" value=" " />
<input type="hidden" name="item_name" value="@pro.Name" />
<input type="hidden" name="amount" value="@pro.SalesRate" />
<input type="hidden" name="currency_code" value="USD" />
<input type="submit" name="submit" value="Add to cart" class="button" />
</fieldset>
Вот мой js:
paypal.minicart.cart.on('checkout', function (evt) {
var items = this.items(),
len = items.length,
total = 0,
i;
for (i = 0; i < len; i++) {
total += items[i].get('quantity');
Productname = items[i].get('item_name');
productPrice = items[i].get('amount');
}
});
После оформления покупки элемент корзины перенаправляется на контроллер.Это код minicart.js:
var defaults = module.exports = {
name: 'PPMiniCart',
parent: (typeof document !== 'undefined') ? document.body : null,
action: '/Home/CheckOut',
target: '',
duration: 30,
template: '<%var items = cart.items();var settings = cart.settings();var hasItems = !!items.length;var priceFormat = { format: true, currency: cart.settings("currency_code") };var totalFormat = { format: true, showCode: true };%><form method="post" class="<% if (!hasItems) { %>minicart-empty<% } %>" action="<%= config.action %>" target="<%= config.target %>"> <button type="button" class="minicart-closer">×</button> <ul> <% for (var i= 0, idx = i + 1, len = items.length; i < len; i++, idx++) { %> <li class="minicart-item"> <div class="minicart-details-name"> <a class="minicart-name" href="<%= items[i].get("href") %>"><%= items[i].get("item_name") %></a> <ul class="minicart-attributes"> <% if (items[i].get("item_number")) { %> <li> <%= items[i].get("item_number") %> <input type="hidden" name="item_number_<%= idx %>" value="<%= items[i].get("item_number") %>" /> </li> <% } %> <% if (items[i].discount()) { %> <li> <%= config.strings.discount %> <%= items[i].discount(priceFormat) %> <input type="hidden" name="discount_amount_<%= idx %>" value="<%= items[i].discount() %>" /> </li> <% } %> <% for (var options = items[i].options(), j = 0, len2 = options.length; j < len2; j++) { %> <li> <%= options[j].key %>: <%= options[j].value %> <input type="hidden" name="on<%= j %>_<%= idx %>" value="<%= options[j].key %>" /> <input type="hidden" name="os<%= j %>_<%= idx %>" value="<%= options[j].value %>" /> </li> <% } %> </ul> </div> <div class="minicart-details-quantity"> <input class="minicart-quantity" data-minicart-idx="<%= i %>" name="quantity_<%= idx %>" type="text" pattern="[0-9]*" value="<%= items[i].get("quantity") %>" autocomplete="off" /> </div> <div class="minicart-details-remove"> <button type="button" class="minicart-remove" data-minicart-idx="<%= i %>">×</button> </div> <div class="minicart-details-price"> <span class="minicart-price"><%= items[i].total(priceFormat) %></span> </div> <input type="hidden" name="item_name_<%= idx %>" value="<%= items[i].get("item_name") %>" /> <input type="hidden" name="amount_<%= idx %>" value="<%= items[i].amount() %>" /> <input type="hidden" name="shipping_<%= idx %>" value="<%= items[i].get("shipping") %>" /> <input type="hidden" name="shipping2_<%= idx %>" value="<%= items[i].get("shipping2") %>" /> </li> <% } %> </ul> <div class="minicart-footer"> <% if (hasItems) { %> <div class="minicart-subtotal"> <%= config.strings.subtotal %> <%= cart.total(totalFormat) %> </div> <button class="minicart-submit" type="submit" data-minicart-alt="<%= config.strings.buttonAlt %>"><%- config.strings.button %></button> <% } else { %> <p class="minicart-empty-text"><%= config.strings.empty %></p> <% } %> </div> <input type="hidden" name="cmd" value="_cart" /> <input type="hidden" name="upload" value="1" /> <% for (var key in settings) { %> <input type="hidden" name="<%= key %>" value="<%= settings[key] %>" /> <% } %></form>',
styles: '@keyframes pop-in { 0% { opacity: 0; transform: scale(0.1); } 60% { opacity: 1; transform: scale(1.2); } 100% { transform: scale(1); }}@-webkit-keyframes pop-in { 0% { opacity: 0; -webkit-transform: scale(0.1); } 60% { opacity: 1; -webkit-transform: scale(1.2); } 100% { -webkit-transform: scale(1); }}@-moz-keyframes pop-in { 0% { opacity: 0; -moz-transform: scale(0.1); } 60% { opacity: 1; -moz-transform: scale(1.2); } 100% { -moz-transform: scale(1); }}.minicart-showing #PPMiniCart { display: block; transform: translateZ(0); -webkit-transform: translateZ(0); -moz-transform: translateZ(0); animation: pop-in 0.25s; -webkit-animation: pop-in 0.25s; -moz-animation: pop-in 0.25s;}#PPMiniCart { display: none; position: fixed; left: 50%; top: 75px;}#PPMiniCart form { position: relative; width: 400px; max-height: 400px; margin-left: -200px; padding: 10px 10px 40px; background: #fbfbfb; border: 1px solid #d7d7d7; border-radius: 4px; box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.5); font: 15px/normal arial, helvetica; color: #333;}#PPMiniCart form.minicart-empty { padding-bottom: 10px; font-size: 16px; font-weight: bold;}#PPMiniCart ul { clear: both; float: left; width: 380px; margin: 5px 0 20px; padding: 10px; list-style-type: none; background: #fff; border: 1px solid #ccc; border-radius: 4px; box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);}#PPMiniCart .minicart-empty ul { display: none;}#PPMiniCart .minicart-closer { float: right; margin: -12px -10px 0; padding: 10px; background: 0; border: 0; font-size: 18px; cursor: pointer; font-weight: bold;}#PPMiniCart .minicart-item { clear: left; padding: 6px 0; min-height: 25px;}#PPMiniCart .minicart-item + .minicart-item { border-top: 1px solid #f2f2f2;}#PPMiniCart .minicart-item a { color: #333; text-decoration: none;}#PPMiniCart .minicart-details-name { float: left; width: 62%;}#PPMiniCart .minicart-details-quantity { float: left; width: 15%;}#PPMiniCart .minicart-details-remove { float: left; width: 7%;}#PPMiniCart .minicart-details-price { float: left; width: 16%; text-align: right;}#PPMiniCart .minicart-attributes { margin: 0; padding: 0; background: transparent; border: 0; border-radius: 0; box-shadow: none; color: #999; font-size: 12px; line-height: 22px;}#PPMiniCart .minicart-attributes li { display: inline;}#PPMiniCart .minicart-attributes li:after { content: ",";}#PPMiniCart .minicart-attributes li:last-child:after { content: "";}#PPMiniCart .minicart-quantity { width: 30px; height: 18px; padding: 2px 4px; border: 1px solid #ccc; border-radius: 4px; box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); font-size: 13px; text-align: right; transition: border linear 0.2s, box-shadow linear 0.2s; -webkit-transition: border linear 0.2s, box-shadow linear 0.2s; -moz-transition: border linear 0.2s, box-shadow linear 0.2s;}#PPMiniCart .minicart-quantity:hover { border-color: #0078C1;}#PPMiniCart .minicart-quantity:focus { border-color: #0078C1; outline: 0; box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 3px rgba(0, 120, 193, 0.4);}#PPMiniCart .minicart-remove { width: 18px; height: 19px; margin: 2px 0 0; padding: 0; background: #b7b7b7; border: 1px solid #a3a3a3; border-radius: 3px; color: #fff; font-size: 13px; opacity: 0.70; cursor: pointer;}#PPMiniCart .minicart-remove:hover { opacity: 1;}#PPMiniCart .minicart-footer { clear: left;}#PPMiniCart .minicart-subtotal { position: absolute; bottom: 17px; padding-left: 6px; left: 10px; font-size: 16px; font-weight: bold;}#PPMiniCart .minicart-submit { position: absolute; bottom: 10px; right: 10px; min-width: 153px; height: 33px; margin-right: 6px; padding: 0 9px; border: 1px solid #ffc727; border-radius: 5px; color: #000; text-shadow: 1px 1px 1px #fff6e9; cursor: pointer; background: #ffaa00; background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2ZmZjZlOSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNmZmFhMDAiIHN0b3Atb3BhY2l0eT0iMSIvPgogIDwvbGluZWFyR3JhZGllbnQ+CiAgPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkLXVjZ2ctZ2VuZXJhdGVkKSIgLz4KPC9zdmc+); background: -moz-linear-gradient(top, #fff6e9 0%, #ffaa00 100%); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#fff6e9), color-stop(100%,#ffaa00)); background: -webkit-linear-gradient(top, #fff6e9 0%,#ffaa00 100%); background: -o-linear-gradient(top, #fff6e9 0%,#ffaa00 100%); background: -ms-linear-gradient(top, #fff6e9 0%,#ffaa00 100%); background: linear-gradient(to bottom, #fff6e9 0%,#ffaa00 100%);}#PPMiniCart .minicart-submit img { vertical-align: middle; padding: 4px 0 0 2px;}',
strings: {
button: 'Check Out with <img src="//cdnjs.cloudflare.com/ajax/libs/minicart/3.0.1/paypal_65x18.png" width="65" height="18" alt="PayPal" />',
subtotal: 'Subtotal:',
discount: 'Discount:',
empty: 'Your shopping cart is empty'
}
, но я не могу понять, как передать значение productPrice,Productname
в контроллер '/Home/CheckOut'
.Я новичок в программировании.Любая помощь высоко ценится.