Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function init($context)
 {
     foreach ($this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems() as $group) {
         $this->customerGroups[$group->getId()] = true;
     }
     return parent::init($context);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function isAssignedToObjects()
 {
     $searchCriteria = $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField(CustomerGroup::TAX_CLASS_ID)->setValue($this->getId())->create()])->create();
     $result = $this->customerGroupRepository->getList($searchCriteria);
     $items = $result->getItems();
     return !empty($items);
 }
 /**
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute(Observer $observer)
 {
     if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && $this->taxHelper->isCatalogPriceDisplayAffectedByTax()) {
         /** @var \Magento\Customer\Model\Data\Customer $customer */
         $customer = $observer->getData('customer');
         $customerGroupId = $customer->getGroupId();
         $customerGroup = $this->groupRepository->getById($customerGroupId);
         $customerTaxClassId = $customerGroup->getTaxClassId();
         $this->customerSession->setCustomerTaxClassId($customerTaxClassId);
         /** @var \Magento\Customer\Api\Data\AddressInterface[] $addresses */
         $addresses = $customer->getAddresses();
         if (isset($addresses)) {
             $defaultShippingFound = false;
             $defaultBillingFound = false;
             foreach ($addresses as $address) {
                 if ($address->isDefaultBilling()) {
                     $defaultBillingFound = true;
                     $this->customerSession->setDefaultTaxBillingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegion()->getRegionId() : null, 'postcode' => $address->getPostcode()]);
                 }
                 if ($address->isDefaultShipping()) {
                     $defaultShippingFound = true;
                     $this->customerSession->setDefaultTaxShippingAddress(['country_id' => $address->getCountryId(), 'region_id' => $address->getRegion() ? $address->getRegion()->getRegionId() : null, 'postcode' => $address->getPostcode()]);
                 }
                 if ($defaultShippingFound && $defaultBillingFound) {
                     break;
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Prepare Data Source
  *
  * @param array $dataSource
  * @return void
  */
 public function prepareDataSource(array &$dataSource)
 {
     if (isset($dataSource['data']['items'])) {
         foreach ($dataSource['data']['items'] as &$item) {
             $item[$this->getData('name')] = $this->groupRepository->getById($item[$this->getData('name')])->getCode();
         }
     }
 }
Ejemplo n.º 5
0
 protected function processInit($groupId)
 {
     $searchResult = $this->getMock('Magento\\Customer\\Api\\Data\\GroupSearchResultsInterface', [], [], '', false);
     $this->groupRepositoryInterface->expects($this->once())->method('getList')->willReturn($searchResult);
     $group = $this->getMock('Magento\\Customer\\Model\\Data\\Group', [], [], '', false);
     $group->expects($this->once())->method('getId')->willReturn($groupId);
     $searchResult->expects($this->once())->method('getItems')->willReturn([$group]);
     return $this->tierPrice->init(null);
 }
Ejemplo n.º 6
0
 /**
  * @covers \Magento\Sales\Ui\Component\DataProvider\Document::getCustomAttribute
  */
 public function testGetCustomerGroupAttribute()
 {
     $this->document->setData('customer_group_id', 1);
     $group = $this->getMockForAbstractClass(GroupInterface::class);
     $this->groupRepository->expects(static::once())->method('getById')->willReturn($group);
     $group->expects(static::once())->method('getCode')->willReturn('General');
     $attribute = $this->document->getCustomAttribute('customer_group_id');
     static::assertEquals('General', $attribute->getValue());
 }
Ejemplo n.º 7
0
 /**
  * @return \Magento\Customer\Api\Data\GroupInterface
  */
 protected function loadSource()
 {
     if ($this->isBackendOrder()) {
         // For backend orders
         $customerGroupId = $this->objectManager->get('Magento\\Backend\\Model\\Session\\Quote')->getQuote()->getCustomerGroupId();
     } else {
         $customerGroupId = $this->objectManager->get('Magento\\Customer\\Model\\Session')->getCustomerGroupId();
     }
     return $this->groupRepository->getById($customerGroupId);
 }
Ejemplo n.º 8
0
 /**
  * Retrieve the header text, either editing an existing group or creating a new one.
  *
  * @return \Magento\Framework\Phrase
  */
 public function getHeaderText()
 {
     $groupId = $this->coreRegistry->registry(RegistryConstants::CURRENT_GROUP_ID);
     if ($groupId === null) {
         return __('New Customer Group');
     } else {
         $group = $this->groupRepository->getById($groupId);
         return __('Edit Customer Group "%1"', $this->escapeHtml($group->getCode()));
     }
 }
Ejemplo n.º 9
0
 /**
  * Update customer group value
  * Method set group code instead id value
  * @return void
  */
 private function setCustomerGroupValue()
 {
     $value = $this->getData(self::$customerGroupAttributeCode);
     try {
         $group = $this->groupRepository->getById($value);
         $this->setCustomAttribute(self::$customerGroupAttributeCode, $group->getCode());
     } catch (NoSuchEntityException $e) {
         $this->setCustomAttribute(self::$customerGroupAttributeCode, 'N/A');
     }
 }
Ejemplo n.º 10
0
 public function testGetDefaultRateRequest()
 {
     $customerDataSet = $this->customerRepository->getById(self::FIXTURE_CUSTOMER_ID);
     $address = $this->addressRepository->getById(self::FIXTURE_ADDRESS_ID);
     $rateRequest = $this->_model->getRateRequest(null, null, null, null, $customerDataSet->getId());
     $this->assertNotNull($rateRequest);
     $this->assertEquals($address->getCountryId(), $rateRequest->getCountryId());
     $this->assertEquals($address->getRegion()->getRegionId(), $rateRequest->getRegionId());
     $this->assertEquals($address->getPostcode(), $rateRequest->getPostcode());
     $customerTaxClassId = $this->groupRepository->getById($customerDataSet->getGroupId())->getTaxClassId();
     $this->assertEquals($customerTaxClassId, $rateRequest->getCustomerClassId());
 }
Ejemplo n.º 11
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] : '']]]]]]];
 }
 public function testPrepareDataSource()
 {
     $itemName = 'itemName';
     $oldItemValue = 'oldItemValue';
     $newItemValue = 'newItemValue';
     $dataSource = ['data' => ['items' => [[$itemName => $oldItemValue]]]];
     $group = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\GroupInterface');
     $group->expects($this->once())->method('getCode')->willReturn($newItemValue);
     $this->groupRepository->expects($this->once())->method('getById')->with($oldItemValue)->willReturn($group);
     $this->model->setData('name', $itemName);
     $dataSource = $this->model->prepareDataSource($dataSource);
     $this->assertEquals($newItemValue, $dataSource['data']['items'][0][$itemName]);
 }
