Skip to content

Commit b5322bc

Browse files
author
Oleksii Korshenko
authored
MAGETWO-70858: Product attribute notice translation #10274
2 parents 069509a + 2a1828d commit b5322bc

File tree

2 files changed

+148
-77
lines changed
  • app/code/Magento/Catalog
    • Test/Unit/Ui/DataProvider/Product/Form/Modifier
    • Ui/DataProvider/Product/Form/Modifier

2 files changed

+148
-77
lines changed

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/EavTest.php

Lines changed: 147 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Eav\Model\Config;
1111
use Magento\Framework\App\RequestInterface;
1212
use Magento\Framework\EntityManager\EventManager;
13+
use Magento\Framework\Phrase;
1314
use Magento\Store\Model\StoreManagerInterface;
1415
use Magento\Store\Api\Data\StoreInterface;
1516
use Magento\Ui\DataProvider\EavValidationRules;
@@ -452,12 +453,13 @@ public function testModifyData()
452453
* @param int $productId
453454
* @param bool $productRequired
454455
* @param string $attrValue
456+
* @param string $note
455457
* @param array $expected
456458
* @covers \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav::isProductExists
457459
* @covers \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav::setupAttributeMeta
458460
* @dataProvider setupAttributeMetaDataProvider
459461
*/
460-
public function testSetupAttributeMetaDefaultAttribute($productId, $productRequired, $attrValue, $expected)
462+
public function testSetupAttributeMetaDefaultAttribute($productId, $productRequired, $attrValue, $note, $expected)
461463
{
462464
$configPath = 'arguments/data/config';
463465
$groupCode = 'product-details';
@@ -483,6 +485,10 @@ public function testSetupAttributeMetaDefaultAttribute($productId, $productRequi
483485
->method('getValue')
484486
->willReturn('value');
485487

488+
$this->productAttributeMock->expects($this->any())
489+
->method('getNote')
490+
->willReturn($note);
491+
486492
$attributeMock = $this->getMockBuilder(AttributeInterface::class)
487493
->disableOriginalConstructor()
488494
->getMock();
@@ -527,82 +533,147 @@ public function testSetupAttributeMetaDefaultAttribute($productId, $productRequi
527533
public function setupAttributeMetaDataProvider()
528534
{
529535
return [
530-
'default_null_prod_not_new_and_required' => [
531-
'productId' => 1,
532-
'productRequired' => true,
533-
'attrValue' => 'val',
534-
'expected' => [
535-
'dataType' => null,
536-
'formElement' => null,
537-
'visible' => null,
538-
'required' => true,
539-
'notice' => null,
540-
'default' => null,
541-
'label' => null,
542-
'code' => 'code',
543-
'source' => 'product-details',
544-
'scopeLabel' => '',
545-
'globalScope' => false,
546-
'sortOrder' => 0
547-
],
548-
],
549-
'default_null_prod_not_new_and_not_required' => [
550-
'productId' => 1,
551-
'productRequired' => false,
552-
'attrValue' => 'val',
553-
'expected' => [
554-
'dataType' => null,
555-
'formElement' => null,
556-
'visible' => null,
557-
'required' => false,
558-
'notice' => null,
559-
'default' => null,
560-
'label' => null,
561-
'code' => 'code',
562-
'source' => 'product-details',
563-
'scopeLabel' => '',
564-
'globalScope' => false,
565-
'sortOrder' => 0
566-
],
567-
],
568-
'default_null_prod_new_and_not_required' => [
569-
'productId' => null,
570-
'productRequired' => false,
571-
'attrValue' => null,
572-
'expected' => [
573-
'dataType' => null,
574-
'formElement' => null,
575-
'visible' => null,
576-
'required' => false,
577-
'notice' => null,
578-
'default' => 'required_value',
579-
'label' => null,
580-
'code' => 'code',
581-
'source' => 'product-details',
582-
'scopeLabel' => '',
583-
'globalScope' => false,
584-
'sortOrder' => 0
585-
],
536+
'default_null_prod_not_new_and_required' => $this->defaultNullProdNotNewAndRequired(),
537+
'default_null_prod_not_new_and_not_required' => $this->defaultNullProdNotNewAndNotRequired(),
538+
'default_null_prod_new_and_not_required' => $this->defaultNullProdNewAndNotRequired(),
539+
'default_null_prod_new_and_required' => $this->defaultNullProdNewAndRequired(),
540+
'default_null_prod_new_and_required_and_filled_notice' =>
541+
$this->defaultNullProdNewAndRequiredAndFilledNotice()
542+
];
543+
}
544+
545+
/**
546+
* @return array
547+
*/
548+
private function defaultNullProdNotNewAndRequired()
549+
{
550+
return [
551+
'productId' => 1,
552+
'productRequired' => true,
553+
'attrValue' => 'val',
554+
'note' => null,
555+
'expected' => [
556+
'dataType' => null,
557+
'formElement' => null,
558+
'visible' => null,
559+
'required' => true,
560+
'notice' => null,
561+
'default' => null,
562+
'label' => null,
563+
'code' => 'code',
564+
'source' => 'product-details',
565+
'scopeLabel' => '',
566+
'globalScope' => false,
567+
'sortOrder' => 0
568+
],
569+
];
570+
}
571+
572+
/**
573+
* @return array
574+
*/
575+
private function defaultNullProdNotNewAndNotRequired()
576+
{
577+
return [
578+
'productId' => 1,
579+
'productRequired' => false,
580+
'attrValue' => 'val',
581+
'note' => null,
582+
'expected' => [
583+
'dataType' => null,
584+
'formElement' => null,
585+
'visible' => null,
586+
'required' => false,
587+
'notice' => null,
588+
'default' => null,
589+
'label' => null,
590+
'code' => 'code',
591+
'source' => 'product-details',
592+
'scopeLabel' => '',
593+
'globalScope' => false,
594+
'sortOrder' => 0
595+
],
596+
];
597+
}
598+
599+
/**
600+
* @return array
601+
*/
602+
private function defaultNullProdNewAndNotRequired()
603+
{
604+
return [
605+
'productId' => null,
606+
'productRequired' => false,
607+
'attrValue' => null,
608+
'note' => null,
609+
'expected' => [
610+
'dataType' => null,
611+
'formElement' => null,
612+
'visible' => null,
613+
'required' => false,
614+
'notice' => null,
615+
'default' => 'required_value',
616+
'label' => null,
617+
'code' => 'code',
618+
'source' => 'product-details',
619+
'scopeLabel' => '',
620+
'globalScope' => false,
621+
'sortOrder' => 0
622+
],
623+
];
624+
}
625+
626+
/**
627+
* @return array
628+
*/
629+
private function defaultNullProdNewAndRequired()
630+
{
631+
return [
632+
'productId' => null,
633+
'productRequired' => false,
634+
'attrValue' => null,
635+
'note' => null,
636+
'expected' => [
637+
'dataType' => null,
638+
'formElement' => null,
639+
'visible' => null,
640+
'required' => false,
641+
'notice' => null,
642+
'default' => 'required_value',
643+
'label' => null,
644+
'code' => 'code',
645+
'source' => 'product-details',
646+
'scopeLabel' => '',
647+
'globalScope' => false,
648+
'sortOrder' => 0
649+
],
650+
];
651+
}
652+
653+
/**
654+
* @return array
655+
*/
656+
private function defaultNullProdNewAndRequiredAndFilledNotice()
657+
{
658+
return [
659+
'productId' => null,
660+
'productRequired' => false,
661+
'attrValue' => null,
662+
'note' => 'example notice',
663+
'expected' => [
664+
'dataType' => null,
665+
'formElement' => null,
666+
'visible' => null,
667+
'required' => false,
668+
'notice' => __('example notice'),
669+
'default' => 'required_value',
670+
'label' => null,
671+
'code' => 'code',
672+
'source' => 'product-details',
673+
'scopeLabel' => '',
674+
'globalScope' => false,
675+
'sortOrder' => 0
586676
],
587-
'default_null_prod_new_and_required' => [
588-
'productId' => null,
589-
'productRequired' => false,
590-
'attrValue' => null,
591-
'expected' => [
592-
'dataType' => null,
593-
'formElement' => null,
594-
'visible' => null,
595-
'required' => false,
596-
'notice' => null,
597-
'default' => 'required_value',
598-
'label' => null,
599-
'code' => 'code',
600-
'source' => 'product-details',
601-
'scopeLabel' => '',
602-
'globalScope' => false,
603-
'sortOrder' => 0
604-
],
605-
]
606677
];
607678
}
608679
}

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ public function setupAttributeMeta(ProductAttributeInterface $attribute, $groupC
555555
'formElement' => $this->getFormElementsMapValue($attribute->getFrontendInput()),
556556
'visible' => $attribute->getIsVisible(),
557557
'required' => $attribute->getIsRequired(),
558-
'notice' => $attribute->getNote(),
558+
'notice' => $attribute->getNote() === null ? null : __($attribute->getNote()),
559559
'default' => (!$this->isProductExists()) ? $attribute->getDefaultValue() : null,
560560
'label' => $attribute->getDefaultFrontendLabel(),
561561
'code' => $attribute->getAttributeCode(),

0 commit comments

Comments
 (0)