Ejemplo n.º 1
0
 /**
  * @param string     $id
  * @param Store      $store
  * @param Translator $i18n
  * @param array      $countries
  * @param array      $paymentMethods
  * @param string     $tosUrl
  */
 public function __construct($id, $store, $i18n, $countries = array(), $paymentMethods = array(), $tosUrl = '')
 {
     $this->id = $id;
     $this->store = $store;
     $this->updateLocale($i18n);
     $this->attr(['action' => '', 'method' => 'POST']);
     $this->add(['modeToCart' => Field::submit()->val('toCart')->html($i18n->translate('button.backToCart'))->render(function ($e) {
         // set name to avoid setting name from form
         $e->attr(['name' => 'mode']);
         return '<div class="cartButtonBar">' . $e . '</div>';
     }), 'customer' => Field::group(['email' => Field::email()->required()->label($i18n->translate('checkoutForm.customer.email') . ' *'), 'telephone' => Field::tel()->label($i18n->translate('checkoutForm.customer.tel')), 'paymentMethod' => Field::select()->options($paymentMethods)->label($i18n->translate('checkoutForm.paymentMethod'))])->render(function ($group) {
         return '<div class="group customer"><h3>' . $group->label . '</h3>' . $group->childrenToHtml() . '</div>';
     })->label($i18n->translate('checkoutForm.customer.title')), 'billing' => $this->createAddress($countries, $i18n)->label($i18n->translate('checkoutForm.billingAdr.title')), 'shipping' => $this->createShippingAddress($countries, $i18n)->label($i18n->translate('checkoutForm.shippingAdr.title')), 'extra' => Field::group(['comment' => Field::textarea()->rows(8)])->render(function ($group) {
         return '<div class="group"><h3>' . $group->label . '</h3>' . $group->childrenToHtml() . '</div>';
     })->label($i18n->translate('checkoutForm.customer.comment')), 'accept_tos' => Field::checkbox()->required()->label(str_replace('%s', $tosUrl, $i18n->translate('checkoutForm.tosAccept')))->render(function ($field) {
         return "<label class='checkbox small'>{$field->input} " . $field->label() . '</label>';
     }), 'modePayment' => Field::submit()->val('payment')->addClass('primary')->html($i18n->translate('button.doCheckout'))->render(function ($e) {
         // set name to avoid setting name from form
         $e->attr(['name' => 'mode']);
         return '<div class="cartButtonBar">' . $e . '</div>';
     })]);
 }