Dailydeal.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. namespace Smartwave\Dailydeals\Block\Adminhtml\Dailydeal\Edit\Tab;
  3. class Dailydeal extends \Magento\Backend\Block\Widget\Form\Generic implements \Magento\Backend\Block\Widget\Tab\TabInterface
  4. {
  5. /**
  6. * Country options
  7. *
  8. * @var \Magento\Config\Model\Config\Source\Yesno
  9. */
  10. protected $booleanOptions;
  11. /**
  12. * Discount Type options
  13. *
  14. * @var \Smartwave\Dailydeals\Model\Dailydeal\Source\SwDiscountType
  15. */
  16. protected $swDiscountTypeOptions;
  17. protected $swDealProductOptions;
  18. /**
  19. * constructor
  20. *
  21. * @param \Magento\Config\Model\Config\Source\Yesno $booleanOptions
  22. * @param \Smartwave\Dailydeals\Model\Dailydeal\Source\SwDiscountType $swDiscountTypeOptions
  23. * @param \Magento\Backend\Block\Template\Context $context
  24. * @param \Magento\Framework\Registry $registry
  25. * @param \Magento\Framework\Data\FormFactory $formFactory
  26. * @param array $data
  27. */
  28. public function __construct(
  29. \Magento\Config\Model\Config\Source\Yesno $booleanOptions,
  30. \Smartwave\Dailydeals\Model\Dailydeal\Source\SwDiscountType $swDiscountTypeOptions,
  31. \Smartwave\Dailydeals\Model\Dailydeal\Source\SwDealProduct $swDealProductOptions,
  32. \Magento\Backend\Block\Template\Context $context,
  33. \Magento\Framework\Registry $registry,
  34. \Magento\Framework\Data\FormFactory $formFactory,
  35. array $data = []
  36. ) {
  37. $this->booleanOptions = $booleanOptions;
  38. $this->swDiscountTypeOptions = $swDiscountTypeOptions;
  39. $this->swDealProductOptions = $swDealProductOptions;
  40. parent::__construct($context, $registry, $formFactory, $data);
  41. }
  42. /**
  43. * Prepare form
  44. *
  45. * @return $this
  46. */
  47. protected function _prepareForm()
  48. {
  49. /** @var \Smartwave\Dailydeals\Model\Dailydeal $dailydeal */
  50. $dailydeal = $this->_coreRegistry->registry('sw_dailydeals_dailydeal');
  51. $form = $this->_formFactory->create();
  52. $form->setHtmlIdPrefix('dailydeal_');
  53. $form->setFieldNameSuffix('dailydeal');
  54. $fieldset = $form->addFieldset(
  55. 'base_fieldset',
  56. [
  57. 'legend' => __('Dailydeal Information'),
  58. 'class' => 'fieldset-wide'
  59. ]
  60. );
  61. if ($dailydeal->getId()) {
  62. $fieldset->addField(
  63. 'dailydeal_id',
  64. 'hidden',
  65. ['name' => 'dailydeal_id']
  66. );
  67. }
  68. $fieldset->addField(
  69. 'sw_product_sku',
  70. 'select',
  71. [
  72. 'name' => 'sw_product_sku',
  73. 'label' => __('Product Sku'),
  74. 'title' => __('Product Sku'),
  75. 'onchange' => 'checkSelectedItem(this.value)',
  76. 'values' => array_merge(['' => ''], $this->swDealProductOptions->toOptionArray()),
  77. ]
  78. );
  79. $fieldset->addField(
  80. 'sw_deal_enable',
  81. 'select',
  82. [
  83. 'name' => 'sw_deal_enable',
  84. 'label' => __('Enable Deal'),
  85. 'title' => __('Enable Deal'),
  86. 'values' => $this->booleanOptions->toOptionArray(),
  87. ]
  88. );
  89. $fieldset->addField(
  90. 'sw_discount_type',
  91. 'select',
  92. [
  93. 'name' => 'sw_discount_type',
  94. 'label' => __('Discount Type'),
  95. 'title' => __('Discount Type'),
  96. 'values' => array_merge(['' => ''], $this->swDiscountTypeOptions->toOptionArray()),
  97. ]
  98. );
  99. $fieldset->addField(
  100. 'sw_discount_amount',
  101. 'text',
  102. [
  103. 'name' => 'sw_discount_amount',
  104. 'label' => __('Discount Value'),
  105. 'title' => __('Discount Value'),
  106. ]
  107. );
  108. $fieldset->addField(
  109. 'sw_date_from',
  110. 'date',
  111. [
  112. 'name' => 'sw_date_from',
  113. 'label' => __('Date From'),
  114. 'title' => __('Date From'),
  115. 'date_format' => $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT),
  116. 'time_format' => $this->_localeDate->getTimeFormat(\IntlDateFormatter::SHORT),
  117. 'class' => 'validate-date',
  118. ]
  119. );
  120. $fieldset->addField(
  121. 'sw_date_to',
  122. 'date',
  123. [
  124. 'name' => 'sw_date_to',
  125. 'label' => __('Date To'),
  126. 'title' => __('Date To'),
  127. 'date_format' => $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT),
  128. 'time_format' => $this->_localeDate->getTimeFormat(\IntlDateFormatter::SHORT),
  129. // 'time_format' => 'hh:mm:ss a',
  130. 'class' => 'validate-date',
  131. ]
  132. );
  133. $dailydealData = $this->_session->getData('sw_dailydeals_dailydeal_data', true);
  134. if ($dailydealData) {
  135. $dailydeal->addData($dailydealData);
  136. } else {
  137. if (!$dailydeal->getId()) {
  138. $dailydeal->addData($dailydeal->getDefaultValues());
  139. }
  140. }
  141. $form->addValues($dailydeal->getData());
  142. $this->setForm($form);
  143. return parent::_prepareForm();
  144. }
  145. /**
  146. * Prepare label for tab
  147. *
  148. * @return string
  149. */
  150. public function getTabLabel()
  151. {
  152. return __('Dailydeal');
  153. }
  154. /**
  155. * Prepare title for tab
  156. *
  157. * @return string
  158. */
  159. public function getTabTitle()
  160. {
  161. return $this->getTabLabel();
  162. }
  163. /**
  164. * Can show tab in tabs
  165. *
  166. * @return boolean
  167. */
  168. public function canShowTab()
  169. {
  170. return true;
  171. }
  172. /**
  173. * Tab is hidden
  174. *
  175. * @return boolean
  176. */
  177. public function isHidden()
  178. {
  179. return false;
  180. }
  181. }