Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
Project
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Gorodkov Denis
Project
Commits
8cddbf2d
Commit
8cddbf2d
authored
Jun 20, 2022
by
Gorodkov Denis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commerce
parent
1e886dda
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
92 additions
and
70 deletions
+92
-70
BatchForm.php
app/docroot/modules/custom/batch/src/Form/BatchForm.php
+18
-17
context_defenition.info.yml
...les/custom/context_defenition/context_defenition.info.yml
+7
-0
ContextDefinition.php
...context_defenition/src/Plugin/Block/ContextDefinition.php
+38
-0
ProductSuggest.js
...croot/modules/custom/custom_commerce/js/ProductSuggest.js
+6
-2
CustomNormalizer.php
...ustom/custom_commerce/src/Normalizer/CustomNormalizer.php
+8
-5
CustomPromotion.php
...ce/src/Plugin/Commerce/PromotionOffer/CustomPromotion.php
+15
-46
No files found.
app/docroot/modules/custom/batch/src/Form/BatchForm.php
View file @
8cddbf2d
...
@@ -7,27 +7,28 @@ use Drupal\Core\Form\FormStateInterface;
...
@@ -7,27 +7,28 @@ use Drupal\Core\Form\FormStateInterface;
use
Drupal\batch\Batch\ImportSwapi
;
use
Drupal\batch\Batch\ImportSwapi
;
class
BatchForm
extends
FormBase
{
class
BatchForm
extends
FormBase
{
public
function
getFormId
()
{
public
function
getFormId
()
{
return
'batch_form'
;
return
'batch_form'
;
}
}
public
function
buildForm
(
array
$form
,
FormStateInterface
$form_state
)
{
public
function
buildForm
(
array
$form
,
FormStateInterface
$form_state
)
{
$form
[
'date'
]
=
array
(
$form
[
'date'
]
=
array
(
'#type'
=>
'datetime'
,
'#type'
=>
'datetime'
,
'#title'
=>
'Date and time'
,
'#title'
=>
'Date and time'
,
);
);
$form
[
'actions'
][
'submit'
]
=
array
(
$form
[
'actions'
][
'submit'
]
=
array
(
'#type'
=>
'submit'
,
'#type'
=>
'submit'
,
'#value'
=>
'Import'
,
'#value'
=>
'Import'
,
'#button_type'
=>
'primary'
,
'#button_type'
=>
'primary'
,
);
);
return
$form
;
return
$form
;
}
}
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
$batch
=
new
ImportSwapi
();
$batch
=
new
ImportSwapi
();
$batch
->
getOperations
();
$batch
->
getOperations
();
$batch
->
setBatch
();
$batch
->
setBatch
();
}
}
}
}
app/docroot/modules/custom/context_defenition/context_defenition.info.yml
0 → 100644
View file @
8cddbf2d
name
:
Context definition
description
:
Custom task
package
:
Tasks
type
:
module
core
:
8.x
core_version_requirement
:
^8 || ^9
app/docroot/modules/custom/context_defenition/src/Plugin/Block/ContextDefinition.php
0 → 100644
View file @
8cddbf2d
<?php
namespace
Drupal\context_definiton\Plugin\Block
;
use
Drupal\Core\Block\BlockBase
;
/**
* Provides
*
* @Block(
* id = "test_context_definition",
* admin_label = @Translation("Test block with context_definition"),
* context_definitions = {
* "node" = @ContextDefinition("entity:node", required = FALSE, label = @Translation("Node")),
* "term" = @ContextDefinition("entity:taxonomy_term", required = FALSE, label = @Translation("Term")),
* }
* )
*/
class
ContextDefinition
extends
BlockBase
{
public
function
build
()
{
$node
=
$this
->
getContextValue
(
'node'
);
$term
=
$this
->
getContextValue
(
'term'
);
$build
=
[
'#markup'
=>
'Hello, From mymodule/Block'
];
if
(
!
empty
(
$node
)
or
!
empty
(
$term
))
{
empty
(
$node
)
?
$entiy
=
$term
:
$entiy
=
$node
;
empty
(
$node
)
?
$entiy_type_id
=
'taxonomy_term'
:
$entiy_type_id
=
'node'
;
$build
=
\Drupal
::
entityTypeManager
()
->
getViewBuilder
(
$entiy_type_id
)
->
view
(
$entiy
,
'teaser'
);
$tags
=
$entiy
->
getCacheTags
();
foreach
(
$tags
as
$tag
)
{
$build
[
'#cache'
][
'tags'
][]
=
$tag
;
}
}
return
$build
;
}
}
app/docroot/modules/custom/custom_commerce/js/ProductSuggest.js
View file @
8cddbf2d
...
@@ -22,9 +22,13 @@
...
@@ -22,9 +22,13 @@
console
.
log
(
data
);
console
.
log
(
data
);
var
content
=
'<div class="cart">'
;
var
content
=
'<div class="cart">'
;
data
[
'items'
].
forEach
(
function
(
item
)
{
data
[
'items'
].
forEach
(
function
(
item
)
{
img_attr
=
'width="60" height="60" src="'
+
src
+
item
[
'uri'
]
+
'"'
;
src_item
=
""
;
if
(
item
[
'uri'
])
{
src_item
=
src
+
item
[
'uri'
];
}
img_attr
=
'width="60" height="60" src="'
+
src_item
+
'"'
;
img
=
'<div class="item-img-container"><img '
+
img_attr
+
'></div>'
;
img
=
'<div class="item-img-container"><img '
+
img_attr
+
'></div>'
;
content
=
content
+
'<div class="card">'
content
=
content
+
'<div class="card">'
;
content
=
content
+
'<div class="item-img-container">'
+
img
+
'</div>'
;
content
=
content
+
'<div class="item-img-container">'
+
img
+
'</div>'
;
content
=
content
+
'<div class="item-name">Наименование товара: '
+
item
[
'name'
]
+
'</div>'
;
content
=
content
+
'<div class="item-name">Наименование товара: '
+
item
[
'name'
]
+
'</div>'
;
content
=
content
+
'<div class="item-count">Количество: '
+
Math
.
round
(
item
[
'quantity'
])
+
'</div>'
;
content
=
content
+
'<div class="item-count">Количество: '
+
Math
.
round
(
item
[
'quantity'
])
+
'</div>'
;
...
...
app/docroot/modules/custom/custom_commerce/src/Normalizer/CustomNormalizer.php
View file @
8cddbf2d
...
@@ -27,13 +27,15 @@ class CustomNormalizer extends NormalizerBase {
...
@@ -27,13 +27,15 @@ class CustomNormalizer extends NormalizerBase {
if
(
!
empty
(
$referens_arr
[
'product_id'
]))
{
if
(
!
empty
(
$referens_arr
[
'product_id'
]))
{
$product
=
$referens
->
getProduct
();
$product
=
$referens
->
getProduct
();
if
(
$product
->
hasField
(
'field_node'
))
{
if
(
$product
->
hasField
(
'field_node'
)
&&
!
empty
(
$product
->
get
(
'field_node'
)
->
getValue
())
)
{
$node
=
$product
->
get
(
'field_node'
)
->
referencedEntities
();
$node
=
$product
->
get
(
'field_node'
)
->
referencedEntities
();
$node
=
$node
[
0
];
$node
=
$node
[
0
];
$media
=
$node
->
get
(
'field_media'
)
->
referencedEntities
();
if
(
$node
->
hasField
(
'field_media'
)
&&
!
empty
(
$node
->
get
(
'field_media'
)
->
getValue
()))
{
$media
=
$media
[
0
];
$media
=
$node
->
get
(
'field_media'
)
->
referencedEntities
();
$uri
=
$media
->
get
(
'field_media_image'
)
->
entity
->
getFileUri
();
$media
=
$media
[
0
];
$uri
=
explode
(
'//'
,
$uri
);
$uri
=
$media
->
get
(
'field_media_image'
)
->
entity
->
getFileUri
();
$uri
=
explode
(
'//'
,
$uri
);
}
}
}
}
}
}
}
...
@@ -45,6 +47,7 @@ class CustomNormalizer extends NormalizerBase {
...
@@ -45,6 +47,7 @@ class CustomNormalizer extends NormalizerBase {
'item_total_price'
=>
$price
,
'item_total_price'
=>
$price
,
'uri'
=>
$uri
[
1
],
'uri'
=>
$uri
[
1
],
];
];
unset
(
$uri
);
}
}
$data
=
[
$data
=
[
...
...
app/docroot/modules/custom/custom_commerce/src/Plugin/Commerce/PromotionOffer/CustomPromotion.php
View file @
8cddbf2d
...
@@ -20,57 +20,24 @@ use Drupal\multivalue_form_element\Element\MultiValue;
...
@@ -20,57 +20,24 @@ use Drupal\multivalue_form_element\Element\MultiValue;
*/
*/
class
CustomPromotion
extends
OrderPromotionOfferBase
{
class
CustomPromotion
extends
OrderPromotionOfferBase
{
public
function
getIdsFromForm
(
$form_state
)
{
$info
=
$form_state
->
getUserInput
();
$items
=
$info
[
'offer'
][
0
][
"target_plugin_configuration"
][
"custom_commerce_custom_promotion"
][
"items"
][
0
][
0
];
#$values = $form_state->getValue($form['items']);
foreach
(
$items
as
$item
)
{
if
(
!
empty
(
$item
))
{
$item_id
=
explode
(
'('
,
$item
);
$item_id
=
end
(
$item_id
);
$item_id
=
explode
(
')'
,
$item_id
);
$id
=
$item_id
[
0
];
$ids
[]
=
$id
;
}
}
return
$ids
;
}
public
function
buildConfigurationForm
(
array
$form
,
FormStateInterface
$form_state
)
{
public
function
buildConfigurationForm
(
array
$form
,
FormStateInterface
$form_state
)
{
$form
=
parent
::
buildConfigurationForm
(
$form
,
$form_state
);
$form
=
parent
::
buildConfigurationForm
(
$form
,
$form_state
);
$ids
=
$this
->
getIdsFromForm
(
$form_state
);
/*if (!empty($ids)) {
foreach ($ids as $id_product_item) {
$default_value = \Drupal::entityTypeManager()->getStorage('commerce_product')->load($id_product_item);
$items[] = [
'#type' => 'entity_autocomplete',
'#target_type' => 'commerce_product',
'#title' => 'Выберите товар',
'#default_value' => !empty($default_value) ? $default_value : '',
];
}
} else {
$items[] = [
'#type' => 'entity_autocomplete',
'#target_type' => 'commerce_product',
'#title' => 'Выберите товар',
];
}*/
$items
[]
=
[
$default_first_item
=
\Drupal
::
entityTypeManager
()
->
getStorage
(
'commerce_product'
)
->
load
(
$this
->
configuration
[
'first_item'
]);
$default_second_item
=
\Drupal
::
entityTypeManager
()
->
getStorage
(
'commerce_product'
)
->
load
(
$this
->
configuration
[
'second_item'
]);
$form
[
'first_item'
]
=
[
'#type'
=>
'entity_autocomplete'
,
'#type'
=>
'entity_autocomplete'
,
'#target_type'
=>
'commerce_product'
,
'#target_type'
=>
'commerce_product'
,
'#title'
=>
'Выберите товар'
,
'#title'
=>
'Выберите первый продукт'
,
'#default_value'
=>
!
empty
(
$default_first_item
)
?
$default_first_item
:
''
,
];
];
$form
[
'items'
]
=
[
$form
[
'second_item'
]
=
[
'#type'
=>
'multivalue'
,
'#type'
=>
'entity_autocomplete'
,
'#title'
=>
$this
->
t
(
'Items'
),
'#target_type'
=>
'commerce_product'
,
'#cardinality'
=>
MultiValue
::
CARDINALITY_UNLIMITED
,
'#title'
=>
'Выберите второй продукт'
,
'item'
=>
[
'#default_value'
=>
!
empty
(
$default_second_item
)
?
$default_second_item
:
''
,
'#type'
=>
'entity_autocomplete'
,
'#target_type'
=>
'commerce_product'
,
'#title'
=>
'Выберите товар'
,
],
];
];
return
$form
;
return
$form
;
...
@@ -78,13 +45,15 @@ class CustomPromotion extends OrderPromotionOfferBase {
...
@@ -78,13 +45,15 @@ class CustomPromotion extends OrderPromotionOfferBase {
public
function
submitConfigurationForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
public
function
submitConfigurationForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
if
(
!
$form_state
->
getErrors
())
{
if
(
!
$form_state
->
getErrors
())
{
$this
->
configuration
[
'items'
]
=
$this
->
getIdsFromForm
(
$form_state
);
$values
=
$form_state
->
getValue
(
$form
[
'#parents'
]);
$this
->
configuration
[
'first_item'
]
=
$values
[
'first_item'
];
$this
->
configuration
[
'second_item'
]
=
$values
[
'second_item'
];
}
}
}
}
public
function
apply
(
EntityInterface
$entity
,
PromotionInterface
$promotion
)
{
public
function
apply
(
EntityInterface
$entity
,
PromotionInterface
$promotion
)
{
$this
->
assertEntity
(
$entity
);
$this
->
assertEntity
(
$entity
);
/** @var \Drupal\commerce_order\Entity\Order
ItemInterface $order_item
*/
/** @var \Drupal\commerce_order\Entity\Order
$order
*/
$order
=
$entity
;
$order
=
$entity
;
$first_item
=
$this
->
configuration
[
'first_item'
];
$first_item
=
$this
->
configuration
[
'first_item'
];
$second_item
=
$this
->
configuration
[
'second_item'
];
$second_item
=
$this
->
configuration
[
'second_item'
];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment