Skip to content

Commit 7ba4a09

Browse files
committed
Added default value in custom option of product
1 parent 300a17c commit 7ba4a09

File tree

5 files changed

+150
-9
lines changed

5 files changed

+150
-9
lines changed

Diff for: .gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
.php_cs.cache
3+
php-cs-fixer

Diff for: .php_cs.dist

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
$finder = \PhpCsFixer\Finder::create()
4+
->in(__DIR__);
5+
6+
return \PhpCsFixer\Config::create()
7+
->setRules([
8+
'@PSR2' => true,
9+
'@PhpCsFixer' => true,
10+
'@PHP71Migration' => true,
11+
'concat_space' => ['spacing' => 'one'],
12+
'phpdoc_summary' => false,
13+
'phpdoc_align' => false,
14+
'no_short_echo_tag' => true,
15+
'no_useless_else' => true,
16+
'is_null' => true,
17+
'no_multiline_whitespace_before_semicolons' => true,
18+
'no_null_property_initialization' => true,
19+
'list_syntax' => ['syntax' => 'short'],
20+
'array_syntax' => ['syntax' => 'short'],
21+
'php_unit_strict' => true,
22+
'strict_comparison' => true,
23+
'strict_param' => true,
24+
'declare_strict_types' => true,
25+
'yoda_style' => false,
26+
'ordered_class_elements' => true,
27+
'date_time_immutable' => true,
28+
'no_unused_imports' => true,
29+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
30+
'no_trailing_comma_in_singleline_array' => true,
31+
'trailing_comma_in_multiline_array' => true,
32+
'whitespace_after_comma_in_array' => true,
33+
'native_function_invocation' => [
34+
'include' => ['@compiler_optimized']
35+
],
36+
'method_argument_space' => [
37+
'on_multiline' => 'ensure_fully_multiline'
38+
],
39+
'fully_qualified_strict_types' => true,
40+
'no_unreachable_default_argument_value' => true,
41+
'new_with_braces' => true,
42+
'no_empty_statement' => true,
43+
'no_extra_consecutive_blank_lines' => true,
44+
'no_leading_import_slash' => true,
45+
'no_leading_namespace_whitespace' => true,
46+
'no_multiline_whitespace_around_double_arrow' => true,
47+
'no_singleline_whitespace_before_semicolons' => true,
48+
'no_whitespace_in_blank_line' => true,
49+
'object_operator_without_whitespace' => true,
50+
'standardize_not_equals' => true,
51+
'ternary_operator_spaces' => true,
52+
])
53+
->setFinder($finder)
54+
;

Diff for: LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 dmitrykazak
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Diff for: Plugin/Catalog/UI/Form/Modifier/IsDefaultCustomOption.php

+30-9
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,43 @@
55
namespace DK\CustomOptionDefaultValue\Plugin\Catalog\UI\Form\Modifier;
66

77
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\CustomOptions;
8-
use Magento\Ui\Component\Form\Element\DataType\Text;
98
use Magento\Ui\Component\Form\Element\Checkbox;
9+
use Magento\Ui\Component\Form\Element\DataType\Text;
1010
use Magento\Ui\Component\Form\Field;
1111

1212
class IsDefaultCustomOption
1313
{
14-
private const FIELD_IS_DEFAULT = 'is_default';
14+
protected const FIELD_IS_DEFAULT = 'is_default';
15+
private const DEFAULT_SORT_ORDER = 70;
1516

1617
public function afterModifyMeta(CustomOptions $subject, array $meta): array
1718
{
18-
echo "<pre>";
19-
print_r($meta);
20-
die();
21-
22-
$result = array_replace_recursive($meta, [
23-
CustomOptions::GROUP_CUSTOM_OPTIONS_NAME
19+
return array_replace_recursive($meta, [
20+
CustomOptions::GROUP_CUSTOM_OPTIONS_NAME => [
21+
'children' => [
22+
CustomOptions::GRID_OPTIONS_NAME => [
23+
'children' => [
24+
'record' => [
25+
'children' => [
26+
CustomOptions::CONTAINER_OPTION => [
27+
'children' => [
28+
CustomOptions::GRID_TYPE_SELECT_NAME => [
29+
'children' => [
30+
'record' => [
31+
'children' => [
32+
static::FIELD_IS_DEFAULT => $this->getIsDefaultFieldConfig(self::DEFAULT_SORT_ORDER),
33+
],
34+
],
35+
],
36+
],
37+
],
38+
],
39+
],
40+
],
41+
],
42+
],
43+
],
44+
],
2445
]);
2546
}
2647

@@ -39,7 +60,7 @@ protected function getIsDefaultFieldConfig($sortOrder): array
3960
'value' => '0',
4061
'valueMap' => [
4162
'true' => '1',
42-
'false' => '0'
63+
'false' => '0',
4364
],
4465
],
4566
],

Diff for: composer.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"name": "dmitrykazak/magento2-custom-option-default-value",
3+
"description": "This extension will allow you to set the default of product custom options for Magento 2",
4+
"authors": [{
5+
"name": "Dmitry Kazak",
6+
"email": "[email protected]"
7+
}],
8+
"homepage": "https://github.com/dmitrykazak/magento2-custom-option-default-value",
9+
"keywords": [
10+
"magento 2",
11+
"magento2-extension",
12+
"custom options",
13+
"default value",
14+
"magento"
15+
],
16+
"require": {
17+
"php": "~7.2.0|~7.3.0"
18+
},
19+
"type": "magento2-module",
20+
"version": "1.0.0",
21+
"license": "MIT",
22+
"autoload": {
23+
"files": [
24+
"registration.php"
25+
],
26+
"psr-4": {
27+
"DK\\CustomOptionDefaultValue\\": ""
28+
}
29+
},
30+
"scripts": {
31+
"cs:check": [
32+
"wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar -O php-cs-fixer",
33+
"chmod a+x php-cs-fixer",
34+
"./php-cs-fixer fix --config=.php_cs.dist -v --allow-risky=yes --dry-run --diff --stop-on-violation"
35+
],
36+
"cs:fix": [
37+
"wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar -O php-cs-fixer",
38+
"chmod a+x php-cs-fixer",
39+
"./php-cs-fixer fix --config=.php_cs.dist -v --allow-risky=yes --diff"
40+
]
41+
}
42+
}

0 commit comments

Comments
 (0)