Guest User

Untitled

a guest
May 16th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from "react";
  2. export default class Order extends React.Component {
  3.     constructor(props) {
  4.  
  5.         super(props)
  6.  
  7.         var products = [
  8.             { name: "Motorhead glasses", price: 300, amount: 1 },
  9.             { name: "Judaspriest glasses", price: 499, amount: 1 }
  10.         ]
  11.  
  12.         this.state = { products: products }
  13.         this.handleMinus = this.handleMinus.bind(this)
  14.  
  15.     }
  16.  
  17.  
  18.     handleMinus(key) {
  19.             var stateCopy = Object.assign({}, this.state.products);
  20.             stateCopy.products[key].amount += 1;
  21.             this.setState({products : stateCopy });
  22.     }
  23.     render() {
  24.         return (
  25.             <div className="order">
  26.                 {this.state.products.map(function (product, i) {
  27.                     return <div className="order-product" key={i}>
  28.                         <div className="order-product_img"><img src="./assets/img/pic-item.png" alt="" /></div>
  29.                         <h3 className="order-product_name">{product.name}</h3>
  30.                         <div className="order-product_amount">
  31.                             <div className="amount">
  32.                                 <button id="minus" onClick={this.handleMinus = this.handleMinus.bind(this)}><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
  33.                                     <g fill="none" fill-rule="evenodd">
  34.                                         <circle cx="12" cy="12" r="11.5" stroke="#333" />
  35.                                         <polygon fill="#000" fill-rule="nonzero" points="6.5 13 17.5 13 17.5 12 6.5 12" />
  36.                                     </g>
  37.                                 </svg>
  38.  
  39.                                 </button>
  40.                                 <p>{product.amount}</p>
  41.                                 <button className="plus"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
  42.                                     <g fill="none" fill-rule="evenodd">
  43.                                         <circle cx="12" cy="12" r="11.5" stroke="#333" />
  44.                                         <polygon fill="#000" fill-rule="nonzero" points="6.5 13 17.5 13 17.5 12 6.5 12" />
  45.                                         <polygon fill="#000" fill-rule="nonzero" points="11.5 7 11.5 18 12.5 18 12.5 7" />
  46.                                     </g>
  47.                                 </svg>
  48.                                 </button>
  49.                             </div>
  50.  
  51.                         </div>
  52.                         <div className="order-product_price"><span className="l">Price</span><span className="right">${product.price}</span></div>
  53.                     </div>
  54.                 }, this)
  55.                 }
  56.  
  57.                 <div className="order-summary">
  58.                     <h3>Order Summary</h3>
  59.                     <div className="order-summary_summary">
  60.                         <p>Subtotal <span className="price">$300</span></p>
  61.                         <p>Shipping <span className="price">$20</span></p>
  62.                         <hr />
  63.                         <p>Total <span className="price">$320</span></p>
  64.                     </div>
  65.                 </div>
  66.             </div>
  67.  
  68.         )
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment