Exemple #1
0
 /**
  * Prepare group specific fieldset
  *
  * @param \Magento\Framework\Data\Form $form
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _prepareStoreFieldset(\Magento\Framework\Data\Form $form)
 {
     $groupModel = $this->_coreRegistry->registry('store_data');
     $postData = $this->_coreRegistry->registry('store_post_data');
     if ($postData) {
         $groupModel->setData($postData['group']);
     }
     $fieldset = $form->addFieldset('group_fieldset', ['legend' => __('Store Information')]);
     $storeAction = $this->_coreRegistry->registry('store_action');
     if ($storeAction == 'edit' || $storeAction == 'add') {
         $websites = $this->_websiteFactory->create()->getCollection()->toOptionArray();
         $fieldset->addField('group_website_id', 'select', ['name' => 'group[website_id]', 'label' => __('Web Site'), 'value' => $groupModel->getWebsiteId(), 'values' => $websites, 'required' => true, 'disabled' => $groupModel->isReadOnly()]);
         if ($groupModel->getId() && $groupModel->getWebsite()->getDefaultGroupId() == $groupModel->getId()) {
             if ($groupModel->getWebsite()->getIsDefault() || $groupModel->getWebsite()->getGroupsCount() == 1) {
                 $form->getElement('group_website_id')->setDisabled(true);
                 $fieldset->addField('group_hidden_website_id', 'hidden', ['name' => 'group[website_id]', 'no_span' => true, 'value' => $groupModel->getWebsiteId()]);
             } else {
                 $fieldset->addField('group_original_website_id', 'hidden', ['name' => 'group[original_website_id]', 'no_span' => true, 'value' => $groupModel->getWebsiteId()]);
             }
         }
     }
     $fieldset->addField('group_name', 'text', ['name' => 'group[name]', 'label' => __('Name'), 'value' => $groupModel->getName(), 'required' => true, 'disabled' => $groupModel->isReadOnly()]);
     $categories = $this->_category->toOptionArray();
     $fieldset->addField('group_root_category_id', 'select', ['name' => 'group[root_category_id]', 'label' => __('Root Category'), 'value' => $groupModel->getRootCategoryId(), 'values' => $categories, 'required' => true, 'disabled' => $groupModel->isReadOnly()]);
     if ($this->_coreRegistry->registry('store_action') == 'edit') {
         $storeActive = 1;
         $stores = $this->_storeFactory->create()->getCollection()->addGroupFilter($groupModel->getId())->addStatusFilter($storeActive)->toOptionArray();
         $fieldset->addField('group_default_store_id', 'select', ['name' => 'group[default_store_id]', 'label' => __('Default Store View'), 'value' => $groupModel->getDefaultStoreId(), 'values' => $stores, 'required' => false, 'disabled' => $groupModel->isReadOnly()]);
     }
     $fieldset->addField('group_group_id', 'hidden', ['name' => 'group[group_id]', 'no_span' => true, 'value' => $groupModel->getId()]);
 }
Exemple #2
0
 /**
  * Prepare store specific fieldset
  *
  * @param \Magento\Framework\Data\Form $form
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _prepareStoreFieldset(\Magento\Framework\Data\Form $form)
 {
     $storeModel = $this->_coreRegistry->registry('store_data');
     $postData = $this->_coreRegistry->registry('store_post_data');
     if ($postData) {
         $storeModel->setData($postData['store']);
     }
     $fieldset = $form->addFieldset('store_fieldset', array('legend' => __('Store View Information')));
     $storeAction = $this->_coreRegistry->registry('store_action');
     if ($storeAction == 'edit' || $storeAction == 'add') {
         $fieldset->addField('store_group_id', 'select', array('name' => 'store[group_id]', 'label' => __('Store'), 'value' => $storeModel->getGroupId(), 'values' => $this->_getStoreGroups(), 'required' => true, 'disabled' => $storeModel->isReadOnly()));
         if ($storeModel->getId() && $storeModel->getGroup()->getDefaultStoreId() == $storeModel->getId()) {
             if ($storeModel->getGroup() && $storeModel->getGroup()->getStoresCount() > 1) {
                 $form->getElement('store_group_id')->setDisabled(true);
                 $fieldset->addField('store_hidden_group_id', 'hidden', array('name' => 'store[group_id]', 'no_span' => true, 'value' => $storeModel->getGroupId()));
             } else {
                 $fieldset->addField('store_original_group_id', 'hidden', array('name' => 'store[original_group_id]', 'no_span' => true, 'value' => $storeModel->getGroupId()));
             }
         }
     }
     $fieldset->addField('store_name', 'text', array('name' => 'store[name]', 'label' => __('Name'), 'value' => $storeModel->getName(), 'required' => true, 'disabled' => $storeModel->isReadOnly()));
     $fieldset->addField('store_code', 'text', array('name' => 'store[code]', 'label' => __('Code'), 'value' => $storeModel->getCode(), 'required' => true, 'disabled' => $storeModel->isReadOnly()));
     $fieldset->addField('store_is_active', 'select', array('name' => 'store[is_active]', 'label' => __('Status'), 'value' => $storeModel->getIsActive(), 'options' => array(0 => __('Disabled'), 1 => __('Enabled')), 'required' => true, 'disabled' => $storeModel->isReadOnly()));
     $fieldset->addField('store_sort_order', 'text', array('name' => 'store[sort_order]', 'label' => __('Sort Order'), 'value' => $storeModel->getSortOrder(), 'required' => false, 'disabled' => $storeModel->isReadOnly()));
     $fieldset->addField('store_is_default', 'hidden', array('name' => 'store[is_default]', 'no_span' => true, 'value' => $storeModel->getIsDefault()));
     $fieldset->addField('store_store_id', 'hidden', array('name' => 'store[store_id]', 'no_span' => true, 'value' => $storeModel->getId(), 'disabled' => $storeModel->isReadOnly()));
 }
 /**
  * @param \Magento\Framework\Data\Form $form
  * @return void
  */
 public function lock(\Magento\Framework\Data\Form $form)
 {
     /** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attributeObject */
     $attributeObject = $this->registry->registry('entity_attribute');
     if ($attributeObject->getId()) {
         foreach ($this->attributeConfig->getLockedFields($attributeObject) as $field) {
             if ($element = $form->getElement($field)) {
                 $element->setDisabled(1);
                 $element->setReadonly(1);
             }
         }
     }
 }
Exemple #4
0
 /**
  * Handle Read-Only customer
  *
  * @param \Magento\Framework\Data\Form $form
  * @param int $customerId
  * @param \Magento\Customer\Service\V1\Data\Eav\AttributeMetadata[] $attributes
  * @return void
  */
 protected function _handleReadOnlyCustomer($form, $customerId, $attributes)
 {
     if ($customerId && !$this->_customerAccountService->canModify($customerId)) {
         foreach ($attributes as $attribute) {
             $element = $form->getElement($attribute->getAttributeCode());
             if ($element) {
                 $element->setReadonly(true, true);
             }
         }
     }
 }
Exemple #5
0
 /**
  * Prepare group id field in the fieldset
  *
  * @param \Magento\Framework\Data\Form $form
  * @param \Magento\Store\Model\Store $storeModel
  * @param \Magento\Framework\Data\Form\Element\Fieldset $fieldset
  * @return \Magento\Framework\Data\Form\Element\Fieldset
  */
 private function prepareGroupIdField(\Magento\Framework\Data\Form $form, \Magento\Store\Model\Store $storeModel, \Magento\Framework\Data\Form\Element\Fieldset $fieldset)
 {
     if ($storeModel->getId() && $storeModel->getGroup()->getDefaultStoreId() == $storeModel->getId()) {
         if ($storeModel->getGroup() && $storeModel->getGroup()->getStoresCount() > 1) {
             $form->getElement('store_group_id')->setDisabled(true);
             $fieldset->addField('store_hidden_group_id', 'hidden', ['name' => 'store[group_id]', 'no_span' => true, 'value' => $storeModel->getGroupId()]);
         } else {
             $fieldset->addField('store_original_group_id', 'hidden', ['name' => 'store[original_group_id]', 'no_span' => true, 'value' => $storeModel->getGroupId()]);
         }
     }
     return $fieldset;
 }
Exemple #6
0
 /**
  * Update form elements from session data
  *
  * @param \Magento\Framework\Data\Form $form
  * @param int $customerId
  * @return void
  */
 protected function updateFromSession(\Magento\Framework\Data\Form $form, $customerId)
 {
     $data = $this->_backendSession->getCustomerFormData();
     if (!empty($data)) {
         $dataCustomerId = isset($data['customer']['entity_id']) ? $data['customer']['entity_id'] : null;
         if (isset($data['subscription']) && $dataCustomerId == $customerId) {
             $form->getElement('subscription')->setIsChecked($data['subscription']);
         }
     }
 }
 /**
  * Move original fields to the new fieldset.
  *
  * @param Form $form Form
  *
  * @return FrontPlugin
  */
 private function moveOrginalFields(Form $form)
 {
     $originalFieldset = $form->getElement('front_fieldset');
     $targetFieldset = $form->getElement('elasticsuite_catalog_attribute_fieldset');
     foreach ($this->movedFields as $elementId) {
         $element = $form->getElement($elementId);
         if ($element) {
             $originalFieldset->removeField($elementId);
             $targetFieldset->addElement($element);
         }
     }
     return $this;
 }
Exemple #8
0
 /**
  * Handle Read-Only customer
  *
  * @param \Magento\Framework\Data\Form $form
  * @param int $customerId
  * @param AttributeMetadataInterface[] $attributes
  * @return void
  */
 protected function _handleReadOnlyCustomer($form, $customerId, $attributes)
 {
     if ($customerId && $this->_accountManagement->isReadonly($customerId)) {
         foreach ($attributes as $attribute) {
             $element = $form->getElement($attribute->getAttributeCode());
             if ($element) {
                 $element->setReadonly(true, true);
             }
         }
     }
 }