Ejemplo n.º 1
0
 /**
  * Retrieve customer groups as array
  *
  * @return array
  */
 public function toOptionArray()
 {
     if (!$this->_options) {
         $groups = $this->_groupService->getGroups(false);
         $this->_options = $this->_converter->toOptionArray($groups, 'id', 'code');
     }
     return $this->_options;
 }
Ejemplo n.º 2
0
 /**
  */
 public function testGetGroupsFiltered()
 {
     $groups = $this->_groupService->getGroups(false);
     $this->assertEquals(3, count($groups));
     $this->assertEquals([1, 'General', 3], [$groups[0]->getId(), $groups[0]->getCode(), $groups[0]->getTaxClassId()]);
     $this->assertEquals([2, 'Wholesale', 3], [$groups[1]->getId(), $groups[1]->getCode(), $groups[1]->getTaxClassId()]);
     $this->assertEquals([3, 'Retailer', 3], [$groups[2]->getId(), $groups[2]->getCode(), $groups[2]->getTaxClassId()]);
 }
Ejemplo n.º 3
0
 /**
  * @return array
  */
 public function toOptionArray()
 {
     if (!$this->_options) {
         $groups = $this->_groupService->getGroups(false);
         $this->_options = $this->_converter->toOptionArray($groups, 'id', 'code');
         array_unshift($this->_options, array('value' => '', 'label' => __('-- Please Select --')));
     }
     return $this->_options;
 }
Ejemplo n.º 4
0
 /**
  * Retrieve allowed customer groups
  *
  * @param int $groupId return name by customer group id
  * @return array|string
  */
 protected function _getCustomerGroups($groupId = null)
 {
     if (is_null($this->_customerGroups)) {
         $this->_customerGroups = array();
         foreach ($this->_groupService->getGroups() as $item) {
             /* @var $item \Magento\Customer\Service\V1\Data\CustomerGroup */
             $this->_customerGroups[$item->getId()] = $item->getCode();
         }
     }
     if (!is_null($groupId)) {
         return isset($this->_customerGroups[$groupId]) ? $this->_customerGroups[$groupId] : null;
     }
     return $this->_customerGroups;
 }
