-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5097 from magento-tsg-csl3/2.4-develop-pr1
[TSG-CSL3] For 2.4 (pr1)
- Loading branch information
Showing
43 changed files
with
1,416 additions
and
280 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,60 +7,60 @@ | |
/** | ||
* Product attribute add/edit form main tab | ||
* | ||
* @author Magento Core Team <[email protected]> | ||
* @author Magento Core Team <[email protected]> | ||
*/ | ||
namespace Magento\Catalog\Block\Adminhtml\Product\Attribute\Edit\Tab; | ||
|
||
use Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Apply as HelperApply; | ||
use Magento\Eav\Block\Adminhtml\Attribute\Edit\Main\AbstractMain; | ||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
use Magento\Framework\Data\Form\Element\Fieldset; | ||
use Magento\Framework\DataObject; | ||
|
||
/** | ||
* Product attribute add/edit form main tab | ||
* | ||
* @api | ||
* @SuppressWarnings(PHPMD.DepthOfInheritance) | ||
* @since 100.0.2 | ||
*/ | ||
class Main extends AbstractMain | ||
{ | ||
/** | ||
* Adding product form elements for editing attribute | ||
* | ||
* @return $this | ||
* @SuppressWarnings(PHPMD.UnusedLocalVariable) | ||
* @inheritdoc | ||
*/ | ||
protected function _prepareForm() | ||
{ | ||
parent::_prepareForm(); | ||
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attributeObject */ | ||
$attributeObject = $this->getAttributeObject(); | ||
/* @var $form \Magento\Framework\Data\Form */ | ||
$form = $this->getForm(); | ||
/* @var $fieldset \Magento\Framework\Data\Form\Element\Fieldset */ | ||
$fieldset = $form->getElement('base_fieldset'); | ||
$fieldsToRemove = ['attribute_code', 'is_unique', 'frontend_class']; | ||
|
||
foreach ($fieldset->getElements() as $element) { | ||
/** @var \Magento\Framework\Data\Form\AbstractForm $element */ | ||
if (substr($element->getId(), 0, strlen('default_value')) == 'default_value') { | ||
$fieldsToRemove[] = $element->getId(); | ||
} | ||
} | ||
foreach ($fieldsToRemove as $id) { | ||
$fieldset->removeField($id); | ||
} | ||
$this->removeUnusedFields(); | ||
$this->processFrontendInputTypes(); | ||
|
||
$this->_eventManager->dispatch('product_attribute_form_build_main_tab', ['form' => $this->getForm()]); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function _getAdditionalElementTypes() | ||
{ | ||
return ['apply' => HelperApply::class]; | ||
} | ||
|
||
/** | ||
* Process frontend input types for product attributes | ||
* | ||
* @return void | ||
*/ | ||
private function processFrontendInputTypes(): void | ||
{ | ||
$form = $this->getForm(); | ||
/** @var AbstractElement $frontendInputElm */ | ||
$frontendInputElm = $form->getElement('frontend_input'); | ||
$additionalTypes = [ | ||
['value' => 'price', 'label' => __('Price')], | ||
['value' => 'media_image', 'label' => __('Media Image')], | ||
]; | ||
$additionalReadOnlyTypes = ['gallery' => __('Gallery')]; | ||
if (isset($additionalReadOnlyTypes[$attributeObject->getFrontendInput()])) { | ||
$additionalTypes[] = [ | ||
'value' => $attributeObject->getFrontendInput(), | ||
'label' => $additionalReadOnlyTypes[$attributeObject->getFrontendInput()], | ||
]; | ||
} | ||
$additionalTypes = $this->getAdditionalFrontendInputTypes(); | ||
|
||
$response = new \Magento\Framework\DataObject(); | ||
$response = new DataObject(); | ||
$response->setTypes([]); | ||
$this->_eventManager->dispatch('adminhtml_product_attribute_types', ['response' => $response]); | ||
$_hiddenFields = []; | ||
|
@@ -74,19 +74,51 @@ protected function _prepareForm() | |
|
||
$frontendInputValues = array_merge($frontendInputElm->getValues(), $additionalTypes); | ||
$frontendInputElm->setValues($frontendInputValues); | ||
} | ||
|
||
$this->_eventManager->dispatch('product_attribute_form_build_main_tab', ['form' => $form]); | ||
/** | ||
* Get additional Frontend Input Types for product attributes | ||
* | ||
* @return array | ||
*/ | ||
private function getAdditionalFrontendInputTypes(): array | ||
{ | ||
$additionalTypes = [ | ||
['value' => 'price', 'label' => __('Price')], | ||
['value' => 'media_image', 'label' => __('Media Image')], | ||
]; | ||
|
||
return $this; | ||
$additionalReadOnlyTypes = ['gallery' => __('Gallery')]; | ||
$attributeObject = $this->getAttributeObject(); | ||
if (isset($additionalReadOnlyTypes[$attributeObject->getFrontendInput()])) { | ||
$additionalTypes[] = [ | ||
'value' => $attributeObject->getFrontendInput(), | ||
'label' => $additionalReadOnlyTypes[$attributeObject->getFrontendInput()], | ||
]; | ||
} | ||
|
||
return $additionalTypes; | ||
} | ||
|
||
/** | ||
* Retrieve additional element types for product attributes | ||
* Remove unused form fields | ||
* | ||
* @return array | ||
* @return void | ||
*/ | ||
protected function _getAdditionalElementTypes() | ||
private function removeUnusedFields(): void | ||
{ | ||
return ['apply' => \Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Apply::class]; | ||
$form = $this->getForm(); | ||
/* @var $fieldset Fieldset */ | ||
$fieldset = $form->getElement('base_fieldset'); | ||
$fieldsToRemove = ['attribute_code', 'is_unique', 'frontend_class']; | ||
foreach ($fieldset->getElements() as $element) { | ||
/** @var AbstractElement $element */ | ||
if (substr($element->getId(), 0, strlen('default_value')) === 'default_value') { | ||
$fieldsToRemove[] = $element->getId(); | ||
} | ||
} | ||
foreach ($fieldsToRemove as $id) { | ||
$fieldset->removeField($id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateDatetimeProductAttributeTest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> | ||
<test name="AdminCreateDatetimeProductAttributeTest"> | ||
<annotations> | ||
<features value="Catalog"/> | ||
<stories value="Datetime product attributes support"/> | ||
<title value="Datetime product attribute type is supported"/> | ||
<description value="Admin should be able to create datetime product attribute"/> | ||
<severity value="CRITICAL"/> | ||
<testCaseId value="MC-21451"/> | ||
<group value="catalog"/> | ||
</annotations> | ||
<before> | ||
<actionGroup ref="LoginAsAdmin" stepKey="login"/> | ||
</before> | ||
<after> | ||
<actionGroup ref="deleteProductAttribute" stepKey="deleteAttribute"> | ||
<argument name="ProductAttribute" value="DatetimeProductAttribute"/> | ||
</actionGroup> | ||
<actionGroup ref="AdminGridFilterResetActionGroup" stepKey="resetGridFilter"/> | ||
<actionGroup ref="logout" stepKey="logout"/> | ||
</after> | ||
<!-- Generate the datetime default value --> | ||
<generateDate date="now" format="m/j/y g:i A" stepKey="generateDefaultValue"/> | ||
<!-- Create new datetime product attribute --> | ||
<amOnPage url="{{AdminProductAttributeGridPage.url}}" stepKey="goToProductAttributes"/> | ||
<waitForPageLoad stepKey="waitForPageLoadAttributes"/> | ||
<actionGroup ref="CreateProductAttributeWithDatetimeField" stepKey="createAttribute"> | ||
<argument name="attribute" value="DatetimeProductAttribute"/> | ||
<argument name="date" value="{$generateDefaultValue}"/> | ||
</actionGroup> | ||
<!-- Navigate to created product attribute --> | ||
<actionGroup ref="navigateToCreatedProductAttribute" stepKey="navigateToAttribute"> | ||
<argument name="ProductAttribute" value="DatetimeProductAttribute"/> | ||
</actionGroup> | ||
<!-- Check the saved datetime default value --> | ||
<actionGroup ref="AdminNavigateToProductAttributeAdvancedSection" stepKey="goToAdvancedSection"/> | ||
<scrollTo selector="{{AdvancedAttributePropertiesSection.defaultValueDatetime}}" stepKey="scrollToDefaultValue"/> | ||
<seeInField userInput="{$generateDefaultValue}" | ||
selector="{{AdvancedAttributePropertiesSection.defaultValueDatetime}}" | ||
stepKey="checkDefaultValue"/> | ||
</test> | ||
</tests> |
Oops, something went wrong.