예제 #1
0
 /**
  * Adding product form elements for editing attribute
  *
  * @return $this
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _prepareForm()
 {
     $attributeObject = $this->getAttributeObject();
     $form = $this->_formFactory->create(['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]);
     $fieldset = $form->addFieldset('advanced_fieldset', ['legend' => __('Advanced Attribute Properties'), 'collapsable' => true]);
     $yesno = $this->_yesNo->toOptionArray();
     $validateClass = sprintf('validate-code validate-length maximum-length-%d', \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH);
     $fieldset->addField('attribute_code', 'text', ['name' => 'attribute_code', 'label' => __('Attribute Code'), 'title' => __('Attribute Code'), 'note' => __('This is used internally. Make sure you don\'t use spaces or more than %1 symbols.', \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH), 'class' => $validateClass]);
     $fieldset->addField('default_value_text', 'text', ['name' => 'default_value_text', 'label' => __('Default Value'), 'title' => __('Default Value'), 'value' => $attributeObject->getDefaultValue()]);
     $fieldset->addField('default_value_yesno', 'select', ['name' => 'default_value_yesno', 'label' => __('Default Value'), 'title' => __('Default Value'), 'values' => $yesno, 'value' => $attributeObject->getDefaultValue()]);
     $dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
     $fieldset->addField('default_value_date', 'date', ['name' => 'default_value_date', 'label' => __('Default Value'), 'title' => __('Default Value'), 'value' => $attributeObject->getDefaultValue(), 'date_format' => $dateFormat]);
     $fieldset->addField('default_value_textarea', 'textarea', ['name' => 'default_value_textarea', 'label' => __('Default Value'), 'title' => __('Default Value'), 'value' => $attributeObject->getDefaultValue()]);
     $fieldset->addField('is_unique', 'select', ['name' => 'is_unique', 'label' => __('Unique Value'), 'title' => __('Unique Value (not shared with other products)'), 'note' => __('Not shared with other products'), 'values' => $yesno]);
     $fieldset->addField('frontend_class', 'select', ['name' => 'frontend_class', 'label' => __('Input Validation for Store Owner'), 'title' => __('Input Validation for Store Owner'), 'values' => $this->_eavData->getFrontendClasses($attributeObject->getEntityType()->getEntityTypeCode())]);
     if ($attributeObject->getId()) {
         $form->getElement('attribute_code')->setDisabled(1);
         if (!$attributeObject->getIsUserDefined()) {
             $form->getElement('is_unique')->setDisabled(1);
         }
     }
     $scopes = [\Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_STORE => __('Store View'), \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_WEBSITE => __('Website'), \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_GLOBAL => __('Global')];
     if ($attributeObject->getAttributeCode() == 'status' || $attributeObject->getAttributeCode() == 'tax_class_id') {
         unset($scopes[\Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_STORE]);
     }
     $fieldset->addField('is_global', 'select', ['name' => 'is_global', 'label' => __('Scope'), 'title' => __('Scope'), 'note' => __('Declare attribute value saving scope'), 'values' => $scopes], 'attribute_code');
     $this->_eventManager->dispatch('product_attribute_form_build', ['form' => $form]);
     if ($attributeObject->getId() && !$attributeObject->getIsUserDefined()) {
         $form->getElement('is_global')->setDisabled(1);
     }
     $this->setForm($form);
     return $this;
 }
예제 #2
0
 public function testToHtml()
 {
     $fieldSet = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Fieldset', [], [], '', false);
     $form = $this->getMock('Magento\\Framework\\Data\\Form', [], [], '', false);
     $attributeModel = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Eav\\Attribute', [], [], '', false);
     $entityType = $this->getMock('Magento\\Eav\\Model\\Entity\\Type', [], [], '', false);
     $formElement = $this->getMock('Magento\\Framework\\Data\\Form\\Element\\Text', ['setDisabled'], [], '', false);
     $directoryReadInterface = $this->getMock('\\Magento\\Framework\\Filesystem\\Directory\\ReadInterface');
     $this->registry->expects($this->any())->method('registry')->with('entity_attribute')->willReturn($attributeModel);
     $this->formFactory->expects($this->any())->method('create')->willReturn($form);
     $form->expects($this->any())->method('addFieldset')->willReturn($fieldSet);
     $form->expects($this->any())->method('getElement')->willReturn($formElement);
     $fieldSet->expects($this->any())->method('addField')->willReturnSelf();
     $attributeModel->expects($this->any())->method('getDefaultValue')->willReturn('default_value');
     $attributeModel->expects($this->any())->method('setDisabled')->willReturnSelf();
     $attributeModel->expects($this->any())->method('getId')->willReturn(1);
     $attributeModel->expects($this->any())->method('getEntityType')->willReturn($entityType);
     $attributeModel->expects($this->any())->method('getIsUserDefined')->willReturn(false);
     $attributeModel->expects($this->any())->method('getAttributeCode')->willReturn('attribute_code');
     $this->localeDate->expects($this->any())->method('getDateFormat')->willReturn('mm/dd/yy');
     $entityType->expects($this->any())->method('getEntityTypeCode')->willReturn('entity_type_code');
     $this->eavData->expects($this->any())->method('getFrontendClasses')->willReturn([]);
     $formElement->expects($this->exactly(3))->method('setDisabled')->willReturnSelf();
     $this->yesNo->expects($this->any())->method('toOptionArray')->willReturn(['yes', 'no']);
     $this->filesystem->expects($this->any())->method('getDirectoryRead')->willReturn($directoryReadInterface);
     $directoryReadInterface->expects($this->any())->method('getRelativePath')->willReturn('relative_path');
     $this->block->setData(['action' => 'save']);
     $this->block->toHtml();
 }
예제 #3
0
파일: Advanced.php 프로젝트: aiesh/magento2
 /**
  * Adding product form elements for editing attribute
  *
  * @return $this
  */
 protected function _prepareForm()
 {
     $attributeObject = $this->getAttributeObject();
     $form = $this->_formFactory->create(array('data' => array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post')));
     $fieldset = $form->addFieldset('advanced_fieldset', array('legend' => __('Advanced Attribute Properties'), 'collapsable' => true));
     $yesno = $this->_yesNo->toOptionArray();
     $validateClass = sprintf('validate-code validate-length maximum-length-%d', \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH);
     $fieldset->addField('attribute_code', 'text', array('name' => 'attribute_code', 'label' => __('Attribute Code'), 'title' => __('Attribute Code'), 'note' => __('For internal use. Must be unique with no spaces. Maximum length of attribute code must be less than %1 symbols', \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH), 'class' => $validateClass));
     $fieldset->addField('default_value_text', 'text', array('name' => 'default_value_text', 'label' => __('Default Value'), 'title' => __('Default Value'), 'value' => $attributeObject->getDefaultValue()));
     $fieldset->addField('default_value_yesno', 'select', array('name' => 'default_value_yesno', 'label' => __('Default Value'), 'title' => __('Default Value'), 'values' => $yesno, 'value' => $attributeObject->getDefaultValue()));
     $dateFormat = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT);
     $fieldset->addField('default_value_date', 'date', array('name' => 'default_value_date', 'label' => __('Default Value'), 'title' => __('Default Value'), 'image' => $this->getViewFileUrl('images/grid-cal.gif'), 'value' => $attributeObject->getDefaultValue(), 'date_format' => $dateFormat));
     $fieldset->addField('default_value_textarea', 'textarea', array('name' => 'default_value_textarea', 'label' => __('Default Value'), 'title' => __('Default Value'), 'value' => $attributeObject->getDefaultValue()));
     $fieldset->addField('is_unique', 'select', array('name' => 'is_unique', 'label' => __('Unique Value'), 'title' => __('Unique Value (not shared with other products)'), 'note' => __('Not shared with other products'), 'values' => $yesno));
     $fieldset->addField('frontend_class', 'select', array('name' => 'frontend_class', 'label' => __('Input Validation for Store Owner'), 'title' => __('Input Validation for Store Owner'), 'values' => $this->_eavData->getFrontendClasses($attributeObject->getEntityType()->getEntityTypeCode())));
     if ($attributeObject->getId()) {
         $form->getElement('attribute_code')->setDisabled(1);
         if (!$attributeObject->getIsUserDefined()) {
             $form->getElement('is_unique')->setDisabled(1);
         }
     }
     $scopes = array(\Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_STORE => __('Store View'), \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_WEBSITE => __('Website'), \Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_GLOBAL => __('Global'));
     if ($attributeObject->getAttributeCode() == 'status' || $attributeObject->getAttributeCode() == 'tax_class_id') {
         unset($scopes[\Magento\Catalog\Model\Resource\Eav\Attribute::SCOPE_STORE]);
     }
     $fieldset->addField('is_global', 'select', array('name' => 'is_global', 'label' => __('Scope'), 'title' => __('Scope'), 'note' => __('Declare attribute value saving scope'), 'values' => $scopes), 'attribute_code');
     $this->_eventManager->dispatch('product_attribute_form_build', array('form' => $form));
     $this->setForm($form);
     return $this;
 }
예제 #4
0
 /**
  * @param \Magento\Eav\Helper\Data $eavData
  */
 public function __construct(\Magento\Eav\Helper\Data $eavData)
 {
     $this->_eavData = $eavData;
     //set data haystack
     $haystack = $this->_eavData->getInputTypesValidatorData();
     //reset message template and set custom
     $this->_messageTemplates = null;
     $this->_initMessageTemplates();
     //parent construct with options
     parent::__construct(['haystack' => $haystack, 'strict' => true]);
 }
예제 #5
0
 /**
  * Add customer details(email, firstname, lastname) to select
  *
  * @return $this
  */
 public function addCustomerDetails()
 {
     $select = $this->getSelect()->joinInner(array('ce' => $this->getTable('customer_entity')), 'ce.entity_id = main_table.customer_id', array('customer_email' => 'email'));
     $adapter = $this->getConnection();
     $firstNameMetadata = $this->_eavHelper->getAttributeMetadata(CustomerMetadataServiceInterface::ENTITY_TYPE_CUSTOMER, 'firstname');
     $joinExpr = 'firstname.entity_id = main_table.customer_id AND ' . $adapter->quoteInto('firstname.entity_type_id = ?', $firstNameMetadata['entity_type_id']) . ' AND ' . $adapter->quoteInto('firstname.attribute_id = ?', $firstNameMetadata['attribute_id']);
     $select->joinLeft(array('firstname' => $firstNameMetadata['attribute_table']), $joinExpr, array('customer_firstname' => 'value'));
     $lastNameMetadata = $this->_eavHelper->getAttributeMetadata(CustomerMetadataServiceInterface::ENTITY_TYPE_CUSTOMER, 'lastname');
     $joinExpr = 'lastname.entity_id = main_table.customer_id AND ' . $adapter->quoteInto('lastname.entity_type_id = ?', $lastNameMetadata['entity_type_id']) . ' AND ' . $adapter->quoteInto('lastname.attribute_id = ?', $lastNameMetadata['attribute_id']);
     $select->joinLeft(array('lastname' => $lastNameMetadata['attribute_table']), $joinExpr, array('customer_lastname' => 'value'));
     return $this;
 }
예제 #6
0
 /**
  * Preparing default form elements for editing attribute
  *
  * @return $this
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _prepareForm()
 {
     $attributeObject = $this->getAttributeObject();
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create(['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post']]);
     $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Attribute Properties')]);
     if ($attributeObject->getAttributeId()) {
         $fieldset->addField('attribute_id', 'hidden', ['name' => 'attribute_id']);
     }
     $this->_addElementTypes($fieldset);
     $yesno = $this->_yesnoFactory->create()->toOptionArray();
     $labels = $attributeObject->getFrontendLabel();
     $fieldset->addField('attribute_label', 'text', ['name' => 'frontend_label[0]', 'label' => __('Default Label'), 'title' => __('Default label'), 'required' => true, 'value' => is_array($labels) ? $labels[0] : $labels]);
     $validateClass = sprintf('validate-code validate-length maximum-length-%d', \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH);
     $fieldset->addField('attribute_code', 'text', ['name' => 'attribute_code', 'label' => __('Attribute Code'), 'title' => __('Attribute Code'), 'note' => __('This is used internally. Make sure you don\'t use spaces or more than %1 symbols.', \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH), 'class' => $validateClass, 'required' => true]);
     $fieldset->addField('frontend_input', 'select', ['name' => 'frontend_input', 'label' => __('Catalog Input Type for Store Owner'), 'title' => __('Catalog Input Type for Store Owner'), 'value' => 'text', 'values' => $this->_inputTypeFactory->create()->toOptionArray()]);
     $fieldset->addField('is_required', 'select', ['name' => 'is_required', 'label' => __('Values Required'), 'title' => __('Values Required'), 'values' => $yesno]);
     $fieldset->addField('default_value_text', 'text', ['name' => 'default_value_text', 'label' => __('Default Value'), 'title' => __('Default Value'), 'value' => $attributeObject->getDefaultValue()]);
     $fieldset->addField('default_value_yesno', 'select', ['name' => 'default_value_yesno', 'label' => __('Default Value'), 'title' => __('Default Value'), 'values' => $yesno, 'value' => $attributeObject->getDefaultValue()]);
     $dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
     $fieldset->addField('default_value_date', 'date', ['name' => 'default_value_date', 'label' => __('Default Value'), 'title' => __('Default Value'), 'value' => $attributeObject->getDefaultValue(), 'date_format' => $dateFormat]);
     $fieldset->addField('default_value_textarea', 'textarea', ['name' => 'default_value_textarea', 'label' => __('Default Value'), 'title' => __('Default Value'), 'value' => $attributeObject->getDefaultValue()]);
     $fieldset->addField('is_unique', 'select', ['name' => 'is_unique', 'label' => __('Unique Value'), 'title' => __('Unique Value (not shared with other products)'), 'note' => __('Not shared with other products.'), 'values' => $yesno]);
     $fieldset->addField('frontend_class', 'select', ['name' => 'frontend_class', 'label' => __('Input Validation for Store Owner'), 'title' => __('Input Validation for Store Owner'), 'values' => $this->_eavData->getFrontendClasses($attributeObject->getEntityType()->getEntityTypeCode())]);
     if ($attributeObject->getId()) {
         $form->getElement('attribute_code')->setDisabled(1);
         $form->getElement('frontend_input')->setDisabled(1);
         if (!$attributeObject->getIsUserDefined()) {
             $form->getElement('is_unique')->setDisabled(1);
         }
     }
     $this->propertyLocker->lock($form);
     $this->setForm($form);
     return parent::_prepareForm();
 }
예제 #7
0
 /**
  * Preparing default form elements for editing attribute
  *
  * @return $this
  */
 protected function _prepareForm()
 {
     $attributeObject = $this->getAttributeObject();
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create(array('data' => array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post')));
     $fieldset = $form->addFieldset('base_fieldset', array('legend' => __('Attribute Properties')));
     if ($attributeObject->getAttributeId()) {
         $fieldset->addField('attribute_id', 'hidden', array('name' => 'attribute_id'));
     }
     $this->_addElementTypes($fieldset);
     $yesno = $this->_yesnoFactory->create()->toOptionArray();
     $labels = $attributeObject->getFrontendLabel();
     $fieldset->addField('attribute_label', 'text', array('name' => 'frontend_label[0]', 'label' => __('Attribute Label'), 'title' => __('Attribute Label'), 'required' => true, 'value' => is_array($labels) ? $labels[0] : $labels));
     $validateClass = sprintf('validate-code validate-length maximum-length-%d', \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH);
     $fieldset->addField('attribute_code', 'text', array('name' => 'attribute_code', 'label' => __('Attribute Code'), 'title' => __('Attribute Code'), 'note' => __('For internal use. Must be unique with no spaces. Maximum length of attribute code must be less than %1 symbols', \Magento\Eav\Model\Entity\Attribute::ATTRIBUTE_CODE_MAX_LENGTH), 'class' => $validateClass, 'required' => true));
     $fieldset->addField('frontend_input', 'select', array('name' => 'frontend_input', 'label' => __('Catalog Input Type for Store Owner'), 'title' => __('Catalog Input Type for Store Owner'), 'value' => 'text', 'values' => $this->_inputTypeFactory->create()->toOptionArray()));
     $fieldset->addField('is_required', 'select', array('name' => 'is_required', 'label' => __('Values Required'), 'title' => __('Values Required'), 'values' => $yesno));
     $fieldset->addField('default_value_text', 'text', array('name' => 'default_value_text', 'label' => __('Default Value'), 'title' => __('Default Value'), 'value' => $attributeObject->getDefaultValue()));
     $fieldset->addField('default_value_yesno', 'select', array('name' => 'default_value_yesno', 'label' => __('Default Value'), 'title' => __('Default Value'), 'values' => $yesno, 'value' => $attributeObject->getDefaultValue()));
     $dateFormat = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT);
     $fieldset->addField('default_value_date', 'date', array('name' => 'default_value_date', 'label' => __('Default Value'), 'title' => __('Default Value'), 'image' => $this->getViewFileUrl('images/grid-cal.gif'), 'value' => $attributeObject->getDefaultValue(), 'date_format' => $dateFormat));
     $fieldset->addField('default_value_textarea', 'textarea', array('name' => 'default_value_textarea', 'label' => __('Default Value'), 'title' => __('Default Value'), 'value' => $attributeObject->getDefaultValue()));
     $fieldset->addField('is_unique', 'select', array('name' => 'is_unique', 'label' => __('Unique Value'), 'title' => __('Unique Value (not shared with other products)'), 'note' => __('Not shared with other products'), 'values' => $yesno));
     $fieldset->addField('frontend_class', 'select', array('name' => 'frontend_class', 'label' => __('Input Validation for Store Owner'), 'title' => __('Input Validation for Store Owner'), 'values' => $this->_eavData->getFrontendClasses($attributeObject->getEntityType()->getEntityTypeCode())));
     if ($attributeObject->getId()) {
         $form->getElement('attribute_code')->setDisabled(1);
         $form->getElement('frontend_input')->setDisabled(1);
         if (!$attributeObject->getIsUserDefined()) {
             $form->getElement('is_unique')->setDisabled(1);
         }
     }
     $this->setForm($form);
     return parent::_prepareForm();
 }
예제 #8
0
 /**
  * Add Customer data to collection
  *
  * @return $this
  */
 public function addCustomerData()
 {
     // alias => attribute_code
     $attributes = ['customer_lastname' => 'lastname', 'customer_firstname' => 'firstname', 'customer_email' => 'email'];
     foreach ($attributes as $alias => $attributeCode) {
         $attribute = $this->_eavHelper->getAttributeMetadata(\Magento\Customer\Api\CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, $attributeCode);
         $tableAlias = 'customer_' . $attributeCode;
         if ($attribute['backend_type'] == 'static') {
             $this->getSelect()->joinLeft([$tableAlias => $attribute['attribute_table']], sprintf('%s.entity_id=main_table.customer_id', $tableAlias), [$alias => $attributeCode]);
             $this->_fields[$alias] = sprintf('%s.%s', $tableAlias, $attributeCode);
         } else {
             $joinConds = [sprintf('%s.entity_id=main_table.customer_id', $tableAlias), $this->getConnection()->quoteInto($tableAlias . '.attribute_id=?', $attribute['attribute_id'])];
             $this->getSelect()->joinLeft([$tableAlias => $attribute['attribute_table']], join(' AND ', $joinConds), [$alias => 'value']);
             $this->_fields[$alias] = sprintf('%s.value', $tableAlias);
         }
     }
     $this->setFlag('has_customer_data', true);
     return $this;
 }
예제 #9
0
 /**
  * Adds customer info to select
  *
  * @return $this
  */
 public function showCustomerInfo()
 {
     $adapter = $this->getConnection();
     $lastNameData = $this->_customerHelperData->getAttributeMetadata(CustomerMetadataService::ENTITY_TYPE_CUSTOMER, 'lastname');
     $firstNameData = $this->_customerHelperData->getAttributeMetadata(CustomerMetadataService::ENTITY_TYPE_CUSTOMER, 'firstname');
     $this->getSelect()->joinLeft(array('customer_lastname_table' => $lastNameData['attribute_table']), $adapter->quoteInto('customer_lastname_table.entity_id=main_table.customer_id
                                  AND customer_lastname_table.attribute_id = ?', (int) $lastNameData['attribute_id']), array('customer_lastname' => 'value'))->joinLeft(array('customer_firstname_table' => $firstNameData['attribute_table']), $adapter->quoteInto('customer_firstname_table.entity_id=main_table.customer_id
                                  AND customer_firstname_table.attribute_id = ?', (int) $firstNameData['attribute_id']), array('customer_firstname' => 'value'));
     return $this;
 }
예제 #10
0
 public function testGetInputTypesValidatorData()
 {
     $configValue = 'config_value';
     $this->scopeConfigMock->expects($this->once())->method('getValue')->with(\Magento\Eav\Helper\Data::XML_PATH_VALIDATOR_DATA_INPUT_TYPES, ScopeInterface::SCOPE_STORE)->willReturn($configValue);
     $this->assertEquals($configValue, $this->helper->getInputTypesValidatorData());
 }
예제 #11
0
 /**
  * @covers \Magento\Eav\Helper\Data::getAttributeLockedFields
  */
 public function testGetAttributeLockedFieldsNoLockedFields()
 {
     $this->attributeConfig->expects($this->once())->method('getEntityAttributesLockedFields')->with('entityTypeCode')->will($this->returnValue([]));
     $this->assertEquals([], $this->_helper->getAttributeLockedFields('entityTypeCode'));
 }