Ejemplo n.º 13
0
 /**
  * Return array of customer groups
  *
  * @return array
  */
 public function toOptionArray()
 {
     if (!$this->moduleManager->isEnabled('Magento_Customer')) {
         return [];
     }
     $customerGroups = [['label' => __('ALL GROUPS'), 'value' => GroupInterface::CUST_GROUP_ALL]];
     /** @var GroupInterface[] $groups */
     $groups = $this->groupRepository->getList($this->searchCriteriaBuilder->create());
     foreach ($groups->getItems() as $group) {
         $customerGroups[] = ['label' => $group->getCode(), 'value' => $group->getId()];
     }
     return $customerGroups;
 }
Ejemplo n.º 14
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer_group.php
  */
 public function testDeleteButtonExistInCustomGroup()
 {
     $builder = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\FilterBuilder');
     /** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteria */
     $searchCriteria = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\SearchCriteriaBuilder')->addFilters([$builder->setField('code')->setValue('custom_group')->create()])->create();
     $customerGroup = $this->groupRepository->getList($searchCriteria)->getItems()[0];
     $this->getRequest()->setParam('id', $customerGroup->getId());
     $this->registry->register(RegistryConstants::CURRENT_GROUP_ID, $customerGroup->getId());
     /** @var $block Edit */
     $block = $this->layout->createBlock('Magento\\Customer\\Block\\Adminhtml\\Group\\Edit', 'block');
     $buttonsHtml = $block->getButtonsHtml();
     $this->assertContains('delete', $buttonsHtml);
 }
Ejemplo n.º 15
0
 public function testToOptionArray()
 {
     $customerGroups = [['label' => __('ALL GROUPS'), 'value' => 32000], ['label' => __('NOT LOGGED IN'), 'value' => 0]];
     $this->moduleManagerMock->expects($this->any())->method('isEnabled')->willReturn(true);
     $this->searchCriteriaBuilderMock->expects($this->any())->method('create')->willReturn($this->searchCriteriaMock);
     $this->groupRepositoryMock->expects($this->any())->method('getList')->with($this->searchCriteriaMock)->willReturn($this->searchResultMock);
     $this->groupRepositoryMock->expects($this->any())->method('getList')->with($this->searchCriteriaMock)->willReturn($this->searchResultMock);
     $groupTest = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\GroupInterface')->disableOriginalConstructor()->setMethods(['getCode', 'getId'])->getMockForAbstractClass();
     $groupTest->expects($this->any())->method('getCode')->willReturn(__('NOT LOGGED IN'));
     $groupTest->expects($this->any())->method('getId')->willReturn(0);
     $groups = [$groupTest];
     $this->searchResultMock->expects($this->any())->method('getItems')->willReturn($groups);
     $this->assertEquals($customerGroups, $this->model->toOptionArray());
 }
Ejemplo n.º 16
0
 /**
  * Retrieve allowed customer groups
  *
  * @param int $groupId return name by customer group id
  * @return array|string
  */
 protected function _getCustomerGroups($groupId = null)
 {
     if ($this->_customerGroups === null) {
         $this->_customerGroups = [];
         foreach ($this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems() as $item) {
             $this->_customerGroups[$item->getId()] = $item->getCode();
         }
         $notLoggedInGroup = $this->groupManagement->getNotLoggedInGroup();
         $this->_customerGroups[$notLoggedInGroup->getId()] = $notLoggedInGroup->getCode();
     }
     if ($groupId !== null) {
         return isset($this->_customerGroups[$groupId]) ? $this->_customerGroups[$groupId] : null;
     }
     return $this->_customerGroups;
 }
Ejemplo n.º 17
0
 /**
  * Prepare Data Source
  *
  * @param array $dataSource
  * @return array
  */
 public function prepareDataSource(array $dataSource)
 {
     if (isset($dataSource['data']['items'])) {
         foreach ($dataSource['data']['items'] as &$item) {
             try {
                 $item[$this->getData('name')] = $this->groupRepository->getById($item[$this->getData('name')])->getCode();
             } catch (NoSuchEntityException $exception) {
                 $item[$this->getData('name')] = __('Group was removed');
             } catch (\Exception $exception) {
                 $item[$this->getData('name')] = '';
             }
         }
     }
     return $dataSource;
 }
Ejemplo n.º 18
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer_group.php
  */
 public function testGetFormExistInCustomGroup()
 {
     $builder = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\FilterBuilder');
     /** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteria */
     $searchCriteria = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\SearchCriteriaBuilder')->addFilters([$builder->setField('code')->setValue('custom_group')->create()]);
     /** @var GroupInterface $customerGroup */
     $customerGroup = $this->groupRepository->getList($searchCriteria->create())->getItems()[0];
     $this->registry->register(RegistryConstants::CURRENT_GROUP_ID, $customerGroup->getId());
     /** @var $block Form */
     $block = $this->layout->createBlock('Magento\\Customer\\Block\\Adminhtml\\Group\\Edit\\Form', 'block');
     $form = $block->getForm();
     $this->assertEquals('edit_form', $form->getId());
     $this->assertEquals('post', $form->getMethod());
     $baseFieldSet = $form->getElement('base_fieldset');
     $this->assertNotNull($baseFieldSet);
     $groupCodeElement = $form->getElement('customer_group_code');
     $this->assertNotNull($groupCodeElement);
     $taxClassIdElement = $form->getElement('tax_class_id');
     $this->assertNotNull($taxClassIdElement);
     $idElement = $form->getElement('id');
     $this->assertNotNull($idElement);
     $this->assertEquals($customerGroup->getId(), $idElement->getValue());
     $this->assertEquals($customerGroup->getTaxClassId(), $taxClassIdElement->getValue());
     /** @var \Magento\Tax\Model\TaxClass\Source\Customer $taxClassCustomer */
     $taxClassCustomer = Bootstrap::getObjectManager()->get('Magento\\Tax\\Model\\TaxClass\\Source\\Customer');
     $this->assertEquals($taxClassCustomer->toOptionArray(false), $taxClassIdElement->getData('values'));
     $this->assertEquals($customerGroup->getCode(), $groupCodeElement->getValue());
 }
Ejemplo n.º 19
0
 public function testSetAccountData()
 {
     $taxClassId = 1;
     $attributes = [['email', '*****@*****.**'], ['group_id', 1]];
     $attributeMocks = [];
     foreach ($attributes as $attribute) {
         $attributeMock = $this->getMock('Magento\\Customer\\Api\\Data\\AttributeMetadataInterface', [], [], '', false);
         $attributeMock->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attribute[0]));
         $attributeMocks[] = $attributeMock;
     }
     $customerGroupMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\GroupInterface', [], '', false, true, true, ['getTaxClassId']);
     $customerGroupMock->expects($this->once())->method('getTaxClassId')->will($this->returnValue($taxClassId));
     $customerFormMock = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', [], [], '', false);
     $customerFormMock->expects($this->any())->method('getAttributes')->will($this->returnValue($attributeMocks));
     $customerFormMock->expects($this->any())->method('extractData')->will($this->returnValue([]));
     $customerFormMock->expects($this->any())->method('restoreData')->will($this->returnValue([]));
     $customerFormMock->expects($this->any())->method('prepareRequest')->will($this->returnValue($this->getMock('Magento\\Framework\\App\\RequestInterface')));
     $customerMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $this->customerMapper->expects($this->atLeastOnce())->method('toFlatArray')->willReturn(['email' => '*****@*****.**', 'group_id' => 1, 'gender' => 1]);
     $quoteMock = $this->getMock('Magento\\Quote\\Model\\Quote', [], [], '', false);
     $quoteMock->expects($this->any())->method('getCustomer')->will($this->returnValue($customerMock));
     $quoteMock->expects($this->once())->method('addData')->with(['customer_email' => $attributes[0][1], 'customer_group_id' => $attributes[1][1], 'customer_tax_class_id' => $taxClassId]);
     $this->dataObjectHelper->expects($this->once())->method('populateWithArray')->with($customerMock, ['email' => '*****@*****.**', 'group_id' => 1, 'gender' => 1], '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerFormMock));
     $this->sessionQuoteMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock));
     $this->customerFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerMock));
     $this->groupRepositoryMock->expects($this->once())->method('getById')->will($this->returnValue($customerGroupMock));
     $this->adminOrderCreate->setAccountData([]);
 }
Ejemplo n.º 20
0
 /**
  * {@inheritdoc}
  */
 public function getLoggedInGroups()
 {
     $notLoggedInFilter[] = $this->filterBuilder->setField(GroupInterface::ID)->setConditionType('neq')->setValue(self::NOT_LOGGED_IN_ID)->create();
     $groupAll[] = $this->filterBuilder->setField(GroupInterface::ID)->setConditionType('neq')->setValue(self::CUST_GROUP_ALL)->create();
     $searchCriteria = $this->searchCriteriaBuilder->addFilters($notLoggedInFilter)->addFilters($groupAll)->create();
     return $this->groupRepository->getList($searchCriteria)->getItems();
 }
Ejemplo n.º 21
0
 /**
  * Get Customer Group By Id
  *
  * @param int $customerGroupId
  * @param null $allGroups
  * @return string
  */
 protected function _getCustomerGroupById($customerGroupId, $allGroups = null)
 {
     if ($allGroups) {
         return ImportAdvancedPricing::VALUE_ALL_GROUPS;
     } else {
         return $this->_groupRepository->getById($customerGroupId)->getCode();
     }
 }
