voucher-code.phtml 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @version 7.9 [rev.7.9.01]
  4. */
  5. $userId = (!empty($userId)) ? $userId : null;
  6. $listingId = (!empty($listingId)) ? $listingId : null;
  7. $voucherCode = (!empty($voucherCode)) ? $voucherCode : $this->request()->getRequest()->getParam('voucher_code');
  8. $voucher = null;
  9. if ($voucherCode) {
  10. $vouchersService = new \Ppb\Service\Vouchers();
  11. $voucher = $vouchersService->findBy($voucherCode, $userId);
  12. }
  13. ?>
  14. <div class="form-group">
  15. <div class="input-group">
  16. <?php echo $this->formElement('text', 'voucher_code')
  17. ->setValue($voucherCode)
  18. ->setAttributes(array(
  19. 'class' => 'form-control',
  20. 'placeholder' => $this->_('Voucher Code'),
  21. ))
  22. ->render();
  23. ?>
  24. <span class="input-group-btn">
  25. <?php echo $this->formElement('submit', 'voucher_add', $this->_('Apply'))
  26. ->setAttributes(array(
  27. 'class' => 'btn btn-primary',
  28. ))
  29. ->render();
  30. ?>
  31. </span>
  32. </div>
  33. <div>
  34. <?php
  35. $valid = true;
  36. if ($voucher instanceof \Ppb\Db\Table\Row\Voucher) {
  37. if ($voucher->isValid($listingId)) {
  38. ?>
  39. <span class="label label-voucher label-success">
  40. <?php echo sprintf(
  41. $this->_('The voucher is valid. %s reduction applied'),
  42. (($voucher['reduction_type'] == 'percent') ?
  43. \Cube\Locale\Format::getInstance()->numericToLocalized($voucher['reduction_amount']) . '%' :
  44. $this->amount($voucher['reduction_amount']))); ?>
  45. </span>
  46. <?php
  47. }
  48. else {
  49. $valid = false;
  50. }
  51. }
  52. if ($voucherCode && !$valid) {
  53. ?>
  54. <span class="label label-voucher label-danger">
  55. <?php echo $this->_('The voucher is not valid.'); ?>
  56. </span>
  57. <?php
  58. }
  59. else {
  60. ?>
  61. <span class="help-block">
  62. <?php echo $this->_('Enter your voucher code (if applicable) then click apply.'); ?>
  63. </span>
  64. <?php } ?>
  65. </div>
  66. </div>