Example #1
0
 /**
  * Retrieve customer groups as array
  *
  * @return array
  */
 public function toOptionArray()
 {
     if (!$this->_options) {
         $groups = $this->_groupManagement->getLoggedInGroups();
         $this->_options = $this->_converter->toOptionArray($groups, 'id', 'code');
     }
     return $this->_options;
 }
Example #2
0
 /**
  * @return array
  */
 public function toOptionArray()
 {
     if (!$this->_options) {
         $groups = $this->_groupManagement->getLoggedInGroups();
         $this->_options = $this->_converter->toOptionArray($groups, 'id', 'code');
         array_unshift($this->_options, ['value' => '', 'label' => __('-- Please Select --')]);
     }
     return $this->_options;
 }
Example #3
0
 /**
  * Retrieve all tax rates as an options array.
  *
  * @return array
  */
 public function toOptionArray()
 {
     if (!$this->options) {
         $searchCriteria = $this->searchCriteriaBuilder->create();
         $searchResults = $this->taxRateRepository->getList($searchCriteria);
         $this->options = $this->converter->toOptionArray($searchResults->getItems(), Rate::KEY_ID, Rate::KEY_CODE);
     }
     return $this->options;
 }
Example #4
0
 /**
  * Retrieve all tax rates as an options array.
  *
  * @return array
  */
 public function toOptionArray()
 {
     if (!$this->options) {
         $searchCriteria = $this->searchCriteriaBuilder->create();
         $searchResults = $this->sliderRepository->getList($searchCriteria);
         $this->options = $this->converter->toOptionArray($searchResults->getItems(), Slider::ID, Slider::SLIDER_TITLE);
     }
     return $this->options;
 }
Example #5
0
 /**
  * Get metadata for sales rule form. It will be merged with form UI component declaration.
  *
  * @param Rule $rule
  * @return array
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function getMetadataValues(\Magento\SalesRule\Model\Rule $rule)
 {
     $customerGroups = $this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems();
     $applyOptions = [['label' => __('Percent of product price discount'), 'value' => Rule::BY_PERCENT_ACTION], ['label' => __('Fixed amount discount'), 'value' => Rule::BY_FIXED_ACTION], ['label' => __('Fixed amount discount for whole cart'), 'value' => Rule::CART_FIXED_ACTION], ['label' => __('Buy X get Y free (discount amount is Y)'), 'value' => Rule::BUY_X_GET_Y_ACTION]];
     $couponTypesOptions = [];
     $couponTypes = $this->salesRuleFactory->create()->getCouponTypes();
     foreach ($couponTypes as $key => $couponType) {
         $couponTypesOptions[] = ['label' => $couponType, 'value' => $key];
     }
     $labels = $rule->getStoreLabels();
     return ['rule_information' => ['children' => ['website_ids' => ['arguments' => ['data' => ['config' => ['options' => $this->store->getWebsiteValuesForForm()]]]], 'is_active' => ['arguments' => ['data' => ['config' => ['options' => [['label' => __('Active'), 'value' => '1'], ['label' => __('Inactive'), 'value' => '0']]]]]], 'customer_group_ids' => ['arguments' => ['data' => ['config' => ['options' => $this->objectConverter->toOptionArray($customerGroups, 'id', 'code')]]]], 'coupon_type' => ['arguments' => ['data' => ['config' => ['options' => $couponTypesOptions]]]], 'is_rss' => ['arguments' => ['data' => ['config' => ['options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]]]]]]], 'actions' => ['children' => ['simple_action' => ['arguments' => ['data' => ['config' => ['options' => $applyOptions]]]], 'discount_amount' => ['arguments' => ['data' => ['config' => ['value' => '0']]]], 'discount_qty' => ['arguments' => ['data' => ['config' => ['value' => '0']]]], 'apply_to_shipping' => ['arguments' => ['data' => ['config' => ['options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]]]]], 'stop_rules_processing' => ['arguments' => ['data' => ['config' => ['options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]]]]]]], 'labels' => ['children' => ['store_labels[0]' => ['arguments' => ['data' => ['config' => ['value' => isset($labels[0]) ? $labels[0] : '']]]]]]];
 }
Example #6
0
 public function testConvertDataToArray()
 {
     $object = new \stdClass();
     $object->a = [[1]];
     $mockFirst = $this->getMock('Magento\\Framework\\DataObject', ['getData']);
     $mockSecond = $this->getMock('Magento\\Framework\\DataObject', ['getData']);
     $mockFirst->expects($this->any())->method('getData')->will($this->returnValue(['id' => 1, 'o' => $mockSecond]));
     $mockSecond->expects($this->any())->method('getData')->will($this->returnValue(['id' => 2, 'o' => $mockFirst]));
     $data = ['object' => $mockFirst, 'stdClass' => $object, 'test' => 'test'];
     $result = ['object' => ['id' => 1, 'o' => ['id' => 2, 'o' => '*** CYCLE DETECTED ***']], 'stdClass' => ['a' => [[1]]], 'test' => 'test'];
     $this->assertEquals($result, $this->model->convertDataToArray($data));
 }
Example #7
0
 /**
  * Prepare form before rendering HTML
  *
  * @return $this
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 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', ['legend' => __('General Information')]);
     if ($model->getId()) {
         $fieldset->addField('rule_id', 'hidden', ['name' => 'rule_id']);
     }
     $fieldset->addField('product_ids', 'hidden', ['name' => 'product_ids']);
     $fieldset->addField('name', 'text', ['name' => 'name', 'label' => __('Rule Name'), 'title' => __('Rule Name'), 'required' => true]);
     $fieldset->addField('description', 'textarea', ['name' => 'description', 'label' => __('Description'), 'title' => __('Description'), 'style' => 'height: 100px;']);
     $fieldset->addField('is_active', 'select', ['label' => __('Status'), 'title' => __('Status'), 'name' => 'is_active', 'required' => true, 'options' => ['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', ['name' => 'website_ids[]', 'value' => $websiteId]);
         $model->setWebsiteIds($websiteId);
     } else {
         $field = $fieldset->addField('website_ids', 'multiselect', ['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->groupRepository->getList($this->_searchCriteriaBuilder->create())->getItems();
     $fieldset->addField('customer_group_ids', 'multiselect', ['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', ['name' => 'coupon_type', 'label' => __('Coupon'), 'required' => true, 'options' => $this->_salesRule->create()->getCouponTypes()]);
     $couponCodeFiled = $fieldset->addField('coupon_code', 'text', ['name' => 'coupon_code', 'label' => __('Coupon Code'), 'required' => true]);
     $autoGenerationCheckbox = $fieldset->addField('use_auto_generation', 'checkbox', ['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', ['name' => 'uses_per_coupon', 'label' => __('Uses per Coupon')]);
     $fieldset->addField('uses_per_customer', 'text', ['name' => 'uses_per_customer', 'label' => __('Uses per Customer'), 'note' => __('Usage limit enforced for logged in customers only.')]);
     $dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
     $fieldset->addField('from_date', 'date', ['name' => 'from_date', 'label' => __('From'), 'title' => __('From'), 'input_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT, 'date_format' => $dateFormat]);
     $fieldset->addField('to_date', 'date', ['name' => 'to_date', 'label' => __('To'), 'title' => __('To'), 'input_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT, 'date_format' => $dateFormat]);
     $fieldset->addField('sort_order', 'text', ['name' => 'sort_order', 'label' => __('Priority')]);
     $fieldset->addField('is_rss', 'select', ['label' => __('Public In RSS Feed'), 'title' => __('Public In RSS Feed'), 'name' => 'is_rss', 'options' => ['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\\SalesRule\\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', ['form' => $form]);
     return parent::_prepareForm();
 }
Example #8
0
 /**
  * @return Form
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 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', ['legend' => __('General Information')]);
     if ($model->getId()) {
         $fieldset->addField('rule_id', 'hidden', ['name' => 'rule_id']);
     }
     $fieldset->addField('name', 'text', ['name' => 'name', 'label' => __('Rule Name'), 'title' => __('Rule Name'), 'required' => true]);
     $fieldset->addField('description', 'textarea', ['name' => 'description', 'label' => __('Description'), 'title' => __('Description'), 'style' => 'height: 100px;']);
     $fieldset->addField('is_active', 'select', ['label' => __('Status'), 'title' => __('Status'), 'name' => 'is_active', 'required' => true, 'options' => ['1' => __('Active'), '0' => __('Inactive')]]);
     if ($this->_storeManager->isSingleStoreMode()) {
         $websiteId = $this->_storeManager->getStore(true)->getWebsiteId();
         $fieldset->addField('website_ids', 'hidden', ['name' => 'website_ids[]', 'value' => $websiteId]);
         $model->setWebsiteIds($websiteId);
     } else {
         $field = $fieldset->addField('website_ids', 'multiselect', ['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);
     }
     $customerGroups = $this->_groupRepository->getList($this->_searchCriteriaBuilder->create())->getItems();
     $fieldset->addField('customer_group_ids', 'multiselect', ['name' => 'customer_group_ids[]', 'label' => __('Customer Groups'), 'title' => __('Customer Groups'), 'required' => true, 'values' => $this->_objectConverter->toOptionArray($customerGroups, 'id', 'code')]);
     $dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
     $fieldset->addField('from_date', 'date', ['name' => 'from_date', 'label' => __('From'), 'title' => __('From'), 'input_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT, 'date_format' => $dateFormat]);
     $fieldset->addField('to_date', 'date', ['name' => 'to_date', 'label' => __('To'), 'title' => __('To'), 'input_format' => \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT, 'date_format' => $dateFormat]);
     $fieldset->addField('sort_order', 'text', ['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', ['form' => $form]);
     return parent::_prepareForm();
 }
 /**
  * @return array
  */
 public function toOptionArray()
 {
     $customerGroups = $this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems();
     return $this->objectConverter->toOptionArray($customerGroups, 'id', 'code');
 }
 /**
  * @return void
  */
 protected function initMeta()
 {
     $customerGroups = $this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems();
     $applyOptions = [['label' => __('Apply as percentage of original'), 'value' => 'by_percent'], ['label' => __('Apply as fixed amount'), 'value' => 'by_fixed'], ['label' => __('Adjust final price to this percentage'), 'value' => 'to_percent'], ['label' => __('Adjust final price to discount value'), 'value' => 'to_fixed']];
     $this->meta = ['rule_information' => ['fields' => ['website_ids' => ['options' => $this->store->getWebsiteValuesForForm()], 'is_active' => ['options' => [['label' => __('Active'), 'value' => '1'], ['label' => __('Inactive'), 'value' => '0']]], 'customer_group_ids' => ['options' => $this->objectConverter->toOptionArray($customerGroups, 'id', 'code')]]], 'actions' => ['fields' => ['simple_action' => ['options' => $applyOptions], 'stop_rules_processing' => ['options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]]]]];
 }