Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function isAssignedToObjects()
 {
     $searchCriteria = $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField('tax_class_id')->setValue($this->getId())->create()])->create();
     $result = $this->groupService->searchGroups($searchCriteria);
     $items = $result->getItems();
     return !empty($items);
 }
Esempio n. 2
0
 /**
  * @param string $formCode
  * @param RequestInterface $request
  * @return \Magento\Customer\Service\V1\Data\Customer
  */
 public function extract($formCode, RequestInterface $request)
 {
     $customerForm = $this->formFactory->create('customer', $formCode);
     $allowedAttributes = $customerForm->getAllowedAttributes();
     $isGroupIdEmpty = true;
     $customerData = array();
     foreach ($allowedAttributes as $attribute) {
         // confirmation in request param is the repeated password, not a confirmation code.
         if ($attribute === 'confirmation') {
             continue;
         }
         $attributeCode = $attribute->getAttributeCode();
         if ($attributeCode == 'group_id') {
             $isGroupIdEmpty = false;
         }
         $customerData[$attributeCode] = $request->getParam($attributeCode);
     }
     $this->customerBuilder->populateWithArray($customerData);
     $store = $this->storeManager->getStore();
     if ($isGroupIdEmpty) {
         $this->customerBuilder->setGroupId($this->groupService->getDefaultGroup($store->getId())->getId());
     }
     $this->customerBuilder->setWebsiteId($store->getWebsiteId());
     $this->customerBuilder->setStoreId($store->getId());
     return $this->customerBuilder->create();
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function set($productSku, \Magento\Catalog\Service\V1\Data\Product\GroupPrice $price)
 {
     $customerGroup = $this->customerGroupService->getGroup($price->getCustomerGroupId());
     $product = $this->productRepository->get($productSku, true);
     $groupPrices = $product->getData('group_price');
     $websiteId = 0;
     if ($this->config->getValue('catalog/price/scope', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE) != 0) {
         $websiteId = $this->storeManager->getWebsite()->getId();
     }
     $found = false;
     foreach ($groupPrices as &$currentPrice) {
         if (intval($currentPrice['cust_group']) === $price->getCustomerGroupId() && intval($currentPrice['website_id']) === intval($websiteId)) {
             $currentPrice['price'] = $price->getValue();
             $found = true;
             break;
         }
     }
     if (!$found) {
         $groupPrices[] = array('cust_group' => $customerGroup->getId(), 'website_id' => $websiteId, 'price' => $price->getValue());
     }
     $product->setData('group_price', $groupPrices);
     $errors = $product->validate();
     if (is_array($errors) && count($errors)) {
         $errorAttributeCodes = implode(', ', array_keys($errors));
         throw new InputException(sprintf('Values of following attributes are invalid: %s', $errorAttributeCodes));
     }
     try {
         $product->save();
     } catch (\Exception $e) {
         throw new CouldNotSaveException('Could not save group price');
     }
     return true;
 }
Esempio n. 4
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;
 }
Esempio n. 5
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;
 }
Esempio n. 6
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;
 }
 /**
  * @param $testGroup
  * @param $storeId
  */
 private function assertDefaultGroupMatches($testGroup, $storeId)
 {
     $group = $this->_groupService->getDefaultGroup($storeId);
     $this->assertEquals($testGroup['id'], $group->getId());
     $this->assertEquals($testGroup['code'], $group->getCode());
     $this->assertEquals($testGroup['tax_class_id'], $group->getTaxClassId());
 }
Esempio n. 8
0
 public function testSetAccountData()
 {
     $taxClassId = 1;
     $attributes = array(array('email', '*****@*****.**'), array('group_id', 1));
     $attributeMocks = array();
     foreach ($attributes as $attribute) {
         $attributeMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Eav\\AttributeMetadata', array(), array(), '', false);
         $attributeMock->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attribute[0]));
         $attributeMocks[] = $attributeMock;
     }
     $customerGroupMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\CustomerGroup', array(), array(), '', false);
     $customerGroupMock->expects($this->once())->method('getTaxClassId')->will($this->returnValue($taxClassId));
     $customerFormMock = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', array(), array(), '', false);
     $customerFormMock->expects($this->any())->method('getAttributes')->will($this->returnValue($attributeMocks));
     $customerFormMock->expects($this->any())->method('extractData')->will($this->returnValue(array()));
     $customerFormMock->expects($this->any())->method('restoreData')->will($this->returnValue(array()));
     $customerFormMock->expects($this->any())->method('prepareRequest')->will($this->returnValue($this->getMock('Magento\\Framework\\App\\RequestInterface')));
     $customerMock = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Customer', array(), array(), '', false);
     $customerMock->expects($this->any())->method('__toArray')->will($this->returnValue(array('email' => '*****@*****.**', 'group_id' => 1)));
     $quoteMock = $this->getMock('Magento\\Sales\\Model\\Quote', array(), array(), '', false);
     $quoteMock->expects($this->any())->method('getCustomerData')->will($this->returnValue($customerMock));
     $quoteMock->expects($this->once())->method('addData')->with(array('customer_email' => $attributes[0][1], 'customer_group_id' => $attributes[1][1], 'customer_tax_class_id' => $taxClassId));
     $this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerFormMock));
     $this->sessionQuoteMock->expects($this->any())->method('getQuote')->will($this->returnValue($quoteMock));
     $this->customerBuilderMock->expects($this->any())->method('populateWithArray')->will($this->returnSelf());
     $this->customerBuilderMock->expects($this->any())->method('create')->will($this->returnValue($customerMock));
     $this->customerBuilderMock->expects($this->any())->method('mergeDataObjectWithArray')->will($this->returnArgument(0));
     $this->customerGroupServiceMock->expects($this->once())->method('getGroup')->will($this->returnValue($customerGroupMock));
     $this->adminOrderCreate->setAccountData(array());
 }
 /**
  * Load customer group collection data from service
  *
  * @param bool $printQuery
  * @param bool $logQuery
  * @return $this
  */
 public function loadData($printQuery = false, $logQuery = false)
 {
     if (!$this->isLoaded()) {
         $searchCriteria = $this->getSearchCriteria();
         $searchResults = $this->groupService->searchGroups($searchCriteria);
         $this->_totalRecords = $searchResults->getTotalCount();
         /** @var CustomerGroup[] $groups */
         $groups = $searchResults->getItems();
         foreach ($groups as $group) {
             $groupItem = new \Magento\Framework\Object();
             $groupItem->addData(\Magento\Framework\Service\DataObjectConverter::toFlatArray($group));
             $this->_addItem($groupItem);
         }
         $this->_setIsLoaded();
     }
     return $this;
 }
Esempio n. 10
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();
 }
Esempio n. 11
0
 /**
  * @param int $groupId
  * @return \Magento\Customer\Service\V1\Data\CustomerGroup|null
  */
 private function getGroup($groupId)
 {
     try {
         $group = $this->_groupService->getGroup($groupId);
     } catch (NoSuchEntityException $e) {
         $group = null;
     }
     return $group;
 }
Esempio n. 12
0
 /**
  * Fetch default customer tax classId
  *
  * @param null|Store|string|int $store
  * @return int
  */
 private function _getDefaultCustomerTaxClassId($store = null)
 {
     if (is_null($this->_defaultCustomerTaxClassId)) {
         //Not catching the exception here since default group is expected
         $defaultCustomerGroup = $this->_groupService->getDefaultGroup($store);
         $this->_defaultCustomerTaxClassId = $defaultCustomerGroup->getTaxClassId();
     }
     return $this->_defaultCustomerTaxClassId;
 }
Esempio n. 13
0
 /**
  * Return name of the customer group.
  *
  * @return string
  */
 public function getCustomerGroupName()
 {
     if ($this->getOrder()) {
         $customerGroupId = $this->getOrder()->getCustomerGroupId();
         if (!is_null($customerGroupId)) {
             return $this->_groupService->getGroup($customerGroupId)->getCode();
         }
     }
     return '';
 }
Esempio n. 14
0
 /**
  * Retrieve the header text, either editing an existing group or creating a new one.
  *
  * @return string
  */
 public function getHeaderText()
 {
     $groupId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_GROUP_ID);
     if (is_null($groupId)) {
         return __('New Customer Group');
     } else {
         $group = $this->_groupService->getGroup($groupId);
         return __('Edit Customer Group "%1"', $this->escapeHtml($group->getCode()));
     }
 }
Esempio n. 15
0
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function set($productSku, $customerGroupId, \Magento\Catalog\Service\V1\Data\Product\TierPrice $price)
 {
     $product = $this->productRepository->get($productSku, true);
     $customerGroup = $this->customerGroupService->getGroup($customerGroupId);
     $tierPrices = $product->getData('tier_price');
     $websiteId = 0;
     if ($this->config->getValue('catalog/price/scope', \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITE) != 0) {
         $websiteId = $this->storeManager->getWebsite()->getId();
     }
     $found = false;
     foreach ($tierPrices as &$item) {
         if ('all' == $customerGroupId) {
             $isGroupValid = $item['all_groups'] == 1;
         } else {
             $isGroupValid = $item['cust_group'] == $customerGroupId;
         }
         if ($isGroupValid && $item['website_id'] == $websiteId && $item['price_qty'] == $price->getQty()) {
             $item['price'] = $price->getValue();
             $found = true;
             break;
         }
     }
     if (!$found) {
         $mappedCustomerGroupId = 'all' == $customerGroupId ? \Magento\Customer\Service\V1\CustomerGroupServiceInterface::CUST_GROUP_ALL : $customerGroup->getId();
         $tierPrices[] = array('cust_group' => $mappedCustomerGroupId, 'price' => $price->getValue(), 'website_price' => $price->getValue(), 'website_id' => $websiteId, 'price_qty' => $price->getQty());
     }
     $product->setData('tier_price', $tierPrices);
     $errors = $product->validate();
     if (is_array($errors) && count($errors)) {
         $errorAttributeCodes = implode(', ', array_keys($errors));
         throw new InputException(sprintf('Values of following attributes are invalid: %s', $errorAttributeCodes));
     }
     try {
         $product->save();
     } catch (\Exception $e) {
         throw new CouldNotSaveException('Could not save group price');
     }
     return true;
 }
Esempio n. 16
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\Service\V1\Data\CustomerGroup $customerGroup */
     if (is_null($groupId)) {
         $customerGroup = $this->_groupBuilder->create();
     } else {
         $customerGroup = $this->_groupService->getGroup($groupId);
     }
     $fieldset = $form->addFieldset('base_fieldset', array('legend' => __('Group Information')));
     $validateClass = sprintf('required-entry validate-length maximum-length-%d', \Magento\Customer\Service\V1\CustomerGroupServiceInterface::GROUP_CODE_MAX_LENGTH);
     $name = $fieldset->addField('customer_group_code', 'text', array('name' => 'code', 'label' => __('Group Name'), 'title' => __('Group Name'), 'note' => __('Maximum length must be less then %1 symbols', \Magento\Customer\Service\V1\CustomerGroupServiceInterface::GROUP_CODE_MAX_LENGTH), 'class' => $validateClass, 'required' => true));
     if ($customerGroup->getId() == 0 && $customerGroup->getCode()) {
         $name->setDisabled(true);
     }
     $fieldset->addField('tax_class_id', 'select', array('name' => 'tax_class', 'label' => __('Tax Class'), 'title' => __('Tax Class'), 'class' => 'required-entry', 'required' => true, 'values' => $this->_taxCustomer->toOptionArray(false)));
     if (!is_null($customerGroup->getId())) {
         // If edit add id
         $form->addField('id', 'hidden', array('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(array('id' => $customerGroup->getId(), 'customer_group_code' => $customerGroup->getCode(), 'tax_class_id' => $customerGroup->getTaxClassId()));
     }
     $form->setUseContainer(true);
     $form->setId('edit_form');
     $form->setAction($this->getUrl('customer/*/save'));
     $form->setMethod('post');
     $this->setForm($form);
 }
 public function testGetSearchCriteriaAnd()
 {
     // Test ((A > 1) and (B > 1))
     $fieldA = 'A';
     $fieldB = 'B';
     $value = 1;
     /** @var SearchCriteria $expectedSearchCriteria */
     $expectedSearchCriteria = $this->searchCriteriaBuilder->setCurrentPage(1)->setPageSize(0)->addSortOrder('name', SearchCriteria::SORT_ASC)->addFilter([$this->filterBuilder->setField($fieldA)->setConditionType('gt')->setValue($value)->create()])->addFilter([$this->filterBuilder->setField($fieldB)->setConditionType('gt')->setValue($value)->create()])->create();
     // Verifies that the search criteria Data Object created by the serviceCollection matches expected
     $this->groupServiceMock->expects($this->once())->method('searchGroups')->with($this->equalTo($expectedSearchCriteria))->will($this->returnValue($this->searchResults));
     // Now call service collection to load the data.  This causes it to create the search criteria Data Object
     $this->serviceCollection->addFieldToFilter($fieldA, ['gt' => $value]);
     $this->serviceCollection->addFieldToFilter($fieldB, ['gt' => $value]);
     $this->serviceCollection->setOrder('name', ServiceCollection::SORT_ORDER_ASC);
     $this->serviceCollection->loadData();
 }
Esempio n. 18
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;
 }
Esempio n. 19
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();
 }
Esempio n. 20
0
 /**
  * Add account data to quote
  *
  * @param array $accountData
  * @return $this
  */
 public function setAccountData($accountData)
 {
     $customer = $this->getQuote()->getCustomerData();
     $form = $this->_createCustomerForm($customer);
     // emulate request
     $request = $form->prepareRequest($accountData);
     $data = $form->extractData($request);
     $data = $form->restoreData($data);
     $customer = $this->_customerBuilder->mergeDataObjectWithArray($customer, $data);
     $this->getQuote()->updateCustomerData($customer);
     $data = array();
     $customerData = \Magento\Framework\Service\ExtensibleDataObjectConverter::toFlatArray($customer);
     foreach ($form->getAttributes() as $attribute) {
         $code = sprintf('customer_%s', $attribute->getAttributeCode());
         $data[$code] = isset($customerData[$attribute->getAttributeCode()]) ? $customerData[$attribute->getAttributeCode()] : null;
     }
     if (isset($data['customer_group_id'])) {
         $customerGroup = $this->_customerGroupService->getGroup($data['customer_group_id']);
         $data['customer_tax_class_id'] = $customerGroup->getTaxClassId();
         $this->setRecollect(true);
     }
     $this->getQuote()->addData($data);
     return $this;
 }
Esempio n. 21
0
 /**
  * Initialize customer groups.
  *
  * @return $this
  */
 protected function _initCustomerGroups()
 {
     foreach ($this->_customerGroupService->getGroups() as $group) {
         $this->_customerGroups[$group->getId()] = true;
     }
     return $this;
 }
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testGetGroupName()
 {
     $groupName = $this->_groupService->getGroup($this->_loadCustomer()->getGroupId())->getCode();
     $this->assertEquals($groupName, $this->_block->getGroupName());
 }
Esempio n. 23
0
 /**
  * Get default customer group id
  *
  * @param \Magento\Store\Model\Store|string|int $store
  * @return int
  */
 public function getDefaultCustomerGroupId($store = null)
 {
     return $this->_groupService->getDefaultGroup($store)->getId();
 }
Esempio n. 24
0
 /**
  * Get customer tax class ID.
  *
  * @return string
  */
 public function getCustomerTaxClassId()
 {
     /**
      * tax class can vary at any time. so instead of using the value from session,
      * we need to retrieve from db every time to get the correct tax class
      */
     //if (!$this->getData('customer_group_id') && !$this->getData('customer_tax_class_id')) {
     $groupId = $this->getCustomerGroupId();
     if (!is_null($groupId)) {
         $taxClassId = $this->_customerGroupService->getGroup($this->getCustomerGroupId())->getTaxClassId();
         $this->setCustomerTaxClassId($taxClassId);
     }
     return $this->getData('customer_tax_class_id');
 }
Esempio n. 25
0
 /**
  * Get request object with information necessary for getting tax rate
  *
  * Request object contain:
  *  country_id (->getCountryId())
  *  region_id (->getRegionId())
  *  postcode (->getPostcode())
  *  customer_class_id (->getCustomerClassId())
  *  store (->getStore())
  *
  * @param null|bool|\Magento\Framework\Object|\Magento\Customer\Service\V1\Data\Address $shippingAddress
  * @param null|bool|\Magento\Framework\Object|\Magento\Customer\Service\V1\Data\Address $billingAddress
  * @param null|int $customerTaxClass
  * @param null|int|\Magento\Store\Model\Store $store
  * @param int $customerId
  * @return  \Magento\Framework\Object
  */
 public function getRateRequest($shippingAddress = null, $billingAddress = null, $customerTaxClass = null, $store = null, $customerId = null)
 {
     if ($shippingAddress === false && $billingAddress === false && $customerTaxClass === false) {
         return $this->getRateOriginRequest($store);
     }
     $address = new \Magento\Framework\Object();
     $basedOn = $this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_BASED_ON, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
     if ($shippingAddress === false && $basedOn == 'shipping' || $billingAddress === false && $basedOn == 'billing') {
         $basedOn = 'default';
     } else {
         if ((is_null($billingAddress) || !$billingAddress->getCountryId()) && $basedOn == 'billing' || (is_null($shippingAddress) || !$shippingAddress->getCountryId()) && $basedOn == 'shipping') {
             if ($customerId) {
                 try {
                     $defaultBilling = $this->_addressService->getDefaultBillingAddress($customerId);
                 } catch (NoSuchEntityException $e) {
                 }
                 try {
                     $defaultShipping = $this->_addressService->getDefaultShippingAddress($customerId);
                 } catch (NoSuchEntityException $e) {
                 }
                 if ($basedOn == 'billing' && isset($defaultBilling) && $defaultBilling->getCountryId()) {
                     $billingAddress = $defaultBilling;
                 } elseif ($basedOn == 'shipping' && isset($defaultShipping) && $defaultShipping->getCountryId()) {
                     $shippingAddress = $defaultShipping;
                 } else {
                     $basedOn = 'default';
                 }
             } else {
                 $basedOn = 'default';
             }
         }
     }
     switch ($basedOn) {
         case 'billing':
             $address = $billingAddress;
             break;
         case 'shipping':
             $address = $shippingAddress;
             break;
         case 'origin':
             $address = $this->getRateOriginRequest($store);
             break;
         case 'default':
             $address->setCountryId($this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_COUNTRY, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store))->setRegionId($this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_REGION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store))->setPostcode($this->_scopeConfig->getValue(\Magento\Tax\Model\Config::CONFIG_XML_PATH_DEFAULT_POSTCODE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store));
             break;
         default:
             break;
     }
     if (is_null($customerTaxClass) || $customerTaxClass === false) {
         if ($customerId) {
             $customerData = $this->customerAccountService->getCustomer($customerId);
             $customerTaxClass = $this->_groupService->getGroup($customerData->getGroupId())->getTaxClassId();
         } else {
             $customerTaxClass = $this->_groupService->getGroup(GroupServiceInterface::NOT_LOGGED_IN_ID)->getTaxClassId();
         }
     }
     $request = new \Magento\Framework\Object();
     //TODO: Address is not completely refactored to use Data objects
     if ($address->getRegion() instanceof RegionDataObject) {
         $regionId = $address->getRegion()->getRegionId();
     } else {
         $regionId = $address->getRegionId();
     }
     $request->setCountryId($address->getCountryId())->setRegionId($regionId)->setPostcode($address->getPostcode())->setStore($store)->setCustomerClassId($customerTaxClass);
     return $request;
 }
Esempio n. 26
0
 /**
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->_eavConfig = $this->getMock('Magento\\Eav\\Model\\Config', array('getEntityType', 'getEntityTypeId'), array(), '', false);
     $this->_eavConfig->expects($this->atLeastOnce())->method('getEntityType')->with($this->equalTo('catalog_product'))->will($this->returnSelf());
     $this->_eavConfig->expects($this->atLeastOnce())->method('getEntityTypeId')->will($this->returnValue('1'));
     $this->_optionModel = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product\\Option', array(), array(), '', false);
     $this->_optionFactory = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product\\OptionFactory', array('create'), array(), '', false);
     $this->_optionFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->_optionModel));
     $this->_storeManager = $this->getMock('\\Magento\\Store\\Model\\StoreManager', array('getWebsites', 'getStores'), array(), '', false);
     $this->_storeManager->expects($this->atLeastOnce())->method('getWebsites')->will($this->returnValue(array()));
     $this->_storeManager->expects($this->atLeastOnce())->method('getStores')->will($this->returnValue(array()));
     $this->_setCol = $this->getMock('\\Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\Collection', array('setEntityTypeFilter'), array(), '', false);
     $this->_setCol->expects($this->atLeastOnce())->method('setEntityTypeFilter')->with($this->equalTo('1'))->will($this->returnValue(array()));
     $this->_setColFactory = $this->getMock('\\Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\CollectionFactory', array('create'), array(), '', false);
     $this->_setColFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->_setCol));
     $this->_importConfig = $this->getMock('\\Magento\\ImportExport\\Model\\Import\\Config', array('getEntityTypes'), array(), '', false);
     $this->_importConfig->expects($this->atLeastOnce())->method('getEntityTypes')->with('catalog_product')->will($this->returnValue(array()));
     $this->_categoryCol = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Category\\Collection', array('addNameToResult'), array(), '', false);
     $this->_categoryCol->expects($this->atLeastOnce())->method('addNameToResult')->will($this->returnValue(array()));
     $this->_categoryColFactory = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Category\\CollectionFactory', array('create'), array(), '', false);
     $this->_categoryColFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->_categoryCol));
     $this->_product = $this->getMock('\\Magento\\Catalog\\Model\\Product', array('getProductEntitiesInfo', '__wakeup'), array(), '', false);
     $this->_product->expects($this->atLeastOnce())->method('getProductEntitiesInfo')->with($this->equalTo(array('entity_id', 'type_id', 'attribute_set_id', 'sku')))->will($this->returnValue(array()));
     $this->_productFactory = $this->getMock('\\Magento\\Catalog\\Model\\ProductFactory', array('create'), array(), '', false);
     $this->_productFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->_product));
     $this->_customerGroupService = $this->getMock('Magento\\Customer\\Service\\V1\\CustomerGroupService', array('getGroups'), array(), '', false);
     $this->_customerGroupService->expects($this->atLeastOnce())->method('getGroups')->will($this->returnValue(array()));
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->_model = $objectManager->getObject('\\Magento\\CatalogImportExport\\Model\\Import\\Product', array('config' => $this->_eavConfig, 'optionFactory' => $this->_optionFactory, 'storeManager' => $this->_storeManager, 'setColFactory' => $this->_setColFactory, 'importConfig' => $this->_importConfig, 'categoryColFactory' => $this->_categoryColFactory, 'productFactory' => $this->_productFactory, 'customerGroupService' => $this->_customerGroupService));
 }
Esempio n. 27
0
 /**
  * Retrieve customer tax class identifier
  *
  * @return int
  */
 public function getTaxClassId()
 {
     if (!$this->getData('tax_class_id')) {
         $groupTaxClassId = $this->_groupService->getGroup($this->getGroupId())->getTaxClassId();
         $this->setData('tax_class_id', $groupTaxClassId);
     }
     return $this->getData('tax_class_id');
 }