Ejemplo n.º 22
0
 public function testInitAddToCustomerGroups()
 {
     $searchCriteria = $this->getMock('Magento\\Framework\\Api\\SearchCriteria', [], [], '', false);
     $this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria);
     $groupSearchResult = $this->getMockForAbstractClass('\\Magento\\Customer\\Api\\Data\\GroupSearchResultsInterface', [], '', false);
     $this->groupRepository->expects($this->once())->method('getList')->with($searchCriteria)->willReturn($groupSearchResult);
     $groupTest = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\GroupInterface')->disableOriginalConstructor()->setMethods(['getCode', 'getId'])->getMockForAbstractClass();
     $expectedCode = 'code';
     $expectedId = 'id';
     $expectedCustomerGroups = [$expectedCode => $expectedId];
     $groupTest->expects($this->once())->method('getCode')->willReturn($expectedCode);
     $groupTest->expects($this->once())->method('getId')->willReturn($expectedId);
     $groups = [$groupTest];
     $groupSearchResult->expects($this->once())->method('getItems')->willReturn($groups);
     $this->groupPrice->init();
     $this->assertEquals($expectedCustomerGroups, $this->getPropertyValue($this->groupPrice, 'customerGroups'));
 }
 /**
  * Load customer group collection data from service
  *
  * @param bool $printQuery
  * @param bool $logQuery
  * @return $this
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function loadData($printQuery = false, $logQuery = false)
 {
     if (!$this->isLoaded()) {
         $searchCriteria = $this->getSearchCriteria();
         $searchResults = $this->groupRepository->getList($searchCriteria);
         $this->_totalRecords = $searchResults->getTotalCount();
         /** @var GroupInterface[] $groups */
         $groups = $searchResults->getItems();
         foreach ($groups as $group) {
             $groupItem = new \Magento\Framework\DataObject();
             $groupItem->addData($this->simpleDataObjectConverter->toFlatArray($group, '\\Magento\\Customer\\Api\\Data\\GroupInterface'));
             $this->_addItem($groupItem);
         }
         $this->_setIsLoaded();
     }
     return $this;
 }
Ejemplo n.º 24
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\\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', ['form' => $form]);
     return parent::_prepareForm();
 }
Ejemplo n.º 25
0
 /**
  * Retrieve customer group by id
  *
  * @param int $groupId
  * @return \Magento\Customer\Api\Data\GroupInterface|null
  */
 private function getGroup($groupId)
 {
     try {
         $group = $this->groupRepository->getById($groupId);
     } catch (NoSuchEntityException $e) {
         $group = null;
     }
     return $group;
 }
 private function _loadCustomerGroups()
 {
     $crit = $this->_builderSearchCriteria->create();
     $crit->setSortOrders(null);
     $all = $this->_repoCustomerGroup->getList($crit);
     /** @var \Magento\Customer\Model\Data\Group $item */
     foreach ($all->getItems() as $item) {
         $this->_custGroups[] = $item->getId();
     }
 }
Ejemplo n.º 27
0
 /**
  * Find the group with a given code.
  *
  * @param string $code
  * @return int
  */
 protected function findGroupIdWithCode($code)
 {
     /** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchBuilder */
     $searchBuilder = $this->_objectManager->create('Magento\\Framework\\Api\\SearchCriteriaBuilder');
     foreach ($this->groupRepository->getList($searchBuilder->create())->getItems() as $group) {
         if ($group->getCode() === $code) {
             return $group->getId();
         }
     }
     return -1;
 }
Ejemplo n.º 28
0
 /**
  * @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute
  */
 public function testGetWebsiteAttribute()
 {
     $websiteId = 1;
     $this->document->setData('website_id', $websiteId);
     $this->groupRepository->expects(static::never())->method('getById');
     $this->customerMetadata->expects(static::never())->method('getAttributeMetadata');
     $website = $this->getMockForAbstractClass(WebsiteInterface::class);
     $this->storeManager->expects(static::once())->method('getWebsites')->willReturn([$websiteId => $website]);
     $website->expects(static::once())->method('getName')->willReturn('Main Website');
     $attribute = $this->document->getCustomAttribute('website_id');
     static::assertEquals('Main Website', $attribute->getValue());
 }
Ejemplo n.º 29
0
 public function testExecuteWithTaxClassAndException()
 {
     $taxClass = '3';
     $groupId = 0;
     $code = 'NOT LOGGED IN';
     $this->request->expects($this->exactly(3))->method('getParam')->withConsecutive(['tax_class'], ['id'], ['code'])->willReturnOnConsecutiveCalls($taxClass, $groupId, null);
     $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect);
     $this->groupRepositoryMock->expects($this->once())->method('getById')->with($groupId)->willReturn($this->group);
     $this->group->expects($this->once())->method('getCode')->willReturn($code);
     $this->group->expects($this->once())->method('setCode')->with($code);
     $this->group->expects($this->once())->method('setTaxClassId')->with($taxClass);
     $this->groupRepositoryMock->expects($this->once())->method('save')->with($this->group);
     $this->messageManager->expects($this->once())->method('addSuccess')->with(__('You saved the customer group.'));
     $exception = new \Exception('Exception');
     $this->resultRedirect->expects($this->at(0))->method('setPath')->with('customer/group')->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addError')->with('Exception');
     $this->dataObjectProcessorMock->expects($this->once())->method('buildOutputDataArray')->with($this->group, '\\Magento\\Customer\\Api\\Data\\GroupInterface')->willReturn(['code' => $code]);
     $this->session->expects($this->once())->method('setCustomerGroupData')->with(['customer_group_code' => $code]);
     $this->resultRedirect->expects($this->at(1))->method('setPath')->with('customer/group/edit', ['id' => $groupId]);
     $this->assertSame($this->resultRedirect, $this->controller->execute());
 }
Ejemplo n.º 30
0
 /**
  * Prepare form for render
  *
  * @return void
  */
 protected function _prepareLayout()
 {
     parent::_prepareLayout();
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create();
     $groupId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_GROUP_ID);
     /** @var \Magento\Customer\Api\Data\GroupInterface $customerGroup */
     if ($groupId === null) {
         $customerGroup = $this->groupDataFactory->create();
         $defaultCustomerTaxClass = $this->_taxHelper->getDefaultCustomerTaxClass();
     } else {
         $customerGroup = $this->_groupRepository->getById($groupId);
         $defaultCustomerTaxClass = $customerGroup->getTaxClassId();
     }
     $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Group Information')]);
     $validateClass = sprintf('required-entry validate-length maximum-length-%d', \Magento\Customer\Model\GroupManagement::GROUP_CODE_MAX_LENGTH);
     $name = $fieldset->addField('customer_group_code', 'text', ['name' => 'code', 'label' => __('Group Name'), 'title' => __('Group Name'), 'note' => __('Maximum length must be less then %1 symbols', \Magento\Customer\Model\GroupManagement::GROUP_CODE_MAX_LENGTH), 'class' => $validateClass, 'required' => true]);
     if ($customerGroup->getId() == 0 && $customerGroup->getCode()) {
         $name->setDisabled(true);
     }
     $fieldset->addField('tax_class_id', 'select', ['name' => 'tax_class', 'label' => __('Tax Class'), 'title' => __('Tax Class'), 'class' => 'required-entry', 'required' => true, 'values' => $this->_taxCustomer->toOptionArray()]);
     if ($customerGroup->getId() !== null) {
         // If edit add id
         $form->addField('id', 'hidden', ['name' => 'id', 'value' => $customerGroup->getId()]);
     }
     if ($this->_backendSession->getCustomerGroupData()) {
         $form->addValues($this->_backendSession->getCustomerGroupData());
         $this->_backendSession->setCustomerGroupData(null);
     } else {
         // TODO: need to figure out how the DATA can work with forms
         $form->addValues(['id' => $customerGroup->getId(), 'customer_group_code' => $customerGroup->getCode(), 'tax_class_id' => $defaultCustomerTaxClass]);
     }
     $form->setUseContainer(true);
     $form->setId('edit_form');
     $form->setAction($this->getUrl('customer/*/save'));
     $form->setMethod('post');
     $this->setForm($form);
 }