Ejemplo n.º 5
0
 /**
  * Prepare form before rendering HTML
  *
  * @return $this
  */
 protected function _prepareForm()
 {
     $model = $this->_coreRegistry->registry('current_promo_quote_rule');
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     $form->setHtmlIdPrefix('rule_');
     $fieldset = $form->addFieldset('base_fieldset', array('legend' => __('General Information')));
     if ($model->getId()) {
         $fieldset->addField('rule_id', 'hidden', array('name' => 'rule_id'));
     }
     $fieldset->addField('product_ids', 'hidden', array('name' => 'product_ids'));
     $fieldset->addField('name', 'text', array('name' => 'name', 'label' => __('Rule Name'), 'title' => __('Rule Name'), 'required' => true));
     $fieldset->addField('description', 'textarea', array('name' => 'description', 'label' => __('Description'), 'title' => __('Description'), 'style' => 'height: 100px;'));
     $fieldset->addField('is_active', 'select', array('label' => __('Status'), 'title' => __('Status'), 'name' => 'is_active', 'required' => true, 'options' => array('1' => __('Active'), '0' => __('Inactive'))));
     if (!$model->getId()) {
         $model->setData('is_active', '1');
     }
     if ($this->_storeManager->isSingleStoreMode()) {
         $websiteId = $this->_storeManager->getStore(true)->getWebsiteId();
         $fieldset->addField('website_ids', 'hidden', array('name' => 'website_ids[]', 'value' => $websiteId));
         $model->setWebsiteIds($websiteId);
     } else {
         $field = $fieldset->addField('website_ids', 'multiselect', array('name' => 'website_ids[]', 'label' => __('Websites'), 'title' => __('Websites'), 'required' => true, 'values' => $this->_systemStore->getWebsiteValuesForForm()));
         $renderer = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element');
         $field->setRenderer($renderer);
     }
     $groups = $this->_customerGroupService->getGroups();
     $fieldset->addField('customer_group_ids', 'multiselect', array('name' => 'customer_group_ids[]', 'label' => __('Customer Groups'), 'title' => __('Customer Groups'), 'required' => true, 'values' => $this->_objectConverter->toOptionArray($groups, 'id', 'code')));
     $couponTypeFiled = $fieldset->addField('coupon_type', 'select', array('name' => 'coupon_type', 'label' => __('Coupon'), 'required' => true, 'options' => $this->_salesRule->create()->getCouponTypes()));
     $couponCodeFiled = $fieldset->addField('coupon_code', 'text', array('name' => 'coupon_code', 'label' => __('Coupon Code'), 'required' => true));
     $autoGenerationCheckbox = $fieldset->addField('use_auto_generation', 'checkbox', array('name' => 'use_auto_generation', 'label' => __('Use Auto Generation'), 'note' => __('If you select and save the rule you will be able to generate multiple coupon codes.'), 'onclick' => 'handleCouponsTabContentActivity()', 'checked' => (int) $model->getUseAutoGeneration() > 0 ? 'checked' : ''));
     $autoGenerationCheckbox->setRenderer($this->getLayout()->createBlock('Magento\\SalesRule\\Block\\Adminhtml\\Promo\\Quote\\Edit\\Tab\\Main\\Renderer\\Checkbox'));
     $usesPerCouponFiled = $fieldset->addField('uses_per_coupon', 'text', array('name' => 'uses_per_coupon', 'label' => __('Uses per Coupon')));
     $fieldset->addField('uses_per_customer', 'text', array('name' => 'uses_per_customer', 'label' => __('Uses per Customer'), 'note' => __('Usage limit enforced for logged in customers only.')));
     $dateFormat = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT);
     $fieldset->addField('from_date', 'date', array('name' => 'from_date', 'label' => __('From Date'), 'title' => __('From Date'), 'image' => $this->getViewFileUrl('images/grid-cal.gif'), 'input_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT, 'date_format' => $dateFormat));
     $fieldset->addField('to_date', 'date', array('name' => 'to_date', 'label' => __('To Date'), 'title' => __('To Date'), 'image' => $this->getViewFileUrl('images/grid-cal.gif'), 'input_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT, 'date_format' => $dateFormat));
     $fieldset->addField('sort_order', 'text', array('name' => 'sort_order', 'label' => __('Priority')));
     $fieldset->addField('is_rss', 'select', array('label' => __('Public In RSS Feed'), 'title' => __('Public In RSS Feed'), 'name' => 'is_rss', 'options' => array('1' => __('Yes'), '0' => __('No'))));
     if (!$model->getId()) {
         //set the default value for is_rss feed to yes for new promotion
         $model->setIsRss(1);
     }
     $form->setValues($model->getData());
     $autoGenerationCheckbox->setValue(1);
     if ($model->isReadonly()) {
         foreach ($fieldset->getElements() as $element) {
             $element->setReadonly(true, true);
         }
     }
     //$form->setUseContainer(true);
     $this->setForm($form);
     // field dependencies
     $this->setChild('form_after', $this->getLayout()->createBlock('Magento\\Backend\\Block\\Widget\\Form\\Element\\Dependence')->addFieldMap($couponTypeFiled->getHtmlId(), $couponTypeFiled->getName())->addFieldMap($couponCodeFiled->getHtmlId(), $couponCodeFiled->getName())->addFieldMap($autoGenerationCheckbox->getHtmlId(), $autoGenerationCheckbox->getName())->addFieldMap($usesPerCouponFiled->getHtmlId(), $usesPerCouponFiled->getName())->addFieldDependence($couponCodeFiled->getName(), $couponTypeFiled->getName(), \Magento\SalesRule\Model\Rule::COUPON_TYPE_SPECIFIC)->addFieldDependence($autoGenerationCheckbox->getName(), $couponTypeFiled->getName(), \Magento\SalesRule\Model\Rule::COUPON_TYPE_SPECIFIC)->addFieldDependence($usesPerCouponFiled->getName(), $couponTypeFiled->getName(), \Magento\SalesRule\Model\Rule::COUPON_TYPE_SPECIFIC));
     $this->_eventManager->dispatch('adminhtml_promo_quote_edit_tab_main_prepare_form', array('form' => $form));
     return parent::_prepareForm();
 }
Ejemplo n.º 6
0
 /**
  * Retrieve allowed customer groups
  *
  * @param int|null $groupId  return name by customer group id
  * @return array|string
  */
 public function getCustomerGroups($groupId = null)
 {
     if ($this->_customerGroups === null) {
         if (!$this->_catalogData->isModuleEnabled('Magento_Customer')) {
             return array();
         }
         $groups = $this->_groupService->getGroups();
         $this->_customerGroups = $this->_getInitialCustomerGroups();
         foreach ($groups as $group) {
             $this->_customerGroups[$group->getId()] = $group->getCode();
         }
     }
     if ($groupId !== null) {
         return isset($this->_customerGroups[$groupId]) ? $this->_customerGroups[$groupId] : array();
     }
     return $this->_customerGroups;
 }
Ejemplo n.º 7
0
 /**
  * @return Form
  */
 protected function _prepareForm()
 {
     $model = $this->_coreRegistry->registry('current_promo_catalog_rule');
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     $form->setHtmlIdPrefix('rule_');
     $fieldset = $form->addFieldset('base_fieldset', array('legend' => __('General Information')));
     if ($model->getId()) {
         $fieldset->addField('rule_id', 'hidden', array('name' => 'rule_id'));
     }
     $fieldset->addField('name', 'text', array('name' => 'name', 'label' => __('Rule Name'), 'title' => __('Rule Name'), 'required' => true));
     $fieldset->addField('description', 'textarea', array('name' => 'description', 'label' => __('Description'), 'title' => __('Description'), 'style' => 'height: 100px;'));
     $fieldset->addField('is_active', 'select', array('label' => __('Status'), 'title' => __('Status'), 'name' => 'is_active', 'required' => true, 'options' => array('1' => __('Active'), '0' => __('Inactive'))));
     if ($this->_storeManager->isSingleStoreMode()) {
         $websiteId = $this->_storeManager->getStore(true)->getWebsiteId();
         $fieldset->addField('website_ids', 'hidden', array('name' => 'website_ids[]', 'value' => $websiteId));
         $model->setWebsiteIds($websiteId);
     } else {
         $field = $fieldset->addField('website_ids', 'multiselect', array('name' => 'website_ids[]', 'label' => __('Websites'), 'title' => __('Websites'), 'required' => true, 'values' => $this->_systemStore->getWebsiteValuesForForm()));
         $renderer = $this->getLayout()->createBlock('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element');
         $field->setRenderer($renderer);
     }
     $fieldset->addField('customer_group_ids', 'multiselect', array('name' => 'customer_group_ids[]', 'label' => __('Customer Groups'), 'title' => __('Customer Groups'), 'required' => true, 'values' => $this->_objectConverter->toOptionArray($this->_customerGroup->getGroups(), 'id', 'code')));
     $dateFormat = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT);
     $fieldset->addField('from_date', 'date', array('name' => 'from_date', 'label' => __('From Date'), 'title' => __('From Date'), 'image' => $this->getViewFileUrl('images/grid-cal.gif'), 'input_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT, 'date_format' => $dateFormat));
     $fieldset->addField('to_date', 'date', array('name' => 'to_date', 'label' => __('To Date'), 'title' => __('To Date'), 'image' => $this->getViewFileUrl('images/grid-cal.gif'), 'input_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT, 'date_format' => $dateFormat));
     $fieldset->addField('sort_order', 'text', array('name' => 'sort_order', 'label' => __('Priority')));
     $form->setValues($model->getData());
     if ($model->isReadonly()) {
         foreach ($fieldset->getElements() as $element) {
             $element->setReadonly(true, true);
         }
     }
     $this->setForm($form);
     $this->_eventManager->dispatch('adminhtml_promo_catalog_edit_tab_main_prepare_form', array('form' => $form));
     return parent::_prepareForm();
 }
Ejemplo n.º 8
0
 /**
  * Initialize customer groups.
  *
  * @return $this
  */
 protected function _initCustomerGroups()
 {
     foreach ($this->_customerGroupService->getGroups() as $group) {
         $this->_customerGroups[$group->getId()] = true;
     }
     return $this;
 }